diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java index 42466196c47..700dda57e5c 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java @@ -133,6 +133,10 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker { // declarations IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) element; + IASTDeclSpecifier declSpec = simpleDeclaration.getDeclSpecifier(); + if (AttributeUtil.hasAttribute(declSpec, ATTRIBUTE_UNUSED)) { + return PROCESS_SKIP; + } IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); for (IASTDeclarator decl : declarators) { if (AttributeUtil.hasAttribute(decl, ATTRIBUTE_UNUSED)) diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java index 87eb9e0998e..0bcdc83fd72 100644 --- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java @@ -306,6 +306,7 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase { } // static int v1 __attribute__((unused)); + // static int __attribute__((unused)) v2; // int f1() __attribute__((__unused__)); // extern int f2() __attribute__((unused)); // static void f3() __attribute__((unused)); @@ -314,6 +315,9 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase { public void testAttributeUnused() throws Exception { loadCodeAndRun(getAboveComment()); checkNoErrors(); + + loadCodeAndRunCpp(getAboveComment()); + checkNoErrors(); } // extern int* pxCurrentTCB;