diff mbox

[c++] fix PR 46852, ICE in semicolon recovery code

Message ID 20101209031007.GF25904@nightcrawler
State New
Headers show

Commit Message

Nathan Froyd Dec. 9, 2010, 3:10 a.m. UTC
The patch below fixes PR 46852: before we inspect the type that we just
parsed for a class/struct/union definition, we should make sure that
it's actually a type and not something bogus from a parse error.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

gcc/cp/
	PR c++/46852
	* parser.c (cp_parser_class_specifier): Check for TYPE_P.

gcc/testsuite/
	PR c++/46852
	* g++.dg/pr46852.C: New test.

Comments

Jason Merrill Dec. 15, 2010, 4:47 p.m. UTC | #1
On 12/08/2010 10:10 PM, Nathan Froyd wrote:
> The patch below fixes PR 46852: before we inspect the type that we just
> parsed for a class/struct/union definition, we should make sure that
> it's actually a type and not something bogus from a parse error.
>
> Tested on x86_64-unknown-linux-gnu.  OK to commit?

Yes.  Fixes like this qualify as obvious.

Jason
diff mbox

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ab533f4..089361a 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -16937,7 +16937,9 @@  cp_parser_class_specifier (cp_parser* parser)
 	break;
       }
 
-    if (want_semicolon)
+    /* If we don't have a type, then something is very wrong and we
+       shouldn't try to do anything clever.  */
+    if (TYPE_P (type) && want_semicolon)
       {
 	cp_token_position prev
 	  = cp_lexer_previous_token_position (parser->lexer);
diff --git a/gcc/testsuite/g++.dg/pr46852.C b/gcc/testsuite/g++.dg/pr46852.C
new file mode 100644
index 0000000..2c9d8dd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr46852.C
@@ -0,0 +1,7 @@ 
+// PR c++/46852
+// { dg-do compile }
+
+template
+<
+class
+{				// { dg-error "" }