[cfe-commits] r148505 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/class/class.static/class.static.data/p3.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Jan 19 14:46:17 PST 2012


Author: rsmith
Date: Thu Jan 19 16:46:17 2012
New Revision: 148505

URL: http://llvm.org/viewvc/llvm-project?rev=148505&view=rev
Log:
An instantiation of a constexpr static data member in a class template is
constexpr.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=148505&r1=148504&r2=148505&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Jan 19 16:46:17 2012
@@ -330,6 +330,7 @@
   Var->setThreadSpecified(D->isThreadSpecified());
   Var->setCXXDirectInitializer(D->hasCXXDirectInitializer());
   Var->setCXXForRangeDecl(D->isCXXForRangeDecl());
+  Var->setConstexpr(D->isConstexpr());
 
   // Substitute the nested name specifier, if any.
   if (SubstQualifier(D, Var))

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=148505&r1=148504&r2=148505&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 Jan 19 16:46:17 2012
@@ -24,3 +24,17 @@
 const int S::c;
 constexpr int S::d = 0;
 constexpr int S::d2;
+
+template<typename T>
+struct U {
+  static constexpr int a = 0;
+  static constexpr int b; // expected-error {{declaration of constexpr static data member 'b' requires an initializer}}
+  // FIXME: It'd be nice to error on this at template definition time.
+  static constexpr NonLit h = NonLit(); // expected-error 2{{must be initialized by a constant expression}} expected-note 2{{non-literal type}}
+  static constexpr T c = T(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-literal type}}
+};
+
+U<int> u1; // expected-note {{here}}
+U<NonLit> u2; // expected-note {{here}}
+
+static_assert(U<int>::a == 0, "");





More information about the cfe-commits mailing list