This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 19 Nov 2007 18:21:31 -0500
- Subject: [C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
xref_basetypes relies on the first argument being aggregate type,
but on invalid testcases like the attached one cp_parser_class_specifier
can contain various other types (in this case LANG_TYPE - a type
of OVERLOAD).
As begin_class_definition has all the needed code to report diagnostics
and have sane error recovery and cp_parser_class_specifier calls it shortly
after this, I think the best fix for this is instead of duplicating
such checks and error recovery just not call xref_basetypes for
non-aggregates at all and just let begin_class_definition do its job.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2007-11-19 Jakub Jelinek <jakub@redhat.com>
PR c++/34089
* parser.c (cp_parser_class_specifier): Don't call xref_basetypes
if type is not aggregate type.
* g++.dg/template/crash74.C: New test.
--- gcc/cp/parser.c.jj 2007-11-08 01:19:18.000000000 +0100
+++ gcc/cp/parser.c 2007-11-19 17:47:34.000000000 +0100
@@ -14134,7 +14134,7 @@ cp_parser_class_specifier (cp_parser* pa
/* Process the base classes. If they're invalid, skip the
entire class body. */
- if (!xref_basetypes (type, bases))
+ if (IS_AGGR_TYPE (type) && !xref_basetypes (type, bases))
{
/* Consuming the closing brace yields better error messages
later on. */
--- gcc/testsuite/g++.dg/template/crash74.C.jj 2007-11-19 17:53:27.000000000 +0100
+++ gcc/testsuite/g++.dg/template/crash74.C 2007-11-19 17:54:38.000000000 +0100
@@ -0,0 +1,6 @@
+// PR c++/34089
+// { dg-do compile }
+// { dg-options "" }
+
+template<typename F> void foo () { }
+template<typename F> struct foo<F> { }; // { dg-error "template class without a name|abstract decl" }
Jakub