From patchwork Fri Apr 22 18:33:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 53125 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF57C3856DCF for ; Fri, 22 Apr 2022 18:34:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF57C3856DCF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650652442; bh=VTHcxDjw3C5jEjAH0GDYaNcGWJY9ou7Di9PWIJmQclQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pSNZ1z/kMuGi1Fa9YQPafYQCq+tlXzbddX6l24XpYNHsweLJmLlm69a8DEtGHBLpc pJgHWnxT1foeX71N8/yCqforpk/SoFt4+AyrsdCcDOBr2te8Ha9SYL+ty8cGME36XJ cUSLg3aJvoDAl60lItKougQfpHsUGYTQV6pk2dAo= 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 586283858C83 for ; Fri, 22 Apr 2022 18:33:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 586283858C83 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-517-5Mg8V10hOxKD5umWeadIYw-1; Fri, 22 Apr 2022 14:33:31 -0400 X-MC-Unique: 5Mg8V10hOxKD5umWeadIYw-1 Received: by mail-qt1-f197.google.com with SMTP id o19-20020a05622a009300b002f24529993cso5556344qtw.0 for ; Fri, 22 Apr 2022 11:33:31 -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=CetrgHa70Zt9+VKNqA/h7sc2BKIQO4edCnUf0aJOVKxxiTrKHygGIy6PJ8VOd3KBLx i6rdhI/Zt90O3mnwxmmm4vj6D/lZ1kg4bGuxZM01oxKXFBTkwip/IYFdNP0nAmXhkM5K hzBMz8t1PtDp4BJPWb4LzFXJ6487fnHTrFHXvWslAIwZ9KU0CuStNLY1juw0qVzJ//9N HEsE9tX5spZ4WLpHH/JqDEeMEUHQe9fyXRvhABuJK7tgUPU5MkvoCDykhv5ffAw7qNXe kqk6iPlN1Y3J0j4x8BxR1B4d1mlI0776T8iBaVN6RE/C5o+n00K4bZA3SmvL4oaaM0vf X65g== X-Gm-Message-State: AOAM532QyYd3QxlZhro7XBkD/2FmobazxNlk5WoAWMsvbnq5UjVG4WcT 9JTU/xJVv7sH2dgNsBbDh6j2kPN1MIPeDJi9fgNlK6oop8omQpBqvlfhzcQmvSj5yN3fcEMg4l+ s5swakN8I5sunzR0XSnWkQBqmx0EKoanynlA24i+RERjNudgce+FsEhfU7Q7h4dnYKVg= X-Received: by 2002:ac8:5f88:0:b0:2f3:5d15:437c with SMTP id j8-20020ac85f88000000b002f35d15437cmr1979253qta.618.1650652411015; Fri, 22 Apr 2022 11:33:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwboyUotOqoFblrcXYkSBGnQ7JxheGnP0FLp/3BlHf0s2nmgzwW3HS5an6PzBxGqx2T5rLncw== X-Received: by 2002:ac8:5f88:0:b0:2f3:5d15:437c with SMTP id j8-20020ac85f88000000b002f35d15437cmr1979232qta.618.1650652410687; Fri, 22 Apr 2022 11:33:30 -0700 (PDT) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id r137-20020a37a88f000000b0069ea39ebf75sm1272520qke.110.2022.04.22.11.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 11:33:30 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: partial ordering with dependent NTTP type [PR105289] Date: Fri, 22 Apr 2022 14:33:29 -0400 Message-Id: <20220422183329.3127166-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+patchwork=sourceware.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