From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 2CE7C3857016; Mon, 18 Sep 2023 18:41:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CE7C3857016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695062481; bh=UGX3a4vjWnQPNzX+0ivFzxJIhnQ5G9aAZ6jb25IhP1M=; h=From:To:Subject:Date:From; b=MYi7rpmJfe8GJ8fpig97kWZfhDGIiq2zjZm6ygBvsa2Vow4Uee91hSxQ/k/pIzIgs YHXr6XPw/IxLlGJSgkrDL92Di1Vo7JbNhsFoUM6ayBOrplT713YI6WJX+XHkKMiMMm e8i6YHhGK0uzM/Nme8zzi6EvJN8przeTHi+OUF2k= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4110] c++: unifying identical tmpls from current inst [PR108347] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 155178ccb5f5bc89dcc8261ae1b64bc2fbfdbd45 X-Git-Newrev: a6ac1fc64c3caed19da65c2e6b12f8ddaf551231 Message-Id: <20230918184121.2CE7C3857016@sourceware.org> Date: Mon, 18 Sep 2023 18:41:21 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a6ac1fc64c3caed19da65c2e6b12f8ddaf551231 commit r14-4110-ga6ac1fc64c3caed19da65c2e6b12f8ddaf551231 Author: Patrick Palka Date: Mon Sep 18 14:41:07 2023 -0400 c++: unifying identical tmpls from current inst [PR108347] Here more_specialized_partial_spec wrongly considers the two partial specializations to be unordered ultimately because unify for identical parm=arg=A::C returns failure due to C being dependent. This patch fixes this by relaxing unify's early-exit identity test to also accept dependent decls; we can't deduce anything further from them anyway. In passing this patch removes the CONST_DECL case of unify: we should never see the CONST_DECL version of a template parameter here, and for other CONST_DECLs (such as enumerators) it seems we can rely on them to already have been folded to their DECL_INITIAL. PR c++/108347 gcc/cp/ChangeLog: * pt.cc (unify): Return unify_success for identical dependent DECL_P 'arg' and 'parm'. : Remove handling. gcc/testsuite/ChangeLog: * g++.dg/template/ttp41.C: New test. Diff: --- gcc/cp/pt.cc | 10 ++++------ gcc/testsuite/g++.dg/template/ttp41.C | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index a40b8953e62..31ff80ea6e7 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -24559,7 +24559,8 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, even if ARG == PARM, since we won't record unifications for the template parameters. We might need them if we're trying to figure out which of two things is more specialized. */ - if (arg == parm && !uses_template_parms (parm)) + if (arg == parm + && (DECL_P (parm) || !uses_template_parms (parm))) return unify_success (explain_p); /* Handle init lists early, so the rest of the function can assume @@ -25278,11 +25279,8 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, strict, explain_p); case CONST_DECL: - if (DECL_TEMPLATE_PARM_P (parm)) - return unify (tparms, targs, DECL_INITIAL (parm), arg, strict, explain_p); - if (arg != scalar_constant_value (parm)) - return unify_template_argument_mismatch (explain_p, parm, arg); - return unify_success (explain_p); + /* CONST_DECL should already have been folded to its DECL_INITIAL. */ + gcc_unreachable (); case FIELD_DECL: case TEMPLATE_DECL: diff --git a/gcc/testsuite/g++.dg/template/ttp41.C b/gcc/testsuite/g++.dg/template/ttp41.C new file mode 100644 index 00000000000..c81e5dd2405 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp41.C @@ -0,0 +1,17 @@ +// PR c++/108347 + +template +struct A { + template struct C { }; + + template class TT, class U> + struct B; + + template + struct B; + + template + struct B { }; +}; + +A::B::C, const int*> b;