diff options
author | Nathan Ridge | 2018-05-04 05:30:49 +0000 |
---|---|---|
committer | Nathan Ridge | 2018-05-11 02:47:43 +0000 |
commit | 45bbb2bb5b5e4e9c93d4103a9c5e5c24db71d752 (patch) | |
tree | 224da2107f10ca3ffbeee40cf49879378e6c9b3e | |
parent | d8d04e27317a25d52d0a27f51794f674b8962f60 (diff) | |
download | org.eclipse.cdt-45bbb2bb5b5e4e9c93d4103a9c5e5c24db71d752.tar.gz org.eclipse.cdt-45bbb2bb5b5e4e9c93d4103a9c5e5c24db71d752.tar.xz org.eclipse.cdt-45bbb2bb5b5e4e9c93d4103a9c5e5c24db71d752.zip |
Bug 534332 - In the unused symbol checker, check for 'unused' attribute on the decl-specifier too
Change-Id: Ib4f26e5a04742af93c884819a5b2f1f714faeb97
2 files changed, 8 insertions, 0 deletions
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; |