Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow forward declared template methods #70

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cxxheaderparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,8 @@ def _parse_function(
self.visitor.on_class_method(state, method)
else:
assert isinstance(state, (ExternBlockState, NamespaceBlockState))
if not method.has_body:
# only template specializations can be declared without a body here
if not method.has_body and not method.template:
raise self._parse_error(None, expected="Method body")
self.visitor.on_method_impl(state, method)

Expand Down
40 changes: 40 additions & 0 deletions tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1987,3 +1987,43 @@ def test_extern_template() -> None:
},
)
)


def test_fwd_declared_method() -> None:
content = """
// forward declaration for specialized template function
template <> Clazz<A>::Clazz();
"""
data = parse_string(content, cleandoc=True)

assert data == ParsedData(
namespace=NamespaceScope(
method_impls=[
Method(
return_type=None,
name=PQName(
segments=[
NameSpecifier(
name="Clazz",
specialization=TemplateSpecialization(
args=[
TemplateArgument(
arg=Type(
typename=PQName(
segments=[NameSpecifier(name="A")]
)
)
)
]
),
),
NameSpecifier(name="Clazz"),
]
),
parameters=[],
template=TemplateDecl(),
constructor=True,
)
]
)
)