OSDN Git Service

2008-08-27 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 Aug 2008 23:54:36 +0000 (23:54 +0000)
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 Aug 2008 23:54:36 +0000 (23:54 +0000)
PR c/31673
* c-decl.c (check_for_loop_decls): Improve error message. Give
hint.
testsuite/
* gcc.dg/c90-fordecl-1.c: Update.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@139681 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c90-fordecl-1.c

index d091380..63b1981 100644 (file)
@@ -1,5 +1,11 @@
 2008-08-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
+       PR c/31673
+       * c-decl.c (check_for_loop_decls): Improve error message. Give
+       hint.
+
+2008-08-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
        PR c/37186
        * c-typeck.c (WARN_FOR_ASSIGNMENT): Add OPT parameter.
        (convert_for_assignment): Pass corrent OPT_W* parameter to
index 056cb38..ee04d9a 100644 (file)
@@ -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 ("%<for%> loop initial declaration used outside C99 mode");
+      error ("%<for%> 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:
index 9fad734..d5d73d7 100644 (file)
@@ -1,5 +1,10 @@
 2008-08-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
+       PR c/31673
+       * gcc.dg/c90-fordecl-1.c: Update.
+
+2008-08-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
        PR c/37186
        * gcc.dg/pr37186.c: New.
 
index 8e48dd6..4aa3c58 100644 (file)
@@ -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 }} */
 }