aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard@metafoo.co.uk>2020-02-18 14:53:54 -0800
committerRichard Smith <richard@metafoo.co.uk>2020-02-18 14:57:13 -0800
commite28d9bae4b3be60e90daa69a2eeb3254c952e051 (patch)
treeca9e2dda2bef91e7c1e1d74d0a972216ee472003 /clang/lib/AST/ExprConstant.cpp
parent52861809994c9199ceb45b98d982ab736a376e67 (diff)
downloadllvm-e28d9bae4b3be60e90daa69a2eeb3254c952e051.zip
llvm-e28d9bae4b3be60e90daa69a2eeb3254c952e051.tar.gz
llvm-e28d9bae4b3be60e90daa69a2eeb3254c952e051.tar.bz2
PR44958: Allow member calls and typeid / dynamic_cast on mutable objects
and objects with mutable subobjects. The standard wording doesn't really cover these cases; accepting all such cases seems most in line with what we do in other cases and what other compilers do. (Essentially this means we're assuming that objects external to the evaluation are always in-lifetime.)
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index dfa9444..641368e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3140,6 +3140,13 @@ struct CompleteObject {
: Base(Base), Value(Value), Type(Type) {}
bool mayAccessMutableMembers(EvalInfo &Info, AccessKinds AK) const {
+ // If this isn't a "real" access (eg, if it's just accessing the type
+ // info), allow it. We assume the type doesn't change dynamically for
+ // subobjects of constexpr objects (even though we'd hit UB here if it
+ // did). FIXME: Is this right?
+ if (!isAnyAccess(AK))
+ return true;
+
// In C++14 onwards, it is permitted to read a mutable member whose
// lifetime began within the evaluation.
// FIXME: Should we also allow this in C++11?