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 local class handling in lookup_template_class


Hi

The following obvious patch fixes the ICE reported as PR12495.
The function 'lookup_template_class' fails to realize that
'current_class_type' may be a local class, and therefore 'ctx'
could be a FUNCTION_DECL.  Then 'same_type_p' asserts that
both of its arguments are types and fails.

Tested on i686-pc-linux-gnu.  Committed to the mainline.

--Kriang


2003-10-18  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/12495
	* pt.c (lookup_template_class): Handle when current_class_type
	is a local class.

2003-10-18  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/12495
	* g++.dg/template/crash21.C: New test.



diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c	Fri Oct 17 15:56:28 2003
--- gcc-main-new/gcc/cp/pt.c	Sat Oct 18 22:30:01 2003
*************** lookup_template_class (tree d1, 
*** 4163,4176 ****
  	      tree ctx;
  	      
  	      for (ctx = current_class_type; 
! 		   ctx; 
! 		   ctx = TYPE_CONTEXT (ctx))
! 		{
! 		  if (TREE_CODE (ctx) == NAMESPACE_DECL)
! 		    break;
! 		  if (same_type_p (ctx, template_type))
! 		    goto found_ctx;
! 		}
  	      
  	      /* We're not in the scope of the class, so the
  		 TEMPLATE_TYPE is not the type we want after all.  */
--- 4163,4174 ----
  	      tree ctx;
  	      
  	      for (ctx = current_class_type; 
! 		   ctx && TREE_CODE (ctx) != NAMESPACE_DECL;
! 		   ctx = (TYPE_P (ctx)
! 			  ? TYPE_CONTEXT (ctx)
! 			  : DECL_CONTEXT (ctx)))
! 		if (TYPE_P (ctx) && same_type_p (ctx, template_type))
! 		  goto found_ctx;
  	      
  	      /* We're not in the scope of the class, so the
  		 TEMPLATE_TYPE is not the type we want after all.  */
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/crash12.C gcc-main-new/gcc/testsuite/g++.dg/template/crash12.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/crash12.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/crash12.C	Sat Oct 18 22:25:03 2003
***************
*** 0 ****
--- 1,16 ----
+ // { dg-do compile }
+ 
+ // Origin: rmerkert@alphatech.com
+ //         Volker Reichelt <reichelt@gcc.gnu.org>
+ 
+ // PR c++/12495: ICE looking up class template in local class.
+ 
+ template <typename> struct A {};
+ 
+ template <typename T> void foo()
+ {
+     struct B
+     {
+         B (const A<T>&);
+     };
+ }


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