mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 534420 - Add support for [[maybe_unused]] attribute
Change-Id: I7214b4f9b11a190c81bad50dace87c69fe404886 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
parent
c0402d5d06
commit
24ce60ba3f
2 changed files with 11 additions and 2 deletions
|
@ -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<IBinding, IASTDeclarator> externFunctionDeclarations = new HashMap<>();
|
||||
private Map<IBinding, IASTDeclarator> 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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue