From patchwork Fri Mar 24 16:31:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 66868 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 78EC33847820 for ; Fri, 24 Mar 2023 16:32:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78EC33847820 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679675551; bh=ydtZp+e4x4ppRiPtr4Fh17QNZST0pELNCsEatyLg1Mk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=viAvRLFXZGSXBB0LEZ4KcyPMXXyQg/MAp/+e5smB0QedlvsX5ZeCuJdwV97pSGOrM Up7FdvFHQGsbQwxD4owia3/CwwgHM2KnB99TjyQxMYsy2ep5WZvYhtFnQF+oIeMyfF /x9KKgc9oLUjva9y97CflgGW4Ei8Q1c3To3D2JzM= 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 83C35384F00D for ; Fri, 24 Mar 2023 16:31:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83C35384F00D Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-jKhVL_sMOhKwGQNcwqC5Ug-1; Fri, 24 Mar 2023 12:31:57 -0400 X-MC-Unique: jKhVL_sMOhKwGQNcwqC5Ug-1 Received: by mail-yb1-f197.google.com with SMTP id e129-20020a251e87000000b00b56598237f5so2267463ybe.16 for ; Fri, 24 Mar 2023 09:31:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679675517; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ydtZp+e4x4ppRiPtr4Fh17QNZST0pELNCsEatyLg1Mk=; b=FsiPVBnTyEICRRNShiKv1GlSleSmgKZf0kMaz93aRf3jrjmnwxTp+RystGVZ3YvfsW 8qGy7kRpS+wt/QHK6s2yZpmEBbDwxh2JRp1RsK2vyPfths0++1z8ziKuOd5rNhkT/+PR /XwDajieT2AMnCGIzLxR9DctJ893njConHv4JFi5lIP7eYd2uoIMVN79HhI7rToMDE9p diIFzq3hB5eVZMqn5lg8mK9WZdatz2bqOS8cK9cxZgmgfwvRafo+o4FqovLhFmApt1zr zdMw9YxeSUeDcB/sYFeZjfGG5yHf+v6wMpkkSVMNuVlnS9eJkwR14JwTVNQx1LEf47HE 1VNg== X-Gm-Message-State: AAQBX9eT1giPGR1U7a0QavYfzWWY/Jshtr6ihsrC5JqqQmvlnVvtcfpA y9jyclUeHizkoQNzSQGneKqt6wYIPTed9fo0i7GWNNfX+ij3wpZRQC2kj9fBxZUmR+6xFVwvk1D ZjhIO04h/9io7tr/eL2zX1iytNcOLU6cIqM2qoH2XVwVbjGngDqoq08Bo3vDzT31NRbmjZawdvA == X-Received: by 2002:a81:4f10:0:b0:536:509a:a6a with SMTP id d16-20020a814f10000000b00536509a0a6amr2968339ywb.25.1679675517054; Fri, 24 Mar 2023 09:31:57 -0700 (PDT) X-Google-Smtp-Source: AKy350YypxzRZPkQ1ulZoCWC5sBGJxCBMw3UdvobIJpP9KXw2QkJuq9OZ2GPLe5RTW720sbGboPgiw== X-Received: by 2002:a81:4f10:0:b0:536:509a:a6a with SMTP id d16-20020a814f10000000b00536509a0a6amr2968304ywb.25.1679675516535; Fri, 24 Mar 2023 09:31:56 -0700 (PDT) Received: from jason.cygnus.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id g2-20020a37b602000000b0071aacb2c76asm14120064qkf.132.2023.03.24.09.31.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 09:31:56 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: default template arg, partial ordering [PR105481] Date: Fri, 24 Mar 2023 12:31:53 -0400 Message-Id: <20230324163153.3200112-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- The default argument code in type_unification_real was assuming that all targs we've deduced by that point are non-dependent, but that's not the case for partial ordering. PR c++/105481 gcc/cp/ChangeLog: * pt.cc (type_unification_real): Adjust for partial ordering. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/fntmpdefarg-partial1.C: New test. --- gcc/cp/pt.cc | 18 ++++++++++++++---- .../g++.dg/cpp0x/fntmpdefarg-partial1.C | 8 ++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/fntmpdefarg-partial1.C base-commit: c4792bd1de0621932a47fb86aca09fafafdb2972 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 40deedc9ba9..3bb98ebeac1 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -23304,14 +23304,24 @@ type_unification_real (tree tparms, return unify_parameter_deduction_failure (explain_p, tparm); } + /* During partial ordering, we deduce dependent template args. */ + bool any_dependent_targs = false; + /* Now substitute into the default template arguments. */ for (i = 0; i < ntparms; i++) { tree targ = TREE_VEC_ELT (targs, i); tree tparm = TREE_VEC_ELT (tparms, i); - if (targ || tparm == error_mark_node) + if (targ) + { + if (!any_dependent_targs && dependent_template_arg_p (targ)) + any_dependent_targs = true; + continue; + } + if (tparm == error_mark_node) continue; + tree parm = TREE_VALUE (tparm); tree arg = TREE_PURPOSE (tparm); reopen_deferring_access_checks (*checks); @@ -23347,9 +23357,9 @@ type_unification_real (tree tparms, do this substitution without processing_template_decl. This is important if the default argument contains something that might be instantiation-dependent like access (87480). */ - processing_template_decl_sentinel s; + processing_template_decl_sentinel s (!any_dependent_targs); tree substed = NULL_TREE; - if (saw_undeduced == 1) + if (saw_undeduced == 1 && !any_dependent_targs) { /* First instatiate in template context, in case we still depend on undeduced template parameters. */ @@ -23372,7 +23382,7 @@ type_unification_real (tree tparms, complain, i, NULL_TREE); else if (saw_undeduced == 1) arg = NULL_TREE; - else + else if (!any_dependent_targs) arg = error_mark_node; } diff --git a/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg-partial1.C b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg-partial1.C new file mode 100644 index 00000000000..2a6783e566b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg-partial1.C @@ -0,0 +1,8 @@ +// PR c++/105481 +// { dg-do compile { target c++11 } } + +template struct uint; +template uint f(const uint &); +template> uint f(T); +using X = uint<1>; +X (*fp)(X const &) = f;