]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/44772 (-Wc++-compat warns incorrectly for anonymous unions)
authorJakub Jelinek <jakub@redhat.com>
Thu, 11 Nov 2010 20:40:32 +0000 (21:40 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 11 Nov 2010 20:40:32 +0000 (21:40 +0100)
Backport from mainline
2010-11-05  Jakub Jelinek  <jakub@redhat.com>

PR c/44772
* c-decl.c (warn_cxx_compat_finish_struct): Don't call
pointer_set_contains if DECL_NAME is NULL.

* gcc.dg/Wcxx-compat-21.c: New test.

From-SVN: r166620

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

index 8d0a103f3a0b2d8b1855880bb1ab4e2414ebe807..ad047e8197c26ba8e421ae9a996950829d19a51d 100644 (file)
@@ -3,6 +3,10 @@
        Backport from mainline
        2010-11-05  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/44772
+       * c-decl.c (warn_cxx_compat_finish_struct): Don't call
+       pointer_set_contains if DECL_NAME is NULL.
+
        PR tree-optimization/46099
        * tree-parloops.c (take_address_of): Add GSI argument.  Return NULL
        if it is NULL and uid wasn't found in the hash table.  Just fold the
index b6ff3f476e6f57ad9372cd37ef71179e9a4a495c..9763b37ff27515f6ac410bd03b6b37d1bd1bb77f 100644 (file)
@@ -6709,7 +6709,8 @@ warn_cxx_compat_finish_struct (tree fieldlist)
 
       for (x = fieldlist; x != NULL_TREE; x = TREE_CHAIN (x))
        {
-         if (pointer_set_contains (tset, DECL_NAME (x)))
+         if (DECL_NAME (x) != NULL_TREE
+             && pointer_set_contains (tset, DECL_NAME (x)))
            {
              warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
                          ("using %qD as both field and typedef name is "
index e549f45a41eae2d297ab1bb5652d45cfb2de6d2d..67dcced17cdb756217b0b44689ace61c25c0f169 100644 (file)
@@ -3,6 +3,9 @@
        Backport from mainline
        2010-11-05  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/44772
+       * gcc.dg/Wcxx-compat-21.c: New test.
+
        PR c++/46160
        * g++.dg/opt/empty2.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/Wcxx-compat-21.c b/gcc/testsuite/gcc.dg/Wcxx-compat-21.c
new file mode 100644 (file)
index 0000000..183f0f1
--- /dev/null
@@ -0,0 +1,25 @@
+/* PR c/44772 */
+/* { dg-do compile } */
+/* { dg-options "-Wc++-compat" } */
+
+typedef enum { E1, E2 } E;
+
+typedef struct
+{
+  E e;
+  union
+  {
+    int i;
+    char *c;
+  };                   /* { dg-bogus "as both field and typedef name" } */
+} S;
+
+S s;
+
+typedef int T;
+
+struct U
+{
+  T t;
+  union { int i; };    /* { dg-bogus "as both field and typedef name" } */
+};