From patchwork Tue Oct 17 21:38:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 154577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4412147vqb; Tue, 17 Oct 2023 14:39:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4cTgl9GtXdywH55BwQiooaONzLgwgXUupKf3zd3kIBCV0AGuZV3fW+YznBHGDmqIu2405 X-Received: by 2002:a05:6122:179a:b0:48f:8891:296b with SMTP id o26-20020a056122179a00b0048f8891296bmr4235696vkf.0.1697578741291; Tue, 17 Oct 2023 14:39:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697578741; cv=pass; d=google.com; s=arc-20160816; b=0BQ30Hk5dYhB1rJ2r5l6nWxGNeFk3Uf0e+OQkbzYNU4JxaHRNTifXkNAX4gb+LeMq/ 2m7JdPFx7EjQ7Y54467LivUWWC+QfbXdnVZjSWO5vbsfRrUI3Clrt3eEgvLy6k5HZBsz XjiOXt0rsBsgpI9wMuUn0wVqE2em9cgqsHNpMi7JrmrIONoPYir0msHDZhJTUcLuj6Rb 9VT2BtlfMfC5LBdIfMT4Wa48K4FqwVrE64qGczYr5iITw0omGBCFpMgEkVNMgHnS4W5i YPkJ5fm+TeomFC5nDdFj9hT9ZX61g3B8vd3P9mf+lDjG7lSca79RYCVIyCIymLzOGhn+ e9zQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=Lh9IXHyVCbzNnqE552KRG486JAP+jokMz7BQH8GdAVg=; fh=2BFo3VQCimnyWTJsWe6sNdepvNrW+J/2ctoM6N7MZ0Y=; b=iUzRxMIVsGKguSLwWXr19t1cjij/8eTNpMxaEOzN+MbOTL1erq9o/auPYwV6zzUgnH wUKhtr5KFLdEYR+QO1k9p10iIW3z1t4qV4KTc80fmIEDZNTPpnf09ftdvf0h8yZ+IU8+ aXJPKazbedB/QLR00AwkPHjUCOfuSrV7Hi4YdADkXm/8uVSOGQhFzSxBTgrJFoWTQKOB 8x4FGtfWPtPYXd7QpB9buIFlU7TkneHbl02R1OWZbSk7S4In7OSQgJvxLkBsGx9576O5 iOx3Rv6GuPK3MMjnricR8XIiyOrWJetb999MzjfyEWbqLhRHoNSKYAcV+W5nB59Zs57n wzpA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QWChydU8; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f1-20020ac859c1000000b0041b77382a1fsi1723559qtf.598.2023.10.17.14.39.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 14:39:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QWChydU8; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 130BF3858291 for ; Tue, 17 Oct 2023 21:39:01 +0000 (GMT) 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C94C83858C52 for ; Tue, 17 Oct 2023 21:38:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C94C83858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C94C83858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697578718; cv=none; b=Nz4g/nDHHq5dbiHZsMq9lMKTZTuq/OPjNFpRAZeVyRCbZXG12GKJTZhM2hZY6PLbOBLVv2Om+gDblnXD0RKjRxU/ovt5nEluAu635AAi0T/xnXyFj7rXfRLcTl6mqj8VCZJS8l5gUc1d1dCSEA5dX+Mzacl3WP8lRkGInwBSsmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697578718; c=relaxed/simple; bh=iicf9UZ046Sde86DAFAz+klrSmBd0l/9vXgSUv+wLsU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vJbCw02Hy6yg1RrderHQbIh4RtQjQXBHasyPJg66ff1R6MOE0j5YnaoYyevz40Rui1FV6cUPi1CzB8v77+CQlWNNiDvflHhMgoN4xNKTvG1012FtQRLV8jui1JqF0RnwOCc4vZTjY6aPDWwCtRCZu8wXX1EYK7S1UD4BvXPW6lk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697578716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Lh9IXHyVCbzNnqE552KRG486JAP+jokMz7BQH8GdAVg=; b=QWChydU8FTGyXbDEf5y0S6QX6K0CRyMZT/BVqSJDixQDGOFKajrNehfMWvKQvEIvF1Yx1l SezS/JLRU4wIs2UfVNOb6xhSGoEJPFMERdVI+SzFbc4mnuTRgWmgwTCvsDFMSeL6/Rt2to GEkmomTcIZMyyyTfiZfoXV+Cca9sSrg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-308-yf5OFjdxM-ScCqNQgB-aAw-1; Tue, 17 Oct 2023 17:38:30 -0400 X-MC-Unique: yf5OFjdxM-ScCqNQgB-aAw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C1D123801EE2 for ; Tue, 17 Oct 2023 21:38:29 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.33.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2BBC492BEE; Tue, 17 Oct 2023 21:38:29 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: accepts-invalid with =delete("") [PR111840] Date: Tue, 17 Oct 2023 17:38:26 -0400 Message-ID: <20231017213826.1040138-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780040326689639631 X-GMAIL-MSGID: 1780040326689639631 Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- r6-2367 added a DECL_INITIAL check to cp_parser_simple_declaration so that we don't emit multiple errors in g++.dg/parse/error57.C. But that means we don't diagnose int f1() = delete("george_crumb"); anymore, because fn decls often have error_mark_node in their DECL_INITIAL. (The code may be allowed one day via https://wg21.link/P2573R0.) I was hoping I could use cp_parser_error_occurred but that would regress error57.C. PR c++/111840 gcc/cp/ChangeLog: * parser.cc (cp_parser_simple_declaration): Do cp_parser_error for FUNCTION_DECLs. gcc/testsuite/ChangeLog: * g++.dg/parse/error65.C: New test. --- gcc/cp/parser.cc | 14 +++++++------- gcc/testsuite/g++.dg/parse/error65.C | 10 ++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/parse/error65.C base-commit: bac21b7ea62bd3a7911e01cf803d6bf6516fbf7b diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 59b9852895e..57b62fb7363 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -15669,6 +15669,7 @@ cp_parser_simple_declaration (cp_parser* parser, maybe_range_for_decl, &init_loc, &auto_result); + const bool fndecl_p = TREE_CODE (decl) == FUNCTION_DECL; /* If an error occurred while parsing tentatively, exit quickly. (That usually happens when in the body of a function; each statement is treated as a declaration-statement until proven @@ -15682,16 +15683,13 @@ cp_parser_simple_declaration (cp_parser* parser, init-declarator, they shall all form declarations of variables. */ if (auto_function_declaration == NULL_TREE) - auto_function_declaration - = TREE_CODE (decl) == FUNCTION_DECL ? decl : error_mark_node; - else if (TREE_CODE (decl) == FUNCTION_DECL - || auto_function_declaration != error_mark_node) + auto_function_declaration = fndecl_p ? decl : error_mark_node; + else if (fndecl_p || auto_function_declaration != error_mark_node) { error_at (decl_specifiers.locations[ds_type_spec], "non-variable %qD in declaration with more than one " "declarator with placeholder type", - TREE_CODE (decl) == FUNCTION_DECL - ? decl : auto_function_declaration); + fndecl_p ? decl : auto_function_declaration); auto_function_declaration = error_mark_node; } } @@ -15763,7 +15761,9 @@ cp_parser_simple_declaration (cp_parser* parser, /* If we have already issued an error message we don't need to issue another one. */ if ((decl != error_mark_node - && DECL_INITIAL (decl) != error_mark_node) + /* grokfndecl sets DECL_INITIAL to error_mark_node for + functions. */ + && (fndecl_p || DECL_INITIAL (decl) != error_mark_node)) || cp_parser_uncommitted_to_tentative_parse_p (parser)) cp_parser_error (parser, "expected %<,%> or %<;%>"); /* Skip tokens until we reach the end of the statement. */ diff --git a/gcc/testsuite/g++.dg/parse/error65.C b/gcc/testsuite/g++.dg/parse/error65.C new file mode 100644 index 00000000000..d9e0a4bfbcb --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/error65.C @@ -0,0 +1,10 @@ +// PR c++/111840 +// { dg-do compile { target c++11 } } + +// NB: =delete("reason") may be allowed via P2573. +int f1() = delete("should have a reason"); // { dg-error "expected" } +int f2() = delete[""]; // { dg-error "expected" } +int f3() = delete{""}; // { dg-error "expected" } +int f4() = delete""; // { dg-error "expected" } +int f5() = delete[{'a'""; // { dg-error "expected" } +int i = f5();