diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d091380e3e8..63b1981daae 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-08-27 Manuel Lopez-Ibanez + + PR c/31673 + * c-decl.c (check_for_loop_decls): Improve error message. Give + hint. + 2008-08-27 Manuel Lopez-Ibanez PR c/37186 diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 056cb386058..ee04d9aa43b 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -6796,13 +6796,19 @@ check_for_loop_decls (void) tree one_decl = NULL_TREE; int n_decls = 0; - if (!flag_isoc99) { + static bool hint = true; /* If we get here, declarations have been used in a for loop without the C99 for loop scope. This doesn't make much sense, so don't allow it. */ - error ("% loop initial declaration used outside C99 mode"); + error ("% loop initial declarations are only allowed in C99 mode"); + if (hint) + { + inform (input_location, + "use option -std=c99 or -std=gnu99 to compile your code"); + hint = false; + } return NULL_TREE; } /* C99 subclause 6.8.5 paragraph 3: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9fad734ca66..d5d73d74a0c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-08-27 Manuel Lopez-Ibanez + + PR c/31673 + * gcc.dg/c90-fordecl-1.c: Update. + 2008-08-27 Manuel Lopez-Ibanez PR c/37186 diff --git a/gcc/testsuite/gcc.dg/c90-fordecl-1.c b/gcc/testsuite/gcc.dg/c90-fordecl-1.c index 8e48dd61752..4aa3c583022 100644 --- a/gcc/testsuite/gcc.dg/c90-fordecl-1.c +++ b/gcc/testsuite/gcc.dg/c90-fordecl-1.c @@ -9,5 +9,6 @@ foo (void) int j = 0; for (int i = 1; i <= 10; i++) /* { dg-bogus "warning" "warning in place of error" } */ j += i; - /* { dg-error "parse|decl" "declaration in for loop" { target *-*-* } 10 } */ + /* { dg-error "'for' loop initial declarations are only allowed in C99 mode" "declaration in for loop" { target *-*-* } 10 } */ + /* { dg-message "note: use option -std=c99 or -std=gnu99 to compile your code" "note" { target *-*-* } 10 }} */ }