Parse auto functions with trailing return

This commit is contained in:
Dustin Spicuzza 2023-10-04 03:28:28 -04:00
parent 1f5ba1b3ca
commit e30c117b62
2 changed files with 54 additions and 1 deletions

View File

@ -1773,7 +1773,7 @@ class CxxParser:
setattr(method, tok_value, True) setattr(method, tok_value, True)
elif tok_value in ("&", "&&"): elif tok_value in ("&", "&&"):
method.ref_qualifier = tok_value method.ref_qualifier = tok_value
elif tok_value == "ARROW": elif tok_value == "->":
self._parse_trailing_return_type(method) self._parse_trailing_return_type(method)
break break
elif tok_value == "throw": elif tok_value == "throw":

View File

@ -4,6 +4,8 @@ from cxxheaderparser.types import (
Array, Array,
AutoSpecifier, AutoSpecifier,
ClassDecl, ClassDecl,
DecltypeSpecifier,
Field,
Function, Function,
FunctionType, FunctionType,
FundamentalSpecifier, FundamentalSpecifier,
@ -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",
)
],
)
]
)
)