From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 00D8B3858C50 for ; Tue, 3 May 2022 20:07:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 00D8B3858C50 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-274-JrCige_HPb6hkxabGtdxSg-1; Tue, 03 May 2022 16:07:06 -0400 X-MC-Unique: JrCige_HPb6hkxabGtdxSg-1 Received: by mail-qk1-f198.google.com with SMTP id q5-20020a05620a0d8500b004738c1b48beso13153937qkl.7 for ; Tue, 03 May 2022 13:07:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=tsL8C50C35AEqagzdq1VXGh8/X5/PAPsb81+RBefBqI=; b=7mxenINds1Xb/taO6BchL/oA2X4ceb1YkJ20t7rHNzyfR9ruPpXMQXKljIKae15oIo 2nrBP0XPwei/Le9yB5aCGmbcfYL3KbtyFGz/dbLLQvlK6D5m2n7x/Qfpb8sNV6u6jhTZ 62HCQdLKutsHO6qsE15H6E5SGgVWN9rlmMmuoa1U/aTXhFceufu5xkNeG3wmjotaqqG8 0ecte2fsa8ZwHgWf1dzm//1zkL/Yz+6wshPHnMvCY/zTW6DnxQHsN5urkYbQ+Jbnd4cj U7A5TWtRKE7zyr5C5VZEYsN2p07psdHEr+HMcWBerOEerDI4Cb2PMFtAuB6eQc9qosur 8MeA== X-Gm-Message-State: AOAM530cMjQps205/ivlysoMhx7WhUoWQ1DPRaYKe5rJtcrh+U0UrQOi Xope/j7TE6vHks0i0oHbpyoTDRuFzNHGLic8CpuGtRReHoDkALNCycXAqGOoCiwPPWY9P8pdPcz UvmjTvRWggz+tBf0Eig== X-Received: by 2002:a05:6214:768:b0:45a:afdf:ae39 with SMTP id f8-20020a056214076800b0045aafdfae39mr1268202qvz.113.1651608423640; Tue, 03 May 2022 13:07:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIWarIGSc4R/sgj7DkZiZKd+1EE/YHQ8jsRfJbLVhsvu3J0zylPd+y2lBAyxTY/f8fRymtKg== X-Received: by 2002:a05:6214:768:b0:45a:afdf:ae39 with SMTP id f8-20020a056214076800b0045aafdfae39mr1268174qvz.113.1651608423248; Tue, 03 May 2022 13:07:03 -0700 (PDT) Received: from [192.168.1.100] (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 g20-20020ac84694000000b002f39b99f6b6sm6399580qto.80.2022.05.03.13.07.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 May 2022 13:07:02 -0700 (PDT) Message-ID: Date: Tue, 3 May 2022 16:07:01 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH] c++: partial spec constraint checking context [PR105220] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20220502185029.92137-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20220502185029.92137-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Tue, 03 May 2022 20:07:19 -0000 On 5/2/22 14:50, Patrick Palka wrote: > Currently when checking the constraints of a class template, we do so in > the context of the template, not the specialized type. This is the best > we can do for a primary template since the specialized type is valid > only if the primary template's constraints are satisfied. Hmm, that's unfortunate. It ought to be possible, if awkward, to form the type long enough to check its constraints. > But for a > partial specialization, we can assume the specialized type is valid (as > a consequence of constraints being checked only when necessary), so we > arguably should check the constraints on a partial specialization more > specifically in the context of the specialized type, not the template. > > This patch implements this by substituting and setting the access > context appropriately in satisfy_declaration_constraints. Note that > setting the access context in this case is somewhat redundant since the > relevant caller most_specialized_partial_spec will already have set the > access context to the specialiation, but this redundancy should be harmless. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk and perhaps 12.2 (after the branch is thawed)? > > PR c++/105220 > > gcc/cp/ChangeLog: > > * constraint.cc (satisfy_declaration_constraints): When checking > the constraints of a partial template specialization, do so in > the context of the specialized type not the template. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-partial-spec12.C: New test. > --- > gcc/cp/constraint.cc | 17 ++++++++++++++--- > .../g++.dg/cpp2a/concepts-partial-spec12.C | 19 +++++++++++++++++++ > 2 files changed, 33 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec12.C > > diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc > index 94f6222b436..772f8532b47 100644 > --- a/gcc/cp/constraint.cc > +++ b/gcc/cp/constraint.cc > @@ -3253,11 +3253,22 @@ satisfy_declaration_constraints (tree t, tree args, sat_info info) > { > if (!push_tinst_level (t, args)) > return result; > - tree pattern = DECL_TEMPLATE_RESULT (t); > + tree ascope = DECL_TEMPLATE_RESULT (t); > + if (CLASS_TYPE_P (TREE_TYPE (t)) > + && CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (t))) > + { > + gcc_checking_assert (t == most_general_template (t)); > + /* When checking the constraints on a partial specialization, > + do so in the context of the specialized type, not the template. > + This substitution should always succeed since we shouldn't > + be checking constraints thereof unless the specialized type > + is valid. */ > + ascope = tsubst (ascope, args, tf_none, info.in_decl); > + } > push_to_top_level (); > - push_access_scope (pattern); > + push_access_scope (ascope); > result = satisfy_normalized_constraints (norm, args, info); > - pop_access_scope (pattern); > + pop_access_scope (ascope); > pop_from_top_level (); > pop_tinst_level (); > } > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec12.C b/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec12.C > new file mode 100644 > index 00000000000..641d456722d > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec12.C > @@ -0,0 +1,19 @@ > +// PR c++/105220 > +// { dg-do compile { target c++20 } } > + > +template > +concept fooable = requires(T t) { t.foo(); }; > + > +template > +struct A; // #1, incomplete > + > +template > +struct A { }; // #2 > + > +struct B { > +private: > + friend struct A; > + void foo(); > +}; > + > +template struct A; // OK, B::foo() is accessible from #2