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
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 11e753c..3581d97 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -4381,6 +4381,14 @@
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 @@
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);