diff options
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 20 | ||||
| -rw-r--r-- | clang/lib/AST/ExprCXX.cpp | 15 | ||||
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 3 |
4 files changed, 23 insertions, 17 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 1426a29f17e..ad48dffb4d4 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3177,7 +3177,7 @@ QualType ASTContext::getDecltypeType(Expr *e, QualType UnderlyingType) const { if (Canon) { // We already have a "canonical" version of an equivalent, dependent // decltype type. Use that as our canonical type. - dt = new (*this, TypeAlignment) DecltypeType(e, DependentTy, + dt = new (*this, TypeAlignment) DecltypeType(e, UnderlyingType, QualType((DecltypeType*)Canon, 0)); } else { // Build a new, canonical typeof(expr) type. diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 8ae7a2ddc3f..24361efafa6 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -2757,22 +2757,10 @@ bool Expr::HasSideEffects(const ASTContext &Ctx) const { break; } - case CXXTypeidExprClass: { - // A typeid expression has side-effects if it can throw. - const CXXTypeidExpr *TE = cast<CXXTypeidExpr>(this); - if (TE->isTypeOperand()) - return false; - const CXXRecordDecl *RD = - TE->getExprOperand()->getType()->getAsCXXRecordDecl(); - if (!RD || !RD->isPolymorphic() || - !TE->getExprOperand()-> - Classify(const_cast<ASTContext&>(Ctx)).isGLValue()) - // Not a glvalue of polymorphic class type: the expression is an - // unevaluated operand. - return false; - // Might throw. - return true; - } + case CXXTypeidExprClass: + // typeid might throw if its subexpression is potentially-evaluated, so has + // side-effects in that case whether or not its subexpression does. + return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated(); case CXXConstructExprClass: case CXXTemporaryObjectExprClass: { diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index ec9c978f3c9..b290fb423a4 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -24,6 +24,21 @@ using namespace clang; // Child Iterators for iterating over subexpressions/substatements //===----------------------------------------------------------------------===// +bool CXXTypeidExpr::isPotentiallyEvaluated() const { + if (isTypeOperand()) + return false; + + // C++11 [expr.typeid]p3: + // When typeid is applied to an expression other than a glvalue of + // polymorphic class type, [...] the expression is an unevaluated operand. + const Expr *E = getExprOperand(); + if (const CXXRecordDecl *RD = E->getType()->getAsCXXRecordDecl()) + if (RD->isPolymorphic() && E->isGLValue()) + return true; + + return false; +} + QualType CXXTypeidExpr::getTypeOperand() const { assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); return Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType() diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 567002cf828..06c41a2e7ea 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2881,6 +2881,9 @@ bool LValueExprEvaluator::VisitCXXTypeidExpr(const CXXTypeidExpr *E) { if (E->isTypeOperand()) return Success(E); CXXRecordDecl *RD = E->getExprOperand()->getType()->getAsCXXRecordDecl(); + // FIXME: The standard says "a typeid expression whose operand is of a + // polymorphic class type" is not a constant expression, but it probably + // means "a typeid expression whose operand is potentially evaluated". if (RD && RD->isPolymorphic()) { Info.Diag(E, diag::note_constexpr_typeid_polymorphic) << E->getExprOperand()->getType() |

