]> granicus.if.org Git - clang/commitdiff
Per discussion, remove the explicit restriction on static const data members with
authorJohn McCall <rjmccall@apple.com>
Sat, 6 Feb 2010 01:07:37 +0000 (01:07 +0000)
committerJohn McCall <rjmccall@apple.com>
Sat, 6 Feb 2010 01:07:37 +0000 (01:07 +0000)
out-of-line initializers as integer constant expressions.  Fixes PR6206.

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

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

index 50ddc9156a9697dad524b037cb3b8aedb8cb6d8d..4e6cdcab0044c78994c6aaa1dda083d62a92432b 100644 (file)
@@ -1665,16 +1665,9 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
               return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation());
           }
 
-          // C++ [class.static.data]p4:
-          //   If a static data member is of const integral or const 
-          //   enumeration type, its declaration in the class definition can
-          //   specify a constant-initializer which shall be an integral 
-          //   constant expression (5.19). In that case, the member can appear
-          //   in integral constant expressions.
-          if (ID->isOutOfLine()) {
-            Dcl->setInitKnownICE(false);
-            return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation());
-          }
+          // It's an ICE whether or not the definition we found is
+          // out-of-line.  See DR 721 and the discussion in Clang PR
+          // 6206 for details.
 
           if (Dcl->isCheckingICE()) {
             return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation());
index 8c70bc258701c298a5f038707b108746ebf6de8c..4f2f1974678347af520142caaf83e4b1711b1359 100644 (file)
@@ -21,3 +21,19 @@ int a() {
     case t:; // expected-error {{not an integer constant expression}}
   }
 }
+
+// PR6206:  out-of-line definitions are legit
+namespace pr6206 {
+  class Foo {
+  public:
+    static const int kBar;
+  };
+
+  const int Foo::kBar = 20;
+  
+  char Test() {
+    char str[Foo::kBar];
+    str[0] = '0';
+    return str[0];
+  }
+}