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