c++: refine CWG 2369 satisfaction vs non-dep convs [PR99599]
commit2154bcd6d43cfd821ca70e1583880c4ed955355d
authorPatrick Palka <ppalka@redhat.com>
Fri, 8 Sep 2023 16:02:20 +0000 (8 12:02 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 8 Sep 2023 16:02:20 +0000 (8 12:02 -0400)
tree08a66354526ac2493844e746e13c4225acce4e02
parentd8bdc978dc9cd4a6210997edacedb954375af70d
c++: refine CWG 2369 satisfaction vs non-dep convs [PR99599]

As described in detail in the PR, the CWG 2369 resolution has the
surprising consequence of introducing constraint recursion in seemingly
valid and innocent code.

This patch attempts to fix this surpising behavior for the majority of
problematic cases.  Rather than checking satisfaction before _all_
non-dependent conversions, as specified by the CWG resolution, this patch
makes us first check "safe" non-dependent conversions, then satisfaction,
then followed by other non-dependent conversions.  A conversion is
considered "safe" if computing it is guaranteed to not induce template
instantiation, and we conservatively determine this by checking for
user-declared constructors (resp. conversion functions) in the parm
(resp. arg) class type, roughly.

PR c++/99599

gcc/cp/ChangeLog:

* pt.cc (check_non_deducible_conversions): Add bool parameter
passed down to check_non_deducible_conversion.
(fn_type_unification): Call check_non_deducible_conversions
an extra time before satisfaction with noninst_only_p=true.
(conversion_may_instantiate_p): Define.
(check_non_deducible_conversion): Add bool parameter controlling
whether to compute only conversions that are guaranteed to
not induce template instantiation.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-recursive-sat4.C: Make 'Int' non-aggregate
in order to preserve intent of the testcase.
* g++.dg/cpp2a/concepts-nondep4.C: New test.
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/concepts-nondep4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-recursive-sat4.C