This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for PR 15749
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 31 May 2004 22:12:07 +0000 (UTC)
- Subject: Patch for PR 15749
Bug 15749 (a regression in 3.4 and 3.5) reports a problem with
-pedantic-errors rejecting glibc's <stdio.h> for flexible array
misuses. The reason this didn't happen before 3.4 (although the
detection of these misuses went into 3.3) is that pedwarn_with_decl
didn't give any diagnostics in system headers at all, whereas with
-pedantic-errors pedwarns in system headers cause errors unless
there's a separate in_system_header check. We may wish to revisit
this and cause pedwarn() not to give diagnostics in system headers at
all unless -Wsystem-headers (and also to revisit the various local
in_system_header checks on warnings or, after such a change, pedwarns,
that may predate -Wsystem-headers and the general disabling of
warnings in system headers by default), but the safe fix for 3.4
branch is clearly that below which adds local tests of
in_system_header to the pedwarns-if-pedantic for flexible array member
misuse.
Bootstrapped with no regressions on i686-pc-linux-gnu. Applied to
mainline and 3.4 branch.
2004-05-31 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/15749
* c-decl.c (grokdeclarator, finish_struct): Don't pedwarn for
misuses of structures with flexible array members if
in_system_header.
testsuite:
2004-05-31 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/15749
* gcc.dg/pr15749-1.c, gcc.dg/pr15749-1.h: New test.
diff -rupN gcc.orig/c-decl.c gcc/c-decl.c
--- gcc.orig/c-decl.c 2004-03-24 10:52:04.000000000 +0000
+++ gcc/c-decl.c 2004-05-31 15:26:32.000000000 +0000
@@ -3832,7 +3832,7 @@ grokdeclarator (tree declarator, tree de
type = error_mark_node;
}
- if (pedantic && flexible_array_type_p (type))
+ if (pedantic && !in_system_header && flexible_array_type_p (type))
pedwarn ("invalid use of structure with flexible array member");
if (size == error_mark_node)
@@ -5027,7 +5027,7 @@ finish_struct (tree t, tree fieldlist, t
}
}
- if (pedantic && TREE_CODE (t) == RECORD_TYPE
+ if (pedantic && !in_system_header && TREE_CODE (t) == RECORD_TYPE
&& flexible_array_type_p (TREE_TYPE (x)))
pedwarn ("%Jinvalid use of structure with flexible array member", x);
diff -rupN gcc.orig/testsuite/gcc.dg/pr15749-1.c gcc/testsuite/gcc.dg/pr15749-1.c
--- gcc.orig/testsuite/gcc.dg/pr15749-1.c 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/pr15749-1.c 2004-05-31 15:22:50.000000000 +0000
@@ -0,0 +1,8 @@
+/* Flexible array misuses (that are accepted without -pedantic) should
+ be OK in system headers even with -pedantic-errors. PR 15749
+ from Tuomo dot Tikkanen at nokia dot com. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+#include "pr15749-1.h"
diff -rupN gcc.orig/testsuite/gcc.dg/pr15749-1.h gcc/testsuite/gcc.dg/pr15749-1.h
--- gcc.orig/testsuite/gcc.dg/pr15749-1.h 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/pr15749-1.h 2004-05-31 15:19:23.000000000 +0000
@@ -0,0 +1,28 @@
+/* Similar to c99-flex-array-3.c, but a system header so should not
+ have diagnostics even with -pedantic-errors. */
+
+#pragma GCC system_header
+
+struct flex { int a; int b[]; };
+union rf1 { struct flex a; int b; };
+union rf2 { int a; struct flex b; };
+union rf3 { int a; union rf1 b; };
+union rf4 { union rf2 a; int b; };
+
+struct t0 { struct flex a; };
+struct t1 { union rf1 a; };
+struct t2 { union rf2 a; };
+struct t3 { union rf3 a; };
+struct t4 { union rf4 a; };
+
+void f0 (struct flex[]);
+void f1 (union rf1[]);
+void f2 (union rf2[]);
+void f3 (union rf3[]);
+void f4 (union rf4[]);
+
+struct flex a0[1];
+union rf1 a1[1];
+union rf2 a2[1];
+union rf3 a3[1];
+union rf4 a4[1];
--
Joseph S. Myers
jsm@polyomino.org.uk