This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++0x] avoid extra tentative parse in range-based for loops


As you mentioned, this now needs a tweak for the colon autocorrect patch.

       /* If the tentative parse failed, then we shall need to look for an
         expression-statement.  */

This comment is in the wrong place now; it should stay with the call to cp_parser_parse_definitely.


+      if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
+       {
+         /* It is a range-for, consume the ':' */
+         cp_lexer_consume_token (parser->lexer);
+         if (cxx_dialect < cxx0x)
+           {
+             error_at (cp_lexer_peek_token (parser->lexer)->location,
+                       "range-based-for loops are not allowed "
+                       "in C++98 mode");
+           }
+         else if (*decl && *decl != error_mark_node )
+           is_range_for = true;
+         /* Else an error has been found in the declaration. It should have
+            been reported by now, so no message is required.  */
+       }

I think error-recovery will be better if we always set is_range_for when we see a colon.


Otherwise, looks good.

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]