c++: local alias in typename in lambda [PR105518]
authorPatrick Palka <ppalka@redhat.com>
Thu, 15 Dec 2022 20:54:31 +0000 (15:54 -0500)
committerPatrick Palka <ppalka@redhat.com>
Thu, 15 Dec 2022 20:54:31 +0000 (15:54 -0500)
commitbe124477b38a71ba8ba0b24d859ae764bb44a4eb
tree75410ad2cd9d58aa08e91983acef4d5ba11f213c
parent38304846d18d6bb14b0fd6c627c5c6d43a814d01
c++: local alias in typename in lambda [PR105518]

We substitute the qualifying scope of a TYPENAME_TYPE directly using
tsubst_aggr_type (so that we can pass entering_scope=true) instead of
going through tsubst, which means we don't properly reuse typedefs
during this substitution.  This ends up causing us to reject the below
testcase because we substitute the TYPENAME_TYPE alias::type as if it
were written without the A<t> alias, and thus we expect the non-capturing
lambda to capture t.

This patch fixes this by making tsubst_aggr_type delegate typedefs
to tsubst so that get consistently reused, and then adjusting the result
appropriately if entering_scope is true.  In passing, this refactors
tsubst_aggr_type into two functions, one that's intended to be called
directly and a more minimal one that's intended to be called only from
the RECORD/UNION/ENUMERAL_TYPE cases of tsubst (and contains only the
necessary bits for that call site).

PR c++/105518

gcc/cp/ChangeLog:

* pt.cc (tsubst_aggr_type): Handle typedefs by delegating to
tsubst and adjusting the result if entering_scope.  Split out
the main part of the function into ...
(tsubst_aggr_type_1) ... here.
(tsubst): Use tsubst_aggr_type_1 instead of tsubst_aggr_type.
Handle TYPE_PTRMEMFUNC_P RECORD_TYPEs here instead of in
tsubst_aggr_type_1.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-alias1.C: New test.
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-alias1.C [new file with mode: 0644]