https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95568
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>: https://gcc.gnu.org/g:b1005f553d3543bb56dc6b9b34ee35455d697ca4 commit r11-1713-gb1005f553d3543bb56dc6b9b34ee35455d697ca4 Author: Marek Polacek <pola...@redhat.com> Date: Tue Jun 23 18:07:34 2020 -0400 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.