With PR121068 partially addressed by r16-2432-gfdbc5ff61b4710,
placement new can now be used to initialize the internal array of
std::inplace_vector.

libstdc++-v3/ChangeLog:

        * include/std/inplace_vector (inplace_vector::_M_init):
        Use placement new to creat array.
---
v2 uses std::addressof properly.

 libstdc++-v3/include/std/inplace_vector | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/std/inplace_vector 
b/libstdc++-v3/include/std/inplace_vector
index 290cf6eb0e9..c75b5242605 100644
--- a/libstdc++-v3/include/std/inplace_vector
+++ b/libstdc++-v3/include/std/inplace_vector
@@ -877,12 +877,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          }
        else
          {
-           // TODO: use new(_M_elems) _Tp[_Nm]() once PR121068 is fixed
            if constexpr (is_trivial_v<_Tp>)
-             for (size_t __i = 0; __i < _Nm; ++__i)
-               _M_elems[__i] = _Tp();
+             new (static_cast<void*>(std::addressof(_M_elems))) _Tp[_Nm]();
            else
-             __builtin_unreachable(); // only trivial types are supported at 
compile time
+             // only trivial types are supported at compile time
+             __builtin_unreachable();
          }
       }
 
-- 
2.49.0

Reply via email to