[cfe-commits] r95463 - in /cfe/trunk: lib/AST/Expr.cpp test/SemaCXX/i-c-e-cxx.cpp

John McCall rjmccall at apple.com
Fri Feb 5 17:07:38 PST 2010


Author: rjmccall
Date: Fri Feb  5 19:07:37 2010
New Revision: 95463

URL: http://llvm.org/viewvc/llvm-project?rev=95463&view=rev
Log:
Per discussion, remove the explicit restriction on static const data members with
out-of-line initializers as integer constant expressions.  Fixes PR6206.


Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=95463&r1=95462&r2=95463&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Feb  5 19:07:37 2010
@@ -1665,16 +1665,9 @@
               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());

Modified: cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp?rev=95463&r1=95462&r2=95463&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp (original)
+++ cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp Fri Feb  5 19:07:37 2010
@@ -21,3 +21,19 @@
     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];
+  }
+}





More information about the cfe-commits mailing list