]> gcc.gnu.org Git - gcc.git/commit
c++: cv-quals of dummy obj for non-dep memfn call [PR105637]
authorPatrick Palka <ppalka@redhat.com>
Fri, 3 Jun 2022 16:06:59 +0000 (12:06 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 3 Jun 2022 16:06:59 +0000 (12:06 -0400)
commit44a5bd6d933d86ed988fc4695aa00f122cf83eb4
tree1f6aec81644279b919bf874b9a89b69775b3fe06
parent6a098f4e16351617ebbb9ad66fb802e8c4a57c77
c++: cv-quals of dummy obj for non-dep memfn call [PR105637]

In non-dependent23.C below we expect the Base::foo calls to
resolve to the second, third and fourth overloads respectively in light
of the cv-qualifiers of 'this' in each case.  But ever since
r12-6075-g2decd2cabe5a4f, the calls incorrectly resolve to the first
overload at instantiation time.

This happens because the calls to Base::foo are all deemed
non-dependent (ever since r7-755-g23cb72663051cd made us ignore 'this'
dependence when considering the dependence of a non-static memfn call),
hence we end up checking the call ahead of time, using as the object
argument a dummy object of type Base.  Since this object argument is
cv-unqualified, the calls in turn resolve to the unqualified overload
of baseDevice.  Before r12-6075 this incorrect result would just get
silently discarded and we'd end up redoing OR at instantiation time
using 'this' as the object argument.  But after r12-6075 we now reuse
this incorrect result at instantiation time.

This patch fixes this by making maybe_dummy_object respect the cv-quals
of (the non-lambda) 'this' when returning a dummy object.  Thus, ahead
of time OR using a dummy object will give us the right answer that's
consistent with the instantiation time answer.

An earlier version of this patch didn't handle 'this'-capturing lambdas
correctly, which broke lambda-this22.C below.

PR c++/105637

gcc/cp/ChangeLog:

* tree.cc (maybe_dummy_object): When returning a dummy
object, respect the cv-quals of 'this' if available.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-this22.C: New test.
* g++.dg/template/non-dependent23.C: New test.
gcc/cp/tree.cc
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this22.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/non-dependent23.C [new file with mode: 0644]
This page took 0.066422 seconds and 6 git commands to generate.