diff options
author | Joseph Myers <joseph@codesourcery.com> | 2019-11-08 01:21:40 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2019-11-08 01:21:40 +0000 |
commit | 017c6491077bee998eed9ed6520026285c906d37 (patch) | |
tree | 17e627d2d781e8f6c48233b95f8bec50f1734fe2 /gcc/c/c-decl.c | |
parent | 3d6e7aa95cf3b354dded4cb1a8c546cbe217beb9 (diff) | |
download | gcc-017c6491077bee998eed9ed6520026285c906d37.zip gcc-017c6491077bee998eed9ed6520026285c906d37.tar.gz gcc-017c6491077bee998eed9ed6520026285c906d37.tar.bz2 |
Handle removal of old-style function definitions in C2x.
C2x removes support for old-style function definitions with identifier
lists, changing () in function definitions to be equivalent to (void)
(while () in declarations that are not definitions still gives an
unprototyped type).
This patch updates GCC accordingly. The new semantics for () are
implemented for C2x mode (meaning () in function definitions isn't
diagnosed by -Wold-style-definition in that mode).
-Wold-style-definition is enabled by default, and turned into a
pedwarn, for C2x.
Bootstrapped with no regressions on x86_64-pc-linux-gnu.
gcc:
* doc/invoke.texi (-Wold-style-definition): Document () not being
considered an old-style definition for C2x.
gcc/c:
* c-decl.c (grokparms): Convert () in a function definition to
(void) for C2x.
(store_parm_decls_oldstyle): Pedwarn for C2x.
(store_parm_decls): Update comment about () not generating a
prototype.
gcc/c-family:
* c.opt (Wold-style-definition): Initialize to -1.
* c-opts.c (c_common_post_options): Set warn_old_style_definition
to flag_isoc2x if not set explicitly.
gcc/testsuite:
* gcc.dg/c11-old-style-definition-1.c,
gcc.dg/c11-old-style-definition-2.c,
gcc.dg/c2x-old-style-definition-1.c,
gcc.dg/c2x-old-style-definition-2.c,
gcc.dg/c2x-old-style-definition-3.c,
gcc.dg/c2x-old-style-definition-4.c,
gcc.dg/c2x-old-style-definition-5.c,
gcc.dg/c2x-old-style-definition-6.c: New tests.
From-SVN: r277945
Diffstat (limited to 'gcc/c/c-decl.c')
-rw-r--r-- | gcc/c/c-decl.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index ae0ee3a..2841b4f 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -7416,6 +7416,13 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag) tree parm, type, typelt; unsigned int parmno; + /* In C2X, convert () in a function definition to (void). */ + if (flag_isoc2x + && funcdef_flag + && !arg_types + && !arg_info->parms) + arg_types = arg_info->types = void_list_node; + /* If there is a parameter of incomplete type in a definition, this is an error. In a declaration this is valid, and a struct or union type may be completed later, before any calls @@ -9261,8 +9268,15 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info) hash_set<tree> seen_args; if (!in_system_header_at (input_location)) - warning_at (DECL_SOURCE_LOCATION (fndecl), - OPT_Wold_style_definition, "old-style function definition"); + { + if (flag_isoc2x) + pedwarn (DECL_SOURCE_LOCATION (fndecl), + OPT_Wold_style_definition, "old-style function definition"); + else + warning_at (DECL_SOURCE_LOCATION (fndecl), + OPT_Wold_style_definition, + "old-style function definition"); + } /* Match each formal parameter name with its declaration. Save each decl in the appropriate TREE_PURPOSE slot of the parmids chain. */ @@ -9578,11 +9592,10 @@ store_parm_decls (void) struct c_arg_info *arg_info = current_function_arg_info; current_function_arg_info = 0; - /* True if this definition is written with a prototype. Note: - despite C99 6.7.5.3p14, we can *not* treat an empty argument - list in a function definition as equivalent to (void) -- an - empty argument list specifies the function has no parameters, - but only (void) sets up a prototype for future calls. */ + /* True if this definition is written with a prototype. In C2X, an + empty argument list was converted to (void) in grokparms; in + older C standard versions, it does not give the function a type + with a prototype for future calls. */ proto = arg_info->types != 0; if (proto) |