]> 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>
Wed, 2 Jun 2021 12:33:41 +0000 (13:33 +0100)
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.

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 1090a398e1e0788232238a0b76175526210dbfc6..2130c958262a2f23b7b3d3ae75afc605040e5387 100644 (file)
@@ -1162,7 +1162,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)
@@ -1188,7 +1188,7 @@ namespace __detail
       _Tp& _M_get() { return _M_tp; }
 
     private:
-      _Tp _M_tp;
+      _Tp _M_tp{};
     };
 
   /**
@@ -1246,6 +1246,7 @@ namespace __detail
       // We need the default constructor for the local iterators and _Hashtable
       // default constructor.
       _Hash_code_base() = default;
+
       _Hash_code_base(const _Hash& __hash) : __ebo_hash(__hash) { }
 
       __hash_code
@@ -1639,6 +1640,7 @@ namespace __detail
 
     protected:
       _Hashtable_base() = default;
+
       _Hashtable_base(const _Hash& __hash, const _Equal& __eq)
       : __hash_code_base(__hash), _EqualEBO(__eq)
       { }
index bbfd683d433042e0143df4e8c280f7142c7bc8d3..12f1163951eddde28b0f578c99a192557895d476 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 6ee32d45cebeb14d1f1e4db060912125f71069b7..1ea6603024e136add5c4daa644d9b1fee23b1661 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>