= ((pedantic && !flag_isoc23 && warn_c11_c23_compat != 0)
|| warn_c11_c23_compat > 0);
+ /* Likewise for -Wfree-labels. */
+ if (warn_free_labels == -1)
+ warn_free_labels = ((pedantic && !flag_isoc23 && warn_c11_c23_compat != 0)
+ || warn_c11_c23_compat > 0);
+
if (warn_deprecated_non_prototype == -1)
warn_deprecated_non_prototype = warn_c11_c23_compat > 0;
C ObjC C++ ObjC++ Var(warn_frame_address) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
Warn when __builtin_frame_address or __builtin_return_address is used unsafely.
+Wfree-labels
+C ObjC Var(warn_free_labels) Init(-1) Warning
+Warn about labels on declarations and at the end of compound statements.
+
Wglobal-module
C++ ObjC++ Var(warn_global_module) Warning Init(1)
Warn about the global module fragment not containing only preprocessing directives.
Wframe-address
UrlSuffix(gcc/Warning-Options.html#index-Wframe-address)
+Wfree-labels
+UrlSuffix(gcc/Warning-Options.html#index-Wfree-labels)
+
Wglobal-module
UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-Wglobal-module)
&& (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
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);
}
@item C and Objective-C-only Warning Options
-@gccoptlist{-Wbad-function-cast -Wdeprecated-non-prototype -Wmissing-declarations
--Wmissing-parameter-name -Wmissing-parameter-type
+@gccoptlist{-Wbad-function-cast -Wdeprecated-non-prototype -Wfree-labels
+-Wmissing-declarations -Wmissing-parameter-name -Wmissing-parameter-type
-Wdeclaration-missing-parameter-type -Wmissing-prototypes
-Wmissing-variable-declarations -Wnested-externs -Wold-style-declaration
-Wold-style-definition -Wstrict-prototypes -Wtraditional
warnings for redefinition of @code{__TIMESTAMP__}, @code{__TIME__},
@code{__DATE__}, @code{__FILE__}, and @code{__BASE_FILE__}.
+@opindex Wfree-labels
+@opindex Wno-free-labels
+@item -Wfree-labels @r{(C and Objective-C only)}
+Warn if a label is applied to a non-statement, or occurs at the end of a
+compound statement. Such labels are allowed by C23 and later dialects
+of C, and are available as a GCC extension in all other dialects.
+
+This warning is also enabled by @option{-Wc11-c23-compat}. It is turned
+into an error if building for a C version before C23 by
+@option{-pedantic-errors}.
+
@opindex Wheader-guard
@item -Wheader-guard
Warn if a valid preprocessor header multiple inclusion guard has
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Wfree-labels" } */
+
+void
+f (void)
+{
+ goto l;
+ l: /* { dg-warning "label at end of compound statement" } */
+}
+
+int
+g (void)
+{
+ goto l;
+ l:
+ int x = 0; /* { dg-warning "a label can only be part of a statement" } */
+ return x;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic -Wno-free-labels" } */
+
+void
+f (void)
+{
+ goto l;
+ l:
+}
+
+int
+g (void)
+{
+ goto l;
+ l:
+ int x = 0;
+ return x;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Wc11-c23-compat -Wno-free-labels" } */
+
+void
+f (void)
+{
+ goto l;
+ l:
+}
+
+int
+g (void)
+{
+ goto l;
+ l:
+ int x = 0;
+ return x;
+}