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 483FF3858D20 for ; Mon, 14 Feb 2022 16:33:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 483FF3858D20 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-7O4p8_YxPV6Ub3LYVH_JUA-1; Mon, 14 Feb 2022 11:32:57 -0500 X-MC-Unique: 7O4p8_YxPV6Ub3LYVH_JUA-1 Received: by mail-qv1-f69.google.com with SMTP id g2-20020a0562141cc200b004123b0abe18so12046119qvd.2 for ; Mon, 14 Feb 2022 08:32:57 -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:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IB91Jom7K5HGXHNvMkOqZaAhibG8qJIKHyJOFT9Bw3k=; b=EO1epXr4fzuwohYyiz+A73y0LSgVI2TKX8SlcmCivrtgZnuTw/K0CAXLS5sPQHZUSH FNSe1GQuoCkBck7XUN16VEtmG+rMvjZ29wHmRMmWKXBjBgVQz9kWd+6Go60gWbqZpyVS SQyCDS7UozipQQKxlCBRK4FX5SaIkLnf73hPfslm+f1OaLro32B6WECAK1EJMYNRcVtb QhP2k8XB8D2twHMTZJT+uhOPyK5mQpg3em0d2nkrihj+qU/im0k1eLDWZ3iSILxrcSMs f9qwbE0xhuEWYL38TQa+u+PTfZTSsDSXooitXH979v22JVV4rDglAa/aeDYD1OyYQSPh gbew== X-Gm-Message-State: AOAM533oBafNlj/h4MtgVTkTABeNmRr4cyBVVcz3uEVNg0lHthSmAL3s Ua+j7cN9+oPW9+V7n8QLS6dBmGJ6ClubmDfqwfYyUt+ulQOR4t7Xv+weoooyIR+oim8oIQ6hfe+ OQPO0SfUydpK5UNudq5/i+UTAbIfZAOeEUBcMpmysigCA2oxZooo8oGQ3Da6i5780nEQ= X-Received: by 2002:ae9:ed4d:: with SMTP id c74mr290286qkg.370.1644856376675; Mon, 14 Feb 2022 08:32:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJw06MaA5Dd0UiPDi5NtpExO3sDo4CnfT5BQkK6gQACKvsGNiFj1qPac9NqKHJPVFLcK/wqsVA== X-Received: by 2002:ae9:ed4d:: with SMTP id c74mr290261qkg.370.1644856376286; Mon, 14 Feb 2022 08:32:56 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id m1sm7807060qtw.65.2022.02.14.08.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 08:32:55 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: return-type-req in constraint using only outer tparms [PR104527] Date: Mon, 14 Feb 2022 11:32:50 -0500 Message-Id: <20220214163250.3454164-1-ppalka@redhat.com> X-Mailer: git-send-email 2.35.1.102.g2b9c120970 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.4 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:33:03 -0000 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 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