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]

[C++ PATCH,committed] Fix PR5767 (Error recovery in cp_parser_class_name)


Hi

This patch fixes an error recovery bug.  We are calling make_typename_type
even when 'scope' is an error_mark_node, inside cp_parser_class_name.
make_typename_type then returns error_mark_node which triggers ICE
trying to access its TYPE_NAME.  Patch committed to trunk as obvious.
Tested on i686-pc-linux-gnu with no regressions.

--Kriang

2003-08-07  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/5767
	* parser.c (cp_parser_class_name): Return immediately when scope
	is error_mark_node.

2003-08-07  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/5767
	* g++.dg/parse/crash11.C: New test.


diff -cprN gcc-main-save/gcc/cp/parser.c gcc-main-new/gcc/cp/parser.c
*** gcc-main-save/gcc/cp/parser.c	Fri Aug  1 21:53:51 2003
--- gcc-main-new/gcc/cp/parser.c	Thu Aug  7 18:53:55 2003
*************** cp_parser_class_name (cp_parser *parser,
*** 10957,10962 ****
--- 10955,10963 ----
    /* PARSER->SCOPE can be cleared when parsing the template-arguments
       to a template-id, so we save it here.  */
    scope = parser->scope;
+   if (scope == error_mark_node)
+     return error_mark_node;
+   
    /* Any name names a type if we're following the `typename' keyword
       in a qualified name where the enclosing scope is type-dependent.  */
    typename_p = (typename_keyword_p && scope && TYPE_P (scope)
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/parse/crash11.C gcc-main-new/gcc/testsuite/g++.dg/parse/crash11.C
*** gcc-main-save/gcc/testsuite/g++.dg/parse/crash11.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/parse/crash11.C	Thu Aug  7 19:54:11 2003
***************
*** 0 ****
--- 1,34 ----
+ // { dg-do compile }
+ 
+ // Origin: priesnit@math.uni-goettingen.de
+ 
+ // PR c++/5767: ICE parsing typename with invalid scope.
+ 
+ template <template <typename> class TP>
+ struct A
+ {
+   template <typename T>
+   struct Template
+   {
+     typedef typename TP<T>::Type Type;
+   };
+ };
+ template <template <typename> class TP>
+ struct B
+ {
+   template <typename T>
+   struct Template
+   {
+     typedef typename A<A<TP>::Template>
+       ::template Template<T>::Type Type; { dg-error "mismatch|class template|unqualified-id" }
+   };
+ };
+ template <typename T>
+ struct C
+ {
+   typedef void Type;
+ };
+ int main()
+ {
+   typedef B<C>::Template<void>::Type Type; { dg-error "init-declarator|;" }
+ }


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