public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/86439] CTAD with deleted copy constructor fails due to deduction-guide taking by value
[not found] <bug-86439-4@http.gcc.gnu.org/bugzilla/>
@ 2021-06-21 12:56 ` ppalka at gcc dot gnu.org
2021-06-22 14:25 ` ppalka at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-21 12:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86439
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC| |ppalka at gcc dot gnu.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/86439] CTAD with deleted copy constructor fails due to deduction-guide taking by value
[not found] <bug-86439-4@http.gcc.gnu.org/bugzilla/>
2021-06-21 12:56 ` [Bug c++/86439] CTAD with deleted copy constructor fails due to deduction-guide taking by value ppalka at gcc dot gnu.org
@ 2021-06-22 14:25 ` ppalka at gcc dot gnu.org
2021-06-23 12:25 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-22 14:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86439
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Another side effect of this is that GCC incorrectly rejects the following use
of CTAD + braced-init-lists:
struct B { };
struct C { };
template<class T>
struct A {
A(T, B);
};
template<class T>
A(T, C) -> A<T>;
A a(0, {});
The problem is that building the call to the deduction guide has the side
effect of changing the type of the {} to C, which causes later overload
resolution to fail because C isn't convertible to B.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/86439] CTAD with deleted copy constructor fails due to deduction-guide taking by value
[not found] <bug-86439-4@http.gcc.gnu.org/bugzilla/>
2021-06-21 12:56 ` [Bug c++/86439] CTAD with deleted copy constructor fails due to deduction-guide taking by value ppalka at gcc dot gnu.org
2021-06-22 14:25 ` ppalka at gcc dot gnu.org
@ 2021-06-23 12:25 ` cvs-commit at gcc dot gnu.org
2021-07-09 19:34 ` ppalka at gcc dot gnu.org
2021-09-01 14:13 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-23 12:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86439
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:3eecc1db4c691a87ef4a229d059aa863066d9a1c
commit r12-1744-g3eecc1db4c691a87ef4a229d059aa863066d9a1c
Author: Patrick Palka <ppalka@redhat.com>
Date: Wed Jun 23 08:24:34 2021 -0400
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/86439] CTAD with deleted copy constructor fails due to deduction-guide taking by value
[not found] <bug-86439-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2021-06-23 12:25 ` cvs-commit at gcc dot gnu.org
@ 2021-07-09 19:34 ` ppalka at gcc dot gnu.org
2021-09-01 14:13 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-07-09 19:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86439
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |toe-ger at web dot de
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 88026 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/86439] CTAD with deleted copy constructor fails due to deduction-guide taking by value
[not found] <bug-86439-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2021-07-09 19:34 ` ppalka at gcc dot gnu.org
@ 2021-09-01 14:13 ` ppalka at gcc dot gnu.org
4 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-09-01 14:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86439
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-01 14:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-86439-4@http.gcc.gnu.org/bugzilla/>
2021-06-21 12:56 ` [Bug c++/86439] CTAD with deleted copy constructor fails due to deduction-guide taking by value ppalka at gcc dot gnu.org
2021-06-22 14:25 ` ppalka at gcc dot gnu.org
2021-06-23 12:25 ` cvs-commit at gcc dot gnu.org
2021-07-09 19:34 ` ppalka at gcc dot gnu.org
2021-09-01 14:13 ` ppalka at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).