]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/79983 (Improve enum and struct redefinition diagnostic)
authorMarek Polacek <polacek@redhat.com>
Tue, 6 Jun 2017 17:40:34 +0000 (17:40 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 6 Jun 2017 17:40:34 +0000 (17:40 +0000)
PR c/79983
* c-decl.c (start_struct): Use the location of TYPE_STUB_DECL of
ref.
(start_enum): Use the location of TYPE_STUB_DECL of enumtype.

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

From-SVN: r248927

gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr79983.c [new file with mode: 0644]

index d849b014fec258abc233939396f678e239212ccc..63cd3d4ab7927f96997666fa258f9da2631ab1af 100644 (file)
@@ -1,3 +1,10 @@
+2017-06-06  Marek Polacek  <polacek@redhat.com>
+
+       PR c/79983
+       * c-decl.c (start_struct): Use the location of TYPE_STUB_DECL of
+       ref.
+       (start_enum): Use the location of TYPE_STUB_DECL of enumtype.
+
 2017-06-02  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
        * c-parser.c (c_parser_binary_expression): Implement the
index f2b8096d84a1ec07a7699662b8727edd2400c734..3a0a4f5173703228a8abbb6702a9b85a49d85d94 100644 (file)
@@ -7453,6 +7453,9 @@ start_struct (location_t loc, enum tree_code code, tree name,
     ref = lookup_tag (code, name, true, &refloc);
   if (ref && TREE_CODE (ref) == code)
     {
+      if (TYPE_STUB_DECL (ref))
+       refloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (ref));
+
       if (TYPE_SIZE (ref))
        {
          if (code == UNION_TYPE)
@@ -8185,7 +8188,10 @@ start_enum (location_t loc, struct c_enum_contents *the_enum, tree name)
   /* Update type location to the one of the definition, instead of e.g.
      a forward declaration.  */
   else if (TYPE_STUB_DECL (enumtype))
-    DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc;
+    {
+      enumloc = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype));
+      DECL_SOURCE_LOCATION (TYPE_STUB_DECL (enumtype)) = loc;
+    }
 
   if (C_TYPE_BEING_DEFINED (enumtype))
     error_at (loc, "nested redefinition of %<enum %E%>", name);
index 8b456276571039eebed9e805502003a5b142fc06..bdd579ad67be02034b1c1155a54fc07a1a4426a7 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-06  Marek Polacek  <polacek@redhat.com>
+
+       PR c/79983
+       * gcc.dg/pr79983.c: New test.
+
 2017-06-06  David S. Miller  <davem@davemloft.net>
 
        * gcc.target/sparc/sparc-ret-3.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr79983.c b/gcc/testsuite/gcc.dg/pr79983.c
new file mode 100644 (file)
index 0000000..84aae69
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR c/79983 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct S;
+struct S { int i; }; /* { dg-message "originally defined here" } */
+struct S { int i, j; }; /* { dg-error "redefinition of 'struct S'" } */
+
+enum E;
+enum E { A, B, C }; /* { dg-message "originally defined here" } */
+enum E { D, F }; /* { dg-error "nested redefinition of 'enum E'|redeclaration of 'enum E'" } */
+
+union U;
+union U { int i; }; /* { dg-message "originally defined here" } */
+union U { int i; double d; }; /* { dg-error "redefinition of 'union U'" } */