From patchwork Tue Nov 17 18:05:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1401736 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=pass (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=s0RKd8Tn; 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 4CbDPn6Tdfz9sRR for ; Wed, 18 Nov 2020 05:05:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D199D386F41D; Tue, 17 Nov 2020 18:05:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D199D386F41D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1605636330; bh=O9Qu9HZ91XWWypUIZ1IydmTqY+x86NhzeVn2zcWgvDA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=s0RKd8TnWjC7ss9Uv6eLLaF7lNMnUZM1uXGZZXmwXwrk+iU6yFw/XVQeHkDTTRPQA 8R8hFOeIIIUOlMhzDmF9FxWz2e5odYHe5GqfLu90WWckNmlZJ7YRxFUJf9HopHYJaG JIHr+42CFp6tPAxxB+6SC0c0DHVMJfEAyXZFRk+I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 2D36F386EC78 for ; Tue, 17 Nov 2020 18:05:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2D36F386EC78 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-430-tu2NSwUNPcqwBbBr8MK18Q-1; Tue, 17 Nov 2020 13:05:25 -0500 X-MC-Unique: tu2NSwUNPcqwBbBr8MK18Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F227F1016CE0 for ; Tue, 17 Nov 2020 18:05:24 +0000 (UTC) Received: from pdp-11.hsd1.ma.comcast.net (ovpn-118-216.rdu2.redhat.com [10.10.118.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96FF45B4A2; Tue, 17 Nov 2020 18:05:24 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: Allow template lambdas without lambda-declarator [PR97839] Date: Tue, 17 Nov 2020 13:05:20 -0500 Message-Id: <20201117180520.2364601-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.2 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_H4, 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Our implementation of template lambdas incorrectly requires the optional lambda-declarator. This was probably required by an early draft of generic lambdas, but now the production is [expr.prim.lambda.general]: lambda-expression: lambda-introducer lambda-declarator [opt] compound-statement lambda-introducer < template-parameter-list > requires-clause [opt] lambda-declarator [opt] compound-statement Therefore, we should accept the following test. Incidentally, I noticed we give a terrible diagnostic when the user uses 'mutable', but forgets to type '()' before it, which sounds like a common mistake. So it seems to me we should handle that specifically, rather than to emit this: lambda-generic8.C: In lambda function: lambda-generic8.C:8:18: error: expected '{' before 'mutable' 8 | [] mutable {}.operator()(); | ^~~~~~~ lambda-generic8.C: In function 'int main()': lambda-generic8.C:8:17: error: expected ';' before 'mutable' 8 | [] mutable {}.operator()(); | ^~~~~~~~ | ; lambda-generic8.C:8:28: error: expected primary-expression before '.' token 8 | [] mutable {}.operator()(); | ^ lambda-generic8.C:8:40: error: expected primary-expression before 'int' 8 | [] mutable {}.operator()(); | ^~~ Is it okay to fix this in stage3? Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: PR c++/97839 * parser.c (cp_parser_lambda_declarator_opt): Don't require (). gcc/testsuite/ChangeLog: PR c++/97839 * g++.dg/cpp2a/lambda-generic8.C: New test. --- gcc/cp/parser.c | 14 ++++++-------- gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C | 9 +++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C base-commit: 8661f4faa875f361cd22a197774c1fa04cd0580b diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 42f705266bb..9f09c778c29 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10604,6 +10604,8 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword) lambda-expression: lambda-introducer lambda-declarator [opt] compound-statement + lambda-introducer < template-parameter-list > requires-clause [opt] + lambda-declarator [opt] compound-statement Returns a representation of the expression. */ @@ -11061,13 +11063,11 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr) /* Parse the (optional) middle of a lambda expression. lambda-declarator: - < template-parameter-list [opt] > - requires-clause [opt] - ( parameter-declaration-clause [opt] ) - attribute-specifier [opt] + ( parameter-declaration-clause ) decl-specifier-seq [opt] - exception-specification [opt] - lambda-return-type-clause [opt] + noexcept-specifier [opt] + attribute-specifier-seq [opt] + trailing-return-type [opt] requires-clause [opt] LAMBDA_EXPR is the current representation of the lambda expression. */ @@ -11217,8 +11217,6 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) trailing-return-type in case of decltype. */ pop_bindings_and_leave_scope (); } - else if (template_param_list != NULL_TREE) // generate diagnostic - cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN); /* Create the function call operator. diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C new file mode 100644 index 00000000000..f3c3809b36d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C @@ -0,0 +1,9 @@ +// PR c++/97839 +// { dg-do compile { target c++20 } } +// Test that a lambda with doesn't require +// a lambda-declarator. + +int main() +{ + []{}.operator()(); +}