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: 74633 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp756963vqo; Fri, 24 Mar 2023 09:32:52 -0700 (PDT) X-Google-Smtp-Source: AKy350Z5D/0GZxGLVd/2SZX+tirWIlV47QjKx7yAS2jpeCFo5JQUG3QEnYKBxVdPfBelaqJgJeTP X-Received: by 2002:a05:6402:5178:b0:4fa:57bf:141a with SMTP id d24-20020a056402517800b004fa57bf141amr4444400ede.32.1679675571930; Fri, 24 Mar 2023 09:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679675571; cv=none; d=google.com; s=arc-20160816; b=esxYn0pD0In+g1wvfSCvZ532eBBwJUKbcMEpeH1tV6d/Dh9choM+lRh0waK6z6Epva z32VlIWkAAnuik1ietvgrbL+aLH2u0fA8SgAF5HAnQWsCcCSUvg705oiPR60neYNkOlT 2dSpTKL/vhLSCjCmQ6DoeJsXY6W3YGkGQmkglvTyX1Or0YlWZQoP3sR6IxbLLEOSqh/v HvDWtRgg4mQDm1oPvmRh/E0s7BCCJawa23APdg2N0ucvDZvkL25/PPULjrkaLeWVeFjn kvvbkoEsLhXkPLIYEBgC6qy5DCFHPYvmT2Fpg6vLB0H1Aa14YGPIMGybA3z5RJa17Eoq awQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=ydtZp+e4x4ppRiPtr4Fh17QNZST0pELNCsEatyLg1Mk=; b=OJMxGV/b33fj6VjmzOsLU3eUmxIJLuMmFoKNOmRane35r57K8p+89RvL59/W2WGFYp mx7bQVR2w592NDPLF1Kcxtx5A/mZC2r6OmWUSyMaQE/zNkwR+GBh7dRYbAmthjfMMw4P olrE3nHQegAg8iFEDvAmT6q7yvOWoo20iqMGEs5rX5n1ph1wcu3q3u+zOZcO3xFtUatl Aa26YcD9cc6CIzp2cIOxvIvU5SrkrelSGDllrgw8FWenLy//W3gJe0l+ixzgXPUUooWc +IUCsZ2ok2cc24TKp5UVunRe4mPBBVz+ChlDBjtNRoe0KKiXAmOGfL3u2xhYiGUs40nU k+rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=opK19tol; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l12-20020a056402124c00b004ad02c77d40si22404663edw.29.2023.03.24.09.32.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 09:32:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=opK19tol; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABE1B385043C for ; Fri, 24 Mar 2023 16:32:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABE1B385043C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679675567; bh=ydtZp+e4x4ppRiPtr4Fh17QNZST0pELNCsEatyLg1Mk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=opK19tolFIIKOXYsKisAyqjB8tvxqzREn5QsODNh31nCjq03BuXSxMBN3Tl1wvqJc xnRun6RnoiMm5/utrbhEwZJ3vUjaq5LyR5Es+O9RVo6ha9z1ZUdTwZ2ZNjDQKd4rsz GeuMkyHYnDtPHH2hCUwvr9r9aDNSgwWlUHNdyBqo= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761267492320403317?= X-GMAIL-MSGID: =?utf-8?q?1761267492320403317?= 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;