diff mbox

C PATCH to rephrase error for flexible array members (PR c/71742)

Message ID 20160729152259.GS7007@redhat.com
State New
Headers show

Commit Message

Marek Polacek July 29, 2016, 3:22 p.m. UTC
As outlined in the PR, for code such as

  struct S {
    int :1;
    int a[];
  };

the error message "flexible array member in otherwise empty struct" is not
entirely correct, because the structure isn't otherwise empty.  Martin Sebor
suggested to rephrase the error message as in the following.

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

2016-07-29  Marek Polacek  <polacek@redhat.com>

	PR c/71742
	* c-decl.c (finish_struct): Rephrase an error message.

	* gcc.dg/940510-1.c: Adjust dg-error.
	* gcc.dg/c99-flex-array-1.c: Likewise.
	* gcc.dg/c99-flex-array-typedef-1.c: Likewise.


	Marek

Comments

Jeff Law July 29, 2016, 3:31 p.m. UTC | #1
On 07/29/2016 09:22 AM, Marek Polacek wrote:
> As outlined in the PR, for code such as
>
>   struct S {
>     int :1;
>     int a[];
>   };
>
> the error message "flexible array member in otherwise empty struct" is not
> entirely correct, because the structure isn't otherwise empty.  Martin Sebor
> suggested to rephrase the error message as in the following.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2016-07-29  Marek Polacek  <polacek@redhat.com>
>
> 	PR c/71742
> 	* c-decl.c (finish_struct): Rephrase an error message.
>
> 	* gcc.dg/940510-1.c: Adjust dg-error.
> 	* gcc.dg/c99-flex-array-1.c: Likewise.
> 	* gcc.dg/c99-flex-array-typedef-1.c: Likewise.
OK
jeff
diff mbox

Patch

diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index f2773c5..9a922cc 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -7880,7 +7880,8 @@  finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
 	  else if (!saw_named_field)
 	    {
 	      error_at (DECL_SOURCE_LOCATION (x),
-			"flexible array member in otherwise empty struct");
+			"flexible array member in a struct with no named "
+			"members");
 	      TREE_TYPE (x) = error_mark_node;
 	    }
 	}
diff --git gcc/testsuite/gcc.dg/940510-1.c gcc/testsuite/gcc.dg/940510-1.c
index 2c27e00..1f40d18 100644
--- gcc/testsuite/gcc.dg/940510-1.c
+++ gcc/testsuite/gcc.dg/940510-1.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
 /* { dg-options "-std=c89 -pedantic" } */
 struct { int a[]; } x = { 0 };	/* { dg-warning "ISO C90 does not support flexible array members" } */
-/* { dg-error "flexible array member in otherwise empty struct"  "" { target *-*-* }  3 } */
+/* { dg-error "flexible array member in a struct with no named members"  "" { target *-*-* }  3 } */
 
diff --git gcc/testsuite/gcc.dg/c99-flex-array-1.c gcc/testsuite/gcc.dg/c99-flex-array-1.c
index b14397a..f315709 100644
--- gcc/testsuite/gcc.dg/c99-flex-array-1.c
+++ gcc/testsuite/gcc.dg/c99-flex-array-1.c
@@ -2,7 +2,7 @@ 
 /* { dg-do compile } */
 /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
 
-struct s1 { int x[]; }; /* { dg-error "empty struct" "empty" } */
-struct s2 { int :1; int x[]; }; /* { dg-error "empty struct" "empty" } */
+struct s1 { int x[]; }; /* { dg-error "no named members" "members" } */
+struct s2 { int :1; int x[]; }; /* { dg-error "no named members" "members" } */
 struct s3 { int x[]; int y; }; /* { dg-error "not at end" "not at end" } */
 struct s4 { int x; int y[]; };
diff --git gcc/testsuite/gcc.dg/c99-flex-array-typedef-1.c gcc/testsuite/gcc.dg/c99-flex-array-typedef-1.c
index 93f91f8..8c3b712 100644
--- gcc/testsuite/gcc.dg/c99-flex-array-typedef-1.c
+++ gcc/testsuite/gcc.dg/c99-flex-array-typedef-1.c
@@ -3,7 +3,7 @@ 
 /* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
 
 typedef int A[];
-struct s1 { A x; }; /* { dg-error "empty struct" "empty" } */
-struct s2 { int :1; A x; }; /* { dg-error "empty struct" "empty" } */
+struct s1 { A x; }; /* { dg-error "no named members" "members" } */
+struct s2 { int :1; A x; }; /* { dg-error "no named members" "members" } */
 struct s3 { A x; int y; }; /* { dg-error "not at end" "not at end" } */
 struct s4 { int x; A y; };