From: Patrick Palka Date: Thu, 15 May 2025 15:07:53 +0000 (-0400) Subject: c++: unifying specializations of non-primary tmpls [PR120161] X-Git-Tag: releases/gcc-15.2.0~511 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=488c997aeb6669c333287a1f0063ce5fb706a8b5;p=thirdparty%2Fgcc.git c++: unifying specializations of non-primary tmpls [PR120161] Here unification of P=Wrap::type, A=Wrap::type wrongly succeeds ever since r14-4112 which made the RECORD_TYPE case of unify no longer recurse into template arguments for non-primary templates (since they're a non-deduced context) and so the int/long mismatch that makes the two types distinct goes unnoticed. In the case of (comparing specializations of) a non-primary template, unify should still go on to compare the types directly before returning success. PR c++/120161 gcc/cp/ChangeLog: * pt.cc (unify) : When comparing specializations of a non-primary template, still perform a type comparison. gcc/testsuite/ChangeLog: * g++.dg/template/unify13.C: New test. Reviewed-by: Jason Merrill (cherry picked from commit 0c430503f2849ebb20105695b8ad40d43d797c7b) --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 96230b444c0..be9af50f44f 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -25797,10 +25797,10 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (parm)), INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (t)), UNIFY_ALLOW_NONE, explain_p); - else - return unify_success (explain_p); + gcc_checking_assert (t == arg); } - else if (!same_type_ignoring_top_level_qualifiers_p (parm, arg)) + + if (!same_type_ignoring_top_level_qualifiers_p (parm, arg)) return unify_type_mismatch (explain_p, parm, arg); return unify_success (explain_p); diff --git a/gcc/testsuite/g++.dg/template/unify13.C b/gcc/testsuite/g++.dg/template/unify13.C new file mode 100644 index 00000000000..ec7ca9d17a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/unify13.C @@ -0,0 +1,18 @@ +// PR c++/120161 + +template +struct mp_list { }; + +template +struct Wrap { struct type { }; }; + +struct A : mp_list::type, void> + , mp_list::type, void> { }; + +template +void f(mp_list::type, U>*); + +int main() { + A a; + f(&a); +}