blob: 5640bc30ad4c795c08c84fdd45fbe7253cda8cc7 [file] [log] [blame]
Richard Smith9ca5c422011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Richard Smith62f19e72016-06-25 00:15:56 +00002// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s
Richard Smith2316cd82011-09-29 19:11:37 +00003
Richard Smith6331c402012-02-13 22:16:19 +00004struct NonLit { // expected-note 3{{no constexpr constructors}}
Richard Smith2316cd82011-09-29 19:11:37 +00005 NonLit();
6};
7
8struct S {
9 static constexpr int a = 0;
Richard Smith62f19e72016-06-25 00:15:56 +000010 static constexpr int b; // expected-error {{initializ}} expected-note 0-1{{previous}}
Richard Smith2316cd82011-09-29 19:11:37 +000011
12 static constexpr int c = 0;
13 static const int d;
Richard Smith43a87fe2011-10-06 09:21:12 +000014 static const int d2 = 0;
Richard Smith2316cd82011-09-29 19:11:37 +000015
16 static constexpr double e = 0.0; // ok
David Blaikie8505c292013-01-29 22:26:08 +000017 static const double f = 0.0; // expected-error {{requires 'constexpr' specifier}} expected-note {{add 'constexpr'}}
Richard Smith256336d2011-09-29 23:18:34 +000018 static char *const g = 0; // expected-error {{requires 'constexpr' specifier}}
Richard Smith2316cd82011-09-29 19:11:37 +000019 static const NonLit h = NonLit(); // expected-error {{must be initialized out of line}}
Richard Smith62f19e72016-06-25 00:15:56 +000020
21 static inline int i; // expected-note {{previous}} expected-warning 0-1{{extension}}
22 static inline int j; // expected-note {{previous}} expected-warning 0-1{{extension}}
23 static constexpr int k = 0;
Richard Smith2316cd82011-09-29 19:11:37 +000024};
25
Richard Smith43a87fe2011-10-06 09:21:12 +000026constexpr int S::a;
Richard Smith62f19e72016-06-25 00:15:56 +000027constexpr int S::b = 0; // expected-error 0-1{{redefinition}}
Richard Smith2316cd82011-09-29 19:11:37 +000028
29const int S::c;
30constexpr int S::d = 0;
Richard Smith43a87fe2011-10-06 09:21:12 +000031constexpr int S::d2;
Richard Smith45bb4552012-01-19 22:46:17 +000032
Richard Smith62f19e72016-06-25 00:15:56 +000033int S::i; // expected-error {{redefinition}}
34int S::j; // expected-error {{redefinition}}
35const int S::k; // ok (deprecated)
36
Richard Smith45bb4552012-01-19 22:46:17 +000037template<typename T>
38struct U {
39 static constexpr int a = 0;
Richard Smith62f19e72016-06-25 00:15:56 +000040 static constexpr int b; // expected-error {{initializ}}
Richard Smith3607ffe2012-02-13 03:54:03 +000041 static constexpr NonLit h = NonLit(); // expected-error {{cannot have non-literal type 'const NonLit'}}
Richard Smith6331c402012-02-13 22:16:19 +000042 static constexpr T c = T(); // expected-error {{cannot have non-literal type}}
Richard Smithab3fe0f2012-01-19 22:50:02 +000043 static const T d;
Richard Smith45bb4552012-01-19 22:46:17 +000044};
45
Richard Smith6331c402012-02-13 22:16:19 +000046template<typename T> constexpr T U<T>::d = T(); // expected-error {{non-literal type 'const NonLit'}}
Richard Smithab3fe0f2012-01-19 22:50:02 +000047
Richard Smith3607ffe2012-02-13 03:54:03 +000048U<int> u1;
Richard Smith45bb4552012-01-19 22:46:17 +000049U<NonLit> u2; // expected-note {{here}}
50
51static_assert(U<int>::a == 0, "");
Richard Smithab3fe0f2012-01-19 22:50:02 +000052
Richard Smith263a0a32017-09-23 18:27:11 +000053constexpr int outofline = (U<NonLit>::d, 0); // expected-note {{here}}