diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-10-28 04:47:21 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-10-28 04:47:21 +0000 |
commit | 623ef4bf31bc5ec14ed9b5645921a0a2e0d00ee4 (patch) | |
tree | 3b244223410f71719b0a3f784ac8844aba4589c7 /lib/Sema/SemaDecl.cpp | |
parent | 644e90a17f1bc3dcc2b7b018eb02abb3a1c2022b (diff) |
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'.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166896 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e8d017c098..3576190310 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1205,10 +1205,17 @@ bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const { 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; |