diff options
author | Joseph Myers <josmyers@redhat.com> | 2024-10-19 00:20:15 +0000 |
---|---|---|
committer | Joseph Myers <josmyers@redhat.com> | 2024-10-19 00:21:42 +0000 |
commit | d277ded292d7e9eeaa0b8bce6782c4cd6b32d2c0 (patch) | |
tree | 32d3beac860279637a02a77e6fecf4744a054879 | |
parent | de14559ef53b3a0e8c544bdc65f5983a184767b1 (diff) | |
download | gcc-d277ded292d7e9eeaa0b8bce6782c4cd6b32d2c0.zip gcc-d277ded292d7e9eeaa0b8bce6782c4cd6b32d2c0.tar.gz gcc-d277ded292d7e9eeaa0b8bce6782c4cd6b32d2c0.tar.bz2 |
c: Fix -std=gnu23 -Wtraditional for () in function definitions
We don't yet have clear agreement on removing -Wtraditional (although
it seems there is little to no use for most of the warnings therein),
so fix the bug in its interaction with -std=gnu23 to continue progress
on making -std=gnu23 the default while -Wtraditional remains under
discussion.
The warning for ISO C function definitions with -Wtraditional properly
covers (void), but also wrongly warned for () in C23 mode as that has
the same semantics as (void) in that case. Keep track in c_arg_info
of when () was converted to (void) for C23 so that -Wtraditional can
avoid warning in that case (with an appropriate comment on the
definition of the new field to make clear it can be removed along with
-Wtraditional).
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc/c/
* c-tree.h (c_arg_info): Add c23_empty_parens.
* c-decl.cc (grokparms): Set c23_empty_parens.
(build_arg_info): Clear c23_empty_parens.
(store_parm_decls_newstyle): Do not give -Wtraditional warning for
ISO C function definition if c23_empty_parens.
gcc/testsuite/
* gcc.dg/wtr-gnu17-1.c, gcc.dg/wtr-gnu23-1.c: New tests.
-rw-r--r-- | gcc/c/c-decl.cc | 9 | ||||
-rw-r--r-- | gcc/c/c-tree.h | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-gnu17-1.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-gnu23-1.c | 9 |
4 files changed, 29 insertions, 2 deletions
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 491c24b..3733ecf 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -8519,7 +8519,10 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag) && !arg_types && !arg_info->parms && !arg_info->no_named_args_stdarg_p) - arg_types = arg_info->types = void_list_node; + { + arg_types = arg_info->types = void_list_node; + arg_info->c23_empty_parens = 1; + } /* If there is a parameter of incomplete type in a definition, this is an error. In a declaration this is valid, and a @@ -8589,6 +8592,7 @@ build_arg_info (void) ret->pending_sizes = NULL; ret->had_vla_unspec = 0; ret->no_named_args_stdarg_p = 0; + ret->c23_empty_parens = 0; return ret; } @@ -10923,7 +10927,8 @@ store_parm_decls_newstyle (tree fndecl, const struct c_arg_info *arg_info) its parameter list). */ else if (!in_system_header_at (input_location) && !current_function_scope - && arg_info->types != error_mark_node) + && arg_info->types != error_mark_node + && !arg_info->c23_empty_parens) warning_at (DECL_SOURCE_LOCATION (fndecl), OPT_Wtraditional, "traditional C rejects ISO C style function definitions"); diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index bfdcb78..a1435e7 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -525,6 +525,10 @@ struct c_arg_info { BOOL_BITFIELD had_vla_unspec : 1; /* True when the arguments are a (...) prototype. */ BOOL_BITFIELD no_named_args_stdarg_p : 1; + /* True when empty parentheses have been interpreted as (void) in C23 or + later. This is only for use by -Wtraditional and is no longer needed if + -Wtraditional is removed. */ + BOOL_BITFIELD c23_empty_parens : 1; }; /* A declarator. */ diff --git a/gcc/testsuite/gcc.dg/wtr-gnu17-1.c b/gcc/testsuite/gcc.dg/wtr-gnu17-1.c new file mode 100644 index 0000000..74c06e4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/wtr-gnu17-1.c @@ -0,0 +1,9 @@ +/* Test -Wtraditional -std=gnu17 does not warn for empty parentheses in + function definition. */ +/* { dg-do compile } */ +/* { dg-options "-Wtraditional -std=gnu17" } */ + +void +f () +{ +} diff --git a/gcc/testsuite/gcc.dg/wtr-gnu23-1.c b/gcc/testsuite/gcc.dg/wtr-gnu23-1.c new file mode 100644 index 0000000..207e7c5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/wtr-gnu23-1.c @@ -0,0 +1,9 @@ +/* Test -Wtraditional -std=gnu23 does not warn for empty parentheses in + function definition. */ +/* { dg-do compile } */ +/* { dg-options "-Wtraditional -std=gnu23" } */ + +void +f () +{ +} |