aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2011-03-18 23:26:16 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2011-03-18 23:26:16 +0000
commit8bf872f9e802229ec2def801b4b1d53ffc149c35 (patch)
tree4c5bb74e8984d1dc6006840491fe25e44dbdb0e8 /gcc
parentff8e21599213bbea6ccacecf2522ad19836c8fd1 (diff)
downloadgcc-8bf872f9e802229ec2def801b4b1d53ffc149c35.zip
gcc-8bf872f9e802229ec2def801b4b1d53ffc149c35.tar.gz
gcc-8bf872f9e802229ec2def801b4b1d53ffc149c35.tar.bz2
c-decl.c (diagnose_mismatched_decls): Give an error for redefining a typedef with variably modified type.
* c-decl.c (diagnose_mismatched_decls): Give an error for redefining a typedef with variably modified type. testsuite: * gcc.dg/c1x-typedef-1.c: Expect errors for redefinitions of variably modified typedefs. * gcc.dg/c1x-typedef-2.c: Remove. From-SVN: r171172
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-decl.c16
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/c1x-typedef-1.c10
-rw-r--r--gcc/testsuite/gcc.dg/c1x-typedef-2.c18
5 files changed, 23 insertions, 32 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b6680a9..7c2b4d7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,10 @@
2011-03-18 Joseph Myers <joseph@codesourcery.com>
+ * c-decl.c (diagnose_mismatched_decls): Give an error for
+ redefining a typedef with variably modified type.
+
+2011-03-18 Joseph Myers <joseph@codesourcery.com>
+
* c-decl.c (grokfield): Don't allow typedefs for structures or
unions with no tag by default.
* doc/extend.texi (Unnamed Fields): Update.
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 8f9c444..4e82f28 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -1813,20 +1813,16 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
|| TREE_NO_WARNING (olddecl))
return true; /* Allow OLDDECL to continue in use. */
- if (pedantic && !flag_isoc1x)
+ if (variably_modified_type_p (newtype, NULL))
{
- pedwarn (input_location, OPT_pedantic,
- "redefinition of typedef %q+D", newdecl);
+ error ("redefinition of typedef %q+D with variably modified type",
+ newdecl);
locate_old_decl (olddecl);
}
- else if (variably_modified_type_p (newtype, NULL))
+ else if (pedantic && !flag_isoc1x)
{
- /* Whether there is a constraint violation for the types not
- being the same cannot be determined at compile time; a
- warning that there may be one at runtime is considered
- appropriate (WG14 reflector message 11743, 8 May 2009). */
- warning (0, "redefinition of typedef %q+D may be a constraint "
- "violation at runtime", newdecl);
+ pedwarn (input_location, OPT_pedantic,
+ "redefinition of typedef %q+D", newdecl);
locate_old_decl (olddecl);
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3cda22b..1a30a10 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2011-03-18 Joseph Myers <joseph@codesourcery.com>
+ * gcc.dg/c1x-typedef-1.c: Expect errors for redefinitions of
+ variably modified typedefs.
+ * gcc.dg/c1x-typedef-2.c: Remove.
+
+2011-03-18 Joseph Myers <joseph@codesourcery.com>
+
* gcc.dg/c1x-anon-struct-1.c: Don't test use of typedefs.
* gcc.dg/c1x-anon-struct-3.c: New test.
* gcc.dg/anon-struct-11.c: Update.
diff --git a/gcc/testsuite/gcc.dg/c1x-typedef-1.c b/gcc/testsuite/gcc.dg/c1x-typedef-1.c
index 2b0bc74..a68b23f 100644
--- a/gcc/testsuite/gcc.dg/c1x-typedef-1.c
+++ b/gcc/testsuite/gcc.dg/c1x-typedef-1.c
@@ -3,7 +3,8 @@
/* { dg-options "-std=c1x -pedantic-errors" } */
/* C1X permits typedefs to be redeclared to the same type, but not to
- different-but-compatible types. */
+ different-but-compatible types, and not when the type is variably
+ modified. */
#include <limits.h>
@@ -60,9 +61,10 @@ f (void)
typedef void FN2(int (*p)[*]); /* { dg-message "previous declaration" } */
typedef void FN2(int (*p)[]); /* { dg-error "with different type" } */
typedef int AV[a]; /* { dg-message "previous declaration" } */
- typedef int AV[b-1]; /* { dg-warning "may be a constraint violation at runtime" } */
- typedef int AAa[a];
+ typedef int AV[b-1]; /* { dg-error "redefinition" } */
+ typedef int AAa[a]; /* { dg-message "previous declaration" } */
typedef int AAb[b-1];
typedef AAa *VF(void); /* { dg-message "previous declaration" } */
- typedef AAb *VF(void); /* { dg-warning "may be a constraint violation at runtime" } */
+ typedef AAb *VF(void); /* { dg-error "redefinition" } */
+ typedef AAa AAa; /* { dg-error "redefinition" } */
}
diff --git a/gcc/testsuite/gcc.dg/c1x-typedef-2.c b/gcc/testsuite/gcc.dg/c1x-typedef-2.c
deleted file mode 100644
index fb5d918..0000000
--- a/gcc/testsuite/gcc.dg/c1x-typedef-2.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Test typedef redeclaration in C1X. Side effects from duplicate
- declarations still apply. */
-/* { dg-do run } */
-/* { dg-options "-std=c1x -pedantic-errors" } */
-
-extern void exit (int);
-extern void abort (void);
-
-int
-main (void)
-{
- int a = 1, b = 1;
- typedef int T[++a]; /* { dg-message "previous declaration" } */
- typedef int T[++b]; /* { dg-warning "may be a constraint violation at runtime" } */
- if (a != 2 || b != 2)
- abort ();
- exit (0);
-}