+2019-11-08 Joseph Myers <joseph@codesourcery.com>
+
+ * doc/invoke.texi (-Wold-style-definition): Document () not being
+ considered an old-style definition for C2x.
+
2019-11-07 John David Anglin <danglin@gcc.gnu.org>
* config/pa/pa.md (memory_barrier): Revise to use ldcw barriers.
+2019-11-08 Joseph Myers <joseph@codesourcery.com>
+
+ * 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.
+
2019-11-07 Joseph Myers <joseph@codesourcery.com>
* c-attribs.c (parse_tm_stmt_attr): Handle scoped attributes.
if (warn_implicit_int == -1)
warn_implicit_int = flag_isoc99;
+ /* -Wold-style-definition is enabled by default for C2X. */
+ if (warn_old_style_definition == -1)
+ warn_old_style_definition = flag_isoc2x;
+
/* -Wshift-overflow is enabled by default in C99 and C++11 modes. */
if (warn_shift_overflow == -1)
warn_shift_overflow = cxx_dialect >= cxx11 || flag_isoc99;
Warn for obsolescent usage in a declaration.
Wold-style-definition
-C ObjC Var(warn_old_style_definition) Warning
+C ObjC Var(warn_old_style_definition) Init(-1) Warning
Warn if an old-style parameter definition is used.
Wopenmp-simd
+2019-11-08 Joseph Myers <joseph@codesourcery.com>
+
+ * 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.
+
2019-11-07 Joseph Myers <joseph@codesourcery.com>
* c-parser.c (c_parser_attribute_arguments): New function.
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
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. */
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)
@opindex Wold-style-definition
@opindex Wno-old-style-definition
Warn if an old-style function definition is used. A warning is given
-even if there is a previous prototype.
+even if there is a previous prototype. A definition using @samp{()}
+is not considered an old-style definition in C2X mode, because it is
+equivalent to @samp{(void)} in that case, but is considered an
+old-style definition for older standards.
@item -Wmissing-parameter-type @r{(C and Objective-C only)}
@opindex Wmissing-parameter-type
+2019-11-08 Joseph Myers <joseph@codesourcery.com>
+
+ * 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.
+
2019-11-07 Peter Bergner <bergner@linux.ibm.com>
PR other/92090
--- /dev/null
+/* Test old-style function definitions not in C2x: allowed in C11. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+void
+f (x)
+ int x;
+{
+}
--- /dev/null
+/* Test old-style function definitions not in C2x: () does not give
+ type with a prototype for older standards. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11" } */
+
+void
+f ()
+{
+}
+
+void
+g (void)
+{
+ f (1);
+}
--- /dev/null
+/* Test old-style function definitions not in C2x: warnings. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+
+void
+f (x) /* { dg-warning "old-style function definition" } */
+ int x;
+{
+}
--- /dev/null
+/* Test old-style function definitions not in C2x: errors. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+void
+f (x) /* { dg-error "old-style function definition" } */
+ int x;
+{
+}
--- /dev/null
+/* Test old-style function definitions not in C2x: warnings disabled
+ by -Wno-old-style-definition. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -Wno-old-style-definition" } */
+
+void
+f (x)
+ int x;
+{
+}
--- /dev/null
+/* Test old-style function definitions not in C2x: () gives type with
+ a prototype. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+
+void
+f ()
+{
+}
+
+void
+g (void)
+{
+ f (1); /* { dg-error "too many arguments to function" } */
+}
--- /dev/null
+/* Test old-style function definitions not in C2x: () does not warn
+ with -Wold-style-definition. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -Wold-style-definition" } */
+
+void
+f ()
+{
+}
--- /dev/null
+/* Test old-style function definitions not in C2x: () does not give
+ type with a prototype except for function definitions. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+
+void f1 ();
+
+/* Prototyped function returning a pointer to unprototyped function. */
+void (*f2 (void))() { return f1; }
+
+void
+g (void)
+{
+ f1 (1);
+ f2 () (1);
+}