1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 04:45:38 +02:00

Parse empty __attribute__(()) (#770)

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.
This commit is contained in:
Marc-Andre Laperle 2024-05-17 12:49:41 -04:00 committed by GitHub
parent 35766ce9e2
commit 3062cdc8d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 2 deletions

View file

@ -525,6 +525,12 @@ public class AST2CPPAttributeTests extends AST2TestBase {
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));
// };

View file

@ -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

View file

@ -2529,7 +2529,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
consume();
consume(IToken.tLPAREN);
addAttributesOrDeclspecs(result);
// Allow empty __attribute__(())
if (LT(1) != IToken.tRPAREN) {
addAttributesOrDeclspecs(result);
}
consumeOrEOC(IToken.tRPAREN);
endOffset = consumeOrEOC(IToken.tRPAREN).getEndOffset();