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] Fix PR9602, a regression


Hi

The 'pure_virtuals' field in lang_specific of the type is shared
between pure virtual functions and inline friend functions.
The logic of 'abstract_virtuals_error' is correct only for
non-template class.  However, for class templates, its TYPE_SIZE
is initialized by 'bitsize_zero_node' in 'finish_struct'
and 'pure_virtuals' remains containing inline friends throughout
the life time of this template.  This is fixed by the patch below.
This is a regression from GCC 2.95.

Bootstrapped and tested on i686-pc-linux-gnu.  OK to commit to
the main trunk, 3.3, and maybe 3.2?

--Kriang


2003-02-21  Kriang Lerdsuwanakij  <lerdsuwa at users dot sourceforge dot net>

	PR c++/9602
	* typeck2.c (abstract_virtuals_error): Handle when TYPE is
	a defined class template.

2003-02-21  Kriang Lerdsuwanakij  <lerdsuwa at users dot sourceforge dot net>

	PR c++/9602
	* g++.dg/template/friend16.C: New test.


diff -cprN gcc-main-save/gcc/cp/typeck2.c gcc-main-new/gcc/cp/typeck2.c
*** gcc-main-save/gcc/cp/typeck2.c	Thu Jan 30 21:19:09 2003
--- gcc-main-new/gcc/cp/typeck2.c	Wed Feb 19 23:20:09 2003
*************** abstract_virtuals_error (decl, type)
*** 138,145 ****
    if (!CLASS_TYPE_P (type) || !CLASSTYPE_PURE_VIRTUALS (type))
      return 0;
  
!   if (!TYPE_SIZE (type))
!     /* TYPE is being defined, and during that time
         CLASSTYPE_PURE_VIRTUALS holds the inline friends.  */
      return 0;
  
--- 138,146 ----
    if (!CLASS_TYPE_P (type) || !CLASSTYPE_PURE_VIRTUALS (type))
      return 0;
  
!   if (!TYPE_SIZE (type) || TYPE_SIZE (type) == bitsize_zero_node)
!     /* TYPE_SIZE is NULL_TREE when it is being defined, or
!        bitsize_zero_node when it is a template.  During that time
         CLASSTYPE_PURE_VIRTUALS holds the inline friends.  */
      return 0;
  
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/friend16.C gcc-main-new/gcc/testsuite/g++.dg/template/friend16.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/friend16.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/friend16.C	Thu Feb 20 20:47:11 2003
***************
*** 0 ****
--- 1,16 ----
+ // { dg-do compile }
+ 
+ // Origin: Wolfgang Bangerth <bangerth at ticam dot utexas dot edu>
+ 
+ // PR c++/9602: Inline friend/pure virtual tree data sharing in
+ // class template.
+ 
+ template <typename T> struct X {
+   void foo (X);
+   friend void bar () {}
+ };
+     
+ template <typename T>
+ void X<T>::foo (X x) {}
+     
+ template struct X<int>;


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