diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-23 18:27:11 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-23 18:27:11 +0000 |
commit | eaedd47dbde3c4312be1b89b02368be78780ca34 (patch) | |
tree | 28293ce7089335a5d0d8a1540836e7d3df9cb833 /lib/Sema | |
parent | 1de6f9cae36189a1481570c05329c338291110a0 (diff) | |
download | clang-eaedd47dbde3c4312be1b89b02368be78780ca34.tar.gz |
Don't warn about runtime behavior problems in variable initializers that we
know are going to be constant-evaluated.
Any relevant diagnostics should be produced by constant expression evaluation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314067 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7784126377..75b09cf218 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -15179,10 +15179,24 @@ bool Sema::DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, if (Statement && getCurFunctionOrMethodDecl()) { FunctionScopes.back()->PossiblyUnreachableDiags. push_back(sema::PossiblyUnreachableDiag(PD, Loc, Statement)); + return true; } - else - Diag(Loc, PD); - + + // The initializer of a constexpr variable or of the first declaration of a + // static data member is not syntactically a constant evaluated constant, + // but nonetheless is always required to be a constant expression, so we + // can skip diagnosing. + // FIXME: Using the mangling context here is a hack. + if (auto *VD = dyn_cast_or_null<VarDecl>( + ExprEvalContexts.back().ManglingContextDecl)) { + if (VD->isConstexpr() || + (VD->isStaticDataMember() && VD->isFirstDecl() && !VD->isInline())) + break; + // FIXME: For any other kind of variable, we should build a CFG for its + // initializer and check whether the context in question is reachable. + } + + Diag(Loc, PD); return true; } |