diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-opts.cc | 7 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 4 | ||||
-rw-r--r-- | gcc/c/c-decl.cc | 2 | ||||
-rw-r--r-- | gcc/c/c-errors.cc | 17 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 25 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wmissing-parameter-name-1.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wmissing-parameter-name-2.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wmissing-parameter-name-3.c | 7 |
8 files changed, 64 insertions, 12 deletions
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index b920b7d..127f955 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -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) diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 3f80ec4..61cfe33 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -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. diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 3a45c02..07c18a3 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -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"); } diff --git a/gcc/c/c-errors.cc b/gcc/c/c-errors.cc index 38b11a7..653ad8c 100644 --- a/gcc/c/c-errors.cc +++ b/gcc/c/c-errors.cc @@ -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. */ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 93e096b..36d79d1 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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)} diff --git a/gcc/testsuite/gcc.dg/Wmissing-parameter-name-1.c b/gcc/testsuite/gcc.dg/Wmissing-parameter-name-1.c new file mode 100644 index 0000000..b804f7b --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wmissing-parameter-name-1.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-Wmissing-parameter-name" } */ + +int +f (int) /* { dg-warning "omitting parameter names" } */ +{ +} diff --git a/gcc/testsuite/gcc.dg/Wmissing-parameter-name-2.c b/gcc/testsuite/gcc.dg/Wmissing-parameter-name-2.c new file mode 100644 index 0000000..a02083f --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wmissing-parameter-name-2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic -Wno-missing-parameter-name" } */ + +int +f (int) +{ +} diff --git a/gcc/testsuite/gcc.dg/Wmissing-parameter-name-3.c b/gcc/testsuite/gcc.dg/Wmissing-parameter-name-3.c new file mode 100644 index 0000000..b89d886 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wmissing-parameter-name-3.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-Wc11-c23-compat -Wno-missing-parameter-name" } */ + +int +f (int) +{ +} |