summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2018-05-04 01:30:49 -0400
committerNathan Ridge2018-05-10 22:47:43 -0400
commit45bbb2bb5b5e4e9c93d4103a9c5e5c24db71d752 (patch)
tree224da2107f10ca3ffbeee40cf49879378e6c9b3e
parentd8d04e27317a25d52d0a27f51794f674b8962f60 (diff)
downloadorg.eclipse.cdt-45bbb2bb5b5e4e9c93d4103a9c5e5c24db71d752.zip
org.eclipse.cdt-45bbb2bb5b5e4e9c93d4103a9c5e5c24db71d752.tar.gz
org.eclipse.cdt-45bbb2bb5b5e4e9c93d4103a9c5e5c24db71d752.tar.xz
Bug 534332 - In the unused symbol checker, check for 'unused' attribute on the decl-specifier too
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java4
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java4
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 4246619..700dda5 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 87eb9e0..0bcdc83 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;