In -Wunneeded-internal-declaration, suppress the warning for variables which
might have been used in constant expressions, rather than suppressing it for
variables which are const. The important thing here is that such variables
can have their values used without actually being marked as 'used'.
llvm-svn: 166896
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e8d017c..3576190 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1205,10 +1205,17 @@
return false;
} else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
if (!VD->isFileVarDecl() ||
- VD->getType().isConstant(Context) ||
Context.DeclMustBeEmitted(VD))
return false;
+ // If a variable is usable in constant expressions and it's not odr-used,
+ // its value may still have been used. Conservatively suppress the warning
+ // in this case.
+ const VarDecl *VDWithInit = 0;
+ if (VD->isUsableInConstantExpressions(Context) &&
+ VD->getAnyInitializer(VDWithInit) && VDWithInit->checkInitIsICE())
+ return false;
+
if (VD->isStaticDataMember() &&
VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
return false;