p9.cpp revision 66f85713bd0d22f867efa8e9fb0037befdd6b151
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2
3// A constexpr specifier used in an object declaration declares the object as
4// const.
5constexpr int a = 0;
6extern const int a;
7
8int i;
9constexpr int *b = &i;
10extern int *const b;
11
12constexpr int &c = i;
13extern int &c;
14
15constexpr int (*d)(int) = 0;
16extern int (*const d)(int);
17
18// A variable declaration which uses the constexpr specifier shall have an
19// initializer and shall be initialized by a constant expression.
20constexpr int ni1; // expected-error {{default initialization of an object of const type 'const int'}}
21constexpr struct C { C(); } ni2; // expected-error {{constexpr variable 'ni2' must be initialized by a constant expression}}
22constexpr double &ni3; // expected-error {{declaration of reference variable 'ni3' requires an initializer}}
23
24constexpr int nc1 = i; // expected-error {{constexpr variable 'nc1' must be initialized by a constant expression}}
25constexpr C nc2 = C(); // expected-error {{constexpr variable 'nc2' must be initialized by a constant expression}}
26int &f();
27constexpr int &nc3 = f(); // expected-error {{constexpr variable 'nc3' must be initialized by a constant expression}}
28constexpr int nc4(i); // expected-error {{constexpr variable 'nc4' must be initialized by a constant expression}}
29constexpr C nc5((C())); // expected-error {{constexpr variable 'nc5' must be initialized by a constant expression}}
30int &f();
31constexpr int &nc6(f()); // expected-error {{constexpr variable 'nc6' must be initialized by a constant expression}}
32
33struct pixel {
34  int x, y;
35};
36constexpr pixel ur = { 1294, 1024 }; // ok
37constexpr pixel origin;              // expected-error {{default initialization of an object of const type 'const pixel' requires a user-provided default constructor}}
38