]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Value-initialize objects held by EBO helpers [PR 100863]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 2 Jun 2021 11:34:48 +0000 (12:34 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 26 Nov 2021 15:26:18 +0000 (15:26 +0000)
The allocator, hash function and equality function should all be
value-initialized by the default constructor of an unordered container.
Do it in the EBO helper, so we don't have to get it right in multiple
places.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

PR libstdc++/100863
PR libstdc++/65816
* include/bits/hashtable_policy.h (_Hashtable_ebo_helper):
Value-initialize subobject.
* testsuite/23_containers/unordered_map/allocator/default_init.cc:
Remove XFAIL.
* testsuite/23_containers/unordered_set/allocator/default_init.cc:
Remove XFAIL.

(cherry picked from commit f8f0193b5b83f6e85d65015e79c803295baf5166)

libstdc++-v3/include/bits/hashtable_policy.h
libstdc++-v3/testsuite/23_containers/unordered_map/allocator/default_init.cc
libstdc++-v3/testsuite/23_containers/unordered_set/allocator/default_init.cc

index d34fc39a973a1011161d3b92ac39a6813dedf733..63958cc1d9c9d0996f2e77c24f9518344740831c 100644 (file)
@@ -1109,7 +1109,7 @@ namespace __detail
     struct _Hashtable_ebo_helper<_Nm, _Tp, true>
     : private _Tp
     {
-      _Hashtable_ebo_helper() = default;
+      _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
 
       template<typename _OtherTp>
        _Hashtable_ebo_helper(_OtherTp&& __tp)
@@ -1135,7 +1135,7 @@ namespace __detail
       _Tp& _M_get() { return _M_tp; }
 
     private:
-      _Tp _M_tp;
+      _Tp _M_tp{};
     };
 
   /**
@@ -1789,6 +1789,7 @@ namespace __detail
 
   protected:
     _Hashtable_base() = default;
+
     _Hashtable_base(const _ExtractKey& __ex, const _H1& __h1, const _H2& __h2,
                    const _Hash& __hash, const _Equal& __eq)
     : __hash_code_base(__ex, __h1, __h2, __hash), _EqualEBO(__eq)
index 473a5f1ce47279feec404972de14031e3a855c30..3da42453152dd4fafccedacbd6be8d82358820fe 100644 (file)
@@ -17,7 +17,6 @@
 
 // { dg-do run { target c++11 } }
 // { dg-options "-O0" }
-// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
 
 #include <unordered_map>
 #include <testsuite_hooks.h>
index 37110dd6eb0eb27c093b01b1fb61701609b2b535..1f2f351685902abb77866bc57bcd697a5bfb7663 100644 (file)
@@ -17,7 +17,6 @@
 
 // { dg-do run { target c++11 } }
 // { dg-options "-O0" }
-// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
 
 #include <unordered_set>
 #include <testsuite_hooks.h>