1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 23:15:24 +02:00

Bug 534332 - In the unused symbol checker, check for 'unused' attribute on the decl-specifier too

Change-Id: Ib4f26e5a04742af93c884819a5b2f1f714faeb97
This commit is contained in:
Nathan Ridge 2018-05-04 01:30:49 -04:00
parent d8d04e2731
commit 45bbb2bb5b
2 changed files with 8 additions and 0 deletions

View file

@ -133,6 +133,10 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker {
// declarations // declarations
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) element; IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) element;
IASTDeclSpecifier declSpec = simpleDeclaration.getDeclSpecifier();
if (AttributeUtil.hasAttribute(declSpec, ATTRIBUTE_UNUSED)) {
return PROCESS_SKIP;
}
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
for (IASTDeclarator decl : declarators) { for (IASTDeclarator decl : declarators) {
if (AttributeUtil.hasAttribute(decl, ATTRIBUTE_UNUSED)) if (AttributeUtil.hasAttribute(decl, ATTRIBUTE_UNUSED))

View file

@ -306,6 +306,7 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase {
} }
// static int v1 __attribute__((unused)); // static int v1 __attribute__((unused));
// static int __attribute__((unused)) v2;
// int f1() __attribute__((__unused__)); // int f1() __attribute__((__unused__));
// extern int f2() __attribute__((unused)); // extern int f2() __attribute__((unused));
// static void f3() __attribute__((unused)); // static void f3() __attribute__((unused));
@ -314,6 +315,9 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase {
public void testAttributeUnused() throws Exception { public void testAttributeUnused() throws Exception {
loadCodeAndRun(getAboveComment()); loadCodeAndRun(getAboveComment());
checkNoErrors(); checkNoErrors();
loadCodeAndRunCpp(getAboveComment());
checkNoErrors();
} }
// extern int* pxCurrentTCB; // extern int* pxCurrentTCB;