blob: 1607bac80293f6df6e7234ffccf064245001bf9b [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
Richard Smith6331c402012-02-13 22:16:19 +00003struct NonLit { // expected-note 3{{no constexpr constructors}}
Richard Smith2316cd82011-09-29 19:11:37 +00004 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
David Blaikie8505c292013-01-29 22:26:08 +000016 static const double f = 0.0; // expected-error {{requires 'constexpr' specifier}} expected-note {{add 'constexpr'}}
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}}
Richard Smith3607ffe2012-02-13 03:54:03 +000032 static constexpr NonLit h = NonLit(); // expected-error {{cannot have non-literal type 'const NonLit'}}
Richard Smith6331c402012-02-13 22:16:19 +000033 static constexpr T c = T(); // expected-error {{cannot have non-literal type}}
Richard Smithab3fe0f2012-01-19 22:50:02 +000034 static const T d;
Richard Smith45bb4552012-01-19 22:46:17 +000035};
36
Richard Smith6331c402012-02-13 22:16:19 +000037template<typename T> constexpr T U<T>::d = T(); // expected-error {{non-literal type 'const NonLit'}}
Richard Smithab3fe0f2012-01-19 22:50:02 +000038
Richard Smith3607ffe2012-02-13 03:54:03 +000039U<int> u1;
Richard Smith45bb4552012-01-19 22:46:17 +000040U<NonLit> u2; // expected-note {{here}}
41
42static_assert(U<int>::a == 0, "");
Richard Smithab3fe0f2012-01-19 22:50:02 +000043
44constexpr int outofline = (U<NonLit>::d, 0); // expected-note {{here}} expected-warning {{unused}}