It seems that "(near initialization for )" message should be a "note:" message rather than error/warning. This patch changes error_at/warning calls to inform and fixes the testsuite fallout.
Tested x86_64-unknown-linux-gnu, ok for trunk? 2014-06-09 Marek Polacek <pola...@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. * 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. diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index e4fa0c3..63bd65e 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -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 diff --git gcc/testsuite/gcc.dg/Wcxx-compat-6.c gcc/testsuite/gcc.dg/Wcxx-compat-6.c index 2b327c4..eee6768 100644 --- gcc/testsuite/gcc.dg/Wcxx-compat-6.c +++ gcc/testsuite/gcc.dg/Wcxx-compat-6.c @@ -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 } */ diff --git gcc/testsuite/gcc.dg/array-2.c gcc/testsuite/gcc.dg/array-2.c index 497c586..6187500 100644 --- gcc/testsuite/gcc.dg/array-2.c +++ gcc/testsuite/gcc.dg/array-2.c @@ -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 } */ diff --git gcc/testsuite/gcc.dg/array-const-2.c gcc/testsuite/gcc.dg/array-const-2.c index f6e2bd5..6f76955 100644 --- gcc/testsuite/gcc.dg/array-const-2.c +++ gcc/testsuite/gcc.dg/array-const-2.c @@ -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 } */ diff --git gcc/testsuite/gcc.dg/array-const-3.c gcc/testsuite/gcc.dg/array-const-3.c index 5bb215c..036b0ea 100644 --- gcc/testsuite/gcc.dg/array-const-3.c +++ gcc/testsuite/gcc.dg/array-const-3.c @@ -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 } */ diff --git gcc/testsuite/gcc.dg/c99-flex-array-7.c gcc/testsuite/gcc.dg/c99-flex-array-7.c index 8966e6c..88018b0 100644 --- gcc/testsuite/gcc.dg/c99-flex-array-7.c +++ gcc/testsuite/gcc.dg/c99-flex-array-7.c @@ -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" } */ diff --git gcc/testsuite/gcc.dg/init-bad-1.c gcc/testsuite/gcc.dg/init-bad-1.c index cc808b7..6599de0 100644 --- gcc/testsuite/gcc.dg/init-bad-1.c +++ gcc/testsuite/gcc.dg/init-bad-1.c @@ -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 } */ diff --git gcc/testsuite/gcc.dg/init-bad-2.c gcc/testsuite/gcc.dg/init-bad-2.c index 1f0f78b..e151709 100644 --- gcc/testsuite/gcc.dg/init-bad-2.c +++ gcc/testsuite/gcc.dg/init-bad-2.c @@ -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 } */ diff --git gcc/testsuite/gcc.dg/init-bad-3.c gcc/testsuite/gcc.dg/init-bad-3.c index 109e65e..82a632a 100644 --- gcc/testsuite/gcc.dg/init-bad-3.c +++ gcc/testsuite/gcc.dg/init-bad-3.c @@ -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 } */ diff --git gcc/testsuite/gcc.dg/pedwarn-init.c gcc/testsuite/gcc.dg/pedwarn-init.c index 1261115..e3181d6 100644 --- gcc/testsuite/gcc.dg/pedwarn-init.c +++ gcc/testsuite/gcc.dg/pedwarn-init.c @@ -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" } */ diff --git gcc/testsuite/gcc.dg/pr53119.c gcc/testsuite/gcc.dg/pr53119.c index 044811d..93cd3fd 100644 --- gcc/testsuite/gcc.dg/pr53119.c +++ gcc/testsuite/gcc.dg/pr53119.c @@ -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" } */ diff --git gcc/testsuite/gcc.dg/ucnid-8.c gcc/testsuite/gcc.dg/ucnid-8.c index df1f350..da72e2d 100644 --- gcc/testsuite/gcc.dg/ucnid-8.c +++ gcc/testsuite/gcc.dg/ucnid-8.c @@ -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 } */ diff --git gcc/testsuite/gcc.dg/vla-init-1.c gcc/testsuite/gcc.dg/vla-init-1.c index 316bf98..5e20530 100644 --- gcc/testsuite/gcc.dg/vla-init-1.c +++ gcc/testsuite/gcc.dg/vla-init-1.c @@ -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 } */ } Marek