From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1105) id CD0183858D20; Fri, 27 Jan 2023 21:39:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD0183858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674855582; bh=1h/k9GDnDJ6Fp5uDCcp+4gJjilt3ZVQWZ4HCifC4YF8=; h=From:To:Subject:Date:From; b=hXoApPfHY6CeVN2xv1qdeVPiHKz6sZAwBklQwC7xsUXPLXncUqRqoko6/7d5Q797k FXM0Zsr5RVVWPZ80cGSeH6hjczyRaN5K+vHWvLAyh+mytl6BhOuqhFkW4lPXRormS5 0Vi7JjZ0t92ESKIeRg/QgN9K7diQlx+Pm/i2KzaE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Joseph Myers To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5462] c: Disallow braces around C2x auto initializers X-Act-Checkin: gcc X-Git-Author: Joseph Myers X-Git-Refname: refs/heads/master X-Git-Oldrev: 815e5740162d2d0b7b54031f72c201065016d58c X-Git-Newrev: 84eb39556cc8449e04b5f48bd5c131941a7a2529 Message-Id: <20230127213942.CD0183858D20@sourceware.org> Date: Fri, 27 Jan 2023 21:39:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:84eb39556cc8449e04b5f48bd5c131941a7a2529 commit r13-5462-g84eb39556cc8449e04b5f48bd5c131941a7a2529 Author: Joseph Myers Date: Fri Jan 27 21:38:57 2023 +0000 c: Disallow braces around C2x auto initializers 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: --- gcc/c/c-parser.cc | 13 +------------ gcc/testsuite/gcc.dg/c2x-auto-1.c | 4 ++-- gcc/testsuite/gcc.dg/c2x-auto-3.c | 7 +++++++ 3 files changed, 10 insertions(+), 14 deletions(-) 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" } */ +}