From 76dc465aaf1b74bf92143510b6db5671e1c053d6 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Mon, 31 Jan 2022 15:27:58 -0500 Subject: [PATCH] c++: CTAD for class tmpl defined inside partial spec [PR104294] Here during deduction guide generation for the nested class template B::C, the computation of outer_args yields the template arguments relative to the primary template for B (i.e. {char(int)}) but what we really want is those relative to C's enclosing scope, the partial specialization of B (i.e. {char, int}). PR c++/104294 gcc/cp/ChangeLog: * pt.cc (ctor_deduction_guides_for): Correct computation of outer_args. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/class-deduction106.C: New test. --- gcc/cp/pt.cc | 4 +++- gcc/testsuite/g++.dg/cpp1z/class-deduction106.C | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction106.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 84d63f9..feee629 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -29563,7 +29563,9 @@ ctor_deduction_guides_for (tree tmpl, tsubst_flags_t complain) if (DECL_CLASS_SCOPE_P (tmpl) && CLASSTYPE_TEMPLATE_INSTANTIATION (DECL_CONTEXT (tmpl))) { - outer_args = CLASSTYPE_TI_ARGS (DECL_CONTEXT (tmpl)); + outer_args = copy_node (CLASSTYPE_TI_ARGS (type)); + gcc_assert (TMPL_ARGS_DEPTH (outer_args) > 1); + --TREE_VEC_LENGTH (outer_args); type = TREE_TYPE (most_general_template (tmpl)); } diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction106.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction106.C new file mode 100644 index 0000000..b4c4d26 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction106.C @@ -0,0 +1,16 @@ +// PR c++/104294 +// { dg-do compile { target c++17 } } + +template struct B; + +template +struct B { + template struct C { C(T); }; + C(decltype(nullptr)) -> C; +}; + +using ty1 = decltype(B::C{0}); +using ty1 = B::C; + +using ty2 = decltype(B::C{nullptr}); +using ty2 = B::C; -- 2.7.4