From: Joseph Myers <joseph@codesourcery.com>
To: <gcc-patches@gcc.gnu.org>
Subject: [committed] c: Disallow braces around C2x auto initializers
Date: Fri, 27 Jan 2023 21:39:59 +0000 [thread overview]
Message-ID: <d4c8df3e-bf4f-804b-2e47-6430848d1e81@codesourcery.com> (raw)
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" } */
+}
--
Joseph S. Myers
joseph@codesourcery.com
reply other threads:[~2023-01-27 21:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d4c8df3e-bf4f-804b-2e47-6430848d1e81@codesourcery.com \
--to=joseph@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).