Skip to content

Commit c58a003

Browse files
committed
Parser: support anonymous struct/class at top level with trailing declarators
1 parent 375125b commit c58a003

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/java/Parser.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,13 @@ private List<TopLevelItem> parseTypeDef(List<CppLexerToken> leadingComments, Lis
797797
if (checkPunct("(")) { advance(); int _ad=1; while(!isAtEnd()&&_ad>0){if(checkPunct("("))_ad++;else if(checkPunct(")"))_ad--;advance();} }
798798
}
799799

800-
String name = expectIdentifier().text();
800+
// Anonymous struct/class: "struct { ... } var;" -- generate synthetic name
801+
String name;
802+
if (checkPunct("{")) {
803+
name = "_Anon_" + start.line() + "_" + start.col();
804+
} else {
805+
name = expectIdentifier().text();
806+
}
801807

802808
// Partial or explicit specialization: "template<typename T> struct Foo<T*>"
803809
// or "template<> struct TypeName<int>" -- capture the specialization arg

0 commit comments

Comments
 (0)