| 1 |
// PR c++/91483 |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
|
| 4 |
struct X { |
| 5 |
int const& var; |
| 6 |
}; |
| 7 |
|
| 8 |
struct A { |
| 9 |
A *ap = this; |
| 10 |
}; |
| 11 |
|
| 12 |
constexpr A |
| 13 |
foo () |
| 14 |
{ |
| 15 |
return {}; |
| 16 |
} |
| 17 |
|
| 18 |
void |
| 19 |
test () |
| 20 |
{ |
| 21 |
constexpr int i = 42; // { dg-message "may differ on each invocation" } |
| 22 |
|
| 23 |
constexpr X x{i}; // { dg-error "not a constant expression" } |
| 24 |
// { dg-message "reference to .i. is not a constant expression" "" { target *-*-* } .-1 } |
| 25 |
constexpr const int *p = &i; // { dg-error "not a constant expression" } |
| 26 |
// { dg-message "pointer to .i. is not a constant expression" "" { target *-*-* } .-1 } |
| 27 |
|
| 28 |
constexpr A a = foo (); // { dg-error "not a constant expression" } |
| 29 |
// { dg-message "pointer to .a. is not a constant expression|may differ" "" { target *-*-* } .-1 } |
| 30 |
|
| 31 |
constexpr const int *q = __builtin_launder (&i); // { dg-error "not a constant expression" } |
| 32 |
// { dg-message "pointer to .i. is not a constant expression" "" { target *-*-* } .-1 } |
| 33 |
} |