c++: naming a dependently-scoped template for CTAD [PR104641]
commitd3b0dc686c00bfe9e7f4fe0490def68e9b92157a
authorPatrick Palka <ppalka@redhat.com>
Sat, 12 Mar 2022 20:00:51 +0000 (12 15:00 -0500)
committerPatrick Palka <ppalka@redhat.com>
Sat, 12 Mar 2022 20:00:51 +0000 (12 15:00 -0500)
tree28075dfe71b0a509f6b46e681ec9971663da8b15
parent03c83cf7aa1110e427beb00ea95767dfaf50d694
c++: naming a dependently-scoped template for CTAD [PR104641]

In order to be able to perform CTAD for a dependently-scoped template
(such as A<T>::B in the testcase below), we need to permit a
typename-specifier to resolve to a template as per [dcl.type.simple]/3,
at least when it appears in a CTAD-enabled context.

This patch implements this using a new tsubst flag tf_tst_ok to control
when a TYPENAME_TYPE is allowed to name a template, and sets this flag
when substituting into the type of a CAST_EXPR, CONSTRUCTOR or VAR_DECL
(each of which is a CTAD-enabled context).

PR c++/104641

gcc/cp/ChangeLog:

* cp-tree.h (tsubst_flags::tf_tst_ok): New flag.
* decl.cc (make_typename_type): Allow a typename-specifier to
resolve to a template when tf_tst_ok, in which case return
a CTAD placeholder for the template.
* pt.cc (tsubst_decl) <case VAR_DECL>: Set tf_tst_ok when
substituting the type.
(tsubst): Clear tf_tst_ok and remember if it was set.
<case TYPENAME_TYPE>: Pass tf_tst_ok to make_typename_type
appropriately.
(tsubst_copy) <case CAST_EXPR>: Set tf_tst_ok when substituting
the type.
(tsubst_copy_and_build) <case CAST_EXPR>: Likewise.
<case CONSTRUCTOR>: Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/class-deduction107.C: New test.
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp1z/class-deduction107.C [new file with mode: 0644]