diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-17 02:16:45 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-17 02:16:45 +0000 |
commit | f51dc8d2f98f4029247552bc45ef53628ab3b6b9 (patch) | |
tree | 8f6d1c7da2e3abf603523c71199fca4c942451ff /clang/lib/AST/ExprConstant.cpp | |
parent | 45e76907966bc8a4cce2df48e7b2d94d8c4df4a9 (diff) | |
download | bcm5719-llvm-f51dc8d2f98f4029247552bc45ef53628ab3b6b9.tar.gz bcm5719-llvm-f51dc8d2f98f4029247552bc45ef53628ab3b6b9.zip |
[c++20] P1327R1: Support for typeid applied to objects of polymorphic
class type in constant evaluation.
llvm-svn: 360977
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index e41264e55e4..35000f42b24 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -1349,6 +1349,7 @@ enum AccessKinds { AK_Decrement, AK_MemberCall, AK_DynamicCast, + AK_TypeId, }; static bool isModification(AccessKinds AK) { @@ -1356,6 +1357,7 @@ static bool isModification(AccessKinds AK) { case AK_Read: case AK_MemberCall: case AK_DynamicCast: + case AK_TypeId: return false; case AK_Assign: case AK_Increment: @@ -6029,19 +6031,33 @@ LValueExprEvaluator::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) { } bool LValueExprEvaluator::VisitCXXTypeidExpr(const CXXTypeidExpr *E) { + TypeInfoLValue TypeInfo; + if (!E->isPotentiallyEvaluated()) { - TypeInfoLValue TypeInfo; if (E->isTypeOperand()) TypeInfo = TypeInfoLValue(E->getTypeOperand(Info.Ctx).getTypePtr()); else TypeInfo = TypeInfoLValue(E->getExprOperand()->getType().getTypePtr()); - return Success(APValue::LValueBase::getTypeInfo(TypeInfo, E->getType())); + } else { + if (!Info.Ctx.getLangOpts().CPlusPlus2a) { + Info.CCEDiag(E, diag::note_constexpr_typeid_polymorphic) + << E->getExprOperand()->getType() + << E->getExprOperand()->getSourceRange(); + } + + if (!Visit(E->getExprOperand())) + return false; + + Optional<DynamicType> DynType = + ComputeDynamicType(Info, E, Result, AK_TypeId); + if (!DynType) + return false; + + TypeInfo = + TypeInfoLValue(Info.Ctx.getRecordType(DynType->Type).getTypePtr()); } - Info.FFDiag(E, diag::note_constexpr_typeid_polymorphic) - << E->getExprOperand()->getType() - << E->getExprOperand()->getSourceRange(); - return false; + return Success(APValue::LValueBase::getTypeInfo(TypeInfo, E->getType())); } bool LValueExprEvaluator::VisitCXXUuidofExpr(const CXXUuidofExpr *E) { |