From 3062cdc8d8679e5357bcddda36594b3c94b29a25 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Fri, 17 May 2024 12:49:41 -0400 Subject: [PATCH] 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. --- .../cdt/core/parser/tests/ast2/AST2CPPAttributeTests.java | 6 ++++++ core/org.eclipse.cdt.core/META-INF/MANIFEST.MF | 2 +- .../core/dom/parser/AbstractGNUSourceCodeParser.java | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPAttributeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPAttributeTests.java index 534045966c5..27389611741 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPAttributeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPAttributeTests.java @@ -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)); // }; diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index dccc324851a..f9e52e4949f 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -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 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 283bbea1ffa..5d056af9660 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -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();