diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 491c24b9fe7ee577565fb4fb74c74461669b6cd8..3733ecfc13fc4d49c6cd9ab801bbc0e89ce49113 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 bfdcb78bbcc18b1750b624b0862855fd4de3d22b..a1435e7cb0ca520cd165cc3e2a20e512f4f2c602 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 0000000000000000000000000000000000000000..74c06e4aa4c8bdf1537c845c4d492c872cbefcb7 --- /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 0000000000000000000000000000000000000000..207e7c59d27b2168f68193b53b24b655b659f968 --- /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 () +{ +}