gcc/libstdc++-v3/testsuite
Patrick Palka 3eecc1db4c c++: CTAD and deduction guide selection [PR86439]
During CTAD, we select the best viable deduction guide using
build_new_function_call, which performs overload resolution on the set
of candidate guides and then forms a call to the guide.  As the PR
points out, this latter step is unnecessary and occasionally incorrect
since a call to the selected guide may be ill-formed, or forming the
call may have side effects such as prematurely deducing the type of a {}.

So this patch introduces a specialized subroutine based on
build_new_function_call that stops short of building a call to the
selected function, and makes do_class_deduction use this subroutine
instead.  And since a call is no longer built, do_class_deduction
doesn't need to set tf_decltype or cp_unevaluated_operand anymore.

This change causes us to reject some container CTAD examples in the
libstdc++ testsuite due to deduction failure for {}, which AFAICT is the
correct behavior.  Previously in e.g. the first removed example

  std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}},

the type of the {} would get deduced to less<int> as a side effect of
forming a call to the chosen guide

  template<typename _Key, typename _Tp, typename _Compare = less<_Key>,
           typename _Allocator = allocator<pair<const _Key, _Tp>>>
      map(initializer_list<pair<_Key, _Tp>>,
          _Compare = _Compare(), _Allocator = _Allocator())
      -> map<_Key, _Tp, _Compare, _Allocator>;

which made later overload resolution for the constructor call
unambiguous.  Now, the type of the {} remains undeduced until
constructor overload resolution, and we complain about ambiguity
for the two equally good constructor candidates

  map(initializer_list<value_type>,
      const _Compare& = _Compare(),
      const allocator_type& = allocator_type())

  map(initializer_list<value_type>, const allocator_type&).

This patch fixes these problematic container CTAD examples by giving
the {} an appropriate concrete type.  Two of these adjusted CTAD
examples (one for std::set and one for std::multiset) end up triggering
an unrelated CTAD bug on trunk, PR101174, so these two adjusted examples
are commented out for now.

	PR c++/86439

gcc/cp/ChangeLog:

	* call.c (print_error_for_call_failure): Constify 'args' parameter.
	(perform_dguide_overload_resolution): Define.
	* cp-tree.h: (perform_dguide_overload_resolution): Declare.
	* pt.c (do_class_deduction): Use perform_dguide_overload_resolution
	instead of build_new_function_call.  Don't use tf_decltype or
	set cp_unevaluated_operand.  Remove unnecessary NULL_TREE tests.

libstdc++-v3/ChangeLog:

	* testsuite/23_containers/map/cons/deduction.cc: Replace ambiguous
	CTAD examples.
	* testsuite/23_containers/multimap/cons/deduction.cc: Likewise.
	* testsuite/23_containers/multiset/cons/deduction.cc: Likewise.
	Mention one of the replaced examples is broken due to PR101174.
	* testsuite/23_containers/set/cons/deduction.cc: Likewise.
	* testsuite/23_containers/unordered_map/cons/deduction.cc: Replace
	ambiguous CTAD examples.
	* 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.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1z/class-deduction88.C: New test.
	* g++.dg/cpp1z/class-deduction89.C: New test.
	* g++.dg/cpp1z/class-deduction90.C: New test.
2021-06-23 08:24:34 -04:00
..
17_intro libstdc++: Avoid "__lockable" name defined as macro by newlib 2021-06-23 11:05:51 +01:00
18_support libstdc++: Implement LWG 3465 for std::compare_partial_order_fallback [PR101056] 2021-06-14 14:04:45 +01:00
19_diagnostics libstdc++: Remove redundant -std=gnu++17 option from remaining tests 2021-05-10 16:22:54 +01:00
20_util libstdc++: Remove garbage collection support for C++23 [P2186R2] 2021-06-22 20:58:43 +01:00
21_strings libstdc++: Suppress -Wstringop-overread warning in test 2021-06-18 11:15:28 +01:00
22_locale libstdc++: Fix new test for C++98 mode [PR 89728] 2021-06-01 19:02:42 +01:00
23_containers c++: CTAD and deduction guide selection [PR86439] 2021-06-23 08:24:34 -04:00
24_iterators libstdc++: Implement P2325 changes to default-constructibility of views 2021-06-17 22:29:03 -04:00
25_algorithms libstdc++: Reduce ranges::minmax/minmax_element comparison complexity 2021-06-18 19:33:39 -04:00
26_numerics libstdc++: Implement LWG 3422 for std::seed_seq 2021-06-22 20:58:25 +01:00
27_io libstdc++: Fix filesystem::path comparisons for C++23 2021-06-11 19:18:11 +01:00
28_regex libstdc++: Remove redundant -std=gnu++17 option from remaining tests 2021-05-10 16:22:54 +01:00
29_atomics libstd++: Only support atomic_ref::wait tests which are always lockfree 2021-06-09 13:46:03 -07:00
30_threads libstdc++: Avoid "__lockable" name defined as macro by newlib 2021-06-23 11:05:51 +01:00
abi Update copyright years. 2021-01-04 10:26:59 +01:00
backward Update copyright years. 2021-01-04 10:26:59 +01:00
config Update copyright years. 2021-01-04 10:26:59 +01:00
data
decimal Update copyright years. 2021-01-04 10:26:59 +01:00
experimental libstdc++: Only run Filesystem TS test if supported 2021-06-14 15:10:56 +01:00
ext libstdc++: Suppress more vstring testsuite warnings. [PR 98613] 2021-01-10 18:22:51 -05:00
lib Add 'dg-note', 'dg-lto-note' 2021-05-18 12:39:57 +02:00
libstdc++-abi Update copyright years. 2021-01-04 10:26:59 +01:00
libstdc++-dg libstdc++: Add std::experimental::simd from the Parallelism TS 2 2021-01-27 16:37:26 +00:00
libstdc++-prettyprinters libstdc++: Remove redundant -std=gnu++17 option from remaining tests 2021-05-10 16:22:54 +01:00
libstdc++-xmethods Update copyright years. 2021-01-04 10:26:59 +01:00
performance Update copyright years. 2021-01-04 10:26:59 +01:00
special_functions Update copyright years. 2021-01-04 10:26:59 +01:00
std libstdc++: Implement new views::split as per P2210 2021-06-20 12:47:18 -04:00
tr1 libstdc++: Fix some tests that fail in C++20 mode 2021-04-12 12:30:07 +01:00
tr2 Update copyright years. 2021-01-04 10:26:59 +01:00
util libstdc++: Revert final/non-addressable changes to ranges CPOs 2021-06-16 14:31:04 +01:00
Makefile.am libstdc++: Work around test failures using -mno-tree-vrp 2021-02-03 15:49:30 +00:00
Makefile.in libstdc++: Work around test failures using -mno-tree-vrp 2021-02-03 15:49:30 +00:00