[PATCH][16] libstdc++: Remove unecessary std::start_lifetime_as call in inplace_vector [PR124121].

Jonathan Wakely jwakely@redhat.com
Mon Sep 14 08:47:01 GMT 2026


On Mon, 14 Sept 2026 at 09:24, Tomasz Kamiński <tkaminsk@redhat.com> wrote:
>
> This removes use of std::start_lifetime_as from inplace_vector::_M_init,
> that was preventing optimizations (see PR124121), it is not required as
> GCC treats any write to union as potentially changing active member.
> Furthermore when available __builtin_constexpr_diag is used to emit better
> error message. TODO comment is also removed, as suggested new call is not
> supported until clang 23.
>
> This backports parts of r17-4164-ga6cb4f45, that does not depend on
> start_lifetime.
>
> libstdc++-v3/ChangeLog:
>
>         PR libstdc++/124121
>         (inplace_vector::_M_init): Remove unnecessary start_lifetime_as call.
>         Emit error using __builtin_constexpr_diag.
> ---
> Backporting the changes to #else branch. Unfortunatelly there are not sufficient
> to address PR124121, but are still step froward it.
>
> Tested on x86_64-linux. *inplace* test additionally tested in all standard modes,
> debug, assertions, -m32. OK for 16?

OK


>
>  libstdc++-v3/include/std/inplace_vector | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/inplace_vector b/libstdc++-v3/include/std/inplace_vector
> index 131bdc4ca47..0159f7021f3 100644
> --- a/libstdc++-v3/include/std/inplace_vector
> +++ b/libstdc++-v3/include/std/inplace_vector
> @@ -841,21 +841,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
>        constexpr void
>        _M_init()
>        {
> -       if !consteval
> +       if consteval
>           {
> -#if __glibcxx_start_lifetime_as
> -           std::start_lifetime_as_array<_Tp>(data(), _Nm);
> -#endif
> -         }
> -       else
> -         {
> -           // TODO: use new(_M_elems) _Tp[_Nm]() once PR121068 is fixed
>             if constexpr (is_trivially_default_constructible_v<_Tp>
>                             && is_trivially_copyable_v<_Tp>)
>               for (size_t __i = 0; __i < _Nm; ++__i)
>                 _M_elems[__i] = _Tp();
>             else
> -             __builtin_unreachable(); // only trivial types are supported at compile time
> +#if __has_builtin(__builtin_constexpr_diag)
> +            __builtin_constexpr_diag(2, "",
> +               "std::inplace_vector supports only trivally copyable and "
> +               "trivially default constructible types at compile time");
> +#else
> +            __builtin_unreachable();
> +#endif
>           }
>        }
>
> --
> 2.55.0
>



More information about the Libstdc++ mailing list