Skip to content

Commit

Permalink
Parse empty __attribute__(()) (#770)
Browse files Browse the repository at this point in the history
This is accepted by both GCC and Clang and encountered in real code. It looks a
bit strange but basically a condtionally defined macro was used inside the (())
depending on a configurable feature macro of the project.
  • Loading branch information
MarkZ3 committed May 17, 2024
1 parent 35766ce commit 3062cdc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ public void testGCCAttributedVariableDeclarator_bug391572() throws Exception {
checkAttributeRelations(getAttributeSpecifiers(tu), IASTDeclarator.class);
}

// int a __attribute__ (());
public void testEmptyGCCAttribute() throws Exception {
IASTTranslationUnit tu = parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP, ScannerKind.GNU);
checkAttributeRelations(getAttributeSpecifiers(tu), IASTDeclarator.class);
}

// struct S {
// void foo() override __attribute__((attr));
// };
Expand Down
2 changes: 1 addition & 1 deletion core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
Bundle-Version: 8.4.0.qualifier
Bundle-Version: 8.4.100.qualifier
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2529,7 +2529,10 @@ protected IASTAttributeList __attribute__() throws BacktrackException, EndOfFile
consume();
consume(IToken.tLPAREN);

addAttributesOrDeclspecs(result);
// Allow empty __attribute__(())
if (LT(1) != IToken.tRPAREN) {
addAttributesOrDeclspecs(result);
}

consumeOrEOC(IToken.tRPAREN);
endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset();
Expand Down

0 comments on commit 3062cdc

Please sign in to comment.