]> granicus.if.org Git - clang/commitdiff
In accordance with the C89, C99 and C++98 standards, ICEs can only contain
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 24 Oct 2011 18:26:35 +0000 (18:26 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 24 Oct 2011 18:26:35 +0000 (18:26 +0000)
floating-point literals if they are the immediate operands of casts.
ImplicitCastExpr is not a cast in the language-standards sense.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142832 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 5d34aff7a63945d0c6046a855e885509b91432c6..3bf9eb516f7f8214a2a4c86264d1ff49a7839809 100644 (file)
@@ -3114,9 +3114,12 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
   case Expr::CXXFunctionalCastExprClass:
   case Expr::CXXStaticCastExprClass:
   case Expr::CXXReinterpretCastExprClass:
-  case Expr::CXXConstCastExprClass: 
+  case Expr::CXXConstCastExprClass:
   case Expr::ObjCBridgedCastExprClass: {
     const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr();
+    if (E->getStmtClass() != Expr::ImplicitCastExprClass &&
+        isa<FloatingLiteral>(SubExpr->IgnoreParenImpCasts()))
+      return NoDiag();
     switch (cast<CastExpr>(E)->getCastKind()) {
     case CK_LValueToRValue:
     case CK_NoOp:
@@ -3124,8 +3127,6 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
     case CK_IntegralCast:
       return CheckICE(SubExpr, Ctx);
     default:
-      if (isa<FloatingLiteral>(SubExpr->IgnoreParens()))
-        return NoDiag();
       return ICEDiag(2, E->getLocStart());
     }
   }
index 9b50916f85ffb80094531a1c1d3ab5fb70c686a0..cb9dcabafce0372125e059eaababab3aaab5f34f 100644 (file)
@@ -11,6 +11,9 @@ char w[__builtin_constant_p(expr) ? expr : 1];
 
 char v[sizeof(__builtin_constant_p(0)) == sizeof(int) ? 1 : -1];
 
+int implicitConversion = 1.0;
+char floatArith[(int)(1.0+2.0)]; // expected-warning {{must be an integer constant expression}}
+
 // __builtin_constant_p as the condition of ?: allows arbitrary foldable
 // constants to be transmogrified into i-c-e's.
 char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1];
index 4d02ca8f174e9ef7a518e655f64e56eb839b19cf..ba60054f2e0077ba48e2ae29e1c0ad4f57084e1e 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
 
 // C++-specific tests for integral constant expressions.
 
@@ -48,7 +48,7 @@ void pr6373(const unsigned x = 0) {
 namespace rdar9204520 {
   
 struct A {
-  static const int B = int(0.75 * 1000 * 1000);
+  static const int B = int(0.75 * 1000 * 1000); // expected-warning {{not a constant expression, accepted as an extension}}
 };
 
 int foo() { return A::B; }
@@ -59,5 +59,10 @@ const int x = 10;
 int* y = reinterpret_cast<const char&>(x); // expected-error {{cannot initialize}}
 
 // This isn't an integral constant expression, but make sure it folds anyway.
-struct PR8836 { char _; long long a; };
-int PR8836test[(__typeof(sizeof(int)))&reinterpret_cast<const volatile char&>((((PR8836*)0)->a))];
+struct PR8836 { char _; long long a; }; // expected-warning {{long long}}
+int PR8836test[(__typeof(sizeof(int)))&reinterpret_cast<const volatile char&>((((PR8836*)0)->a))]; // expected-warning {{folded to constant array as an extension}}
+
+const int nonconst = 1.0;
+int arr[nonconst]; // expected-warning {{folded to constant array as an extension}}
+const int castfloat = static_cast<int>(1.0);
+int arr2[castfloat]; // ok