From: Jason Merrill Date: Wed, 14 Apr 2021 18:14:31 +0000 (-0400) Subject: c++: premature overload resolution redux [PR100078] X-Git-Tag: basepoints/gcc-12~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00a2774923c1dc5666cd26bb9b8c37b1b7dd689d;p=thirdparty%2Fgcc.git c++: premature overload resolution redux [PR100078] My patch for PR93085 didn't consider that a default template argument can also make a template dependent. gcc/cp/ChangeLog: PR c++/100078 PR c++/93085 * pt.c (uses_outer_template_parms): Also look at default template argument. gcc/testsuite/ChangeLog: PR c++/100078 * g++.dg/template/dependent-tmpl2.C: New test. --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f488a5a8c120..0f119a552720 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10856,6 +10856,7 @@ uses_outer_template_parms (tree decl) for (int i = TREE_VEC_LENGTH (parms) - 1; i >= 0; --i) { tree parm = TREE_VALUE (TREE_VEC_ELT (parms, i)); + tree defarg = TREE_PURPOSE (TREE_VEC_ELT (parms, i)); if (TREE_CODE (parm) == PARM_DECL && for_each_template_parm (TREE_TYPE (parm), template_parm_outer_level, @@ -10864,6 +10865,10 @@ uses_outer_template_parms (tree decl) if (TREE_CODE (parm) == TEMPLATE_DECL && uses_outer_template_parms (parm)) return true; + if (defarg + && for_each_template_parm (defarg, template_parm_outer_level, + &depth, NULL, /*nondeduced*/true)) + return true; } } tree ci = get_constraints (decl); diff --git a/gcc/testsuite/g++.dg/template/dependent-tmpl2.C b/gcc/testsuite/g++.dg/template/dependent-tmpl2.C new file mode 100644 index 000000000000..040ddb47ee61 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/dependent-tmpl2.C @@ -0,0 +1,10 @@ +// PR c++/100078 +// { dg-do compile { target c++11 } } + +template struct enable_if; +template struct HashMapBucket { + template + static typename enable_if::type selectStructure() { + selectStructure(); + } +};