P3372R3 Implementation attempt

Thor Preimesberger tcpreimesberger@gmail.com
Thu Jul 10 03:13:32 GMT 2025


Hey all,

I wanted to get acquainted with libstdc++ and I figured *attempting*
to implement P3372R3 would be a good first exercise.

I've got my development fork to the point that it doesn't trigger any
new test failures. (It'll take me a bit to clean up the git logs well
enough to send in a draft and to make sure there's no superfluous
constexpr-ing.) But currently this code from the original paper fails:

constexpr int list_test() {
  std::list<int> tmp;
  tmp.emplace_back(42);
  tmp.emplace_front(14);

  return tmp.front() + tmp.back();
}

static_assert(list_test() == 14 + 42);

With error:

constexpr_test3.cc:50:35: error: non-constant condition for static
assertion
   50 | static_assert(forward_list_test() == 14 + 42);
      |               ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
[ ... ]
/home/thor/build/constexpr-container/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/forward_list.h:144:33:
  in ‘constexpr’ expansion of
‘((std::_Fwd_list_node<int>*)this)->std::_Fwd_list_node<int>::_M_storage.__gnu_cxx::__aligned_buffer<i
nt>::_M_ptr()’
/home/thor/build/constexpr-container/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/aligned_buffer.h:120:16:
error: cast from ‘void*’ is not allowed in a constant expression
because pointed-to type ‘unsigned char [4]’ is not similar to ‘int
’
  120 |       { return static_cast<_Tp*>(_M_addr()); }
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/thor/build/constexpr-container/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/aligned_buffer.h:99:47:
note: pointed-to object declared here
   99 |       alignas(__alignof__(_Tp)) unsigned char _M_storage[sizeof(_Tp)];
      |

I'm unsure how to proceed. I'd guess we could maybe replace the
static_cast above with bit_cast, but again I'm unsure. Any help would
be appreciated.

Thanks,
Thor Preimesberger


More information about the Libstdc++ mailing list