diff options
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; |