This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Add -Wold-style-definition


Andreas Jaeger <aj@suse.de> writes:

>> As warning even when there is a previous prototype is what this option
>> adds to -Wstrict-prototypes, the testcase should provide a previous
>> prototype.  (And also test for old-style definitions without parameters,
>> if those are to be included in the option.  And for old-style definitions
>> where there are parameters but they all default to int instead of being
>> explicitly declared.)
>
> It does not warn for these either.
>
> You only get the following warning:
>
> void
> bar (a) int a; { } /* { dg-warning "old-style parameter declaration" } */
>
> void bar1 () {}
>
> extern void bar2 (void);
>
> void bar2 () {}
>
> extern void bar3 (int);
>
> void bar3 (a) {}
>
> void bar4 (a) {}
>
> But I guess, you'd like to see warnings for these also?  Ok, then I
> need to look closer into the parser...

I'm appending a new patch.

Now I get these warnings on the above testcase:
/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c: In function `bar':

/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c:8: warning: old-style parameter declaration
/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c: In function `bar1':

/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c:10: warning: old-style parameter declaration
/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c: In function `bar2':

/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c:14: warning: old-style parameter declaration
/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c: In function `bar3':

/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c:18: warning: old-style parameter declaration
/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c: In function `bar4':

/usr/src/aj/cvs/gcc/gcc/testsuite/gcc.dg/Wold-style-definition-1.c:20: warning: old-style parameter declaration

And no warnings for these two:
void bar5 (int a) {}
void bar6 (void) {}

Bootstrapped/regtested on x86_64-linux-gnu.  Ok to commit?

Andreas

2003-09-14  Andreas Jaeger  <aj@suse.de>
            Kaveh R. Ghazi <ghazi@caip.rutgers.edu>

	* doc/invoke.texi (Warning Options): Describe -Wold-style-definition.
	* c-opts.c (c_common_handle_option): Handle OPT_Wold_style_definition.
	* c-parse.in: Warn about old-style parameter definition.
	* c-common.c: Define warn_old_style_defintion.
	* c-common.h: Declare it.
	* c.opt: Add Wold-style-defintion.

testsuite:
2003-09-14  Andreas Jaeger  <aj@suse.de>

	* gcc.dg/old_style_def.c: New test.

============================================================
Index: gcc/doc/invoke.texi
--- doc/invoke.texi	12 Sep 2003 21:52:00 -0000	1.336
+++ doc/invoke.texi	15 Sep 2003 06:48:41 -0000
@@ -220,7 +220,7 @@ in the following sections.
 -Wmain  -Wmissing-braces @gol
 -Wmissing-format-attribute  -Wmissing-noreturn @gol
 -Wno-multichar  -Wno-format-extra-args  -Wno-format-y2k @gol
--Wno-import  -Wnonnull  -Wpacked  -Wpadded @gol
+-Wno-import  -Wnonnull -Wold-style-definition -Wpacked  -Wpadded @gol
 -Wparentheses  -Wpointer-arith  -Wredundant-decls @gol
 -Wreturn-type  -Wsequence-point  -Wshadow @gol
 -Wsign-compare  -Wstrict-aliasing @gol
@@ -2708,6 +2708,11 @@ Warn if a function is declared or define
 argument types.  (An old-style function definition is permitted without
 a warning if preceded by a declaration which specifies the argument
 types.)
+
+@item -Wold-style-definition @r{(C only)}
+@opindex Wold-style-definition
+Warn if an old-style function definition is used.  A warning is given
+even if there is a previous prototype.
 
 @item -Wmissing-prototypes @r{(C only)}
 @opindex Wmissing-prototypes
============================================================
Index: gcc/c-opts.c
--- gcc/c-opts.c	19 Aug 2003 20:29:00 -0000	1.88
+++ gcc/c-opts.c	15 Sep 2003 06:48:41 -0000
@@ -550,6 +550,10 @@ c_common_handle_option (size_t scode, co
       warn_nonnull = value;
       break;
 
+    case OPT_Wold_style_definition:
+      warn_old_style_definition = value;
+      break;
+
     case OPT_Wold_style_cast:
       warn_old_style_cast = value;
       break;
============================================================
Index: gcc/c-parse.in
--- gcc/c-parse.in	3 Sep 2003 14:57:29 -0000	1.180
+++ gcc/c-parse.in	15 Sep 2003 06:48:41 -0000
@@ -757,9 +757,16 @@ old_style_parm_decls_1:
 	  if (warn_traditional && !in_system_header
 	      && parsing_iso_function_signature)
 	    warning ("traditional C rejects ISO C style function definitions");
+	  if (warn_old_style_definition && !in_system_header
+	      && !parsing_iso_function_signature)
+	    warning ("old-style parameter declaration");
 	  parsing_iso_function_signature = false; /* Reset after warning.  */
 	}
 	| datadecls
+	{
+	  if (warn_old_style_definition && !in_system_header)
+	    warning ("old-style parameter declaration");
+	}
 	;
 
 /* The following are analogous to lineno_decl, decls and decl
============================================================
Index: gcc/c-common.c
--- gcc/c-common.c	9 Sep 2003 03:35:28 -0000	1.454
+++ gcc/c-common.c	15 Sep 2003 06:48:41 -0000
@@ -429,6 +429,10 @@ int warn_implicit_int;
 
 int warn_nonnull;
 
+/* Warn about old-style parameter declaration.  */
+
+int warn_old_style_definition;
+
 
 /* ObjC language option variables.  */
 
============================================================
Index: gcc/c-common.h
--- gcc/c-common.h	9 Sep 2003 03:35:28 -0000	1.206
+++ gcc/c-common.h	15 Sep 2003 06:48:41 -0000
@@ -591,6 +591,10 @@ extern int warn_implicit_int;
       
 extern int warn_nonnull;
 
+/* Warn about old-style parameter declaration.  */
+
+extern int warn_old_style_definition;
+
 
 /* ObjC language option variables.  */
 
============================================================
Index: gcc/c.opt
--- gcc/c.opt	19 Aug 2003 20:29:00 -0000	1.15
+++ gcc/c.opt	15 Sep 2003 06:48:41 -0000
@@ -312,6 +312,10 @@ Wold-style-cast
 C++ ObjC++
 Warn if a C-style cast is used in a program
 
+Wold-style-definition
+C ObjC
+Warn if an old-style parameter definition is used
+
 Woverloaded-virtual
 C++ ObjC++
 Warn about overloaded virtual function names
============================================================
Index: gcc/testsuite/gcc.dg/Wold-style-definition-1.c
--- gcc/testsuite/gcc.dg/Wold-style-definition-1.c	created
+++ gcc/testsuite/gcc.dg/Wold-style-definition-1.c	2003-09-15 08:44:19.000000000 +0200	1.1
@@ -0,0 +1,24 @@
+/* Test for warning about old-style function definition.  */
+
+/* Origin: Andreas Jaeger <aj@suse.de> */
+/* { dg-do compile } */
+/* { dg-options "-Wold-style-definition" } */
+
+void
+bar (a) int a; { } /* { dg-warning "old-style parameter declaration" } */
+
+void bar1 () {} /* { dg-warning "old-style parameter declaration" } */
+
+extern void bar2 (void);
+
+void bar2 () {} /* { dg-warning "old-style parameter declaration" } */
+
+extern void bar3 (int);
+
+void bar3 (a) {} /* { dg-warning "old-style parameter declaration" } */
+
+void bar4 (a) {} /* { dg-warning "old-style parameter declaration" } */
+
+void bar5 (int a) {}
+
+void bar6 (void) {}

-- 
 Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj
  SuSE Linux AG, Deutschherrnstr. 15-19, 90429 Nürnberg, Germany
   GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126

Attachment: pgp00000.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]