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 for 3.4/3.5] Fix PR16706 regression


Hi

This patch fixes the ICE reported in PR16706, a regression in 3.4/3.5
(this has more to do with the fact that access checking of template
instantiation is now enabled than other changes).

When we look for a friend of a declaration, we may peek inside 
uninstantiated templates.  However, processing_template_decl is zero, 
and various parts in the frontend fail because dependent_type_p (and 
related functions) returns incorrect results.  It could trigger template
instantiation and crash.

Tested on i686-pc-linux-gnu.  OK for mainline and 3.4 branch?

--Kriang

2004-08-03  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/16706
	* search.c (friend_accessible_p): Increment processing_template_decl
	when deal with TEMPLATE_DECL of SCOPE.

2004-08-03  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/16706
	* g++.dg/template/crash21.C: New test.
	* g++.dg/template/crash22.C: Likewise.


diff -cprN gcc-main-save/gcc/cp/search.c gcc-main-new/gcc/cp/search.c
*** gcc-main-save/gcc/cp/search.c	Tue Jul 27 22:51:36 2004
--- gcc-main-new/gcc/cp/search.c	Mon Aug  2 16:36:48 2004
*************** friend_accessible_p (tree scope, tree de
*** 836,845 ****
  
        /* Or an instantiation of something which is a friend.  */
        if (DECL_TEMPLATE_INFO (scope))
! 	return friend_accessible_p (DECL_TI_TEMPLATE (scope), decl, binfo);
      }
    else if (CLASSTYPE_TEMPLATE_INFO (scope))
!     return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope), decl, binfo);
  
    return 0;
  }
--- 836,861 ----
  
        /* Or an instantiation of something which is a friend.  */
        if (DECL_TEMPLATE_INFO (scope))
! 	{
! 	  int ret;
! 	  /* Increment processing_template_decl to make sure that
! 	     dependent_type_p works correctly.  */
! 	  ++processing_template_decl;
! 	  ret = friend_accessible_p (DECL_TI_TEMPLATE (scope), decl, binfo);
! 	  --processing_template_decl;
! 	  return ret;
! 	}
      }
    else if (CLASSTYPE_TEMPLATE_INFO (scope))
!     {
!       int ret;
!       /* Increment processing_template_decl to make sure that
! 	 dependent_type_p works correctly.  */
!       ++processing_template_decl;
!       ret = friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope), decl, binfo);
!       --processing_template_decl;
!       return ret;
!     }
  
    return 0;
  }
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/crash21.C gcc-main-new/gcc/testsuite/g++.dg/template/crash21.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/crash21.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/crash21.C	Mon Aug  2 16:38:05 2004
***************
*** 0 ****
--- 1,40 ----
+ // { dg-do compile }
+ 
+ // Origin: Debian GCC maintainers <debian-gcc@lists.debian.org>
+ //	   Wolfgang Bangerth <bangerth@dealii.org>
+ 
+ // PR c++/16706: Dependent type calculation during access checking
+ 
+ template <typename> struct B { 
+     B() throw() {} 
+     struct S { }; 
+     static int i; 
+     typedef unsigned short int dummy; 
+ }; 
+  
+ template <typename _Tp> 
+ struct allocator: B<_Tp> { 
+     template<typename _Tp1> struct rebind 
+     { typedef allocator<_Tp1> other; }; 
+ }; 
+  
+ template<typename T, typename> 
+ struct X { 
+     typename allocator<T>::template rebind<int>::other i; 
+     typedef int* dummy; 
+ }; 
+  
+ template <class T> class A { 
+     typedef typename X<T,allocator<T> >::dummy dummy; 
+     template <class TP> class XWrapper; 
+ }; 
+  
+  
+ template <class T> 
+ template <class TP> struct A<T>::XWrapper<TP *> 
+ { 
+     XWrapper() {} 
+     X<int,allocator<int> > x; 
+ }; 
+  
+ template class A<int>::XWrapper<int *>;
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/crash22.C gcc-main-new/gcc/testsuite/g++.dg/template/crash22.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/crash22.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/crash22.C	Mon Aug  2 16:38:11 2004
***************
*** 0 ****
--- 1,26 ----
+ // { dg-do compile }
+ 
+ // Origin: Debian GCC maintainers <debian-gcc@lists.debian.org>
+ //	   Volker Reichelt <reichelt@gcc.gnu.org>
+ 
+ // PR c++/16706: Dependent type calculation during access checking
+ 
+ template<typename> struct A 
+ {
+     A();
+     template<typename> struct X {};
+ };
+ 
+ template<typename T> struct B
+ {
+     typename A<T>::template X<int> x;
+     template<typename> struct C;
+ };
+ 
+ template<typename T> template<typename U> struct B<T>::C<U*>
+ {
+     C() {}
+     A<int> a;
+ };
+ 
+ template struct B<int>::C<int*>;


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