1 // { dg-do compile { target c++11 } }
5 // Mess with the builtin by redeclaring.
6 constexpr int abs(int x) { return x < 0 ? -x : x; }
11 squaref(float x) { return x * x; }
14 // implicitly inline, already: warn?
15 inline constexpr double
16 squared(double x) { return x * x; }
18 constexpr int squarei(int x) { return x * x; }
19 extern const int side; // { dg-message "not initialized with a constant expression" }
20 constexpr int area = squarei(side); // { dg-error "side|argument" }
21 // error: squarei(side) is not a constant expression
23 int next(constexpr int x) // { dg-error "parameter" }
26 constexpr void f(int x) // { dg-error "return type .void" "" { target c++11_only } }
29 constexpr int prev(int x)
30 { return --x; } // { dg-error "--" "" { target c++11_only } }
32 constexpr int g(int x, int n) // error: body not just ‘‘return expr’’
35 while (--n > 0) r *= x;
37 } // { dg-error "not a return-statement" "" { target c++11_only } }
40 bar(int x, int y) { return x + y + x * y; } // { dg-message "previously" }
42 int bar(int x, int y) // { dg-error "redefinition" }
43 { return x * 2 + 3 * y; }
45 constexpr int twice(int x); // { dg-message "never defined" }
46 enum { bufsz = twice(256) }; // { dg-error "" } twice() isn’t (yet) defined
48 constexpr int fac(int x)
49 { return x > 2 ? x * fac(x - 1) : 1; } // OK