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: G++ question


Mark Mitchell <mark@codesourcery.com> writes:

| Gabriel Dos Reis wrote:
| 
| > 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?
| 
| Historical accident; a patch to remove it is pre-approved after testing.

Thanks for for the prompt answer. 
This patch is regtested on an i686-pc-linux-gnu and committed to
mainline.

-- Gaby
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.4882
diff -p -r1.4882 ChangeLog
*** ChangeLog	9 Sep 2005 21:00:37 -0000	1.4882
--- ChangeLog	9 Sep 2005 23:07:16 -0000
***************
*** 1,3 ****
--- 1,8 ----
+ 2005-09-09  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+ 
+ 	* parser.c (cp_parser_translation_unit): Simplify.  The while-block
+ 	was actually executed at most once.
+ 
  2005-09-09  Richard Henderson  <rth@redhat.com>
  
  	PR debug/20998
Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.356
diff -p -r1.356 parser.c
*** parser.c	8 Sep 2005 13:14:13 -0000	1.356
--- parser.c	9 Sep 2005 23:07:16 -0000
*************** cp_parser_translation_unit (cp_parser* p
*** 2656,2694 ****
        declarator_obstack_base = obstack_next_free (&declarator_obstack);
      }
  
!   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;
! 	}
      }
! 
    /* Make sure the declarator obstack was fully cleaned up.  */
    gcc_assert (obstack_next_free (&declarator_obstack)
  	      == declarator_obstack_base);
--- 2656,2689 ----
        declarator_obstack_base = obstack_next_free (&declarator_obstack);
      }
  
!   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;
!     }
!   else
      {
!       cp_parser_error (parser, "expected declaration");
!       success = false;
      }
!   
    /* Make sure the declarator obstack was fully cleaned up.  */
    gcc_assert (obstack_next_free (&declarator_obstack)
  	      == declarator_obstack_base);


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