| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
// { dg-options "-ftrack-macro-expansion=0" } |
| 3 |
|
| 4 |
#define SA(X) static_assert (X, #X) |
| 5 |
|
| 6 |
struct A |
| 7 |
{ |
| 8 |
int i; |
| 9 |
constexpr A(int _i) { i = _i; } // { dg-warning "empty body" "" { target c++11_only } } |
| 10 |
// { dg-error "'A::i' must be init" "" { target c++17_down } .-1 } |
| 11 |
}; |
| 12 |
|
| 13 |
template <class T> |
| 14 |
struct B |
| 15 |
{ |
| 16 |
T t; |
| 17 |
constexpr B(T _t): t(_t) { } |
| 18 |
}; |
| 19 |
|
| 20 |
B<int> b(1); // { dg-message "not declared .constexpr" } |
| 21 |
SA(b.t==1); // { dg-error "non-constant condition|'b'" } |
| 22 |
constexpr B<int> b2(1); |
| 23 |
SA(b2.t==1); |
| 24 |
|
| 25 |
template <class T> |
| 26 |
constexpr T f(T a, T b) |
| 27 |
{ |
| 28 |
typedef T myT; |
| 29 |
return a + b; |
| 30 |
} |
| 31 |
|
| 32 |
SA(f(1,2)==3); |