c++: Make convert_like complain about bad ck_ref_bind again [PR95789]
authorMarek Polacek <polacek@redhat.com>
Tue, 23 Jun 2020 01:26:49 +0000 (21:26 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 14 Jul 2020 20:02:39 +0000 (16:02 -0400)
commit8e64d182850560dbedfabb88aac90d4fc6155067
treea468074edc704d74694205b893742e8dcf6dcd09
parent0c78f438fafdc2f4b2fc3a4d385f814378e3d3f5
c++: Make convert_like complain about bad ck_ref_bind again [PR95789]

convert_like issues errors about bad_p conversions at the beginning
of the function, but in the ck_ref_bind case, it only issues them
after we've called convert_like on the next conversion.

This doesn't work as expected since r10-7096 because when we see
a conversion from/to class type in a template, we return early, thereby
missing the error, and a bad_p conversion goes by undetected.  That
made the attached test to compile even though it should not.

I had thought that I could just move the ck_ref_bind/bad_p errors
above to the rest of them, but that regressed diagnostics because
expr then wasn't converted yet by the nested convert_like_real call.

So, for bad_p conversions, do the normal processing, but still return
the IMPLICIT_CONV_EXPR to avoid introducing trees that the template
processing can't handle well.  This I achieved by adding a wrapper
function.

gcc/cp/ChangeLog:

PR c++/95789
PR c++/96104
PR c++/96179
* call.c (convert_like_real_1): Renamed from convert_like_real.
(convert_like_real): New wrapper for convert_like_real_1.

gcc/testsuite/ChangeLog:

PR c++/95789
PR c++/96104
PR c++/96179
* g++.dg/conversion/ref4.C: New test.
* g++.dg/conversion/ref5.C: New test.
* g++.dg/conversion/ref6.C: New test.
gcc/cp/call.c
gcc/testsuite/g++.dg/conversion/ref4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/conversion/ref5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/conversion/ref6.C [new file with mode: 0644]