[Bug c++/93989] [c++20] Error initializing trivial types in constexpr constructor

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 2 16:47:14 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93989

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This works fine, i.e. just remove the constexpr specifiers on the local
variables:

consteval void test01()
{
  typedef constexpr_allocator<C> alloc_type;
  typedef bstring<C, traits, alloc_type> test_type;
  alloc_type a1(1);
  test_type v1(a1);
}

Also, there's no need for your traits or allocator type, std::char_traits and
std::allocator are fully constexpr now. So this works too:

consteval void test01()
{
  bstring<C, std::char_traits<C>, std::allocator<C>> v1({});
}


So you should submit the patch for your std::string changes ASAP (to get it
into GCC 12) and just don't use constexpr local variables in your tests. That
isn't necessary, because just using the types in a constexpr or consteval
function already tests that your changes work.


More information about the Gcc-bugs mailing list