]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: CTAD and forwarding references [PR88252]
authorPatrick Palka <ppalka@redhat.com>
Wed, 14 Jul 2021 19:37:30 +0000 (15:37 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 14 Jul 2021 19:37:30 +0000 (15:37 -0400)
commitbebd8e9da838c51a7f911985083d5a2b2498a23a
tree1f1fa33ea953166342a0ca303c3b0fa75c3ea7df
parent91bb571d200e551f427e337e00494e0b4f229876
c++: CTAD and forwarding references [PR88252]

Here during CTAD we're incorrectly treating T&& as a forwarding
reference even though T is a template parameter of the class template.

This happens because the template parameter T in the out-of-line
definition of the constructor doesn't have the flag
TEMPLATE_TYPE_PARM_FOR_CLASS set, and during duplicate_decls the
the redeclaration (which is in terms of this unflagged T) prevails.
To fix this, we could perhaps be more consistent about setting the flag,
but it appears we don't really need this flag to make the determination.

Since the template parameters of an synthesized guide consist of the
template parameters of the class template followed by those of the
constructor (if any), it should suffice to look at the index of the
template parameter to determine whether it comes from the class
template or the constructor (template).  This patch replaces the
TEMPLATE_TYPE_PARM_FOR_CLASS flag with this approach.

PR c++/88252

gcc/cp/ChangeLog:

* cp-tree.h (TEMPLATE_TYPE_PARM_FOR_CLASS): Remove.
* pt.c (push_template_decl): Remove TEMPLATE_TYPE_PARM_FOR_CLASS
handling.
(redeclare_class_template): Likewise.
(forwarding_reference_p): Define.
(maybe_adjust_types_for_deduction): Use it instead.  Add 'tparms'
parameter.
(unify_one_argument): Pass tparms to
maybe_adjust_types_for_deduction.
(try_one_overload): Likewise.
(unify): Likewise.
(rewrite_template_parm): Remove TEMPLATE_TYPE_PARM_FOR_CLASS
handling.

gcc/testsuite/ChangeLog:

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