re PR c/63543 (incomplete type error should suppress duplicates)
authorMarek Polacek <polacek@redhat.com>
Fri, 17 Oct 2014 18:53:35 +0000 (18:53 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 17 Oct 2014 18:53:35 +0000 (18:53 +0000)
PR c/63543
* c-tree.h (C_TYPE_ERROR_REPORTED): Define.
* c-typeck.c (build_indirect_ref): Don't print the "dereferencing..."
error multiple times.  Print the type.

* gcc.dg/pr63543.c: New test.
* gcc.dg/array-8.c: Remove dg-error.
* gcc.dg/pr48552-1.c: Remove and adjust dg-error.
* gcc.dg/pr48552-2.c: Likewise.

From-SVN: r216414

gcc/c/ChangeLog
gcc/c/c-tree.h
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/array-8.c
gcc/testsuite/gcc.dg/pr48552-1.c
gcc/testsuite/gcc.dg/pr48552-2.c
gcc/testsuite/gcc.dg/pr63543.c [new file with mode: 0644]

index bb57ee22d41b0ed53903ecb4343ce398db7821a2..294b4ef54ad561e8abd2dd8a813349635c262167 100644 (file)
@@ -1,3 +1,10 @@
+2014-10-17  Marek Polacek  <polacek@redhat.com>
+
+       PR c/63543
+       * c-tree.h (C_TYPE_ERROR_REPORTED): Define.
+       * c-typeck.c (build_indirect_ref): Don't print the "dereferencing..."
+       error multiple times.  Print the type.
+
 2014-10-17  Marek Polacek  <polacek@redhat.com>
 
        PR c/63549
index e6aca01923ba3dfc58e6654ba014ee38dec0ebbb..5ff9d9ccce9d6cb01a83b8833294ebc8e0dc9cd5 100644 (file)
@@ -56,6 +56,9 @@ along with GCC; see the file COPYING3.  If not see
    This is used for -Wc++-compat. */
 #define C_TYPE_DEFINED_IN_STRUCT(TYPE) TYPE_LANG_FLAG_2 (TYPE)
 
+/* Record whether an "incomplete type" error was given for the type.  */
+#define C_TYPE_ERROR_REPORTED(TYPE) TYPE_LANG_FLAG_3 (TYPE)
+
 /* Record whether a typedef for type `int' was actually `signed int'.  */
 #define C_TYPEDEF_EXPLICITLY_SIGNED(EXP) DECL_LANG_FLAG_1 (EXP)
 
index 1e971c1b672d2978fbabae82f380392188731bd8..324736acdf4812597161a6de6a83293cd2a0e697 100644 (file)
@@ -2378,7 +2378,12 @@ build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
 
          if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE)
            {
-             error_at (loc, "dereferencing pointer to incomplete type");
+             if (!C_TYPE_ERROR_REPORTED (TREE_TYPE (ptr)))
+               {
+                 error_at (loc, "dereferencing pointer to incomplete type "
+                           "%qT", t);
+                 C_TYPE_ERROR_REPORTED (TREE_TYPE (ptr)) = 1;
+               }
              return error_mark_node;
            }
          if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
index f9e3458477c998bae1abcc81779bba33a0852992..29ed3e6956ddc342da40d9bf1773315b273b3949 100644 (file)
@@ -1,3 +1,11 @@
+2014-10-17  Marek Polacek  <polacek@redhat.com>
+
+       PR c/63543
+       * gcc.dg/pr63543.c: New test.
+       * gcc.dg/array-8.c: Remove dg-error.
+       * gcc.dg/pr48552-1.c: Remove and adjust dg-error.
+       * gcc.dg/pr48552-2.c: Likewise.
+
 2014-10-17  Marek Polacek  <polacek@redhat.com>
 
        PR c/63549
index d469a80eaf24b788014df7495d20a77740f56396..2872985806e0c2fafda31c2b528481e5a8cbefe6 100644 (file)
@@ -45,5 +45,4 @@ g (void)
   sip[0]; /* { dg-error "invalid use of undefined type 'struct si'" } */
   /* { dg-error "dereferencing pointer to incomplete type" "incomplete" { target *-*-* } 45 } */
   0[sip]; /* { dg-error "invalid use of undefined type 'struct si'" } */
-  /* { dg-error "dereferencing pointer to incomplete type" "incomplete" { target *-*-* } 47 } */
 }
index 877c4c2a88199c17171d6b854ab96442c8dce280..4b833fb3da01cecb0c3dc9871adb0c6be8fdee8f 100644 (file)
@@ -49,5 +49,5 @@ f7 (struct S *x)
 void
 f8 (struct S *x)
 {
-  __asm volatile ("" : "=r" (*x));     /* { dg-error "dereferencing pointer to incomplete type" "incomplete" } */
-}                                      /* { dg-error "invalid lvalue in asm output 0" "invalid lvalue" { target *-*-* } 52 } */
+  __asm volatile ("" : "=r" (*x));     /* { dg-error "invalid lvalue in asm output 0" } */
+}
index a7969837bf5f43021b49e42defe8abd46d2b931f..954c411c5c4450cc8d23e6e3e6053c30c5d347c7 100644 (file)
@@ -49,5 +49,5 @@ f7 (struct S *x)
 void
 f8 (struct S *x)
 {
-  __asm ("" : "=r" (*x));      /* { dg-error "dereferencing pointer to incomplete type" "incomplete" } */
-}                              /* { dg-error "invalid lvalue in asm output 0" "invalid lvalue" { target *-*-* } 52 } */
+  __asm ("" : "=r" (*x));      /* { dg-error "invalid lvalue in asm output 0" } */
+}
diff --git a/gcc/testsuite/gcc.dg/pr63543.c b/gcc/testsuite/gcc.dg/pr63543.c
new file mode 100644 (file)
index 0000000..215b62e
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR c/63543 */
+/* { dg-do compile } */
+
+struct S;
+union U;
+
+int
+f1 (struct S *s)
+{
+  return s->a /* { dg-error "dereferencing pointer to incomplete type .struct S." } */
+        + s->b
+        + s->c;
+}
+
+int
+f2 (union U *u)
+{
+  return u->a /* { dg-error "dereferencing pointer to incomplete type .union U." } */
+        + u->a
+        + u->a;
+}