This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Improve diagnostics a tiny bit (PR c/65050)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Fri, 13 Feb 2015 20:07:12 +0100
- Subject: [C PATCH] Improve diagnostics a tiny bit (PR c/65050)
- Authentication-results: sourceware.org; auth=none
This patch tweaks an error message a little bit so that we also print the
type we're talking about.
This is neither a regression nor a bug fix - should I queue this for GCC 6,
or is it so minor that it can still go into GCC 5?
Bootstrapped/regtested on ppc64-linux.
2015-02-13 Marek Polacek <polacek@redhat.com>
PR c/65050
* c-decl.c (grokdeclarator): Print also the type when giving
the error message about array's incomplete element type.
* gcc.dg/pr65050.c: New test.
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 48c2bcb..4fd3239 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -5962,7 +5962,8 @@ grokdeclarator (const struct c_declarator *declarator,
/* Complain about arrays of incomplete types. */
if (!COMPLETE_TYPE_P (type))
{
- error_at (loc, "array type has incomplete element type");
+ error_at (loc, "array type has incomplete element type %qT",
+ type);
type = error_mark_node;
}
else
diff --git gcc/testsuite/gcc.dg/pr65050.c gcc/testsuite/gcc.dg/pr65050.c
index e69de29..0822a99 100644
--- gcc/testsuite/gcc.dg/pr65050.c
+++ gcc/testsuite/gcc.dg/pr65050.c
@@ -0,0 +1,23 @@
+/* PR c/65050 */
+/* { dg-do compile } */
+
+typedef int A[];
+struct S { int i; A a[5]; } s; /* { dg-error "array type has incomplete element type .A {aka int\\\[\\\]}." } */
+extern void foo (int p[2][]); /* { dg-error "array type has incomplete element type .int\\\[\\\]." } */
+extern void bar (A p[2]); /* { dg-error "array type has incomplete element type .A {aka int\\\[\\\]}." } */
+
+void
+foo (int p[2][]) /* { dg-error "array type has incomplete element type .int\\\[\\\]." } */
+{
+}
+
+void
+bar (A p[2]) /* { dg-error "array type has incomplete element type .A {aka int\\\[\\\]}." } */
+{
+}
+
+struct T;
+struct T t[5]; /* { dg-error "array type has incomplete element type .struct T." } */
+struct U u[] = { { "abc" } }; /* { dg-error "array type has incomplete element type .struct U." } */
+typedef struct T TT;
+TT tt[5]; /* { dg-error "array type has incomplete element type .TT {aka struct T}." } */
Marek