re PR c/36446 (unexplained warning in struct initialization)

PR c/36446
	* c-typeck.c (error_init): Call inform instead of error_at.
	(pedwarn_init): Call inform instead of pedwarn.
	(warning_init): Call inform instead of warning_at.

	* gcc.dg/Wcxx-compat-6.c: Change dg-warning to dg-message.
	* gcc.dg/array-2.c: Likewise.
	* gcc.dg/array-const-2.c: Likewise.
	* gcc.dg/ucnid-8.c: Likewise.
	* gcc.dg/vla-init-1.c: Likewise.
	* gcc.dg/array-const-3.c: Change dg-error to dg-message.
	* gcc.dg/c99-flex-array-7.c: Likewise.
	* gcc.dg/init-bad-1.c: Likewise.
	* gcc.dg/init-bad-3.c: Likewise.
	* gcc.dg/init-bad-2.c: Change dg-error and dg-warning to dg-message.
	* gcc.dg/pedwarn-init.c: Add dg-warning.
	* gcc.dg/pr53119.c: Remove dg-excess-errors.

From-SVN: r211388
This commit is contained in:
Marek Polacek 2014-06-09 20:33:51 +00:00 committed by Marek Polacek
parent 23646391f2
commit d7ff7ae554
15 changed files with 64 additions and 41 deletions

View File

@ -1,3 +1,10 @@
2014-06-09 Marek Polacek <polacek@redhat.com>
PR c/36446
* c-typeck.c (error_init): Call inform instead of error_at.
(pedwarn_init): Call inform instead of pedwarn.
(warning_init): Call inform instead of warning_at.
2014-06-07 Jan Hubicka <hubicka@ucw.cz>
* c-decl.c (merge_decls): Use set_decl_section_name.

View File

@ -5567,7 +5567,7 @@ error_init (location_t loc, const char *gmsgid)
error_at (loc, gmsgid);
ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
if (*ofwhat)
error_at (loc, "(near initialization for %qs)", ofwhat);
inform (loc, "(near initialization for %qs)", ofwhat);
}
/* Issue a pedantic warning for a bad initializer component. OPT is
@ -5579,12 +5579,13 @@ static void
pedwarn_init (location_t location, int opt, const char *gmsgid)
{
char *ofwhat;
bool warned;
/* The gmsgid may be a format string with %< and %>. */
pedwarn (location, opt, gmsgid);
warned = pedwarn (location, opt, gmsgid);
ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
if (*ofwhat)
pedwarn (location, opt, "(near initialization for %qs)", ofwhat);
if (*ofwhat && warned)
inform (location, "(near initialization for %qs)", ofwhat);
}
/* Issue a warning for a bad initializer component.
@ -5597,12 +5598,13 @@ static void
warning_init (location_t loc, int opt, const char *gmsgid)
{
char *ofwhat;
bool warned;
/* The gmsgid may be a format string with %< and %>. */
warning_at (loc, opt, gmsgid);
warned = warning_at (loc, opt, gmsgid);
ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
if (*ofwhat)
warning_at (loc, opt, "(near initialization for %qs)", ofwhat);
if (*ofwhat && warned)
inform (loc, "(near initialization for %qs)", ofwhat);
}
/* If TYPE is an array type and EXPR is a parenthesized string

View File

@ -1,3 +1,19 @@
2014-06-09 Marek Polacek <polacek@redhat.com>
PR c/36446
* gcc.dg/Wcxx-compat-6.c: Change dg-warning to dg-message.
* gcc.dg/array-2.c: Likewise.
* gcc.dg/array-const-2.c: Likewise.
* gcc.dg/ucnid-8.c: Likewise.
* gcc.dg/vla-init-1.c: Likewise.
* gcc.dg/array-const-3.c: Change dg-error to dg-message.
* gcc.dg/c99-flex-array-7.c: Likewise.
* gcc.dg/init-bad-1.c: Likewise.
* gcc.dg/init-bad-3.c: Likewise.
* gcc.dg/init-bad-2.c: Change dg-error and dg-warning to dg-message.
* gcc.dg/pedwarn-init.c: Add dg-warning.
* gcc.dg/pr53119.c: Remove dg-excess-errors.
2014-06-09 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/22556

View File

@ -109,4 +109,4 @@ f(enum E1 e1, enum E2 e2, struct s1 vs1, struct s1 *vp1)
}
/* Match all extra informative notes. */
/* { dg-warning "near initialization for" "expected" { target *-*-* } 0 } */
/* { dg-message "near initialization for" "expected" { target *-*-* } 0 } */

View File

@ -8,7 +8,7 @@ struct f { int w; int x[]; };
struct g { struct f f; };
struct g g1 = { { 0, { } } };
struct g g2 = { { 0, { 1 } } }; /* { dg-error "nested context" "nested" } */
/* { dg-error "near init" "near" { target *-*-* } 10 } */
/* { dg-message "near init" "near" { target *-*-* } 10 } */
struct h { int x[0]; int y; };
struct h h1 = { { 0 }, 1 }; /* { dg-warning "excess elements" "excess" } */
/* { dg-warning "near init" "before end" { target *-*-* } 13 } */
/* { dg-message "near init" "before end" { target *-*-* } 13 } */

View File

@ -6,4 +6,4 @@
extern int i;
int a[] = { [1 ? 1 : i] = 0 }; /* { dg-warning "array index in initializer is not an integer constant expression" } */
/* { dg-warning "near initialization" "near init" { target *-*-* } 8 } */
/* { dg-message "near initialization" "near init" { target *-*-* } 8 } */

View File

@ -6,4 +6,4 @@
extern int i;
int a[] = { [1 ? 1 : i] = 0 }; /* { dg-error "array index in initializer is not an integer constant expression" } */
/* { dg-error "near initialization" "near init" { target *-*-* } 8 } */
/* { dg-message "near initialization" "near init" { target *-*-* } 8 } */

View File

@ -6,12 +6,12 @@
struct s { int a; char b[]; };
struct s a = { 0, "" }; /* { dg-error "initialization of a flexible array member" } */
/* { dg-error "near init" "near init" { target *-*-* } 8 } */
/* { dg-message "near init" "near init" { target *-*-* } 8 } */
struct s b = { 0, { 0 } }; /* { dg-error "initialization of a flexible array member" } */
/* { dg-error "near init" "near init" { target *-*-* } 10 } */
/* { dg-message "near init" "near init" { target *-*-* } 10 } */
struct s c = { 0, { } }; /* { dg-error "ISO C forbids empty initializer braces" } */
struct s d = { .b = "" }; /* { dg-error "initialization of a flexible array member" } */
/* { dg-error "near init" "near init" { target *-*-* } 13 } */
/* { dg-message "near init" "near init" { target *-*-* } 13 } */
struct s e = { .b = { 0 } }; /* { dg-error "initialization of a flexible array member" } */
/* { dg-error "near init" "near init" { target *-*-* } 15 } */
/* { dg-message "near init" "near init" { target *-*-* } 15 } */
struct s f = { .b = { } }; /* { dg-error "ISO C forbids empty initializer braces" } */

View File

@ -19,27 +19,27 @@ char s1[1] = { "x" };
char t[1] = "xy"; /* { dg-warning "initializer-string for array of chars is too long" } */
char t1[1] = { "xy" }; /* { dg-warning "initializer-string for array of chars is too long" } */
char u[1] = { "x", "x" }; /* { dg-error "excess elements in char array initializer" } */
/* { dg-error "near init" "near" { target *-*-* } 21 } */
/* { dg-message "near init" "near" { target *-*-* } 21 } */
int i = { }; /* { dg-error "empty scalar initializer" } */
/* { dg-error "near init" "near" { target *-*-* } 24 } */
/* { dg-message "near init" "near" { target *-*-* } 24 } */
int j = { 1 };
int k = { 1, 2 }; /* { dg-warning "excess elements in scalar initializer" } */
/* { dg-warning "near init" "near" { target *-*-* } 29 } */
/* { dg-message "near init" "near" { target *-*-* } 29 } */
int a1[1] = { [1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 32 } */
/* { dg-message "near init" "near" { target *-*-* } 32 } */
int a2[1] = { [-1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 34 } */
/* { dg-message "near init" "near" { target *-*-* } 34 } */
int a3[1] = { [0 ... 1] = 0 }; /* { dg-error "array index range in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 36 } */
/* { dg-message "near init" "near" { target *-*-* } 36 } */
int a4[2] = { [1 ... 0] = 0 }; /* { dg-error "empty index range in initializer" } */
/* { dg-error "near init" "near" { target *-*-* } 38 } */
/* { dg-message "near init" "near" { target *-*-* } 38 } */
int a5[2] = { [0 ... 2] = 0 }; /* { dg-error "array index range in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 40 } */
/* { dg-message "near init" "near" { target *-*-* } 40 } */
int a6[2] = { [-1 ... 1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 42 } */
/* { dg-message "near init" "near" { target *-*-* } 42 } */
int a7[] = { [-1 ... 1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 44 } */
/* { dg-message "near init" "near" { target *-*-* } 44 } */

View File

@ -11,7 +11,7 @@ void h(a)
int a = 1; /* { dg-error "parameter 'a' is initialized" } */
{
struct s x = { 0 }; /* { dg-error "variable 'x' has initializer but incomplete type" } */
/* { dg-warning "excess elements|near init" "near" { target *-*-* } 13 } */
/* { dg-message "excess elements|near init" "near" { target *-*-* } 13 } */
/* { dg-error "storage size" "size" { target *-*-* } 13 } */
}
@ -20,14 +20,14 @@ char s1[1] = { "x" };
char t[1] = "xy"; /* { dg-warning "initializer-string for array of chars is too long" } */
char t1[1] = { "xy" }; /* { dg-warning "initializer-string for array of chars is too long" } */
char u[1] = { "x", "x" }; /* { dg-error "excess elements in char array initializer" } */
/* { dg-error "near init" "near" { target *-*-* } 22 } */
/* { dg-message "near init" "near" { target *-*-* } 22 } */
int j = { 1 };
int k = { 1, 2 }; /* { dg-warning "excess elements in scalar initializer" } */
/* { dg-warning "near init" "near" { target *-*-* } 27 } */
/* { dg-message "near init" "near" { target *-*-* } 27 } */
int a1[1] = { [1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 30 } */
/* { dg-message "near init" "near" { target *-*-* } 30 } */
int a2[1] = { [-1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 32 } */
/* { dg-message "near init" "near" { target *-*-* } 32 } */

View File

@ -11,7 +11,7 @@ void h(a)
int a = 1; /* { dg-error "parameter 'a' is initialized" } */
{
struct s x = { 0 }; /* { dg-error "variable 'x' has initializer but incomplete type" } */
/* { dg-error "excess elements|near init" "near" { target *-*-* } 13 } */
/* { dg-message "excess elements|near init" "near" { target *-*-* } 13 } */
/* { dg-error "storage size" "size" { target *-*-* } 13 } */
}
@ -20,14 +20,14 @@ char s1[1] = { "x" };
char t[1] = "xy"; /* { dg-error "initializer-string for array of chars is too long" } */
char t1[1] = { "xy" }; /* { dg-error "initializer-string for array of chars is too long" } */
char u[1] = { "x", "x" }; /* { dg-error "excess elements in char array initializer" } */
/* { dg-error "near init" "near" { target *-*-* } 22 } */
/* { dg-message "near init" "near" { target *-*-* } 22 } */
int j = { 1 };
int k = { 1, 2 }; /* { dg-error "excess elements in scalar initializer" } */
/* { dg-error "near init" "near" { target *-*-* } 27 } */
/* { dg-message "near init" "near" { target *-*-* } 27 } */
int a1[1] = { [1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 30 } */
/* { dg-message "near init" "near" { target *-*-* } 30 } */
int a2[1] = { [-1] = 0 }; /* { dg-error "array index in initializer exceeds array bounds" } */
/* { dg-error "near init" "near" { target *-*-* } 32 } */
/* { dg-message "near init" "near" { target *-*-* } 32 } */

View File

@ -12,6 +12,7 @@ int a1 = { 1, 2 }; /* { dg-warning "15:excess elements in scalar initializer" }
int a2[2] = { 1, 2, 3 }; /* { dg-warning "21:excess elements in array initializer" } */
int a3[] = { [1 ? 1 : i] = 0 }; /* { dg-warning "15:array index in initializer is not an integer constant expression" } */
int a4[] = { [1 ... 1 ? 2 : i] = 0 }; /* { dg-warning "15:array index in initializer is not an integer constant expression" } */
/* { dg-warning "ISO C forbids" "ISO C" { target *-*-* } 14 } */
char a5[] = ("lol"); /* { dg-warning "13:array initialized from parenthesized string constant" } */
char a6[] = { ("foo") }; /* { dg-warning "13:array initialized from parenthesized string constant" } */
char *a7 = (char []) { ("bar") }; /* { dg-warning "12:array initialized from parenthesized string constant" } */

View File

@ -1,5 +1,4 @@
/* { dg-do compile } */
/* { dg-options "-Wmissing-braces -Wmissing-field-initializers" } */
struct a {
@ -21,5 +20,3 @@ int main (void)
return 0;
}
/* { dg-excess-errors "note" } */

View File

@ -13,4 +13,4 @@ void f (int b) { int \u00e9[b]; } /* { dg-warning "variable length array '\\\\U0
void g (static int \u00e9); /* { dg-error "storage class specified for parameter '\\\\U000000e9'" } */
struct s2 { int \u00e1; } \u00e9 = { { 0 } }; /* { dg-warning "braces around scalar initializer" } */
/* { dg-warning "near initialization for '\\\\U000000e9\\.\\\\U000000e1'" "UCN diag" { target *-*-* } 15 } */
/* { dg-message "near initialization for '\\\\U000000e9\\.\\\\U000000e1'" "UCN diag" { target *-*-* } 15 } */

View File

@ -11,5 +11,5 @@ foo (void)
{
int x[a] = { 1 }; /* { dg-error "variable-sized object may not be initialized" "VLA init" } */
/* { dg-warning "excess elements in array initializer" "excess" { target *-*-* } 12 } */
/* { dg-warning "near initialization" "near" { target *-*-* } 12 } */
/* { dg-message "near initialization" "near" { target *-*-* } 12 } */
}