blob: 4d5ac470a0c051c2b2653d7952cd6406b0c72036 [file] [log] [blame]
Richard Smith9ca5c422011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Richard Smith2316cd82011-09-29 19:11:37 +00002
3struct NonLit {
4 NonLit();
5};
6
7struct S {
8 static constexpr int a = 0;
Richard Smitheda3c842011-11-07 22:16:17 +00009 static constexpr int b; // expected-error {{declaration of constexpr static data member 'b' requires an initializer}}
Richard Smith2316cd82011-09-29 19:11:37 +000010
11 static constexpr int c = 0;
12 static const int d;
Richard Smith43a87fe2011-10-06 09:21:12 +000013 static const int d2 = 0;
Richard Smith2316cd82011-09-29 19:11:37 +000014
15 static constexpr double e = 0.0; // ok
Richard Smith7b729cd2011-09-30 00:33:19 +000016 static const double f = 0.0; // expected-warning {{extension}} expected-note {{use 'constexpr' specifier}}
Richard Smith256336d2011-09-29 23:18:34 +000017 static char *const g = 0; // expected-error {{requires 'constexpr' specifier}}
Richard Smith2316cd82011-09-29 19:11:37 +000018 static const NonLit h = NonLit(); // expected-error {{must be initialized out of line}}
19};
20
Richard Smith43a87fe2011-10-06 09:21:12 +000021constexpr int S::a;
Richard Smith2316cd82011-09-29 19:11:37 +000022constexpr int S::b = 0;
23
24const int S::c;
25constexpr int S::d = 0;
Richard Smith43a87fe2011-10-06 09:21:12 +000026constexpr int S::d2;
Richard Smith45bb4552012-01-19 22:46:17 +000027
28template<typename T>
29struct U {
30 static constexpr int a = 0;
31 static constexpr int b; // expected-error {{declaration of constexpr static data member 'b' requires an initializer}}
32 // FIXME: It'd be nice to error on this at template definition time.
33 static constexpr NonLit h = NonLit(); // expected-error 2{{must be initialized by a constant expression}} expected-note 2{{non-literal type}}
34 static constexpr T c = T(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-literal type}}
35};
36
37U<int> u1; // expected-note {{here}}
38U<NonLit> u2; // expected-note {{here}}
39
40static_assert(U<int>::a == 0, "");