aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-errors.cc
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2024-11-14 12:42:25 +0100
committerFlorian Weimer <fweimer@redhat.com>2024-11-15 12:18:42 +0100
commit8833389e90d676baabb35c3e7a021a4f5444a5ba (patch)
tree94537a74c81cafc0548890b057fc58478c67ff5f /gcc/c/c-errors.cc
parent71bf2bef5e99aad810eb65847d878360a0042a02 (diff)
downloadgcc-8833389e90d676baabb35c3e7a021a4f5444a5ba.zip
gcc-8833389e90d676baabb35c3e7a021a4f5444a5ba.tar.gz
gcc-8833389e90d676baabb35c3e7a021a4f5444a5ba.tar.bz2
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.
Diffstat (limited to 'gcc/c/c-errors.cc')
-rw-r--r--gcc/c/c-errors.cc17
1 files changed, 12 insertions, 5 deletions
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. */