[committed] libstdc++: Fix non-default constructors for hash containers [PR101583]

Jonathan Wakely jwakely@redhat.com
Thu Jul 22 18:41:41 GMT 2021


On 20/07/21 16:26 +0100, Jonathan Wakely wrote:
>On 02/06/21 13:35 +0100, Jonathan Wakely wrote:
>>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.
>
>
>The recent change to _Hashtable_ebo_helper for this PR broke the
>is_default_constructible trait for a hash container with a non-default
>constructible allocator. That happens because the constructor needs to
>be user-provided in order to initialize the member, and so is not
>defined as deleted when the type is not default constructible.
>
>By making _Hashtable derive from _Enable_special_members we can ensure
>that the default constructor for the std::unordered_xxx containers is
>deleted when it would be ill-formed. This makes the trait give the
>correct answer.
>
>Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
>
>libstdc++-v3/ChangeLog:
>
>        PR libstdc++/100863
>        * include/bits/hashtable.h (_Hashtable): Conditionally delete
>        default constructor by deriving from _Enable_special_members.
>        * testsuite/23_containers/unordered_map/cons/default.cc: New test.
>        * testsuite/23_containers/unordered_set/cons/default.cc: New test.
>

When I added the new mixin to _Hashtable, I forgot to explicitly
construct it in each non-default constructor. That means you can't
use any constructors unless all three of the hash function, equality
function, and allocator are all default constructible.

         PR libstdc++/101583
         * include/bits/hashtable.h (_Hashtable): Replace mixin with
         _Enable_default_ctor. Construct it explicitly in all
         non-forwarding, non-defaulted constructors.
         * testsuite/23_containers/unordered_map/cons/default.cc: Check
         non-default constructors can be used.
         * testsuite/23_containers/unordered_set/cons/default.cc:
         Likewise.

Tested powerpc64le-linux. Committed to trunk.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 6199 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20210722/2544bb33/attachment.bin>


More information about the Libstdc++ mailing list