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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That shouldn't be needed, because a trivial class has to have a trivial default
constructor.

The problem is that we default-initialize the array, which requires the const
members to be initialized.

We also need to check for assignability, because trivial classes can have
deleted assignment operators (for some reason).


--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -434,7 +434,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static_assert(is_constructible_v<_Tp, _Tp&>);
       if constexpr (is_constructible_v<_Tp, _Tp&>)
        {
-         if constexpr (is_trivial_v<_Tp>)
+         if constexpr (is_trivial_v<_Tp> && is_default_constructible_v<_Tp>
+                          && is_copy_assignable_v<_Tp>)
            {
              array<remove_cv_t<_Tp>, _Nm> __arr;
              if (!__is_constant_evaluated() && _Nm != 0)
@@ -463,7 +464,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static_assert(is_move_constructible_v<_Tp>);
       if constexpr (is_move_constructible_v<_Tp>)
        {
-         if constexpr (is_trivial_v<_Tp>)
+         if constexpr (is_trivial_v<_Tp> && is_default_constructible_v<_Tp>
+                          && is_move_assignable_v<_Tp>)
            {
              array<remove_cv_t<_Tp>, _Nm> __arr;
              if (!__is_constant_evaluated() && _Nm != 0)

Reply via email to