diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2021-10-04 14:04:20 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2021-10-04 15:23:28 +0100 |
commit | 22d34a2a50651d01669b6fbcdb9677c18d2197c5 (patch) | |
tree | 98479ac458d4dac2a683cd42f001aff3cc1f6d60 /libstdc++-v3/testsuite/23_containers/forward_list | |
parent | 728e639d82099035fdfe69b716a54717ae7050e0 (diff) | |
download | gcc-22d34a2a50651d01669b6fbcdb9677c18d2197c5.tar.gz |
libstdc++: Implement P1518R2 for container deduction guides
This implements the C++23 P1518R2 proposal "Stop overconstraining
allocators in container deduction guides" as a fix for C++17 and C++20
too.
The changes allow class template argument deduction to ignore the type
of a constructor argument that initializes an allocator_type parameter
if the type should be deducible only from the other arguments. So for
the constructor vector(const vector&, const allocator_type&) only the
first argument is used for deduction, allowing the second argument to be
anything that is implicitly convertible to argument_type. Previously
deduction would fail or an ill-formed type would be deduced if the
second argument wasn't of type allocator_type.
The unordered containers do not need changes, because their
allocator-extended constructors use the allocator_type alias, which
comes from the dependent base class so is already a non-deduced context.
libstdc++-v3/ChangeLog:
* include/bits/forward_list.h (forward_list): Use non-deduced
context for allocator parameter of allocator-extended copy and
move constructors.
* include/bits/stl_bvector.h (vector<bool>): Likewise.
* include/bits/stl_deque.h (deque): Likewise.
* include/bits/stl_list.h (list): Likewise.
* include/bits/stl_map.h (map): Likewise.
* include/bits/stl_multimap.h (multimap): Likewise.
* include/bits/stl_multiset.h (multiset): Likewise.
* include/bits/stl_set.h (set): Likewise.
* include/bits/stl_vector.h (vector): Likewise.
* include/bits/stl_queue.h (queue, priority_queue): Do not
constrain Allocator template parameter of deduction guides that
have a Container parameter.
* include/bits/stl_stack.h (stack): Likewise.
* include/debug/deque (__gnu_debug::deque): Use non-deduced
context for allocator parameter of allocator-extended copy and
move constructors.
* include/debug/list (__gnu_debug::list): Likewise.
* include/debug/map.h (__gnu_debug::map): Likewise.
* include/debug/multimap.h (__gnu_debug::multimap): Likewise.
* include/debug/multiset.h (__gnu_debug::multiset): Likewise.
* include/debug/set.h (__gnu_debug::set): Likewise.
* include/debug/vector (__gnu_debug::vector): Likewise.
* testsuite/23_containers/deque/cons/deduction.cc: Test class
template argument deduction with non-deduced allocator
arguments.
* testsuite/23_containers/forward_list/cons/deduction.cc:
Likewise.
* testsuite/23_containers/list/cons/deduction.cc: Likewise.
* testsuite/23_containers/map/cons/deduction.cc: Likewise.
* testsuite/23_containers/multimap/cons/deduction.cc: Likewise.
* testsuite/23_containers/multiset/cons/deduction.cc: Likewise.
* testsuite/23_containers/priority_queue/deduction.cc: Likewise.
* testsuite/23_containers/queue/deduction.cc: Likewise.
* testsuite/23_containers/set/cons/deduction.cc: Likewise.
* testsuite/23_containers/stack/deduction.cc: Likewise.
* testsuite/23_containers/unordered_map/cons/deduction.cc:
Likewise.
* testsuite/23_containers/unordered_multimap/cons/deduction.cc:
Likewise.
* testsuite/23_containers/unordered_multiset/cons/deduction.cc:
Likewise.
* testsuite/23_containers/unordered_set/cons/deduction.cc:
Likewise.
* testsuite/23_containers/vector/cons/deduction.cc: Likewise.
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/forward_list')
-rw-r--r-- | libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc index eb39682f483..701231d1259 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/cons/deduction.cc @@ -19,6 +19,7 @@ #include <forward_list> #include <testsuite_iterators.h> +#include <testsuite_allocator.h> template<typename T> using input_iterator_seq @@ -67,3 +68,31 @@ test02() std::forward_list s4(1U, 2L, std::allocator<long>()); check_type<std::forward_list<long>>(s4); } + +struct Pool; + +template<typename T> +struct Alloc : __gnu_test::SimpleAllocator<T> +{ + Alloc(Pool*) { } + + template<typename U> + Alloc(const Alloc<U>&) { } +}; + +void +test_p1518r2() +{ + // P1518R2 - Stop overconstraining allocators in container deduction guides. + // This is a C++23 feature but we support it for C++17 too. + + using Flist = std::forward_list<unsigned, Alloc<unsigned>>; + Pool* p = nullptr; + Flist f(p); + + std::forward_list s1(f, p); + check_type<Flist>(s1); + + std::forward_list s2(std::move(f), p); + check_type<Flist>(s2); +} |