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]

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


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.

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 "" }


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