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.129.124]) by sourceware.org (Postfix) with ESMTPS id B48723858D20 for ; Mon, 14 Feb 2022 16:37:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B48723858D20 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-225-7nAcmkbDMZKPBHAS9--Cig-1; Mon, 14 Feb 2022 11:37:12 -0500 X-MC-Unique: 7nAcmkbDMZKPBHAS9--Cig-1 Received: by mail-qk1-f200.google.com with SMTP id bi17-20020a05620a319100b0050850bdcbb2so9445627qkb.17 for ; Mon, 14 Feb 2022 08:37:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=QessRVrEA7byQLjM1dKOPjmIX4rP9+2b4E/LEKl/UqY=; b=qXLghDJFcQa3EyMOL8161hiEfYaYDtIByub8rdHXY+s+gACAX/LQEMsyGSQDgF/DIW 7PMr2QQCnt/wplr8hLIfE+JyklCNycPDJn4ot9r2ilxDpm2freHXaOLhFY2lyJT8l7kq nC9I7A3j7XNE7QMIzWLuOpex4YoOyL1BodZSIN6AtCS53RAJZGoUhQL1NFG+E3+Lt6SZ Yh4AGV3if0QMroiISqW5EMemr5PIjqJ/hH29iOV9XC8wofy83BhkqZ+E7CyCuRtosmn4 hOyIlpMtYS+mwF9SuIsl263KbIYaiIvlgl4+fGvcxvWTF0yb62TJAinhMTv8uy0ypwId /bcw== X-Gm-Message-State: AOAM5339CIqykX3LiOR7hYQRLGscC2LvPiyomHrZ+YVLjldDa3xNd9Ch A6h9mfQh1u/aCU+HPui5ssHBEkVFyqrc64VFL3siwYlfx10xOgZK3/TPfcCW+kFNu9a3tBKmEaT SsQT8Tb1v42aH1WvsKA== X-Received: by 2002:a05:6214:d81:: with SMTP id e1mr351910qve.70.1644856631562; Mon, 14 Feb 2022 08:37:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlf66Qq4wJxNznAa1jp76ufYrFxohRlxztIFmnbNaObe2tVdYOufq3IQQn3YQih7PshkuE5A== X-Received: by 2002:a05:6214:d81:: with SMTP id e1mr351897qve.70.1644856631263; Mon, 14 Feb 2022 08:37:11 -0800 (PST) Received: from [192.168.1.130] (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id u17sm15260172qkj.44.2022.02.14.08.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 08:37:10 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 14 Feb 2022 11:37:09 -0500 (EST) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH] c++: return-type-req in constraint using only outer tparms [PR104527] In-Reply-To: <20220214163250.3454164-1-ppalka@redhat.com> Message-ID: References: <20220214163250.3454164-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.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_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: Mon, 14 Feb 2022 16:37:15 -0000 On Mon, 14 Feb 2022, 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. > > 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 Whoops, this should be r12-6919 (after which we pass outer_targs appropriately during adc_variable_type deduction of non-function-scope variables), not r12-7101, sorry about that. > 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" } > +} > -- > 2.35.1.102.g2b9c120970 > >