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 302EC3858D37 for ; Fri, 22 Apr 2022 18:41:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 302EC3858D37 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-267-PSE99wA0Mc-DmMML2t_dsA-1; Fri, 22 Apr 2022 14:41:14 -0400 X-MC-Unique: PSE99wA0Mc-DmMML2t_dsA-1 Received: by mail-ot1-f71.google.com with SMTP id l20-20020a056830269400b00605523dff90so3189337otu.22 for ; Fri, 22 Apr 2022 11:41: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:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HWHK5um8kUcJWbkMqh1HapaEtx2PWIZDNBXcEncY4TY=; b=FRPcHrwBevXalzkqzmg6GBFndiuyL6h0fXwGG1PDamDDAwWFkMrDeLgaXz58E1xG9I 7W7srAKoJbJYry4oSBByPAqHeLL92I5RktR8QPgXIp37V90nOG8bS3Lw+b2QsiZ/0ZXO rSNMrnvuPvOEpa1Bi/OHH0S4NjniOAYg9VO5wBNQqa4Q+dnCRD1xjVGHo172yzoTWkTN EVtlu4VeuJ9W49zPsJxecqtkeW/73OwSr9hYKl1iIVea/Fn/KHdHzV2bH2G0wSlzkeC5 ITl3vx42ouxKGW3yjWy/yel6pB/l6YihvvCk5TPcDvvXNhQVVm6dXqDqPx/iKSIWWwt5 OFEQ== X-Gm-Message-State: AOAM530WXdD2QZ/Ce6JWdywZzF/+ZRwd3tgMRe5eDppkbnA0+kvebxDF zp8sBozUNXaH9za0GtgajqYp25B5ZIUSYbi9hvschNjLfTZO3Zcq75oZS82qBsPGPp9VFDwhVyD YgyvcVTkaHjp0AP1u+mfgD1LWMwf5zGBasQ== X-Received: by 2002:a05:6870:59b:b0:e2:976c:7720 with SMTP id m27-20020a056870059b00b000e2976c7720mr2594649oap.16.1650652873546; Fri, 22 Apr 2022 11:41:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8bHvPKDkRPeJh/cMIbOX3vO05LKA2PCxw8i2UDtIrezx/CcDhgeETfCgutnhR0X1N6FSHlip+IUxjqz7fOIM= X-Received: by 2002:a05:6870:59b:b0:e2:976c:7720 with SMTP id m27-20020a056870059b00b000e2976c7720mr2594642oap.16.1650652873293; Fri, 22 Apr 2022 11:41:13 -0700 (PDT) MIME-Version: 1.0 References: <20220422183329.3127166-1-ppalka@redhat.com> In-Reply-To: <20220422183329.3127166-1-ppalka@redhat.com> From: Patrick Palka Date: Fri, 22 Apr 2022 14:41:02 -0400 Message-ID: Subject: Re: [PATCH] c++: partial ordering with dependent NTTP type [PR105289] To: GCC Patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 18:41:17 -0000 Whoops, this patch is identical to https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593502.html that I sent about an hour ago, sorry for the noise. On Fri, Apr 22, 2022 at 2:33 PM 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. > > 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