Skip to content

Commit 7f93222

Browse files
authored
Merge pull request #1273 from SekaiArendelle/comptime
string: fix constexpr compliance of basic_string default construction
2 parents c07f3ec + 1f8dd21 commit 7f93222

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

include/fast_io_dsal/impl/string.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ inline constexpr ::fast_io::basic_allocation_least_result<chtype *> string_alloc
3434
// n is not possible to SIZE_MAX since that would overflow the memory which is not possible
3535
::std::size_t const np1{static_cast<::std::size_t>(n + 1u)};
3636
auto [ptr, allocn]{typed_allocator_type::allocate_at_least(np1)};
37-
*::fast_io::freestanding::non_overlapped_copy_n(first, n, ptr) = 0;
37+
::std::construct_at(::fast_io::freestanding::non_overlapped_copy_n(first, n, ptr), chtype{});
3838
return {ptr, static_cast<::std::size_t>(allocn - 1u)};
3939
}
4040

@@ -118,7 +118,7 @@ class basic_string FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
118118
using untyped_allocator_type = generic_allocator_adapter<allocator_type>;
119119
using typed_allocator_type = typed_generic_allocator_adapter<untyped_allocator_type, chtype>;
120120
auto [ptr, cap]{typed_allocator_type::allocate_at_least(2)};
121-
*ptr = 0;
121+
::std::construct_at(ptr, char_type{});
122122
this->imp = {ptr, ptr, ptr + static_cast<size_type>(cap - 1u)};
123123
}
124124
else
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <fast_io_dsal/string.h>
2+
3+
// Tests that default construction (reset_imp) works in constexpr context.
4+
constexpr bool default_construct()
5+
{
6+
::fast_io::u8string s{};
7+
return s.empty();
8+
}
9+
static_assert(default_construct());
10+
11+
int main()
12+
{
13+
return 0;
14+
}

0 commit comments

Comments
 (0)