]> granicus.if.org Git - clang/commitdiff
PR11040: CheckICE should not allow an lvalue bitcast as part of an integer constant...
authorEli Friedman <eli.friedman@gmail.com>
Thu, 29 Sep 2011 21:49:34 +0000 (21:49 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 29 Sep 2011 21:49:34 +0000 (21:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140812 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/SemaCXX/i-c-e-cxx.cpp

index 1ff1430c9c3b2c5319d21a6bfb7d54b930c52a37..742dcab564f67cd1ad33edc590cc70871ff62fc0 100644 (file)
@@ -3089,11 +3089,17 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
   case Expr::CXXConstCastExprClass: 
   case Expr::ObjCBridgedCastExprClass: {
     const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr();
-    if (SubExpr->getType()->isIntegralOrEnumerationType())
+    switch (cast<CastExpr>(E)->getCastKind()) {
+    case CK_LValueToRValue:
+    case CK_NoOp:
+    case CK_IntegralToBoolean:
+    case CK_IntegralCast:
       return CheckICE(SubExpr, Ctx);
-    if (isa<FloatingLiteral>(SubExpr->IgnoreParens()))
-      return NoDiag();
-    return ICEDiag(2, E->getLocStart());
+    default:
+      if (isa<FloatingLiteral>(SubExpr->IgnoreParens()))
+        return NoDiag();
+      return ICEDiag(2, E->getLocStart());
+    }
   }
   case Expr::BinaryConditionalOperatorClass: {
     const BinaryConditionalOperator *Exp = cast<BinaryConditionalOperator>(E);
index 186e32126a39aa07220e8375198401e70ade6607..4ebdada49225c2cf0c9933ef3b497135e07f6c2f 100644 (file)
@@ -54,4 +54,6 @@ struct A {
 int foo() { return A::B; }
 }
 
-
+// PR11040
+const int x = 10;
+int* y = reinterpret_cast<const char&>(x); // expected-error {{cannot initialize}}