]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/7679 (The compiler crashes wen a right parentesis is missing)
authorMark Mitchell <mark@codesourcery.com>
Wed, 23 Oct 2002 21:56:55 +0000 (21:56 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 23 Oct 2002 21:56:55 +0000 (21:56 +0000)
PR c++/7679
* spew.c (next_token): Do not return an endless stream of
END_OF_SAVED_INPUT tokens.
(snarf_method): Add three END_OF_SAVED_INPUT tokens to the end of
the cached token stream.
(snarf_defarg): Likewise.

PR c++/7679
* g++.dg/parse/inline1.C: New test.

From-SVN: r58473

gcc/cp/ChangeLog
gcc/cp/spew.c
gcc/testsuite/ChangeLog

index e5a628c469473d98b39e3ec2d07f0bdc45832781..bd57ba555e3afd0bf80ee4919008c17471ef1f5d 100644 (file)
@@ -1,3 +1,12 @@
+2002-10-23  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/7679
+       * spew.c (next_token): Do not return an endless stream of
+       END_OF_SAVED_INPUT tokens.
+       (snarf_method): Add three END_OF_SAVED_INPUT tokens to the end of
+       the cached token stream.
+       (snarf_defarg): Likewise.
+
 2002-10-22  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/6579
index 93b8348b02931c11d831ce9a6246ccbab55e97e1..278a99ad1755d7d65fefb9025751e6d392fcc564 100644 (file)
@@ -485,9 +485,8 @@ add_token (t)
       memcpy (t, feed->input->pos, sizeof (struct token));
       return (feed->input->pos++)->yychar;
     }
-  
-  memcpy (t, &Teosi, sizeof (struct token));
-  return END_OF_SAVED_INPUT;
+
+  return 0;
 }
 
 /* Shift the next token onto the fifo.  */
@@ -1167,12 +1166,27 @@ snarf_method (decl)
   int starting_lineno = lineno;
   const char *starting_filename = input_filename;
   size_t len;
+  int i;
 
   struct unparsed_text *meth;
 
   /* Leave room for the header, then absorb the block.  */
   obstack_blank (&inline_text_obstack, sizeof (struct unparsed_text));
   snarf_block (starting_filename, starting_lineno);
+  /* Add three END_OF_SAVED_INPUT tokens.  We used to provide an
+     infinite stream of END_OF_SAVED_INPUT tokens -- but that can
+     cause the compiler to get stuck in an infinite loop when
+     encountering invalid code.  We need more than one because the
+     parser sometimes peeks ahead several tokens.  */
+  for (i = 0; i < 3; ++i)
+    {
+      size_t point = obstack_object_size (&inline_text_obstack);
+      obstack_blank (&inline_text_obstack, sizeof (struct token));
+      memcpy ((struct token *)
+             (obstack_base (&inline_text_obstack) + point),
+             &Teosi,
+             sizeof (struct token));
+    }
 
   len = obstack_object_size (&inline_text_obstack);
   meth = (struct unparsed_text *) obstack_finish (&inline_text_obstack);
@@ -1223,6 +1237,7 @@ snarf_defarg ()
   size_t point;
   size_t len;
   struct unparsed_text *buf;
+  int i;
   tree arg;
 
   obstack_blank (&inline_text_obstack, sizeof (struct unparsed_text));
@@ -1252,6 +1267,20 @@ snarf_defarg ()
   push_token ((struct token *) (obstack_base (&inline_text_obstack) + point));
   /* This is the documented way to shrink a growing obstack block.  */
   obstack_blank (&inline_text_obstack, - (int) sizeof (struct token));
+  /* Add three END_OF_SAVED_INPUT tokens.  We used to provide an
+     infinite stream of END_OF_SAVED_INPUT tokens -- but that can
+     cause the compiler to get stuck in an infinite loop when
+     encountering invalid code.  We need more than one because the
+     parser sometimes peeks ahead several tokens.  */
+  for (i = 0; i < 3; ++i)
+    {  
+      point = obstack_object_size (&inline_text_obstack);
+      obstack_blank (&inline_text_obstack, sizeof (struct token));
+      memcpy ((struct token *)
+             (obstack_base (&inline_text_obstack) + point),
+             &Teosi,
+             sizeof (struct token));
+    }
 
  done:
   len = obstack_object_size (&inline_text_obstack);
index 011f9f4af0b3ea0288b0eedb559e0514ad9def6c..27d4ed3b35b1296dd44d373a4c1512fc87085918 100644 (file)
@@ -1,3 +1,8 @@
+2002-10-23  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/7679
+       * g++.dg/parse/inline1.C: New test.
+       
 2002-10-22  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/6579