[PATCH] libstdc++: Add std::inplace_vector for C++26 (P0843R14) [PR119137]
Jonathan Wakely
jwakely@redhat.com
Thu Jul 17 16:02:46 GMT 2025
On 17/07/25 15:31 +0200, Tomasz Kamiński wrote:
>From: Jonathan Wakely <jwakely@redhat.com>
>
>Implement std::inplace_vector as specified in P0843R14, without follow
>up papers, in particular P3074R7 (trivial unions). In consequence
>inplace_vector<T, N> can be used inside constant evaluations only
>if T is trivial of N is equal to zero.
>
>We provide a separate specialization for inplace_vector<T, 0> to meet
>the requirements of N5008 [inplace.vector.overview] p5. In particular
>objects of such types needs to be empty.
>
>To allow contexpr variable of inplace_vector v, where v.size() < v.capacity(),
constexpr
>we need to guaranteed that all elements of the storage array are initialized,
>even ones in range [v.data() + v.size(), v.data() + v.capacity()). This is
>perfomed by _M_init function, that is alled by each constructored. By storing
performed ... called ... constructor
>the array in animous union, we can perform this intialization in constant
anonymous
>evaluation, avoiding the impact on runtime path.
>
>The size() function conveys the information that _M_size <= _Nm to compiler,
>by calling __builtin_unreachable(). In particular this allows us to eliminate
>FP warnings by using _Nm - size() instead of _Nm - _M_size, when computing
Please spell 'false positive' out in full
>available elements.
>
>However, we still have one -Waggressive-loop-optimizations (to best of our
>knowledge false-positive warning produced in cons/from_range.cc and
Missing ')' after knowledge?
>cons/throws.cc. Currently it is pruned using dg-prune-output and tracked by
>PR121143.
>
>The included test cover almost all code paths at runtime, however some
>compile time evaluation test are not yet implemented:
>* operations on range, they depenend on making testsuite_iterators constexpr
depend
>* negative test for invoking operations with preconditions at compile time,
> especially for zero size specialization.
>
More information about the Libstdc++
mailing list