c++: Avoid considering some conversion ops [PR97600]
authorJason Merrill <jason@redhat.com>
Fri, 11 Dec 2020 19:37:09 +0000 (14:37 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 11 Dec 2020 20:41:02 +0000 (15:41 -0500)
commit9324f7a25c7161a813bfae6cc2d180784b165740
tree4301375bb12ac00dd881ca8429bf08be4a112a6f
parent8bab7dce62e321e722346ba2db2d381bdf3fbe4b
c++: Avoid considering some conversion ops [PR97600]

Patrick's earlier patch to check convertibility before constraints for
conversion ops wasn't suitable because checking convertibility can also lead
to unwanted instantiations, but it occurs to me that there's a smaller check
we can do to avoid doing normal consideration of the conversion ops in this
case: since we're in the middle of a user-defined conversion, we can exclude
from consideration any conversion ops that return a type that would need an
additional user-defined conversion to reach the desired type: namely, a type
that differs in class-ness from the desired type.

[temp.inst]/9 allows optimizations like this: "If the function selected by
overload resolution can be determined without instantiating a class template
definition, it is unspecified whether that instantiation actually takes
place."

gcc/cp/ChangeLog:

PR libstdc++/97600
* call.c (build_user_type_conversion_1): Avoid considering
conversion functions that return a clearly unsuitable type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-conv3.C: New test.
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp2a/concepts-conv3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-conv3a.C [new file with mode: 0644]