Skip to content

Commit

Permalink
Merge pull request #72 from robotpy/auto-decltype-fn
Browse files Browse the repository at this point in the history
Parse auto functions with trailing return
  • Loading branch information
virtuald authored Oct 4, 2023
2 parents 1f5ba1b + e30c117 commit 6ac0bdb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cxxheaderparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,7 @@ def _parse_method_end(self, method: Method) -> None:
setattr(method, tok_value, True)
elif tok_value in ("&", "&&"):
method.ref_qualifier = tok_value
elif tok_value == "ARROW":
elif tok_value == "->":
self._parse_trailing_return_type(method)
break
elif tok_value == "throw":
Expand Down
53 changes: 53 additions & 0 deletions tests/test_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Array,
AutoSpecifier,
ClassDecl,
DecltypeSpecifier,
Field,
Function,
FunctionType,
FundamentalSpecifier,
Expand Down Expand Up @@ -1141,3 +1143,54 @@ def test_noexcept_contents() -> None:
]
)
)


def test_auto_decltype_return() -> None:
content = """
class C {
public:
int x;
auto GetSelected() -> decltype(x);
};
"""
data = parse_string(content, cleandoc=True)

assert data == ParsedData(
namespace=NamespaceScope(
classes=[
ClassScope(
class_decl=ClassDecl(
typename=PQName(
segments=[NameSpecifier(name="C")], classkey="class"
)
),
fields=[
Field(
access="public",
type=Type(
typename=PQName(
segments=[FundamentalSpecifier(name="int")]
)
),
name="x",
)
],
methods=[
Method(
return_type=Type(
typename=PQName(
segments=[
DecltypeSpecifier(tokens=[Token(value="x")])
]
)
),
name=PQName(segments=[NameSpecifier(name="GetSelected")]),
parameters=[],
has_trailing_return=True,
access="public",
)
],
)
]
)
)

0 comments on commit 6ac0bdb

Please sign in to comment.