Skip to content

string: fix constexpr compliance of basic_string default construction#1273

Merged
trcrsired merged 1 commit into
cppfastio:nextfrom
SekaiArendelle:comptime
May 14, 2026
Merged

string: fix constexpr compliance of basic_string default construction#1273
trcrsired merged 1 commit into
cppfastio:nextfrom
SekaiArendelle:comptime

Conversation

@SekaiArendelle
Copy link
Copy Markdown

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.

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.
@trcrsired trcrsired merged commit 7f93222 into cppfastio:next May 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants