Skip to content

Commit 375125b

Browse files
committed
Parser: support trailing declarators after class/struct body (} *ptr; } instance;)
1 parent ed8b9bd commit 375125b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/java/Parser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,10 @@ else if (checkOp(">>")) {
864864

865865
TypeDef typeDef = new TypeDef(kind, name, templateParams, baseClasses, members, start.line(), start.col(), leadingComments);
866866
// Trailing declarators: "class Foo { ... } *ptr;" or "} a, b, *c;"
867-
if (!matchPunct(";") && !isAtEnd() && !checkPunct("}")) {
867+
// Only enter if next token is an identifier or pointer star, not a keyword.
868+
boolean nextIsDeclarator = checkOp("*") || checkPunct("*")
869+
|| peek().type() == CppLexerTokenType.IDENTIFIER;
870+
if (!matchPunct(";") && !isAtEnd() && !checkPunct("}") && nextIsDeclarator) {
868871
List<TopLevelItem> result = new ArrayList<>();
869872
result.add(typeDef);
870873
do {

0 commit comments

Comments
 (0)