mirror of
https://github.com/gcc-mirror/gcc.git
synced 2024-11-21 13:40:47 +00:00
c: Introduce -Wmissing-parameter-name
Empirically, omitted parameter names are difficult to catch in code review. With this change, projects can build with -Werror=missing-parameter-name, to avoid this unnecessary incompatibility with older GCC versions. The existing -pedantic-errors option is too broad for that because it also flags widely used and widely available GCC extensions. Likewise for -Werror=c11-c23-compat. gcc/c-family/ * c-opts.cc (c_common_post_options): Initialize warn_missing_parameter_name. * c.opt (Wmissing-parameter-name): New. gcc/c/ * c-decl.cc (store_parm_decls_newstyle): Use OPT_Wmissing_parameter_name for missing parameter name warning. * c-errors.cc (pedwarn_c11): Enable fine-grained warning control via the option_id argument. gcc/ * doc/invoke.texi: Document Wmissing-parameter-name. gcc/testsuite/ * gcc.dg/Wmissing-parameter-name-1.c: New test. * gcc.dg/Wmissing-parameter-name-2.c: New test. * gcc.dg/Wmissing-parameter-name-3.c: New test.
This commit is contained in:
parent
71bf2bef5e
commit
8833389e90
@ -986,6 +986,13 @@ c_common_post_options (const char **pfilename)
|
||||
if (warn_shift_overflow == -1)
|
||||
warn_shift_overflow = cxx_dialect >= cxx11 || flag_isoc99;
|
||||
|
||||
/* -Wmissing-parameter-name is enabled by -pedantic before C23,
|
||||
and for -Wc11-c23-compat. */
|
||||
if (warn_missing_parameter_name == -1)
|
||||
warn_missing_parameter_name
|
||||
= ((pedantic && !flag_isoc23 && warn_c11_c23_compat != 0)
|
||||
|| warn_c11_c23_compat > 0);
|
||||
|
||||
/* -Wshift-negative-value is enabled by -Wextra in C99 and C++11 to C++17
|
||||
modes. */
|
||||
if (warn_shift_negative_value == -1)
|
||||
|
@ -1026,6 +1026,10 @@ Wmissing-include-dirs
|
||||
C ObjC C++ ObjC++ CPP(warn_missing_include_dirs) CppReason(CPP_W_MISSING_INCLUDE_DIRS) Var(cpp_warn_missing_include_dirs) Init(0) Warning
|
||||
Warn about user-specified include directories that do not exist.
|
||||
|
||||
Wmissing-parameter-name
|
||||
C ObjC Var(warn_missing_parameter_name) Init(-1) Warning
|
||||
Warn about function definitions omitting parameter names.
|
||||
|
||||
Wmissing-parameter-type
|
||||
C ObjC Var(warn_missing_parameter_type) Warning EnabledBy(Wextra)
|
||||
Warn about function parameters declared without a type specifier in K&R-style functions.
|
||||
|
@ -10900,7 +10900,7 @@ store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info)
|
||||
warn_if_shadowing (decl);
|
||||
}
|
||||
else
|
||||
pedwarn_c11 (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
|
||||
pedwarn_c11 (DECL_SOURCE_LOCATION (decl), OPT_Wmissing_parameter_name,
|
||||
"ISO C does not support omitting parameter names in "
|
||||
"function definitions before C23");
|
||||
}
|
||||
|
@ -71,7 +71,10 @@ pedwarn_c23 (location_t location,
|
||||
otherwise issue warning MSGID if -Wc11-c23-compat is specified.
|
||||
This function is supposed to be used for matters that are allowed in
|
||||
ISO C23 but not supported in ISO C11, thus we explicitly don't pedwarn
|
||||
when C23 is specified. */
|
||||
when C23 is specified.
|
||||
|
||||
Additionally, warn if OPTION_ID is not OPT_Wpedantic nor
|
||||
OPT_Wc11_c23_compat. */
|
||||
|
||||
bool
|
||||
pedwarn_c11 (location_t location,
|
||||
@ -84,14 +87,18 @@ pedwarn_c11 (location_t location,
|
||||
rich_location richloc (line_table, location);
|
||||
|
||||
va_start (ap, gmsgid);
|
||||
/* If desired, issue the C11/C23 compat warning, which is more specific
|
||||
than -pedantic. */
|
||||
if (warn_c11_c23_compat > 0)
|
||||
/* If desired, issue the C11/C23 compat warning, which is more specific than
|
||||
-pedantic, or the warning specified by option_id. */
|
||||
if (warn_c11_c23_compat > 0 || (option_id.m_idx != OPT_Wpedantic
|
||||
&& option_id.m_idx != OPT_Wc11_c23_compat))
|
||||
{
|
||||
diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
|
||||
(pedantic && !flag_isoc23)
|
||||
? DK_PEDWARN : DK_WARNING);
|
||||
diagnostic.option_id = OPT_Wc11_c23_compat;
|
||||
if (option_id == OPT_Wpedantic)
|
||||
diagnostic.option_id = OPT_Wc11_c23_compat;
|
||||
else
|
||||
diagnostic.option_id = option_id;
|
||||
warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
|
||||
}
|
||||
/* -Wno-c11-c23-compat suppresses even the pedwarns. */
|
||||
|
@ -520,12 +520,12 @@ Objective-C and Objective-C++ Dialects}.
|
||||
}
|
||||
|
||||
@item C and Objective-C-only Warning Options
|
||||
@gccoptlist{-Wbad-function-cast -Wmissing-declarations
|
||||
-Wmissing-parameter-type -Wdeclaration-missing-parameter-type
|
||||
-Wmissing-prototypes -Wmissing-variable-declarations
|
||||
-Wnested-externs -Wold-style-declaration -Wold-style-definition
|
||||
-Wstrict-prototypes -Wtraditional -Wtraditional-conversion
|
||||
-Wdeclaration-after-statement -Wpointer-sign}
|
||||
@gccoptlist{-Wbad-function-cast -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
|
||||
-Wtraditional-conversion -Wdeclaration-after-statement -Wpointer-sign}
|
||||
|
||||
@item Debugging Options
|
||||
@xref{Debugging Options,,Options for Debugging Your Program}.
|
||||
@ -6370,6 +6370,7 @@ name is still supported, but the newer name is more descriptive.)
|
||||
-Wimplicit-fallthrough=3
|
||||
-Wmaybe-uninitialized
|
||||
-Wmissing-field-initializers
|
||||
-Wmissing-parameter-name @r{(C/ObjC only)}
|
||||
-Wmissing-parameter-type @r{(C/ObjC only)}
|
||||
-Wold-style-declaration @r{(C/ObjC only)}
|
||||
-Woverride-init @r{(C/ObjC only)}
|
||||
@ -10048,6 +10049,18 @@ is not considered an old-style definition in C23 mode, because it is
|
||||
equivalent to @samp{(void)} in that case, but is considered an
|
||||
old-style definition for older standards.
|
||||
|
||||
@opindex Wmissing-parameter-name
|
||||
@opindex Wno-missing-parameter-name
|
||||
@item -Wmissing-parameter-name @r{(C and Objective-C only)}
|
||||
Warn if a function definition omits a parameter name, specifying only
|
||||
its type. This can be used to document that a parameter is unused
|
||||
in the definition. It is part of C23 and later dialects of C,
|
||||
and 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 Wmissing-parameter-type
|
||||
@opindex Wno-missing-parameter-type
|
||||
@item -Wmissing-parameter-type @r{(C and Objective-C only)}
|
||||
|
7
gcc/testsuite/gcc.dg/Wmissing-parameter-name-1.c
Normal file
7
gcc/testsuite/gcc.dg/Wmissing-parameter-name-1.c
Normal file
@ -0,0 +1,7 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-Wmissing-parameter-name" } */
|
||||
|
||||
int
|
||||
f (int) /* { dg-warning "omitting parameter names" } */
|
||||
{
|
||||
}
|
7
gcc/testsuite/gcc.dg/Wmissing-parameter-name-2.c
Normal file
7
gcc/testsuite/gcc.dg/Wmissing-parameter-name-2.c
Normal file
@ -0,0 +1,7 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-std=c11 -pedantic -Wno-missing-parameter-name" } */
|
||||
|
||||
int
|
||||
f (int)
|
||||
{
|
||||
}
|
7
gcc/testsuite/gcc.dg/Wmissing-parameter-name-3.c
Normal file
7
gcc/testsuite/gcc.dg/Wmissing-parameter-name-3.c
Normal file
@ -0,0 +1,7 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-Wc11-c23-compat -Wno-missing-parameter-name" } */
|
||||
|
||||
int
|
||||
f (int)
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue
Block a user