This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C PATCH] Clamp down "incomplete type" error (PR c/63543)


We've got a complaint that the "dereferencing pointer to incomplete
type" error is printed for all occurrences of the incomplete type,
which is too verbose.  Also it'd be nicer to print the type as well.
This patch fixes this; if we find an incomplete type, mark it with error
node, then we don't print the error message more than once.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2014-10-15  Marek Polacek  <polacek@redhat.com>

	PR c/63543
	* c-typeck.c (build_indirect_ref): Print the "dereferencing..."
	error only once for each type.  Print also the type.

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

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 5c0697a..f00069c 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -2378,7 +2378,10 @@ 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");
+	      /* Print the error only once for each type.  */
+	      TREE_TYPE (ptr) = error_mark_node;
+	      error_at (loc, "dereferencing pointer to incomplete type %qT",
+			t);
 	      return error_mark_node;
 	    }
 	  if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
diff --git gcc/testsuite/gcc.dg/pr63543.c gcc/testsuite/gcc.dg/pr63543.c
index e69de29..215b62e 100644
--- gcc/testsuite/gcc.dg/pr63543.c
+++ gcc/testsuite/gcc.dg/pr63543.c
@@ -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;
+}

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]