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 98DF03858005 for ; Tue, 15 Feb 2022 23:39:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 98DF03858005 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-674-1HmSkYmjOfSUAcbJSKvw7A-1; Tue, 15 Feb 2022 18:39:36 -0500 X-MC-Unique: 1HmSkYmjOfSUAcbJSKvw7A-1 Received: by mail-qv1-f70.google.com with SMTP id kc30-20020a056214411e00b0042cb92fe8bbso576019qvb.8 for ; Tue, 15 Feb 2022 15:39:36 -0800 (PST) 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=+MiDUJtt+g0JltX4ez1RVhi0l3vkrXaVgd0xRBlsMHc=; b=JPPSuPuu9SlIKAQFD53ZklSxubnsAxtr73YXU4yrJhQVUKBmq9O43iNa/dShwJ7C+s PmHgHvb6RwQMz/zu8170Lx4klWyh5WVobjn9CePTA2yvJ05TIJgPmzItci5vAoP8rB6R bXAUpW3oBOHP7G+tNHLa0oSlu8AFj51C35l+XSPFGHLVttMGT9nZwg+JJeg4E+MgTega v8Ati12XWZsdBmLt03xIeq9scuv66LAnY0Nw6NZ0LpEh9OYjWizdW4NRbk1emmIHEidC UvIi14KdXNfcxqpprWzmGkJqgIFVMdZGXK6ZiP2PmNQNgI5ErikaTjIByFba8HnUFsk4 lgvQ== X-Gm-Message-State: AOAM532XPx4sKDqDI/hujkSMduI7LqvmaSZAk3dYDsmlaEmVN8QKLXFx B/zaVUhgsM67FwKfe5gT24UTTFO4s2i8Mk0cBE6CKw29rTApSzoR0ZilbHkynRVK4ngWwvyhOhu aHp1DDeX5Wtbkrpkh0g== X-Received: by 2002:ac8:59cc:0:b0:2d5:c7fe:88f6 with SMTP id f12-20020ac859cc000000b002d5c7fe88f6mr324747qtf.234.1644968375656; Tue, 15 Feb 2022 15:39:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2psazrrm3xi3lO3QSKnuiDwCtRlXI6TOp7+45t7c4RUabBvR/s5iNlhHKTNaTLmdaw1yu1w== X-Received: by 2002:ac8:59cc:0:b0:2d5:c7fe:88f6 with SMTP id f12-20020ac859cc000000b002d5c7fe88f6mr324734qtf.234.1644968375167; Tue, 15 Feb 2022 15:39:35 -0800 (PST) Received: from [192.168.1.149] (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 f20sm21514233qte.14.2022.02.15.15.39.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Feb 2022 15:39:34 -0800 (PST) Message-ID: <4c1b4638-0ad6-f229-4d9b-ac2fb362d058@redhat.com> Date: Tue, 15 Feb 2022 18:39:33 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH] c++: return-type-req in constraint using only outer tparms [PR104527] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20220214163250.3454164-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20220214163250.3454164-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=-12.9 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, 15 Feb 2022 23:39:41 -0000 On 2/14/22 11:32, Patrick Palka wrote: > Here the template context for the atomic constraint has two levels of > template arguments, but since it depends only on the innermost argument > T we use a single-level argument vector during substitution into the > constraint (built by get_mapped_args). We eventually pass this vector > to do_auto_deduction as part of checking the return-type-requirement > inside the atom, but do_auto_deduction expects outer_targs to be a full > set of arguments for sake of satisfaction. Could we note the current number of levels in the map and use that in get_mapped_args instead of the highest level parameter we happened to use? > do_auto_deduction has a workaround in place to compensate for callers > that pass only the innermost arguments as outer_targs, but here we're > passing the _outermost_ arguments. Since the former situation should > now (after r12-7101) only occur with adc_unify callers and the latter > only with adc_requirement callers, this patch conditions the existing > workaround according to the auto_deduction_context: if the context is > adc_requirement, we add dummy innermost levels, otherwise we add dummy > outermost levels as before and also assert that the context is adc_unify. > > Bootstrapped and regtested on x86_64-pc-linux-gnu and tested on cmcstl2 > and range-v3, does this look OK for trunk? > > PR c++/104527 > > gcc/cp/ChangeLog: > > * pt.cc (do_auto_deduction): When template argument levels are > missing from outer_targs, fill in the innermost rather than the > outermost levels with dummy args if the context is > adc_requirement, otherwise also assert that the context is > adc_unify. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-return-req4.C: New test. > --- > gcc/cp/pt.cc | 28 +++++++++++++------ > .../g++.dg/cpp2a/concepts-return-req4.C | 24 ++++++++++++++++ > 2 files changed, 44 insertions(+), 8 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-return-req4.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 1b18e2a7787..4ff2710b8ba 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -30215,20 +30215,32 @@ do_auto_deduction (tree type, tree init, tree auto_node, > > tree full_targs = add_to_template_args (outer_targs, targs); > > - /* HACK: Compensate for callers not always communicating all levels of > - outer template arguments by filling in the outermost missing levels > - with dummy levels before checking satisfaction. We'll still crash > - if the constraint depends on a template argument belonging to one of > - these missing levels, but this hack otherwise allows us to handle a > - large subset of possible constraints (including all non-dependent > - constraints). */ > if (int missing_levels = (TEMPLATE_TYPE_ORIG_LEVEL (auto_node) > - TMPL_ARGS_DEPTH (full_targs))) > { > tree dummy_levels = make_tree_vec (missing_levels); > for (int i = 0; i < missing_levels; ++i) > TREE_VEC_ELT (dummy_levels, i) = make_tree_vec (0); > - full_targs = add_to_template_args (dummy_levels, full_targs); > + if (context == adc_requirement) > + /* We're checking a requires-expr's return-type-requirement that's > + part of an atomic constraint that doesn't depend on any innermost > + template arguments, so OUTER_TARGS (built by get_mapped_args) is > + missing at least one innermost level. Fill in the innermost > + levels of OUTER_TARGS with dummy levels. */ > + full_targs = add_to_template_args > + (add_to_template_args (outer_targs, dummy_levels), targs); > + else > + { > + /* Otherwise, fill in the _outermost_ levels with dummy levels. > + This compensates for adc_unify callers that only pass the > + innermost level of template arguments as OUTER_TARGS. We'll > + still crash if the constraint depends on a template argument > + belonging to one of these missing levels, but this hack > + otherwise allows us to handle a large subset of possible > + constraints (including all non-dependent constraints). */ > + gcc_checking_assert (context == adc_unify); > + full_targs = add_to_template_args (dummy_levels, full_targs); > + } > } > > if (!constraints_satisfied_p (auto_node, full_targs)) > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-return-req4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-return-req4.C > new file mode 100644 > index 00000000000..471946bc8eb > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-return-req4.C > @@ -0,0 +1,24 @@ > +// PR c++/104527 > +// { dg-do compile { target c++20 } } > + > +template > +concept is_same = __is_same(T, U); > + > +template > +struct A { > + template > + requires requires { { 0 } -> is_same; } > + struct B {}; > + > + template > + requires requires { { 1 } -> is_same; } > + static void f(); > +}; > + > +A::B<> a1; > +A::B<> a2; // { dg-error "constraint" } > + > +int main() { > + A::f(); > + A::f(); // { dg-error "no match" } > +}