From 631cd92b3b3d187860df004d212c4d7f6db517b7 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 27 Nov 2024 09:32:31 +0100 Subject: 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. --- gcc/c/c-parser.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gcc/c') 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); -- cgit v1.1