Another minor fix: use loc instead of input_location. Also add missing OPT_Wpedantic.
After this is in, my plan is to make pedwarn_init and error_init static (I already have a patch for that) and then add location argument to error_init and pass proper location to it, and to pedwarn_init as well -- that should greatly improve initializer warnings/errors. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2014-04-25 Marek Polacek <pola...@redhat.com> PR c/60139 * c-typeck.c (output_init_element): Pass OPT_Wpedantic to pedwarn and pedwarn_init. Use loc insted of input_location. * gcc.dg/pr60139.c: New test. diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 62c72df..a82801f 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -8255,12 +8255,12 @@ output_init_element (location_t loc, tree value, tree origtype, value = error_mark_node; } else if (require_constant_elements) - pedwarn (input_location, 0, + pedwarn (loc, OPT_Wpedantic, "initializer element is not computable at load time"); } else if (!maybe_const && (require_constant_value || require_constant_elements)) - pedwarn_init (input_location, 0, + pedwarn_init (loc, OPT_Wpedantic, "initializer element is not a constant expression"); /* Issue -Wc++-compat warnings about initializing a bitfield with diff --git gcc/testsuite/gcc.dg/pr60139.c gcc/testsuite/gcc.dg/pr60139.c index e69de29..a63d8b5 100644 --- gcc/testsuite/gcc.dg/pr60139.c +++ gcc/testsuite/gcc.dg/pr60139.c @@ -0,0 +1,14 @@ +/* PR c/60139 */ +/* { dg-do compile } */ +/* { dg-options "-Wpedantic" } */ +/* { dg-prune-output ".*near initialization for.*" } */ + +double sin (double); +void +fn (int *p) +{ + int **a[] = { &p, /* { dg-warning "17:initializer element is not computable at load time" } */ + (void *) 0, &p }; /* { dg-warning "28:initializer element is not computable at load time" } */ + double d[] = { sin (1.0), /* { dg-warning "18:initializer element is not a constant expression" } */ + 8.8, sin (1.0), 2.6 }; /* { dg-warning "23:initializer element is not a constant expression" } */ +} Marek