c++: Fix CTAD for aggregates in template [PR95568]
authorMarek Polacek <polacek@redhat.com>
Tue, 23 Jun 2020 22:07:34 +0000 (18:07 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 29 Jun 2020 14:59:40 +0000 (10:59 -0400)
commitb1005f553d3543bb56dc6b9b34ee35455d697ca4
treeddc4fa81ca1981181cb8c136953fe8abd262e86d
parente6cc67f6616c96f3e18a434e0c74ba2f3818cb6d
c++: Fix CTAD for aggregates in template [PR95568]

95568 complains that CTAD for aggregates doesn't work within
requires-clause and it turned out that it doesn't work when we try
the deduction in a template.  The reason is that maybe_aggr_guide
creates a guide that can look like this

  template<class T> X(decltype (X<T>::x))-> X<T>

where the parameter is a decltype, which is a non-deduced context.  So
the subsequent build_new_function_call fails because unify_one_argument
can't deduce anything from it ([temp.deduct.type]: "If a template
parameter is used only in non-deduced contexts and is not explicitly
specified, template argument deduction fails.")

Those decltypes come from finish_decltype_type.  We can just use
TREE_TYPE instead.  I pondered using unlowered_expr_type, but that
didn't make any difference for the FIELD_DECLs I saw in
class-deduction-aggr6.C.

gcc/cp/ChangeLog:

PR c++/95568
* pt.c (collect_ctor_idx_types): Use TREE_TYPE.

gcc/testsuite/ChangeLog:

PR c++/95568
* g++.dg/cpp2a/class-deduction-aggr5.C: New test.
* g++.dg/cpp2a/class-deduction-aggr6.C: New test.
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr6.C [new file with mode: 0644]