From: Eli Friedman Date: Thu, 29 Sep 2011 21:49:34 +0000 (+0000) Subject: PR11040: CheckICE should not allow an lvalue bitcast as part of an integer constant... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eea0e817c609c662f3fef61bb257fddf1ae8f7b7;p=clang PR11040: CheckICE should not allow an lvalue bitcast as part of an integer constant expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140812 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 1ff1430c9c..742dcab564 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -3089,11 +3089,17 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { case Expr::CXXConstCastExprClass: case Expr::ObjCBridgedCastExprClass: { const Expr *SubExpr = cast(E)->getSubExpr(); - if (SubExpr->getType()->isIntegralOrEnumerationType()) + switch (cast(E)->getCastKind()) { + case CK_LValueToRValue: + case CK_NoOp: + case CK_IntegralToBoolean: + case CK_IntegralCast: return CheckICE(SubExpr, Ctx); - if (isa(SubExpr->IgnoreParens())) - return NoDiag(); - return ICEDiag(2, E->getLocStart()); + default: + if (isa(SubExpr->IgnoreParens())) + return NoDiag(); + return ICEDiag(2, E->getLocStart()); + } } case Expr::BinaryConditionalOperatorClass: { const BinaryConditionalOperator *Exp = cast(E); diff --git a/test/SemaCXX/i-c-e-cxx.cpp b/test/SemaCXX/i-c-e-cxx.cpp index 186e32126a..4ebdada492 100644 --- a/test/SemaCXX/i-c-e-cxx.cpp +++ b/test/SemaCXX/i-c-e-cxx.cpp @@ -54,4 +54,6 @@ struct A { int foo() { return A::B; } } - +// PR11040 +const int x = 10; +int* y = reinterpret_cast(x); // expected-error {{cannot initialize}}