c-parse.in (parsing_iso_function_signature): New variable.
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>
Wed, 3 Jul 2002 02:41:34 +0000 (02:41 +0000)
committerKaveh Ghazi <ghazi@gcc.gnu.org>
Wed, 3 Jul 2002 02:41:34 +0000 (02:41 +0000)
gcc:
* c-parse.in (parsing_iso_function_signature): New variable.
(extdef_1): New, copied from...
(extdef): ... here.  Reset parsing_iso_function_signature.
(old_style_parm_decls):  Reset parsing_iso_function_signature.
(old_style_parm_decls_1): New, copied from old_style_parm_decls.
Warn about ISO C style function definitions.
(nested_function, notype_nested_function): Reset
parsing_iso_function_signature.
(parmlist_2): Set parsing_iso_function_signature.

* doc/invoke.texi (-Wtraditional): Document new behavior.

gcc/testsuite:
* gcc.dg/cpp/tr-warn2.c: Use traditional C style function definitions.
* gcc.dg/wtr-aggr-init-1.c: Likewise.
* gcc.dg/wtr-conversion-1.c: Likewise.
* gcc.dg/wtr-escape-1.c: Likewise.
* gcc.dg/wtr-int-type-1.c: Likewise.
* gcc.dg/wtr-label-1.c: Likewise.
* gcc.dg/wtr-static-1.c: Likewise.
* gcc.dg/wtr-strcat-1.c: Likewise.
* gcc.dg/wtr-suffix-1.c: Likewise.
* gcc.dg/wtr-switch-1.c: Likewise.
* gcc.dg/wtr-unary-plus-1.c: Likewise.
* gcc.dg/wtr-union-init-1.c: Likewise.
* gcc.dg/wtr-union-init-2.c: Likewise.
* gcc.dg/wtr-union-init-3.c: Likewise.

* gcc.dg/wtr-func-def-1.c: New test.

From-SVN: r55201

19 files changed:
gcc/ChangeLog
gcc/c-parse.in
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/tr-warn2.c
gcc/testsuite/gcc.dg/wtr-aggr-init-1.c
gcc/testsuite/gcc.dg/wtr-conversion-1.c
gcc/testsuite/gcc.dg/wtr-escape-1.c
gcc/testsuite/gcc.dg/wtr-func-def-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/wtr-int-type-1.c
gcc/testsuite/gcc.dg/wtr-label-1.c
gcc/testsuite/gcc.dg/wtr-static-1.c
gcc/testsuite/gcc.dg/wtr-strcat-1.c
gcc/testsuite/gcc.dg/wtr-suffix-1.c
gcc/testsuite/gcc.dg/wtr-switch-1.c
gcc/testsuite/gcc.dg/wtr-unary-plus-1.c
gcc/testsuite/gcc.dg/wtr-union-init-1.c
gcc/testsuite/gcc.dg/wtr-union-init-2.c
gcc/testsuite/gcc.dg/wtr-union-init-3.c

index 245e83d696005ae8d9f58e3e4cee29010f96b488..8aaa2244fceaeb9a860aa0308d9180cdabc065f5 100644 (file)
@@ -1,3 +1,17 @@
+2002-07-02  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * c-parse.in (parsing_iso_function_signature): New variable.
+       (extdef_1): New, copied from...
+       (extdef): ... here.  Reset parsing_iso_function_signature.
+       (old_style_parm_decls):  Reset parsing_iso_function_signature.
+       (old_style_parm_decls_1): New, copied from old_style_parm_decls.
+       Warn about ISO C style function definitions.
+       (nested_function, notype_nested_function): Reset
+       parsing_iso_function_signature.
+       (parmlist_2): Set parsing_iso_function_signature.
+
+       * doc/invoke.texi (-Wtraditional): Document new behavior.
+
 2002-07-02  Chris Demetriou  <cgd@broadcom.com>
 
        * config.gcc (mips*el-*-*): Use tm_defines to set
index 6ce9a2e9516b93fb58373a4f9b594b2c1abb4495..2a948328f7341bc71d5499506d4482eacd3f740f 100644 (file)
@@ -331,6 +331,8 @@ ifc
 #define OBJC_NEED_RAW_IDENTIFIER(VAL)  /* nothing */
 end ifc
 
+static bool parsing_iso_function_signature;
+
 /* Tell yyparse how to print a token's value, if yydebug is set.  */
 
 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
@@ -382,6 +384,10 @@ extdefs:
        ;
 
 extdef:
+       extdef_1
+       { parsing_iso_function_signature = false; } /* Reset after any external definition.  */
+
+extdef_1:
        fndef
        | datadef
 ifobjc
@@ -787,7 +793,19 @@ objc_string:
 end ifobjc
 
 old_style_parm_decls:
+       old_style_parm_decls_1
+       {
+         parsing_iso_function_signature = false; /* Reset after decls.  */
+       }
+
+old_style_parm_decls_1:
        /* empty */
+       {
+         if (warn_traditional && !in_system_header
+             && parsing_iso_function_signature)
+           warning ("traditional C rejects ISO C style function definitions");
+         parsing_iso_function_signature = false; /* Reset after warning.  */
+       }
        | datadecls
        | datadecls ELLIPSIS
                /* ... is used here to indicate a varargs function.  */
@@ -1586,6 +1604,7 @@ nested_function:
                      pop_function_context ();
                      YYERROR1;
                    }
+                 parsing_iso_function_signature = false; /* Don't warn about nested functions.  */
                }
           old_style_parm_decls
                { store_parm_decls (); }
@@ -1616,6 +1635,7 @@ notype_nested_function:
                      pop_function_context ();
                      YYERROR1;
                    }
+                 parsing_iso_function_signature = false; /* Don't warn about nested functions.  */
                }
          old_style_parm_decls
                { store_parm_decls (); }
@@ -2540,7 +2560,9 @@ parmlist_2:  /* empty */
                  error ("ISO C requires a named argument before `...'");
                }
        | parms
-               { $$ = get_parm_info (1); }
+               { $$ = get_parm_info (1);
+                 parsing_iso_function_signature = true;
+               }
        | parms ',' ELLIPSIS
                { $$ = get_parm_info (0); }
        ;
index 79f184c9f3a4021bd637d35d977ad58777ef7fba..1bf3934653187f0913fef42b18bac05006718228 100644 (file)
@@ -2410,6 +2410,15 @@ Conversions by prototypes between fixed/floating point values and vice
 versa.  The absence of these prototypes when compiling with traditional
 C would cause serious problems.  This is a subset of the possible
 conversion warnings, for the full set use @option{-Wconversion}.
+
+@item
+Use of ISO C style function definitions.  This warning intentionally is
+@emph{not} issued for prototype declarations or variadic functions
+because these ISO C features will appear in your code when using
+libiberty's traditional C compatibility macros, @code{PARAMS} and
+@code{VPARAMS}.  This warning is also bypassed for nested functions
+because that feature is already a gcc extension and thus not relevant to
+traditional C compatibility.
 @end itemize
 
 @item -Wundef
index f78ba7696ec7c9d030230213cdf1254608da814b..06b43e1bc75ded753a63713503b3e648bef6d6b6 100644 (file)
@@ -1,3 +1,22 @@
+2002-07-02  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * gcc.dg/cpp/tr-warn2.c: Use traditional C style function definitions.
+       * gcc.dg/wtr-aggr-init-1.c: Likewise.
+       * gcc.dg/wtr-conversion-1.c: Likewise.
+       * gcc.dg/wtr-escape-1.c: Likewise.
+       * gcc.dg/wtr-int-type-1.c: Likewise.
+       * gcc.dg/wtr-label-1.c: Likewise.
+       * gcc.dg/wtr-static-1.c: Likewise.
+       * gcc.dg/wtr-strcat-1.c: Likewise.
+       * gcc.dg/wtr-suffix-1.c: Likewise.
+       * gcc.dg/wtr-switch-1.c: Likewise.
+       * gcc.dg/wtr-unary-plus-1.c: Likewise.
+       * gcc.dg/wtr-union-init-1.c: Likewise.
+       * gcc.dg/wtr-union-init-2.c: Likewise.
+       * gcc.dg/wtr-union-init-3.c: Likewise.
+
+       * gcc.dg/wtr-func-def-1.c: New test.
+
 2002-07-02 Devang Patel <dpatel@apple.com>
 
        * objc.dg/param-1.m: New test.
index 303b0ff2bb149cfd9877b40d52e733c0aa0a2579..413ac5c4e22342327860721d81d45f58a45faf75 100644 (file)
@@ -8,7 +8,7 @@ enum { SIGN_EXTEND = 23 };
 
 #define SIGN_EXTEND(v) (((v) < 0) ? -1 : 0)
 
-int fun(void)
+int fun()
 {
   return SIGN_EXTEND;  /* { dg-warning "must be used with arguments" } */
 }
index c60a6955003f097907cb41cd29504871b7dd2d1b..f17531e8fb9875565c7048dd7002f738fbbd9e43 100644 (file)
@@ -14,7 +14,7 @@ struct foo f0 = { 0, 0 };
 static struct foo f1 = { 0, 0 };
 
 void
-testfunc1 (void)
+testfunc1 ()
 {
   struct foo f3 = { 0, 0 }; /* { dg-warning "traditional C rejects automatic" "automatic aggregate initialization" } */
   static struct foo f4 = { 0, 0 };
@@ -39,7 +39,7 @@ struct foo f7 = { 0, 0 };
 static struct foo f8 = { 0, 0 };
 
 void
-testfunc2 (void)
+testfunc2 ()
 {
   struct foo f9 = { 0, 0 };
   static struct foo f10 = { 0, 0 };
index ecf688fe40549c5847ee20770a3f8ea81c0a37eb..18d26165f2a657dc857c529dff2dfbb747b2e85a 100644 (file)
@@ -15,7 +15,7 @@ extern long double ld;
 extern __complex__ double cd;
 
 void
-testfunc1 (void)
+testfunc1 ()
 {
   foo_i (i);
   foo_i (f); /* { dg-warning "as integer rather than floating" "prototype conversion warning" } */
@@ -42,7 +42,7 @@ testfunc1 (void)
 /* We are in system headers now, no -Wtraditional warnings should issue.  */
 
 void
-testfunc2 (void)
+testfunc2 ()
 {
   foo_i (i);
   foo_i (f);
index 150b4ce15bfaebac5022b0015ce8b821e48ac7c5..7f48de5e8c61385f3700d2c7df81076dc8520c01 100644 (file)
@@ -5,7 +5,7 @@
 /* { dg-options "-Wtraditional" } */
 
 void
-testfunc (void)
+testfunc ()
 {
   char c;
 
diff --git a/gcc/testsuite/gcc.dg/wtr-func-def-1.c b/gcc/testsuite/gcc.dg/wtr-func-def-1.c
new file mode 100644 (file)
index 0000000..c300d22
--- /dev/null
@@ -0,0 +1,204 @@
+/* Test for -Wtraditional warnings on ISO C function definitions.
+   Note, gcc should omit these warnings in system header files.
+   Origin: Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 6/30/2002.  */
+/* { dg-do compile } */
+/* { dg-options "-Wtraditional" } */
+
+/* Test some simple cases.  */
+
+void f_void1 (void)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return;
+}
+
+void f_void2 ()
+{
+  return;
+}
+
+void f_int1 (int f)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return;
+}
+
+void f_int2 (f)
+     int f;
+{
+  return;
+}
+
+/* Test that we don't ever warn about nested functions.  */
+
+void f_int3 (int f)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  void f3a (void) { return; }
+  void f3b () { return; }
+  void f3c (int f) { return; }
+  void f3d (f) int f; { return; }
+  void f3e (const char *f, ...) { return; }
+  return;
+}
+
+void f_int4 (int f)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  void f4a (void) { return; }
+  void f4b () { return; }
+  void f4c (int f) { return; }
+  void f4d (f) int f; { return; }
+  void f4e (const char *f, ...) { return; }
+  auto f4f (void) { return 0; }
+  return;
+}
+
+void f_int5 (f)
+     int f;
+{
+  void f5a (void) { return; }
+  void f5b () { return; }
+  void f5c (int f) { return; }
+  void f5d (f) int f; { return; }
+  void f5e (const char *f, ...) { return; }
+  return;
+}
+
+void f_int6 (f)
+     int f;
+{
+  void f6a (void) { return; }
+  void f6b () { return; }
+  void f6c (int f) { return; }
+  void f6d (f) int f; { return; }
+  void f6e (const char *f, ...) { return; }
+  auto f6f (void) { return 0; }
+  return;
+}
+
+/* Test that prototypes are silently accepted and function definitions
+   are still warned about.  */
+
+extern void f_int_p1 (int);
+void f_int_p1 (int f)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return;
+}
+
+extern void f_int_p2 (int f);
+void f_int_p2 (int f)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return;
+}
+
+extern void f_int_p3 (int);
+void f_int_p3 (f)
+     int f;
+{
+  return;
+}
+
+extern void f_int_p4 (int f);
+void f_int_p4 (f)
+     int f;
+{
+  return;
+}
+
+extern void f_void_p1 ();
+void f_void_p1 (void)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return;
+}
+
+extern void f_void_p2 (void);
+void f_void_p2 (void)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return;
+}
+
+extern void f_blank_p1 ();
+void f_blank_p1 ()
+{
+  return;
+}
+
+extern void f_blank_p2 (void);
+void f_blank_p2 ()
+{
+  return;
+}
+
+/* Test some implicit int functions.  */
+
+f_impl1()
+{
+  return 0;
+}
+
+f_impl2(void)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return 0;
+}
+
+f_impl3(int f)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return 0;
+}
+
+/* Test that we don't warn about stdarg functions.  */
+
+f_stdarg1(const char *s, ...)
+{
+  return 0;
+}
+
+void f_stdarg2(const char *s, ...)
+{
+  return;
+}
+
+extern void f_stdarg3(const char *, ...);
+void f_stdarg3(const char *s, ...)
+{
+  return;
+}
+
+/* Test handling function pointer parameters.  */
+
+void f_fnptr1 (int f, int (*fp)(int));
+void f_fnptr1 (int f, int (*fp)(int))
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return;
+}
+
+void f_fnptr2 (int f, int (*fp)(int));
+void f_fnptr2 (f, fp)
+     int f;
+     int (*fp)(int);
+{
+  return;
+}
+
+/* Test for main.  */
+
+int
+main (int argc, char **argv)
+{ /* { dg-warning "traditional C rejects ISO C style" } */
+  return 0;
+}
+
+# 182 "sys-header.h" 3
+/* We are in system headers now, no -Wtraditional warnings should issue.  */
+
+void fsys1 (void)
+{
+  return;
+}
+
+void fsys2 (int f)
+{
+  return;
+}
+
+void fsys3 (const char *f, ...)
+{
+  return;
+}
index bb3a7de3cab59db74631066b61c40d45cfae9b7f..d44165d90b987ce36d189ae1bde00eda64297e3d 100644 (file)
@@ -5,7 +5,7 @@
 /* { dg-options "-std=c99 -Wtraditional" } */
 
 void
-testfunc (void)
+testfunc ()
 {
   long long i;
   
index 38ccd16ad87726665e5f35683e6185dd5137c9b2..78a4d6b0a4b6934b3f920b98493a60d958ffa551 100644 (file)
@@ -11,7 +11,8 @@ int foo4;
 typedef int foo5;
 
 void
-testfunc1 (int foo6)
+testfunc1 (foo6)
+     int foo6;
 {
   int foo7;
 
@@ -32,7 +33,8 @@ testfunc1 (int foo6)
 /* We are in system headers now, no -Wtraditional warnings should issue.  */
 
 void
-testfunc2 (int foo6)
+testfunc2 (foo6)
+     int foo6;
 {
   int foo7;
 
index f00cd8a7b5fa4d59c1bf888e92b01d59332577b9..310c1eab925f2d9e76982a4549857d4759ac545e 100644 (file)
@@ -5,10 +5,10 @@
 /* { dg-options "-Wtraditional" } */
 
 static void testfunc1(void);
-void testfunc1(void) {} /* { dg-warning "non-static.*follows static" "non-static follows static" } */
+void testfunc1() {} /* { dg-warning "non-static.*follows static" "non-static follows static" } */
 
 # 11 "sys-header.h" 3
 /* We are in system headers now, no -Wtraditional warnings should issue.  */
 
 static void testfunc2(void);
-void testfunc2(void) {}
+void testfunc2() {}
index ca85a5c4077c984c728c5a89222cf3dfe3dd8c6e..b3966529ad7e13112741e26305ca6e306cdc50f6 100644 (file)
@@ -5,7 +5,7 @@
 /* { dg-options "-Wtraditional" } */
 
 void
-testfunc (void)
+testfunc ()
 {
   const char *foo;
   
index f6b6300ac1f9558a07f4d50722ecffb0afac197a..ed0b40ecf301dd83bac522d2213ee0cc33b10c21 100644 (file)
@@ -5,7 +5,7 @@
 /* { dg-options "-Wtraditional" } */
 
 void
-testfunc (void)
+testfunc ()
 {
   int i;
   double f;
index e1c0d30df9a4c8c39f77955c7582eb27c1f1e787..f0381bc5e3797fbfa701417336ea65ca1b00a131 100644 (file)
@@ -5,7 +5,8 @@
 /* { dg-options "-Wtraditional" } */
 
 void
-testfunc (long l)
+testfunc (l)
+     long l;
 {
   switch (l) /* { dg-warning "switch expression" "switch expression" } */
   {
index b6b053c033d96f5a2f2ef53c94cf41534d6a36fd..aee892c532e615b96c389e37a8dcd5d0139e9faf 100644 (file)
@@ -5,7 +5,7 @@
 /* { dg-options "-Wtraditional" } */
 
 void
-testfunc (void)
+testfunc ()
 {
   int i;
   
index 312bfa926003df71afa7ed737e30dfbc21fdc3c6..18869813d2812d2df497b185a875b9a1277e8e91 100644 (file)
@@ -11,7 +11,7 @@ union foo
 };
 
 void
-testfunc (void)
+testfunc ()
 {
   /* Note we only warn for non-zero initializers.  */
   static union foo f1 = { 0 };
index 6366ff326d88210eb7d20e1bb7af2479e9554ff3..3112ba277622f0b50bbd191dc30967cfdd365274 100644 (file)
@@ -19,7 +19,7 @@ union foo2
 };
 
 void
-testfunc (void)
+testfunc ()
 {
   /* Note we only warn for non-zero initializers.  */
   static union foo1 f1 = {0};
index c5d8e73a37721a139a9623c3f9decdf253b2a504..bb8e300289d865afa9e0ea51692d48620956b4f2 100644 (file)
@@ -38,7 +38,7 @@ struct baz2
 };
 
 void
-testfunc (void)
+testfunc ()
 {
   /* Note we only warn for non-zero initializers.  Xfail on substructures. */
   static union foo f1 = {{0,0}}; /* { dg-bogus "traditional C rejects initialization of unions" "initialization of unions" { xfail *-*-* } } */