[committed] libstdc++: fix is_default_constructible for hash containers [PR 100863]

Jonathan Wakely jwakely@redhat.com
Tue Jul 20 15:26:20 GMT 2021


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.


Tested powerpc64le-linux. Committed to trunk.


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


More information about the Libstdc++ mailing list