Commit 1f8dd21
committed
string: fix constexpr compliance of basic_string default construction
Replace raw pointer write `*ptr = 0` with `std::construct_at(ptr, char_type{})`
in both `reset_imp()` and `string_allocate_init()`. In C++20 constexpr dynamic
allocation, storage returned by `operator new` / `allocate_at_least` has not had
its lifetime started; writing through the pointer without `std::construct_at`
is ill-formed in a constant expression (Clang rejects it outright).
Add constexpr_construct.cc test verifying `u8string{}` compiles and evaluates
as a constant expression.1 parent c07f3ec commit 1f8dd21
2 files changed
Lines changed: 16 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments