Hi,

While working on a project involing checking the internal (logic)
consistency of the C++ front-end, I came across the following code in
cp/parser.c:cp_parser_translation_unit():

  while (true)
    {
      cp_parser_declaration_seq_opt (parser);

      /* If there are no tokens left then all went well.  */
      if (cp_lexer_next_token_is (parser->lexer, CPP_EOF))
        {
          /* Get rid of the token array; we don't need it any more.  */
          cp_lexer_destroy (parser->lexer);
          parser->lexer = NULL;

          /* This file might have been a context that's implicitly extern
             "C".  If so, pop the lang context.  (Only relevant for PCH.) */
          if (parser->implicit_extern_c)
            {
              pop_lang_context ();
              parser->implicit_extern_c = false;
            }

          /* Finish up.  */
          finish_translation_unit ();

          success = true;
          break;
        }
      else
        {
          cp_parser_error (parser, "expected declaration");
          success = false;
          break;
        }
    }


Both branches of the if-statement contain an unconditional "break",
which implies that the apparant unbounded while-loop is executed only
once.  If that reasoning is correct, why do we have the while-loop in
the first place? 

-- Gaby

Reply via email to