c++: Recursive unification with packs and explicit targs [PR94628]
authorPatrick Palka <ppalka@redhat.com>
Mon, 20 Apr 2020 22:34:00 +0000 (18:34 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 20 Apr 2020 22:34:00 +0000 (18:34 -0400)
commita3a4f6be0c7ac1536c4d1def14217840b04dd488
tree37f4719987f10bc9a7e8eb93b53b3b75a09f18d9
parent58d4cf217dab69f64e6cf779fc6be8ef2837afe6
c++: Recursive unification with packs and explicit targs [PR94628]

This PR seems to be similar to PR c++/43382, except that the recursive call to
the variadic function with trailing return type in this testcase is additionally
given some explicit template arguments.

In the first testcase below, when resolving the recursive call to 'select',
fn_type_unification first substitutes in the call's explicit template arguments
before doing unification, and so during this substitution the template argument
pack for Args is incomplete.

Since the pack is incomplete, the substitution of 'args...' in the trailing
return type decltype(f(args...)) is handled by the unsubstituted_packs case of
tsubst_pack_expansion.  But the handling of this case happens _before_ we reset
local_specializations, and so the substitution ends up reusing the old binding
for 'args' from local_specializations rather than building a new one.

This patch fixes this issue by setting up local_specializations sooner in
tsubst_pack_expansion, before the handling of the unsubstituted_packs case.
It also adds a new policy to local_specialization_stack so that we could use the
class here to conditionally replace local_specializations.

gcc/cp/ChangeLog:

PR c++/94628
* cp-tree.h (lss_policy::lss_nop): New enumerator.
* pt.c (local_specialization_stack::local_specialization_stack): Handle
an lss_nop policy.
(local_specialization_stack::~local_specialization_stack): Likewise.
(tsubst_pack_expansion): Use a local_specialization_stack instead of
manually saving and restoring local_specializations.  Conditionally
replace local_specializations sooner, before the handling of the
unsubstituted_packs case.

gcc/testsuite/ChangeLog:

PR c++/94628
* g++.dg/cpp0x/variadic179.C: New test.
* g++.dg/cpp0x/variadic180.C: New test.
gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/variadic179.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/variadic180.C [new file with mode: 0644]