1// Negative examples from N3092 (FCD)
2// { dg-do compile { target c++11 } }
3
4// OK: declaration
5constexpr int square(int x);	// { dg-message "never defined" }
6
7// error: pixel is a type
8constexpr struct pixel {
9  int x;
10  int y;
11  // OK: declaration
12  constexpr pixel(int);
13};				// { dg-error "constexpr" }
14constexpr pixel::pixel(int a)
15// OK: definition
16  : x(square(a)), y(square(a))	// { dg-error "square" }
17{ }
18
19// error: square not defined, so small(2) not constant (5.19), so constexpr
20// not satisfied
21constexpr pixel small(2);	// { dg-message "in constexpr expansion" }
22
23// error: not for parameters
24int next(constexpr int x) {	// { dg-error "parameter" }
25  return x + 1;
26}
27
28// error: not a definition
29extern constexpr int memsz;	// { dg-error "definition" }
30
31// error: return type is void
32constexpr void f(int x)		// { dg-error "void" "" { target c++11_only } }
33{ /* ... */ }
34// error: use of decrement
35constexpr int prev(int x)
36{ return --x; }			// { dg-error "-- x" "" { target c++11_only } }
37
38// error: body not just return expr
39constexpr int g(int x, int n) {
40  int r = 1;
41  while (--n > 0) r *= x;
42  return r;
43} // { dg-error "body of constexpr function" "" { target c++11_only } }
44
45class debug_flag {
46public:
47  explicit debug_flag(bool);
48  constexpr bool is_on();	// { dg-error "not a literal type" } debug_flag not literal type
49private:
50  bool flag;
51};
52// OK
53constexpr int bar(int x, int y) // { dg-message "previously defined here" }
54{ return x + y + x*y; }
55// ...
56// error: redefinition of bar
57int bar(int x, int y)		// { dg-error "redefinition" }
58{ return x * 2 + 3 * y; }
59
60struct pixel2 {	   // { dg-message "no user-provided default constructor" }
61  int x, y;
62};
63constexpr pixel2 ur = { 1294, 1024 };// OK
64constexpr pixel2 origin;	     // { dg-error "uninitialized const" }
65
66constexpr const int* addr(const int& ir) { return &ir; } // OK
67
68// error, initializer for constexpr variable not a constant
69extern constexpr const int* tp = addr(5); // { dg-error "" }
70