aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-opts.c4
-rw-r--r--gcc/c-family/c.opt2
-rw-r--r--gcc/c/ChangeLog8
-rw-r--r--gcc/c/c-decl.c27
-rw-r--r--gcc/doc/invoke.texi5
-rw-r--r--gcc/testsuite/ChangeLog11
-rw-r--r--gcc/testsuite/gcc.dg/c11-old-style-definition-1.c9
-rw-r--r--gcc/testsuite/gcc.dg/c11-old-style-definition-2.c15
-rw-r--r--gcc/testsuite/gcc.dg/c2x-old-style-definition-1.c9
-rw-r--r--gcc/testsuite/gcc.dg/c2x-old-style-definition-2.c9
-rw-r--r--gcc/testsuite/gcc.dg/c2x-old-style-definition-3.c10
-rw-r--r--gcc/testsuite/gcc.dg/c2x-old-style-definition-4.c15
-rw-r--r--gcc/testsuite/gcc.dg/c2x-old-style-definition-5.c9
-rw-r--r--gcc/testsuite/gcc.dg/c2x-old-style-definition-6.c16
16 files changed, 151 insertions, 9 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f1f15da..e723121 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+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.
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 39e7d5a..d3e328f 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+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.
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index b84f05c..75b6959 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -904,6 +904,10 @@ c_common_post_options (const char **pfilename)
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;
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index bb6eeaf..914a2f0 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -960,7 +960,7 @@ C ObjC Var(warn_old_style_declaration) Warning EnabledBy(Wextra)
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
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 29be902..f1d73e4 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,11 @@
+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.
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)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 15fe228..00eb7e7 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -7334,7 +7334,10 @@ is also enabled by @option{-Wextra}.
@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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e1a8da6..459fd89 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,14 @@
+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
diff --git a/gcc/testsuite/gcc.dg/c11-old-style-definition-1.c b/gcc/testsuite/gcc.dg/c11-old-style-definition-1.c
new file mode 100644
index 0000000..74164b7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-old-style-definition-1.c
@@ -0,0 +1,9 @@
+/* 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;
+{
+}
diff --git a/gcc/testsuite/gcc.dg/c11-old-style-definition-2.c b/gcc/testsuite/gcc.dg/c11-old-style-definition-2.c
new file mode 100644
index 0000000..a22f555
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-old-style-definition-2.c
@@ -0,0 +1,15 @@
+/* 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);
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-old-style-definition-1.c b/gcc/testsuite/gcc.dg/c2x-old-style-definition-1.c
new file mode 100644
index 0000000..c775366
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-old-style-definition-1.c
@@ -0,0 +1,9 @@
+/* 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;
+{
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-old-style-definition-2.c b/gcc/testsuite/gcc.dg/c2x-old-style-definition-2.c
new file mode 100644
index 0000000..7bd5a60
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-old-style-definition-2.c
@@ -0,0 +1,9 @@
+/* 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;
+{
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-old-style-definition-3.c b/gcc/testsuite/gcc.dg/c2x-old-style-definition-3.c
new file mode 100644
index 0000000..a250076
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-old-style-definition-3.c
@@ -0,0 +1,10 @@
+/* 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;
+{
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-old-style-definition-4.c b/gcc/testsuite/gcc.dg/c2x-old-style-definition-4.c
new file mode 100644
index 0000000..b1862b1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-old-style-definition-4.c
@@ -0,0 +1,15 @@
+/* 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" } */
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-old-style-definition-5.c b/gcc/testsuite/gcc.dg/c2x-old-style-definition-5.c
new file mode 100644
index 0000000..0c37a06
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-old-style-definition-5.c
@@ -0,0 +1,9 @@
+/* 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 ()
+{
+}
diff --git a/gcc/testsuite/gcc.dg/c2x-old-style-definition-6.c b/gcc/testsuite/gcc.dg/c2x-old-style-definition-6.c
new file mode 100644
index 0000000..fc0e778
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-old-style-definition-6.c
@@ -0,0 +1,16 @@
+/* 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);
+}