From patchwork Fri Jan 27 21:39:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 63818 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 343AB3858404 for ; Fri, 27 Jan 2023 21:40:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 23C8A3858D20 for ; Fri, 27 Jan 2023 21:40:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 23C8A3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.97,252,1669104000"; d="scan'208";a="94994026" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 27 Jan 2023 13:40:03 -0800 IronPort-SDR: C539A6YJxYuhDiKdVvbmC84Kpx0OSsw4hIZZVWAPg/n/GUQ/l58Tig22fADurGrYu0lzB/kXaN CrOPZuh8mE13se4DTK+JYi6z2Ae2iyL3P0tD2X1Lr9lxwoBrm+6pqxIA2qMsrsxcj0NVxFQYxJ O+Q9QZzEUuglZREj7bIWS5EYjyKlZf8pVgRLAaJqiuLb6fzi/65LWITBTfA06EnSxT1OM2tV49 8MwulFD0mx0hqBBLvDTUUTeZlmBE9PEmeM6yYPL1LlwJcCgWMLjTmzYM3uX7LrjzjnvaPtVQRo fOs= Date: Fri, 27 Jan 2023 21:39:59 +0000 From: Joseph Myers To: Subject: [committed] c: Disallow braces around C2x auto initializers Message-ID: MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3114.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" WG14 agreed at this week's meeting to remove support for braces around auto scalar initializers, as incompatible with C++ auto handling of braced initializers; thus remove that support in GCC. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c/ * c-parser.cc (c_parser_declaration_or_fndef): Do not allow braces around auto initializer. gcc/testsuite/ * gcc.dg/c2x-auto-1.c, gcc.dg/c2x-auto-3.c: Expect braces around auto initializers to be disallowed. diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 803b04b8dc1..69230002bc8 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -2480,18 +2480,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, int flag_sanitize_save = flag_sanitize; if (nested && !empty_ok) flag_sanitize = 0; - if (std_auto_type_p - && c_parser_next_token_is (parser, CPP_OPEN_BRACE)) - { - matching_braces braces; - braces.consume_open (parser); - init = c_parser_expr_no_commas (parser, NULL); - if (c_parser_next_token_is (parser, CPP_COMMA)) - c_parser_consume_token (parser); - braces.skip_until_found_close (parser); - } - else - init = c_parser_expr_no_commas (parser, NULL); + init = c_parser_expr_no_commas (parser, NULL); if (std_auto_type_p) finish_underspecified_init (underspec_name, underspec_state); diff --git a/gcc/testsuite/gcc.dg/c2x-auto-1.c b/gcc/testsuite/gcc.dg/c2x-auto-1.c index f8460fb3bfb..c50daccfe89 100644 --- a/gcc/testsuite/gcc.dg/c2x-auto-1.c +++ b/gcc/testsuite/gcc.dg/c2x-auto-1.c @@ -4,14 +4,14 @@ auto i = 1; extern int i; -static auto l = { 0L }; +static auto l = 0L; extern long l; extern auto const d = 0.0; /* { dg-warning "initialized and declared 'extern'" } */ extern const double d; double dx; auto ((i2)) = 3; extern int i2; -const auto i3 [[]] = { 4, }; +const auto i3 [[]] = 4; extern int i4; thread_local auto f = 1.0f; float ff; diff --git a/gcc/testsuite/gcc.dg/c2x-auto-3.c b/gcc/testsuite/gcc.dg/c2x-auto-3.c index a34ce31f6be..1ab3cc74d35 100644 --- a/gcc/testsuite/gcc.dg/c2x-auto-3.c +++ b/gcc/testsuite/gcc.dg/c2x-auto-3.c @@ -62,3 +62,10 @@ f5 () { static int auto e10 = 3; /* { dg-error "multiple storage classes in declaration specifiers" } */ } + +void +f6 () +{ + static auto l = { 0L }; /* { dg-error "expected expression" } */ + const auto i3 [[]] = { 4, }; /* { dg-error "expected expression" } */ +}