From patchwork Fri Apr 22 17:50:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1621064 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=NJjsp87l; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KlMQY4FK8z9s0w for ; Sat, 23 Apr 2022 03:51:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 263543856DE1 for ; Fri, 22 Apr 2022 17:50:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 263543856DE1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650649858; bh=VTHcxDjw3C5jEjAH0GDYaNcGWJY9ou7Di9PWIJmQclQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NJjsp87lJ9WZE9KgumT5cmhTa7lXW251SOV09d0AAaLaASNdRhbY5mnFa23+UIJnM 6f2XUpaM/p+88bg7VOKhSzLs4xjuDypi/qGZ13/1nn6EBMz4MDJZu/G+e/eh5i6hpo 52NAks99iLBKzoxmxPDK/MiwNEVAXR/eG7zKXFB8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 E63943858D37 for ; Fri, 22 Apr 2022 17:50:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E63943858D37 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-671-HeiK3CRJNSO3I_rD8XwgXQ-1; Fri, 22 Apr 2022 13:50:36 -0400 X-MC-Unique: HeiK3CRJNSO3I_rD8XwgXQ-1 Received: by mail-qv1-f69.google.com with SMTP id b8-20020a056214002800b0044666054d36so7162705qvr.12 for ; Fri, 22 Apr 2022 10:50:36 -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:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VTHcxDjw3C5jEjAH0GDYaNcGWJY9ou7Di9PWIJmQclQ=; b=3DhyUeRw/kWuF/pLXEgt8i19AkGtm4wHCQwz6HR9tD+O8YSM9UrJTmiQEODUkNSHVw CQOX3Mh1VIy/GpD/I4W1LBFX1llCLLcCrxYPHkAXaO9UUcXsMO/4SQqfAoSWiGsnaogQ F4x4uDSLRvG2OVnHLii8lcS/JulMdBFwF84rdcmRjbm8l91atp4VjaIG7/YFaXfgo0ao jokTlWkXili7iHldiuUW8LkHlh0YfSsNWs40wGcbrb+M9D/8K44rqWc2kzHfWih1BBmE OsIxxeLfD8/Nlt4osrdzKlj1LNw0B5Cxm/o2Scvi4tF6pZ/TYyuityEssx52m/YCLEfe axGw== X-Gm-Message-State: AOAM531RltRJUQtUvTvsig/1s7Z9h18XZnqXRtxoCnKQMJ/br7ljDufL KBv445hhMfLTEw4zVjCBFMrbGSHUcVI4U8B4rjWFI6TgWa9TNKQMAj31phzkTRmpcIx3+iRoJc6 4RvL+oP8/bz5vfV9U7k08YH1ONdUci0PeGhMrSQhjn5Lj6ZrkaDbEwx6+oEs34EjXhhM= X-Received: by 2002:ac8:578a:0:b0:2e1:a0d2:c3a with SMTP id v10-20020ac8578a000000b002e1a0d20c3amr4118908qta.261.1650649835522; Fri, 22 Apr 2022 10:50:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0jXR0H/NkZ42nszYRa65jHKIk2lWFTUYqR83MyDZysOJNrKJXJa9LBx3LsmDWlkygdsJO7w== X-Received: by 2002:ac8:578a:0:b0:2e1:a0d2:c3a with SMTP id v10-20020ac8578a000000b002e1a0d20c3amr4118887qta.261.1650649835176; Fri, 22 Apr 2022 10:50:35 -0700 (PDT) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id m9-20020a05622a118900b002f1fc51135dsm1634325qtk.57.2022.04.22.10.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 10:50:34 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: partial ordering with dependent NTTP type [PR105289] Date: Fri, 22 Apr 2022 13:50:32 -0400 Message-Id: <20220422175032.3106274-1-ppalka@redhat.com> X-Mailer: git-send-email 2.36.0.rc2.10.g1ac7422e39 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.6 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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