diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-19 22:46:17 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-19 22:46:17 +0000 |
commit | 796c1a1e3e63e459e371383ac878aa5f40b02a8c (patch) | |
tree | c56e4ea43c7a11e3f4a058d5f61af8bd996f8cd6 | |
parent | fcaf27e185695bdf755e202aeba9632e0a8ef3c6 (diff) |
An instantiation of a constexpr static data member in a class template is
constexpr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148505 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 1 | ||||
-rw-r--r-- | test/CXX/class/class.static/class.static.data/p3.cpp | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index c07ae75cb2..ef8f366aad 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -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)) diff --git a/test/CXX/class/class.static/class.static.data/p3.cpp b/test/CXX/class/class.static/class.static.data/p3.cpp index 77870f4255..4d5ac470a0 100644 --- a/test/CXX/class/class.static/class.static.data/p3.cpp +++ b/test/CXX/class/class.static/class.static.data/p3.cpp @@ -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, ""); |