diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-09 19:45:49 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-09 19:45:49 +0000 |
commit | d9c6b039dbcf4a38edf62a5491c2b024724e1b5d (patch) | |
tree | 37040089b1bb7ded0d901872264434d5a9bb87c8 /clang/lib/AST/ExprConstant.cpp | |
parent | ba24f352f4fa47d6caabac3764b8d896d40fb934 (diff) | |
download | bcm5719-llvm-d9c6b039dbcf4a38edf62a5491c2b024724e1b5d.tar.gz bcm5719-llvm-d9c6b039dbcf4a38edf62a5491c2b024724e1b5d.zip |
DR1872: don't allow any calls to virtual functions in constant
evaluation.
Not even in cases where we would not actually perform virtual dispatch.
llvm-svn: 360370
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 11e753c0771..3581d97c8b1 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -4381,6 +4381,14 @@ static bool CheckConstexprFunction(EvalInfo &Info, SourceLocation CallLoc, return false; } + // DR1872: An instantiated virtual constexpr function can't be called in a + // constant expression. + if (isa<CXXMethodDecl>(Declaration) && + cast<CXXMethodDecl>(Declaration)->isVirtual()) { + Info.FFDiag(CallLoc, diag::note_constexpr_virtual_call); + return false; + } + // Can we evaluate this function call? if (Definition && Definition->isConstexpr() && !Definition->isInvalidDecl() && Body) @@ -4999,12 +5007,6 @@ public: if (This && !This->checkSubobject(Info, E, CSK_This)) return false; - // DR1358 allows virtual constexpr functions in some cases. Don't allow - // calls to such functions in constant expressions. - if (This && !HasQualifier && - isa<CXXMethodDecl>(FD) && cast<CXXMethodDecl>(FD)->isVirtual()) - return Error(E, diag::note_constexpr_virtual_call); - const FunctionDecl *Definition = nullptr; Stmt *Body = FD->getBody(Definition); |