]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: decltype of (by-value captured reference) [PR79620]
authorPatrick Palka <ppalka@redhat.com>
Fri, 10 Nov 2023 15:58:06 +0000 (10:58 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 10 Nov 2023 15:58:06 +0000 (10:58 -0500)
commit0410b754e56c0868203c2412e0585ba070ea938d
tree3c2a2bd33d3585d2314b142b2639dda65f33f3b1
parent705ab7927c81b77503d229513fac991106617766
c++: decltype of (by-value captured reference) [PR79620]

The capture_decltype handling in finish_decltype_type wasn't looking
through implicit INDIRECT_REF (added by convert_from_reference), which
caused us to incorrectly resolve decltype((r)) to float& below.  This
patch fixes this, and adds an assert to outer_automatic_var_p to help
prevent against such bugs.

We still don't fully accept the example ultimately because for the
decltype inside the lambda's trailing return type, at that point we're
in lambda type scope but not yet in lambda function scope that the
capture_decltype handling looks for (which is an orthogonal bug).

PR c++/79620

gcc/cp/ChangeLog:

* cp-tree.h (STRIP_REFERENCE_REF): Define.
* semantics.cc (outer_var_p): Assert REFERENCE_REF_P is false.
(finish_decltype_type): Look through implicit INDIRECT_REF when
deciding whether to call capture_decltype.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-decltype3.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-tree.h
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype3.C [new file with mode: 0644]