| 1 |
// Verify we diagnose and accept, as an extension, a non-empty constexpr |
| 2 |
// constructor body in C++11 mode. |
| 3 |
// PR c++/123845 |
| 4 |
// { dg-do compile { target c++11_only } } |
| 5 |
// { dg-options "" } |
| 6 |
|
| 7 |
constexpr int negate(int n) { return -n; } |
| 8 |
|
| 9 |
struct A { |
| 10 |
int m; |
| 11 |
constexpr A() : m(42) { |
| 12 |
++m; |
| 13 |
m = negate(m); |
| 14 |
} // { dg-warning "does not have empty body \[-Wc++14-extensions\]" } |
| 15 |
}; |
| 16 |
static_assert(A().m == -43, ""); |
| 17 |
|
| 18 |
template<class T> |
| 19 |
struct B { |
| 20 |
int m; |
| 21 |
constexpr B() : m(42) { |
| 22 |
++m; |
| 23 |
m = negate(m); |
| 24 |
} // { dg-warning "does not have empty body \[-Wc++14-extensions\]" } |
| 25 |
}; |
| 26 |
static_assert(B<int>().m == -43, ""); |