]> granicus.if.org Git - clang/commitdiff
An instantiation of a constexpr static data member in a class template is
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 19 Jan 2012 22:46:17 +0000 (22:46 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 19 Jan 2012 22:46:17 +0000 (22:46 +0000)
constexpr.

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

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/CXX/class/class.static/class.static.data/p3.cpp

index c07ae75cb2c52d8670dd54c0712938ae9aa69b21..ef8f366aada20b04b30b8253279f7233247cc7ba 100644 (file)
@@ -330,6 +330,7 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
   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))
index 77870f42559887d0dd2751e58fd024b85767f80f..4d5ac470a0c051c2b2653d7952cd6406b0c72036 100644 (file)
@@ -24,3 +24,17 @@ constexpr int S::b = 0;
 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, "");