Skip to content

Commit e30c117

Browse files
committed
Parse auto functions with trailing return
1 parent 1f5ba1b commit e30c117

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

cxxheaderparser/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ def _parse_method_end(self, method: Method) -> None:
17731773
setattr(method, tok_value, True)
17741774
elif tok_value in ("&", "&&"):
17751775
method.ref_qualifier = tok_value
1776-
elif tok_value == "ARROW":
1776+
elif tok_value == "->":
17771777
self._parse_trailing_return_type(method)
17781778
break
17791779
elif tok_value == "throw":

tests/test_fn.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Array,
55
AutoSpecifier,
66
ClassDecl,
7+
DecltypeSpecifier,
8+
Field,
79
Function,
810
FunctionType,
911
FundamentalSpecifier,
@@ -1141,3 +1143,54 @@ def test_noexcept_contents() -> None:
11411143
]
11421144
)
11431145
)
1146+
1147+
1148+
def test_auto_decltype_return() -> None:
1149+
content = """
1150+
class C {
1151+
public:
1152+
int x;
1153+
auto GetSelected() -> decltype(x);
1154+
};
1155+
"""
1156+
data = parse_string(content, cleandoc=True)
1157+
1158+
assert data == ParsedData(
1159+
namespace=NamespaceScope(
1160+
classes=[
1161+
ClassScope(
1162+
class_decl=ClassDecl(
1163+
typename=PQName(
1164+
segments=[NameSpecifier(name="C")], classkey="class"
1165+
)
1166+
),
1167+
fields=[
1168+
Field(
1169+
access="public",
1170+
type=Type(
1171+
typename=PQName(
1172+
segments=[FundamentalSpecifier(name="int")]
1173+
)
1174+
),
1175+
name="x",
1176+
)
1177+
],
1178+
methods=[
1179+
Method(
1180+
return_type=Type(
1181+
typename=PQName(
1182+
segments=[
1183+
DecltypeSpecifier(tokens=[Token(value="x")])
1184+
]
1185+
)
1186+
),
1187+
name=PQName(segments=[NameSpecifier(name="GetSelected")]),
1188+
parameters=[],
1189+
has_trailing_return=True,
1190+
access="public",
1191+
)
1192+
],
1193+
)
1194+
]
1195+
)
1196+
)

0 commit comments

Comments
 (0)