[cfe-commits] r141279 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/class/class.static/class.static.data/p3.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Oct 6 02:21:14 PDT 2011


Author: rsmith
Date: Thu Oct  6 04:21:12 2011
New Revision: 141279

URL: http://llvm.org/viewvc/llvm-project?rev=141279&view=rev
Log:
PR11067: A definition of a constexpr static variable doesn't need an initializer if the in-class declaration had one. Such a declaration must be initialized by a constant expression.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=141279&r1=141278&r2=141279&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Oct  6 04:21:12 2011
@@ -1192,8 +1192,6 @@
   "constexpr variable declaration must be a definition">;
 def err_constexpr_var_requires_init : Error<
   "declaration of constexpr variable %0 requires an initializer">;
-def err_constexpr_initialized_static_member : Error<
-  "definition of initialized static data member %0 cannot be marked constexpr">;
 def err_constexpr_var_requires_const_init : Error<
   "constexpr variable %0 must be initialized by a constant expression">;
 def err_constexpr_redecl_mismatch : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=141279&r1=141278&r2=141279&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct  6 04:21:12 2011
@@ -6032,15 +6032,12 @@
     // C++0x [class.static.data]p3: A static data member can be declared with
     // the constexpr specifier; if so, its declaration shall specify
     // a brace-or-equal-initializer.
-    if (Var->isConstexpr()) {
-      // FIXME: Provide fix-its to convert the constexpr to const.
-      if (Var->isStaticDataMember() && Var->getAnyInitializer()) {
-        Diag(Var->getLocation(), diag::err_constexpr_initialized_static_member)
-          << Var->getDeclName();
-      } else {
-        Diag(Var->getLocation(), diag::err_constexpr_var_requires_init)
-          << Var->getDeclName();
-      }
+    //
+    // A static data member's definition may inherit an initializer from an
+    // in-class declaration.
+    if (Var->isConstexpr() && !Var->getAnyInitializer()) {
+      Diag(Var->getLocation(), diag::err_constexpr_var_requires_init)
+        << Var->getDeclName();
       Var->setInvalidDecl();
       return;
     }

Modified: cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp?rev=141279&r1=141278&r2=141279&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp (original)
+++ cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp Thu Oct  6 04:21:12 2011
@@ -10,6 +10,7 @@
 
   static constexpr int c = 0;
   static const int d;
+  static const int d2 = 0;
 
   static constexpr double e = 0.0; // ok
   static const double f = 0.0; // expected-warning {{extension}} expected-note {{use 'constexpr' specifier}}
@@ -17,8 +18,9 @@
   static const NonLit h = NonLit(); // expected-error {{must be initialized out of line}}
 };
 
-constexpr int S::a; // expected-error {{definition of initialized static data member 'a' cannot be marked constexpr}}
+constexpr int S::a;
 constexpr int S::b = 0;
 
 const int S::c;
 constexpr int S::d = 0;
+constexpr int S::d2;





More information about the cfe-commits mailing list