From patchwork Thu May 28 15:03:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1299872 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ccw969uB; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49XrYX1tr4z9sV3 for ; Fri, 29 May 2020 01:03:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C58F7386F82F; Thu, 28 May 2020 15:03:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C58F7386F82F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1590678205; bh=KtpNIwUtTJVf16cjSlTUpTDUGh2MDtrk/0HRy+nS3Ic=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ccw969uBBcfQnKHzL9KpcNzRjSGuEKHVQlAp1rHt4Ll9Fcembu1mWDtz2uhIJwzHf rjjIPqNtpCwpjZoX5cYOAzmN3ejSAW8XfchOx9bU90C4UQf21OIShbQYZ4EogtuhKp AALTnG/rtM1uZJsc7N2IQRGQZr3As8bIUf92gick= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 763D83851C21 for ; Thu, 28 May 2020 15:03:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 763D83851C21 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-101-Ds5flxd4O8WnaiGJNaIi2g-1; Thu, 28 May 2020 11:03:20 -0400 X-MC-Unique: Ds5flxd4O8WnaiGJNaIi2g-1 Received: by mail-qt1-f199.google.com with SMTP id p31so314353qte.1 for ; Thu, 28 May 2020 08:03:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KtpNIwUtTJVf16cjSlTUpTDUGh2MDtrk/0HRy+nS3Ic=; b=lrbRinIVD1N3cp0iDbLc8f1mjVMbEK7ZZ43Bcyyk/SsmsNvIXDmM85RIZETpB7lH6r gJ6WRbCvw1BL/Wd4V+CtD6ClIdI3o3Y+9obuZO3HbKFwJxEgKa3KceYMT6rcPjg7o1p3 OncJRKcKBS6s+/S+JgHz0C2FD4fo7dttczTseEP/CO6K9xa/zk2xRTISOWtxcyfl/fmP O91LjTFbL1FTbAAk2UIMScp0wrnBwqj7q+r1ibhm4343f1CIgJddVg2KHwZKUB5vOLX8 iWFFw4xGDdtwMGY39kXfWiU3vnfkJsPL8USUv7uyOR21KY5D1bjWkes8UFkPU0YpvbcT YZZg== X-Gm-Message-State: AOAM530s6FDsSwyRGPT5sES/7RHJ7daz0bpEycBw6Qx0BpOaNN8sb/IZ CI6BTrXLw8ZsZolrnqWgrrdu2XLkNCXEy2DSrtx/5I96mfcuDDmTF3B/AjtzUeq5m3SM/KQ8mUS 83WWB/bbcq3DgOf9Khg== X-Received: by 2002:a0c:fecf:: with SMTP id z15mr3445879qvs.76.1590678199889; Thu, 28 May 2020 08:03:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf+pkkLYgbRbvPt0SYe7Ce/j5LlNgVGNBU/jbusqmImYYaMqf15+6EAnqUE3N2N7s/erG6pg== X-Received: by 2002:a0c:fecf:: with SMTP id z15mr3445826qvs.76.1590678199397; Thu, 28 May 2020 08:03:19 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id o3sm5252112qkj.97.2020.05.28.08.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2020 08:03:18 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: lambdas inside constraints [PR92652] Date: Thu, 28 May 2020 11:03:16 -0400 Message-Id: <20200528150316.2078692-1-ppalka@redhat.com> X-Mailer: git-send-email 2.27.0.rc1.5.gae92ac8ae3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-18.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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" When parsing a constraint-expression, a requires-clause or a requires-expression, we temporarily increment processing_template_decl so that we always obtain template trees which we later reduce via substitution even when not inside a template. But incrementing processing_template_decl when we're already inside a template has the unintended side effect of shifting up the template parameter levels of a lambda defined inside one of these constructs, which leads to confusion later during substitution into the lambda. This patch fixes this issue by incrementing processing_template_decl during parsing of these constructs only if it is 0. Passes 'make check-c++', and also tested by building cmcstl2, does this look OK to commit after a full bootstrap/regtest? gcc/cp/ChangeLog: PR c++/92652 PR c++/93698 PR c++/94128 * parser.c (cp_parser_requires_clause_expression): Temporarily increment processing_template_decl only if it is 0. (cp_parser_constraint_expression): Likewise. (cp_parser_requires_expression): Likewise. gcc/testsuite/ChangeLog: PR c++/92652 PR c++/93698 PR c++/94128 * g++.dg/cpp2a/concepts-lambda8.C: New test. * g++.dg/cpp2a/concepts-lambda9.C: New test. * g++.dg/cpp2a/concepts-lambda10.C: New test. --- gcc/cp/parser.c | 15 +++++++++------ gcc/testsuite/g++.dg/cpp2a/concepts-lambda10.C | 7 +++++++ gcc/testsuite/g++.dg/cpp2a/concepts-lambda8.C | 11 +++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-lambda9.C | 11 +++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-lambda10.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-lambda8.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-lambda9.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 54ca875ce54..3bca1f3770a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -27663,11 +27663,12 @@ static tree cp_parser_requires_clause_expression (cp_parser *parser, bool lambda_p) { processing_constraint_expression_sentinel parsing_constraint; - ++processing_template_decl; + temp_override ovr (processing_template_decl); + if (!processing_template_decl) + processing_template_decl = 1; cp_expr expr = cp_parser_constraint_logical_or_expression (parser, lambda_p); if (check_for_bare_parameter_packs (expr)) expr = error_mark_node; - --processing_template_decl; return expr; } @@ -27684,12 +27685,13 @@ static tree cp_parser_constraint_expression (cp_parser *parser) { processing_constraint_expression_sentinel parsing_constraint; - ++processing_template_decl; + temp_override ovr (processing_template_decl); + if (!processing_template_decl) + processing_template_decl = 1; cp_expr expr = cp_parser_binary_expression (parser, false, true, PREC_NOT_OPERATOR, NULL); if (check_for_bare_parameter_packs (expr)) expr = error_mark_node; - --processing_template_decl; expr.maybe_add_location_wrapper (); return expr; } @@ -27798,9 +27800,10 @@ cp_parser_requires_expression (cp_parser *parser) parms = NULL_TREE; /* Parse the requirement body. */ - ++processing_template_decl; + temp_override ovr (processing_template_decl); + if (!processing_template_decl) + processing_template_decl = 1; reqs = cp_parser_requirement_body (parser); - --processing_template_decl; if (reqs == error_mark_node) return error_mark_node; } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda10.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda10.C new file mode 100644 index 00000000000..392da312b28 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda10.C @@ -0,0 +1,7 @@ +// PR c++/94128 +// { dg-do compile { target c++20 } } + +void test(auto param) +requires requires{ { [](auto p){return p;}(param) }; }; + +void test2() { test(1); } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda8.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda8.C new file mode 100644 index 00000000000..c1c9be682d0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda8.C @@ -0,0 +1,11 @@ +// PR c++/92652 +// { dg-do compile { target concepts } } + +template < typename T > + requires ([]{return true ;}()) +void h() { } + +int main() +{ + h(); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda9.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda9.C new file mode 100644 index 00000000000..6b81ba0adac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda9.C @@ -0,0 +1,11 @@ +// PR c++/93698 +// { dg-do compile { target concepts } } + +#include + +template +concept foo = [](std::index_sequence) constexpr { + return (Is + ...) > 10; +}(std::make_index_sequence()); + +bool a = foo<7>;