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 1a32fb61fd7..69b8f5f3e2e 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 @@ -57,6 +57,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; +import org.eclipse.cdt.core.parser.StandardAttributes; import org.eclipse.cdt.core.parser.util.AttributeUtil; /** @@ -72,7 +73,7 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker { * Various attributes that when present for a symbol should make it considered as used. */ private static final String[] USAGE_ATTRIBUTES = new String[] { "__unused__", "unused", "constructor", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ - "destructor" }; //$NON-NLS-1$ + "destructor", StandardAttributes.MAYBE_UNUSED }; //$NON-NLS-1$ private Map externFunctionDeclarations = new HashMap<>(); private Map staticFunctionDeclarations = new HashMap<>(); @@ -145,7 +146,7 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker { IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) element; IASTDeclSpecifier declSpec = simpleDeclaration.getDeclSpecifier(); - boolean hasUsageAttrib = hasUsageAttribute(declSpec); + boolean hasUsageAttrib = hasUsageAttribute(declSpec) || hasUsageAttribute(simpleDeclaration); IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); for (IASTDeclarator decl : declarators) { IASTName astName = decl.getName(); 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 9da91a4b5ae..184d80048ef 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 @@ -384,4 +384,12 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase { loadCodeAndRunCpp(getAboveComment()); checkNoErrors(); } + + // [[maybe_unused]] static int v1; + // [[maybe_unused]] int f1(); + // [[maybe_unused]] extern int f2(); + public void testAttributeCpp17Unused() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkNoErrors(); + } }