This fixes an imprecise location info with abstract declarators. The problem was that when we build_id_declarator, the default location was input_location and we never attempted to use a more precise location. This patch does it.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-06-03 Marek Polacek <pola...@redhat.com> PR c/71362 * c-parser.c (c_parser_direct_declarator): Set location. * gcc.dg/pr71362.c: New test. diff --git gcc/c/c-parser.c gcc/c/c-parser.c index bca8653..799a473 100644 --- gcc/c/c-parser.c +++ gcc/c/c-parser.c @@ -3430,6 +3430,7 @@ c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, && c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) { struct c_declarator *inner = build_id_declarator (NULL_TREE); + inner->id_loc = c_parser_peek_token (parser)->location; return c_parser_direct_declarator_inner (parser, *seen_id, inner); } diff --git gcc/testsuite/gcc.dg/pr71362.c gcc/testsuite/gcc.dg/pr71362.c index e69de29..fd9cd6a 100644 --- gcc/testsuite/gcc.dg/pr71362.c +++ gcc/testsuite/gcc.dg/pr71362.c @@ -0,0 +1,10 @@ +/* PR c/71362 */ +/* { dg-do compile } */ + +extern void foo (int[-1]); /* { dg-error "21:size of unnamed array is negative" } */ + +int +bar (void) +{ + 123 + sizeof (int[-1]); /* { dg-error "20:size of unnamed array is negative" } */ +} Marek