From patchwork Fri Mar 17 15:26:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 71331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp403530wrt; Fri, 17 Mar 2023 08:27:27 -0700 (PDT) X-Google-Smtp-Source: AK7set9cAeIFvGRaBA0CsmwieGwZoiqd/itCd6Pl82K1Jt6R0eMIKQa5ogPSg7QPvlWRjNFdfTGR X-Received: by 2002:aa7:d496:0:b0:4fd:2007:d40b with SMTP id b22-20020aa7d496000000b004fd2007d40bmr3571972edr.9.1679066846965; Fri, 17 Mar 2023 08:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679066846; cv=none; d=google.com; s=arc-20160816; b=iBuikaQjf8ryfVMztMRHzIOcBP5W8pfmL1fL81Ttrxewue07lb/ZhrZlOjAARJB8l/ DuBiyZ1uZmDokiqRIOv8srVlW2gOwDNq96rmDWUMAujIUdhXxNEW6RIm6pVJnlb1H/qL 5UdfxaGJvMUm5NtOmc/lPfMbUIAL9GiP5PSKxZe4AxdF7oik8DqX5zdvHu1CWoD3bYca XjqUf3aE+0XNK+Z9AO1Uqp/+nkvy7qRFqX4LqBhHYlwZS2YEahOY2hnM8o02DO3EpgP4 XiKwbGYDYYOfOZVUwBPmZKF1kQcyANYAZwaYRT629mZBwif4Cvhmqx47ApizbpYKzp4W bdVw== 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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=DLsoOIykDGiIsTLvSBKmftqlshE7sBHwm1moTy038mI=; b=qS6VOLYFT1tvjGOqKULQyU8P30W+LlOmm7wQVlWSEuu6C3LxhLzQDxK5NOW4HQMqhd RFt/c6lW9pWlSHRqp9b/j2tVDnkamQKPDTuLCT484eQpBhNFAqP2cjqwF40LdOdbGsl0 cwLREX5uUspEYBe0AOHr0KTamoVaKYLGNMeQ/9FS990Z7h4QCwPGyW3thh0TpPIwWa9q QvskqLQAli6XYSZ3HWsLNpO94islDqC6pEtKHddxAsCaLZzC45XVOOviPL6XbsYMvIU/ fCnfKr/eiKuZ0iNzKwG2i96yN1XwH4lXWhN8S8nvEcXK36TwDO4mTOhqw7Sg0HdKVLLP RU3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="B/Otx5qf"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f15-20020a056402160f00b004acddcb7501si2760767edv.116.2023.03.17.08.27.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:27:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="B/Otx5qf"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 BF9A438515FB for ; Fri, 17 Mar 2023 15:27:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF9A438515FB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679066845; bh=DLsoOIykDGiIsTLvSBKmftqlshE7sBHwm1moTy038mI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=B/Otx5qf/sl4RXoCrc7nMiU45n6TOBSCbu+OTrlpK6EvFei4VyTWBX60IJqZUzgSs sr9rec9yGjiU4SvDln+9iE0tOoExPn+q4ujX+BRKKR202k8u0e6gJO6d9VoVLr3Nex 1nJ0OLEiqlycjrHAL2So8bxbJ+RkqZ4H//5gDniE= 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 17248385B523 for ; Fri, 17 Mar 2023 15:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17248385B523 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-108-UhvNZxiLPqe5ybJC1LLpHA-1; Fri, 17 Mar 2023 11:26:33 -0400 X-MC-Unique: UhvNZxiLPqe5ybJC1LLpHA-1 Received: by mail-qk1-f200.google.com with SMTP id l27-20020a05620a211b00b00745b3e62004so2773018qkl.4 for ; Fri, 17 Mar 2023 08:26:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679066792; 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=DLsoOIykDGiIsTLvSBKmftqlshE7sBHwm1moTy038mI=; b=OwYOnU45rWRsUePWl00m9tYIeC7N45ytuSelJNTI4HjXJ688sxDeTLK1FG71DlfQHD BcwIznkxcfR+HRUNp822t1DlNLoXjzxiJqiVHVYKrAZPhCsnaKpmVY/T88jWPSgF58v2 VUf1b8nR8R0kXBFX72fNqZP0Koww20u3xbAMoAzdky/kunV4E4XhbROZJpZl7oLJqc0z 2bSDgFBxax5qfOHq0Tl+icIfmJQFX5Hd5FBjUj4NdySl5qTs+WZHgAm1t4lFLAxZaVim nnLcD2fgRB3h6FCJEWjOq4a1LuxgyfioW4/gb3J+TRFl/WEkf6X1MPzW2NOhnYO/bYuW 9cTA== X-Gm-Message-State: AO0yUKVPWZuWmuEGeJWQImnSQzH6CwH2a6QFb/poB1tCnlb8Eu80iHDe 8EziWyQflxpngIqkqSMS2ce5mzWqjByCviNCzkjaH0p2uITCULc7Z4PRK3vv1FMMQH/O9dII43W G/LwxJ2Ng/Vs0lpqOrcnHKem2pcM0i/3rTP14uZb8dWLBfoqvJsf4xfzn1J3DVNFnyDgT6I4Pjg c= X-Received: by 2002:a05:6214:20c1:b0:56e:9dd8:47f3 with SMTP id 1-20020a05621420c100b0056e9dd847f3mr39692727qve.13.1679066792005; Fri, 17 Mar 2023 08:26:32 -0700 (PDT) X-Received: by 2002:a05:6214:20c1:b0:56e:9dd8:47f3 with SMTP id 1-20020a05621420c100b0056e9dd847f3mr39692665qve.13.1679066791497; Fri, 17 Mar 2023 08:26:31 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 20-20020a370314000000b00745a55db5a3sm1873212qkd.24.2023.03.17.08.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 08:26:31 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: NTTP constraint depending on outer args [PR109160] Date: Fri, 17 Mar 2023 11:26:29 -0400 Message-Id: <20230317152629.3944138-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka 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?1760629198110473585?= X-GMAIL-MSGID: =?utf-8?q?1760629198110473585?= Here we're crashing during satisfaction for the NTTP 'C auto' from do_auto_deduction ultimately because convert_template_argument / unify don't pass all outer template arguments to do_auto_deduction, and during satisfaction we need to know all arguments. While these callers do pass some outer arguments, they are only sufficient to properly substitute the 'auto' and are not necessarily the complete set. Fortunately it seems it's possible to obtain the full set of outer arguments from these callers via convert_template_argument's IN_DECL parameter and unify's TPARMS parameter. So this patch adds a TMPL parameter to do_auto_deduction, used only during adc_unify deduction, which contains the (partially instantiated) template corresponding to this auto and from which we can obtain all outer template arguments for satisfaction. This patch also adjusts the IN_DECL argument passed to coerce_template_parms from tsubst_decl so that we could in turn safely assume convert_template_argument's IN_DECL is always a TEMPLATE_DECL, and thus could pass it as-is to do_auto_deduction. (tsubst_decl seems to be the only caller that passes a non-empty non-template IN_DECL to coerce_template_parms.) Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/12? PR c++/109160 gcc/cp/ChangeLog: * cp-tree.h (do_auto_deduction): Add defaulted TMPL parameter. * pt.cc (convert_template_argument): Pass IN_DECL as TMPL to do_auto_deduction. (tsubst_decl) : Pass TMPL instead of T as IN_DECL to coerce_template_parms. (unify) : Pass the corresponding template as TMPL to do_auto_deduction. (do_auto_deduction): Document default arguments. Use TMPL to obtain a full set of template arguments for satisfaction in the adc_unify case. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-placeholder12.C: New test. --- gcc/cp/cp-tree.h | 3 +- gcc/cp/pt.cc | 30 ++++++++++++++----- .../g++.dg/cpp2a/concepts-placeholder12.C | 29 ++++++++++++++++++ 3 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-placeholder12.C diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index dfc1c845768..e7190c5cc62 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7324,7 +7324,8 @@ extern tree do_auto_deduction (tree, tree, tree, auto_deduction_context = adc_unspecified, tree = NULL_TREE, - int = LOOKUP_NORMAL); + int = LOOKUP_NORMAL, + tree = NULL_TREE); extern tree type_uses_auto (tree); extern tree type_uses_auto_or_concept (tree); extern void append_type_to_template_for_access_check (tree, tree, tree, diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index ddbd73371b9..6400b686a58 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -8638,7 +8638,7 @@ convert_template_argument (tree parm, else if (tree a = type_uses_auto (t)) { t = do_auto_deduction (t, arg, a, complain, adc_unify, args, - LOOKUP_IMPLICIT); + LOOKUP_IMPLICIT, in_decl); if (t == error_mark_node) return error_mark_node; } @@ -15243,7 +15243,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) the template. */ argvec = (coerce_template_parms (DECL_TEMPLATE_PARMS (gen_tmpl), - argvec, t, complain)); + argvec, tmpl, complain)); if (argvec == error_mark_node) RETURN (error_mark_node); hash = spec_hasher::hash (gen_tmpl, argvec); @@ -24655,7 +24655,9 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, if (tree a = type_uses_auto (tparm)) { tparm = do_auto_deduction (tparm, arg, a, - complain, adc_unify, targs); + complain, adc_unify, targs, + LOOKUP_NORMAL, + TPARMS_PRIMARY_TEMPLATE (tparms)); if (tparm == error_mark_node) return 1; } @@ -30643,13 +30645,20 @@ unparenthesized_id_or_class_member_access_p (tree init) adc_requirement contexts to communicate the necessary template arguments to satisfaction. OUTER_TARGS is ignored in other contexts. - For partial-concept-ids, extra args may be appended to the list of deduced - template arguments prior to determining constraint satisfaction. */ + Additionally for adc_unify contexts TMPL is the template for which this + auto is a template parameter type. + + For partial-concept-ids, extra args from OUTER_TARGS, TMPL and the current + scope may be appended to the list of deduced template arguments prior to + determining constraint satisfaction as appropriate. */ tree do_auto_deduction (tree type, tree init, tree auto_node, - tsubst_flags_t complain, auto_deduction_context context, - tree outer_targs, int flags) + tsubst_flags_t complain /* = tf_warning_or_error */, + auto_deduction_context context /* = adc_unspecified */, + tree outer_targs /* = NULL_TREE */, + int flags /* = LOOKUP_NORMAL */, + tree tmpl /* = NULL_TREE */) { if (init == error_mark_node) return error_mark_node; @@ -30839,7 +30848,12 @@ do_auto_deduction (tree type, tree init, tree auto_node, } } - tree full_targs = add_to_template_args (outer_targs, targs); + tree full_targs = outer_targs; + + if (context == adc_unify) + full_targs = add_outermost_template_args (tmpl, full_targs); + + full_targs = add_to_template_args (full_targs, targs); /* HACK: Compensate for callers not always communicating all levels of outer template arguments by filling in the outermost missing levels diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder12.C b/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder12.C new file mode 100644 index 00000000000..3d4d138720e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder12.C @@ -0,0 +1,29 @@ +// PR c++/109160 +// { dg-do compile { target c++20 } } + +template +concept C = B; + +template struct X { }; + +template +struct A { + template auto V> static void f(); + template auto V> static void g(X); + template auto V> static inline int value = V; + template auto V> struct D { }; +}; + +int main() { + A::f<0>(); + A::f<0>(); // { dg-error "no match|constraints" } + + A::g(X<0>{}); + A::g(X<0>{}); // { dg-error "no match|constraints" } + + bool v1 = A::value<0>; + bool v2 = A::value<0>; // { dg-error "constraints" } + + A::D<0> d1; + A::D<0> d2; // { dg-error "constraints" } +}