diff options
author | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-07-03 02:41:34 +0000 |
---|---|---|
committer | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-07-03 02:41:34 +0000 |
commit | 3500767473f0cd8cc04b99b171def1a54fb450ef (patch) | |
tree | a69a06c021b85c28921ce3c2d3d47eedb700c92c /gcc | |
parent | 2acf887b32bd1561b691fb4cfa3890c4785a0d64 (diff) | |
download | ppe42-gcc-3500767473f0cd8cc04b99b171def1a54fb450ef.tar.gz ppe42-gcc-3500767473f0cd8cc04b99b171def1a54fb450ef.zip |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55201 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 14 | ||||
-rw-r--r-- | gcc/c-parse.in | 24 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 19 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/tr-warn2.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-aggr-init-1.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-conversion-1.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-escape-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-func-def-1.c | 204 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-int-type-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-label-1.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-static-1.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-strcat-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-suffix-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-switch-1.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-unary-plus-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-union-init-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-union-init-2.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/wtr-union-init-3.c | 2 |
19 files changed, 290 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 245e83d6960..8aaa2244fce 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/c-parse.in b/gcc/c-parse.in index 6ce9a2e9516..2a948328f73 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -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); } ; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 79f184c9f3a..1bf39346531 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f78ba7696ec..06b43e1bc75 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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. diff --git a/gcc/testsuite/gcc.dg/cpp/tr-warn2.c b/gcc/testsuite/gcc.dg/cpp/tr-warn2.c index 303b0ff2bb1..413ac5c4e22 100644 --- a/gcc/testsuite/gcc.dg/cpp/tr-warn2.c +++ b/gcc/testsuite/gcc.dg/cpp/tr-warn2.c @@ -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" } */ } diff --git a/gcc/testsuite/gcc.dg/wtr-aggr-init-1.c b/gcc/testsuite/gcc.dg/wtr-aggr-init-1.c index c60a6955003..f17531e8fb9 100644 --- a/gcc/testsuite/gcc.dg/wtr-aggr-init-1.c +++ b/gcc/testsuite/gcc.dg/wtr-aggr-init-1.c @@ -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 }; diff --git a/gcc/testsuite/gcc.dg/wtr-conversion-1.c b/gcc/testsuite/gcc.dg/wtr-conversion-1.c index ecf688fe405..18d26165f2a 100644 --- a/gcc/testsuite/gcc.dg/wtr-conversion-1.c +++ b/gcc/testsuite/gcc.dg/wtr-conversion-1.c @@ -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); diff --git a/gcc/testsuite/gcc.dg/wtr-escape-1.c b/gcc/testsuite/gcc.dg/wtr-escape-1.c index 150b4ce15bf..7f48de5e8c6 100644 --- a/gcc/testsuite/gcc.dg/wtr-escape-1.c +++ b/gcc/testsuite/gcc.dg/wtr-escape-1.c @@ -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 index 00000000000..c300d22ee3e --- /dev/null +++ b/gcc/testsuite/gcc.dg/wtr-func-def-1.c @@ -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; +} diff --git a/gcc/testsuite/gcc.dg/wtr-int-type-1.c b/gcc/testsuite/gcc.dg/wtr-int-type-1.c index bb3a7de3cab..d44165d90b9 100644 --- a/gcc/testsuite/gcc.dg/wtr-int-type-1.c +++ b/gcc/testsuite/gcc.dg/wtr-int-type-1.c @@ -5,7 +5,7 @@ /* { dg-options "-std=c99 -Wtraditional" } */ void -testfunc (void) +testfunc () { long long i; diff --git a/gcc/testsuite/gcc.dg/wtr-label-1.c b/gcc/testsuite/gcc.dg/wtr-label-1.c index 38ccd16ad87..78a4d6b0a4b 100644 --- a/gcc/testsuite/gcc.dg/wtr-label-1.c +++ b/gcc/testsuite/gcc.dg/wtr-label-1.c @@ -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; diff --git a/gcc/testsuite/gcc.dg/wtr-static-1.c b/gcc/testsuite/gcc.dg/wtr-static-1.c index f00cd8a7b5f..310c1eab925 100644 --- a/gcc/testsuite/gcc.dg/wtr-static-1.c +++ b/gcc/testsuite/gcc.dg/wtr-static-1.c @@ -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() {} diff --git a/gcc/testsuite/gcc.dg/wtr-strcat-1.c b/gcc/testsuite/gcc.dg/wtr-strcat-1.c index ca85a5c4077..b3966529ad7 100644 --- a/gcc/testsuite/gcc.dg/wtr-strcat-1.c +++ b/gcc/testsuite/gcc.dg/wtr-strcat-1.c @@ -5,7 +5,7 @@ /* { dg-options "-Wtraditional" } */ void -testfunc (void) +testfunc () { const char *foo; diff --git a/gcc/testsuite/gcc.dg/wtr-suffix-1.c b/gcc/testsuite/gcc.dg/wtr-suffix-1.c index f6b6300ac1f..ed0b40ecf30 100644 --- a/gcc/testsuite/gcc.dg/wtr-suffix-1.c +++ b/gcc/testsuite/gcc.dg/wtr-suffix-1.c @@ -5,7 +5,7 @@ /* { dg-options "-Wtraditional" } */ void -testfunc (void) +testfunc () { int i; double f; diff --git a/gcc/testsuite/gcc.dg/wtr-switch-1.c b/gcc/testsuite/gcc.dg/wtr-switch-1.c index e1c0d30df9a..f0381bc5e37 100644 --- a/gcc/testsuite/gcc.dg/wtr-switch-1.c +++ b/gcc/testsuite/gcc.dg/wtr-switch-1.c @@ -5,7 +5,8 @@ /* { dg-options "-Wtraditional" } */ void -testfunc (long l) +testfunc (l) + long l; { switch (l) /* { dg-warning "switch expression" "switch expression" } */ { diff --git a/gcc/testsuite/gcc.dg/wtr-unary-plus-1.c b/gcc/testsuite/gcc.dg/wtr-unary-plus-1.c index b6b053c033d..aee892c532e 100644 --- a/gcc/testsuite/gcc.dg/wtr-unary-plus-1.c +++ b/gcc/testsuite/gcc.dg/wtr-unary-plus-1.c @@ -5,7 +5,7 @@ /* { dg-options "-Wtraditional" } */ void -testfunc (void) +testfunc () { int i; diff --git a/gcc/testsuite/gcc.dg/wtr-union-init-1.c b/gcc/testsuite/gcc.dg/wtr-union-init-1.c index 312bfa92600..18869813d28 100644 --- a/gcc/testsuite/gcc.dg/wtr-union-init-1.c +++ b/gcc/testsuite/gcc.dg/wtr-union-init-1.c @@ -11,7 +11,7 @@ union foo }; void -testfunc (void) +testfunc () { /* Note we only warn for non-zero initializers. */ static union foo f1 = { 0 }; diff --git a/gcc/testsuite/gcc.dg/wtr-union-init-2.c b/gcc/testsuite/gcc.dg/wtr-union-init-2.c index 6366ff326d8..3112ba27762 100644 --- a/gcc/testsuite/gcc.dg/wtr-union-init-2.c +++ b/gcc/testsuite/gcc.dg/wtr-union-init-2.c @@ -19,7 +19,7 @@ union foo2 }; void -testfunc (void) +testfunc () { /* Note we only warn for non-zero initializers. */ static union foo1 f1 = {0}; diff --git a/gcc/testsuite/gcc.dg/wtr-union-init-3.c b/gcc/testsuite/gcc.dg/wtr-union-init-3.c index c5d8e73a377..bb8e300289d 100644 --- a/gcc/testsuite/gcc.dg/wtr-union-init-3.c +++ b/gcc/testsuite/gcc.dg/wtr-union-init-3.c @@ -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 *-*-* } } */ |