Here during deduction guide generation for the nested class template
B<char(int)>::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.
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));
}
--- /dev/null
+// PR c++/104294
+// { dg-do compile { target c++17 } }
+
+template<class> struct B;
+
+template<class R, class... Args>
+struct B<R(Args...)> {
+ template<class T> struct C { C(T); };
+ C(decltype(nullptr)) -> C<void*>;
+};
+
+using ty1 = decltype(B<char(int)>::C{0});
+using ty1 = B<char(int)>::C<int>;
+
+using ty2 = decltype(B<char(int)>::C{nullptr});
+using ty2 = B<char(int)>::C<void*>;