From patchwork Tue Feb 6 21:59:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 85384 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 7BAA5385843B for ; Tue, 6 Feb 2024 22:00:35 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 9F99E3858C2F for ; Tue, 6 Feb 2024 22:00:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F99E3858C2F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9F99E3858C2F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707256805; cv=none; b=v2/bLfksW79pP+NQQuZrs0VKeioU9vDdUTWLgBFDESoyTAPgrafHU32aXiUtjcScXDvlxN2zUphRk9mkROVVR0CiZZHyiJA6pdSPVFKJuzrzMIKyOjiEdnh611vvc3S7uFS29poExOK4h1E4SBSzdX3YehG3kK0L44k9VSCDJ4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707256805; c=relaxed/simple; bh=Cergn4LFbl9SY7pbfTAFP6H0xh0WIzGxWefzXaHWvAM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=amqASPepp4F0FBfdKeyGJS3/ffWddnrYe6dx42t+jGVDsX17jLQSTo/Eqb5cjtwZQ3ylUbVEkSiRcIcObc3qKps6udKBwvAv7xp0unbY3/6W9fk2zrRQCQ4nkT02/nOI89WeWjSFSGlDGmqkCZT3cKiBF/4xRwR3sIZ8iWRQYxU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707256802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=w7roiL95fQCCd4Uqrm/j1A9F6pULVJ/g1EYoAI0/2fE=; b=cWmEv8s49I1t9Xt6p2eye93zkq0y1uhAyvWCnp4eR/zHqppGxWvZwiii91dQELfhmOu3QW fB+qy2qJV7+7XitgvK50EgoZKW2HgdY5RXaKLwhRRmHU+bjFx+o9/Z4+7kWruYQ0d3tKLt RWLDKLXiqFPP7cZlTG655mfXeXR6JxA= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-oq9sG6viNKeFVWUOljoVYA-1; Tue, 06 Feb 2024 17:00:00 -0500 X-MC-Unique: oq9sG6viNKeFVWUOljoVYA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-785955e985cso75703785a.3 for ; Tue, 06 Feb 2024 14:00:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707256799; x=1707861599; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w7roiL95fQCCd4Uqrm/j1A9F6pULVJ/g1EYoAI0/2fE=; b=puCR0xoS8bq859kfWhg2NCmu9LdeNYHAt0Z7/Sq8sLIBOg+Ay6rgpQkwidekmkY02u pul2ExHf9r//po1BzRg5uPOejqDqE1hz+doMB9P4y+eEjHwArhzQQkEETZcKMtX30juG b6//2F+xHO89/wxV6zHy4x9hNHiDEKHxJBwwsT/nVNPcAOY6sEJmrjlhkbcNV6QRHvuW K5ikLK2dxWW4MJRwgzJ7PhL6XavyyFvUvcQugAYJREVG3HXlLzAZWkj+21qfTlwAcZmO nmV3V+cjb6ttquNg4SiWs1j7fKBsuKBP29DSlpwK/LilROm1u2PsV5AEdiWm2l1i5acd 27Gw== X-Gm-Message-State: AOJu0Yx8oLzyz/smO80XOO+0ymgj6dpTGzuLmmxDQKaJCu8msKrgXxZL J6A7n/2L2uGliAOGjAXaTksSXyIBsk05yEGLfyrrHyiv1DWt2757SdJZW1tiBV+QA4Yrk9Nlbg6 I+k6ukL7xlF1BYAbzCDqj2cdvK7Di4NaLbI2ShJ/k8GeUHhllVGgkOyfRxzE8kiQ1BxXAcsba49 CAJvso5C6ZYwcSNdpIwojUaMDwa9P2nYie2D3p X-Received: by 2002:a05:6214:240e:b0:68c:7f05:cd87 with SMTP id fv14-20020a056214240e00b0068c7f05cd87mr5365060qvb.41.1707256798791; Tue, 06 Feb 2024 13:59:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8tbrydpnytI/rC5hdbBfvh+mUuRv2yIjSYphcK4B5XnyMW1N2yHKDUMW3bMMmdQ91vPudHQ== X-Received: by 2002:a05:6214:240e:b0:68c:7f05:cd87 with SMTP id fv14-20020a056214240e00b0068c7f05cd87mr5365035qvb.41.1707256798438; Tue, 06 Feb 2024 13:59:58 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXVotMoSNHbcqbUL9rZHXfofkTYkQxkAfyDLGesqr3zjj5hpBf4YjmCfiHLHNZGW2cuVFFSeFMxM9ozRObyn6020w== Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id or12-20020a056214468c00b0068cb393888csm1004206qvb.44.2024.02.06.13.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 13:59:58 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: NTTP type CTAD w/ tmpl from current inst [PR113649] Date: Tue, 6 Feb 2024 16:59:55 -0500 Message-ID: <20240206215955.4107411-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.522.g2a540e432f MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.8 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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Since template argument coercion happens relative to the most general template (for a class template at least), during NTTP type CTAD we might need to consider outer arguments particularly if the CTAD template is from the current instantiation (and so depends on outer template parameters). This patch makes do_class_deduction substitute as many levels of outer template arguments into a CTAD template (from the current instantiation) as it can take. PR c++/113649 gcc/cp/ChangeLog: * pt.cc (do_class_deduction): Add outer_targs parameter. Substitute outer arguments into the CTAD template. (do_auto_deduction): Pass outer_targs to do_class_deduction. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-class64.C: New test. --- gcc/cp/pt.cc | 21 ++++++++++++++++++-- gcc/testsuite/g++.dg/cpp2a/nontype-class64.C | 16 +++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class64.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 903a4a1c363..83c3b1920d6 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -30681,7 +30681,7 @@ ctad_template_p (tree tmpl) type. */ static tree -do_class_deduction (tree ptype, tree tmpl, tree init, +do_class_deduction (tree ptype, tree tmpl, tree init, tree outer_targs, int flags, tsubst_flags_t complain) { /* We should have handled this in the caller. */ @@ -30743,6 +30743,23 @@ do_class_deduction (tree ptype, tree tmpl, tree init, if (type_dependent_expression_p (init)) return ptype; + if (outer_targs) + { + int args_depth = TMPL_ARGS_DEPTH (outer_targs); + int parms_depth = TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (tmpl)); + if (parms_depth > 1) + { + /* Substitute outer arguments into this CTAD template from the + current instantiation. */ + int want = std::min (args_depth, parms_depth - 1); + outer_targs = strip_innermost_template_args (outer_targs, + args_depth - want); + tmpl = tsubst (tmpl, outer_targs, complain, NULL_TREE); + if (tmpl == error_mark_node) + return error_mark_node; + } + } + /* Don't bother with the alias rules for an equivalent template. */ tmpl = get_underlying_template (tmpl); @@ -30998,7 +31015,7 @@ do_auto_deduction (tree type, tree init, tree auto_node, if (tree ctmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node)) /* C++17 class template argument deduction. */ - return do_class_deduction (type, ctmpl, init, flags, complain); + return do_class_deduction (type, ctmpl, init, outer_targs, flags, complain); if (init == NULL_TREE || TREE_TYPE (init) == NULL_TREE) /* Nothing we can do with this, even in deduction context. */ diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class64.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class64.C new file mode 100644 index 00000000000..8397ea5a886 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class64.C @@ -0,0 +1,16 @@ +// PR c++/113649 +// { dg-do compile { target c++20 } } + +template +struct A { + template + struct Fun { constexpr Fun(Ret(*)(Args...)) { } }; + + template + struct B { using type = decltype(f); }; +}; + +bool f(char, long); + +using type = A::B<&f>::type; +using type = A::Fun;