From: Patrick Palka Date: Wed, 22 Apr 2020 19:57:39 +0000 (-0400) Subject: c++: Inherited constructor template arguments [PR94719] X-Git-Tag: upstream/12.2.0~17137 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72d0ef73d2cd46bda2f28e1866d637cfe8edb208;p=platform%2Fupstream%2Fgcc.git c++: Inherited constructor template arguments [PR94719] My fix for PR94549 broke constraints_satisfied_p in the case where the inherited constructor decl points to an instantiation of a constructor template coming from an instantiation of a class template. This is because the DECL_TI_ARGS of the inherited constructor decl in this case contains only the innermost level of template arguments (those for the constructor template), but constraint satisfaction expects to have the full set of template arguments. This causes template argument substitution during constraint satisfaction to fail in various ways. On the other hand, the DECL_TI_ARGS of the DECL_INHERITED_CTOR is a full set of template arguments but with the innermost level still in its dependent form, which is the source of PR94549. So if we could combine these two sets of template arguments then we'd be golden. This patch does just that, by effectively reverting the fix for PR94549 and instead using add_outermost_template_args to combine the template arguments of the inherited constructor decl with those of its DECL_INHERITED_CTOR. gcc/cp/ChangeLog: PR c++/94719 PR c++/94549 * constraint.cc (satisfy_declaration_constraints): If the inherited constructor points to an instantiation of a constructor template, remember and use its attached template arguments. gcc/testsuite/ChangeLog: PR c++/94719 PR c++/94549 * g++.dg/cpp2a/concepts-inherit-ctor9.C: New test. --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b298db4..7380a20 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2020-04-22 Patrick Palka + + PR c++/94719 + PR c++/94549 + * constraint.cc (satisfy_declaration_constraints): If the inherited + constructor points to an instantiation of a constructor template, + remember and use its attached template arguments. + 2020-04-22 Jonathan Wakely PR translation/94698 diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c05fafe..06161b8 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -2736,12 +2736,17 @@ static tree satisfy_declaration_constraints (tree t, subst_info info) { gcc_assert (DECL_P (t)); + const tree saved_t = t; - if (!DECL_TEMPLATE_INFO (t)) - /* For inherited constructors without template information, consider - the original declaration; it has the correct template information - attached. */ - t = strip_inheriting_ctors (t); + /* For inherited constructors, consider the original declaration; + it has the correct template information attached. */ + t = strip_inheriting_ctors (t); + tree inh_ctor_targs = NULL_TREE; + if (t != saved_t) + if (tree ti = DECL_TEMPLATE_INFO (saved_t)) + /* The inherited constructor points to an instantiation of a constructor + template; remember its template arguments. */ + inh_ctor_targs = TI_ARGS (ti); /* Update the declaration for diagnostics. */ info.in_decl = t; @@ -2761,6 +2766,8 @@ satisfy_declaration_constraints (tree t, subst_info info) /* The initial parameter mapping is the complete set of template arguments substituted into the declaration. */ args = TI_ARGS (ti); + if (inh_ctor_targs) + args = add_outermost_template_args (args, inh_ctor_targs); } else { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 955418f..1115eb7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-04-22 Patrick Palka + + PR c++/94719 + PR c++/94549 + * g++.dg/cpp2a/concepts-inherit-ctor9.C: New test. + 2020-04-22 Marek Polacek PR c++/93807 diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor9.C b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor9.C new file mode 100644 index 0000000..7d3201b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor9.C @@ -0,0 +1,20 @@ +// PR c++/94719 +// { dg-do compile { target concepts } } + +template +struct bar +{ + template requires (N == 5) + bar() { } +}; + +template +struct foo : bar +{ + using foo::bar::bar; +}; + +void baz() +{ + foo{}; +}