c: Fix PR 3467

Neil Booth neil@daikokuya.demon.co.uk
Sat Jan 26 11:50:00 GMT 2002


This is an obvious fix for PR 3467.  OK to commit?

Neil.

	* c-decl.c (grokdeclarator): Don't do C89 warnings with C99.
	* testsuite/gcc.dg/c89-array.c, c99-array.c: New tests.

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.289
diff -u -p -r1.289 c-decl.c
--- c-decl.c	2002/01/25 20:45:47	1.289
+++ c-decl.c	2002/01/26 19:34:42
@@ -4577,7 +4670,7 @@ grokdeclarator (declarator, declspecs, d
 		     even if it is (eg) a const variable with known value.  */
 		  size_varies = 1;
 
-		  if (pedantic)
+		  if (pedantic && !flag_isoc99)
 		    {
 		      if (TREE_CONSTANT (size))
 			pedwarn ("ISO C89 forbids array `%s' whose size can't be evaluated",
Index: testsuite/gcc.dg/c89-array.c
===================================================================
RCS file: c89-array.c
diff -N c89-array.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ c89-array.c	Sat Jan 26 11:34:42 2002
@@ -0,0 +1,13 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+
+   Tests we warn about variable-sized arrays with C89 pedantic.
+
+   Source: Neil Booth, 26 Jan 2001; see PR 3467.
+*/
+
+/* { dg-options "-pedantic -std=c89" } */
+
+void foo (int n)
+{
+  typedef int A[n];		/* { dg-warning "forbids variable" } */
+}
Index: testsuite/gcc.dg/c99-array.c
===================================================================
RCS file: c99-array.c
diff -N c99-array.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ c99-array.c	Sat Jan 26 11:34:42 2002
@@ -0,0 +1,13 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+
+   Tests we don't warn about variable-sized arrays with C99 pedantic.
+
+   Source: Neil Booth, 26 Jan 2001; see PR 3467.
+*/
+
+/* { dg-options "-pedantic -std=c99" } */
+
+void foo (int n)
+{
+  typedef int A[n];		/* { dg-bogus "forbids variable" } */
+}



More information about the Gcc-patches mailing list