| 1 |
// PR c++/116741 |
| 2 |
// { dg-do compile { target c++26 } } |
| 3 |
|
| 4 |
struct S { |
| 5 |
int foo; // { dg-message "pointed-to object" } |
| 6 |
}; |
| 7 |
|
| 8 |
struct S2 { |
| 9 |
int foo; // { dg-message "pointed-to object" } |
| 10 |
}; |
| 11 |
|
| 12 |
struct X { |
| 13 |
S2 s; |
| 14 |
}; |
| 15 |
|
| 16 |
constexpr float f1() { |
| 17 |
S s; |
| 18 |
void* p = &s.foo; |
| 19 |
return *static_cast<float*>(p); // { dg-error "not allowed in a constant expression" } |
| 20 |
} |
| 21 |
|
| 22 |
constexpr float f2() { |
| 23 |
X x; |
| 24 |
void* p = &x.s.foo; |
| 25 |
return *static_cast<float*>(p); // { dg-error "not allowed in a constant expression" } |
| 26 |
} |
| 27 |
|
| 28 |
constexpr auto x1 = f1(); |
| 29 |
constexpr auto x2 = f2(); |