| 1 |
// PR c++/101631 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
struct sso { |
| 5 |
union { |
| 6 |
int buf[10]; |
| 7 |
int* alloc; |
| 8 |
}; |
| 9 |
}; |
| 10 |
|
| 11 |
constexpr bool direct() { |
| 12 |
sso val; |
| 13 |
val.alloc = nullptr; |
| 14 |
val.buf[5] = 42; |
| 15 |
return true; |
| 16 |
} |
| 17 |
constexpr bool ok = direct(); |
| 18 |
|
| 19 |
|
| 20 |
constexpr void perform_assignment(int& left, int right) noexcept { |
| 21 |
left = right; // { dg-error "accessing .+ member instead of initialized" } |
| 22 |
} |
| 23 |
|
| 24 |
constexpr bool indirect() { |
| 25 |
sso val; |
| 26 |
val.alloc = nullptr; |
| 27 |
perform_assignment(val.buf[5], 42); // { dg-message "in .constexpr. expansion" } |
| 28 |
return true; |
| 29 |
} |
| 30 |
constexpr bool err = indirect(); // { dg-message "in .constexpr. expansion" } |