From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0F86C3858C83 for ; Fri, 22 Apr 2022 19:27:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0F86C3858C83 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-199-aQmbC1pgOLKzUzT41_MXfg-1; Fri, 22 Apr 2022 15:27:14 -0400 X-MC-Unique: aQmbC1pgOLKzUzT41_MXfg-1 Received: by mail-qt1-f198.google.com with SMTP id i3-20020ac813c3000000b002f202d9471dso5599522qtj.15 for ; Fri, 22 Apr 2022 12:27:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=WN/xZ5aqzlEsbysnE31VLHBe71Sour1EsnRVYcbVvIA=; b=JCJoW+f86cdJxsEdJeLS1ggkphthXo+f+HGq0B2tsImzHSD9555Wve7JIlyF+3+Kon fM7qpVTB7fgWdGA74gpmatXeYysSJ7Xreu5xkVE+hdk/2ndeFrkbiHNvXVxa15R59nFR StH6j9sxFH9zD6iU11TkRr+y3Z3hF2YhqYXwW8WvkgRIt0uUwg6SxpylFW+7pE+p84Cx /TLGrtCy8CuMRL7TXLmfCENesUTjrkEaQsYz9yTQKJRHYtapliElh768E2YeIhPYMeFi 2t8WgLEepY4aaR+kRQIIbm2g7cXGEHtBbrlbPa+yvXHjOSuKH0eGMqvw6WaZplLig/aD TMlg== X-Gm-Message-State: AOAM530cUQQowq77KWOE2DGAQO3my7rZIEU5sDg4s+O0RfsYrKwJa3YR 7Kk9hD6eY2eWENKTVz6niyJZS2lMYbrZuny5+Cem98RR49MytiPvHPOEK59xitoyRd+mKN8mkwv qJn33v0fAkZPOfw12fw== X-Received: by 2002:a05:6214:76d:b0:443:6801:6d0f with SMTP id f13-20020a056214076d00b0044368016d0fmr4605532qvz.60.1650655634134; Fri, 22 Apr 2022 12:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEHMDJd8W9JXU5ghUaExH1EF0j7PU3sm4DU9HhKBDzC8tLEiyKxYQ6NTMzRgcWMPxbveoduA== X-Received: by 2002:a05:6214:76d:b0:443:6801:6d0f with SMTP id f13-20020a056214076d00b0044368016d0fmr4605513qvz.60.1650655633864; Fri, 22 Apr 2022 12:27:13 -0700 (PDT) Received: from [192.168.1.130] (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id v9-20020a05622a130900b002f21e88d93fsm1738624qtk.45.2022.04.22.12.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:27:13 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 22 Apr 2022 15:27:12 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] c++: partial ordering with dependent NTTP type [PR105289] In-Reply-To: <20220422175032.3106274-1-ppalka@redhat.com> Message-ID: <6292a77d-f373-4158-036d-9a56e599bccf@idea> References: <20220422175032.3106274-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Apr 2022 19:27:18 -0000 On Fri, 22 Apr 2022, Patrick Palka wrote: > Here ever since r11-6483-ge2e2f3f2c9400f we're rejecting and crashing > (respectively) on two testcases that we used to accept in C++17 mode. > Both testcases declare partial specializations for which the primary > template contains an NTTP with dependent type, but the correctness of > these partial specializations is unclear according to PR86193. > > This patch restores the previous C++17 behavior for such partial > specializations by restricting the r11-6483 change to just ordinary > deduction as opposed to deduction for sake of partial ordering. Note that if we're okay with rejecting such partial specializations even in C++17 mode (and thus deeming PR105289 to be ICE-on-invalid instead of ICE-on-valid), then the fix for the reported ICE is just: diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index dde62ee052d..6d65f6ad3cf 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -24299,7 +24299,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, /* Now check whether the type of this parameter is still dependent, and give up if so. */ ++processing_template_decl; - tparm = tsubst (tparm, targs, tf_none, NULL_TREE); + tparm = tsubst (TREE_TYPE (parm), targs, tf_none, NULL_TREE); --processing_template_decl; if (uses_template_parms (tparm)) return unify_success (explain_p); i.e. we need to substitute into the original NTTP type, not into the already substituted NTTP type. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk/11? > > PR c++/105289 > PR c++/86193 > > gcc/cp/ChangeLog: > > * pt.cc (unify) : Restrict the > r11-6483 change to just ordinary deduction for function > templates. When substituting into the NTTP type the second > time, use the original type not the substituted type. Remove > now unnecessary level check. > > gcc/testsuite/ChangeLog: > > * g++.dg/template/partial5.C: Revert r11-6483 change. > * g++.dg/template/partial-specialization11.C: New test. > * g++.dg/template/partial-specialization12.C: New test. > --- > gcc/cp/pt.cc | 25 ++++++++++++------- > .../template/partial-specialization11.C | 10 ++++++++ > .../template/partial-specialization12.C | 12 +++++++++ > gcc/testsuite/g++.dg/template/partial5.C | 2 +- > 4 files changed, 39 insertions(+), 10 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/template/partial-specialization11.C > create mode 100644 gcc/testsuite/g++.dg/template/partial-specialization12.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index dde62ee052d..52bd130b7e7 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -24287,8 +24287,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, > /* We haven't deduced the type of this parameter yet. */ > if (cxx_dialect >= cxx17 > /* We deduce from array bounds in try_array_deduction. */ > - && !(strict & UNIFY_ALLOW_INTEGER) > - && TEMPLATE_PARM_LEVEL (parm) <= TMPL_ARGS_DEPTH (targs)) > + && !(strict & UNIFY_ALLOW_INTEGER)) > { > /* Deduce it from the non-type argument. As above, ignore > top-level quals here too. */ > @@ -24296,13 +24295,21 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, > RECUR_AND_CHECK_FAILURE (tparms, targs, > tparm, atype, > UNIFY_ALLOW_NONE, explain_p); > - /* Now check whether the type of this parameter is still > - dependent, and give up if so. */ > - ++processing_template_decl; > - tparm = tsubst (tparm, targs, tf_none, NULL_TREE); > - --processing_template_decl; > - if (uses_template_parms (tparm)) > - return unify_success (explain_p); > + if (!processing_template_decl > + && TPARMS_PRIMARY_TEMPLATE (tparms) > + && DECL_FUNCTION_TEMPLATE_P (TPARMS_PRIMARY_TEMPLATE > + (tparms))) > + { > + /* If the NTTP's type uses still-undeduced template > + parameters, then don't unify it now. This gives > + type_unification_real a chance to retry deduction > + with default template arguments substituted in. */ > + ++processing_template_decl; > + tparm = tsubst (TREE_TYPE (parm), targs, tf_none, NULL_TREE); > + --processing_template_decl; > + if (uses_template_parms (tparm)) > + return unify_success (explain_p); > + } > } > else > /* Try again later. */ > diff --git a/gcc/testsuite/g++.dg/template/partial-specialization11.C b/gcc/testsuite/g++.dg/template/partial-specialization11.C > new file mode 100644 > index 00000000000..20da407d422 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/partial-specialization11.C > @@ -0,0 +1,10 @@ > +// PR c++/105289 > + > +template struct value_type; > + > +template::type V> > +struct push_front_vlist; > + > +template > +struct push_front_vlist { }; > +// { dg-error "not more specialized" "PR86193" { target c++14_down } .-1 } > diff --git a/gcc/testsuite/g++.dg/template/partial-specialization12.C b/gcc/testsuite/g++.dg/template/partial-specialization12.C > new file mode 100644 > index 00000000000..d70f7592790 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/partial-specialization12.C > @@ -0,0 +1,12 @@ > +// PR c++/105289 > +// { dg-do compile { target c++11 } } > + > +template > +struct value_type; > + > +template ::type Element> > +struct push_front_vlist; > + > +template