1 // { dg-do compile }
2 // { dg-options "-std=gnu++0x" }
3
4 // From N2235
5
6 // Mess with the builtin by redeclaring.
abs(int x)7 constexpr int abs(int x) { return x < 0 ? -x : x; }
8
9 extern "C"
10 {
11 constexpr float
squaref(float x)12 squaref(float x) { return x * x; }
13 }
14
15 // implicitly inline, already: warn?
16 inline constexpr double
squared(double x)17 squared(double x) { return x * x; }
18
squarei(int x)19 constexpr int squarei(int x) { return x * x; }
20 extern const int side; // { dg-message "not initialized with a constant expression" }
21 constexpr int area = squarei(side); // { dg-error "side|argument" }
22 // error: squarei(side) is not a constant expression
23
next(constexpr int x)24 int next(constexpr int x) // { dg-error "parameter" }
25 { return x + 1; }
26
f(int x)27 constexpr void f(int x) // { dg-error "return type .void" }
28 { /* ... */ }
29
prev(int x)30 constexpr int prev(int x)
31 { return --x; } // { dg-error "--" }
32
g(int x,int n)33 constexpr int g(int x, int n) // error: body not just ‘‘return expr’’
34 {
35 int r = 1;
36 while (--n > 0) r *= x;
37 return r;
38 } // { dg-error "not a return-statement" }
39
40 constexpr int
bar(int x,int y)41 bar(int x, int y) { return x + y + x * y; } // { dg-error "previously" }
42
bar(int x,int y)43 int bar(int x, int y) // { dg-error "redefinition" }
44 { return x * 2 + 3 * y; }
45
46 constexpr int twice(int x); // { dg-message "never defined" }
47 enum { bufsz = twice(256) }; // { dg-error "" } twice() isn’t (yet) defined
48
fac(int x)49 constexpr int fac(int x)
50 { return x > 2 ? x * fac(x - 1) : 1; } // OK
51