diff options
author | Florian Weimer <fweimer@redhat.com> | 2024-11-27 09:32:31 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2024-11-27 09:32:31 +0100 |
commit | 631cd92b3b3d187860df004d212c4d7f6db517b7 (patch) | |
tree | 28f97c75481b765c760081250d82204f5bacc92d /gcc/c/c-parser.cc | |
parent | 2fd9aef1db1a4260ee823bc3a3d4cfc22e95c543 (diff) | |
download | gcc-631cd92b3b3d187860df004d212c4d7f6db517b7.zip gcc-631cd92b3b3d187860df004d212c4d7f6db517b7.tar.gz gcc-631cd92b3b3d187860df004d212c4d7f6db517b7.tar.bz2 |
c: Introduce -Wfree-labels
This is another recent GCC extension whose use is apparently
difficult to spot in code reviews.
The name of the option is due to Jonathan Wakely. Part of it
could apply to C++ as well (for labels at the end of a compound
statement).
gcc/c-family/
* c-opts.cc (c_common_post_options): Initialize
warn_free_labels.
* c.opt (Wfree-labels): New option.
* c.opt.urls: Regenerate.
gcc/c/
* c-parser.cc (c_parser_compound_statement_nostart): Use
OPT_Wfree_labels for warning about labels on declarations.
(c_parser_compound_statement_nostart): Use OPT_Wfree_labels
for warning about labels at end of compound statements.
gcc/
* doc/invoke.texi: Document -Wfree-labels.
gcc/testsuite/
* gcc.dg/Wfree-labels-1.c: New test.
* gcc.dg/Wfree-labels-2.c: New test.
* gcc.dg/Wfree-labels-3.c: New test.
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r-- | gcc/c/c-parser.cc | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 4868357..47668ec 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -7406,7 +7406,7 @@ c_parser_compound_statement_nostart (c_parser *parser) && (have_std_attrs = true))) { if (last_label) - pedwarn_c11 (c_parser_peek_token (parser)->location, OPT_Wpedantic, + pedwarn_c11 (c_parser_peek_token (parser)->location, OPT_Wfree_labels, "a label can only be part of a statement and " "a declaration is not a statement"); /* It's unlikely we'll see a nested loop in a declaration in @@ -7553,7 +7553,8 @@ c_parser_compound_statement_nostart (c_parser *parser) parser->error = false; } if (last_label) - pedwarn_c11 (label_loc, OPT_Wpedantic, "label at end of compound statement"); + pedwarn_c11 (label_loc, OPT_Wfree_labels, + "label at end of compound statement"); location_t endloc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); |