[C++ PATCH, committed] Fix PR11030 (incorrect name injection)

Kriang Lerdsuwanakij lerdsuwa@users.sourceforge.net
Tue Jul 8 15:36:00 GMT 2003


Hi

This fixes a name injection bug of friend inside template.
For code like

  friend class A<512>;

'instantiate_class_template' incorrectly calls 'xref_tag' for
the class specialization.  So a bogus 'RECORD_TYPE' is created
that has no relationship with its original class template.
This confuses later stage of compilation.

Tested on i686-pc-linux-gnu.  Committed to trunk as obvious.

--Kriang


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

	PR c++/11030
	* pt.c (instantiate_class_template): Don't call xref_tag to
	inject name when the friend class is a specialization.

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

	PR c++/11030
	* g++.dg/template/friend19.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	Sun Jul  6 17:36:17 2003
--- gcc-main-new/gcc/cp/pt.c	Tue Jul  8 20:03:10 2003
*************** instantiate_class_template (tree type)
*** 5430,5435 ****
--- 5430,5437 ----
  	      else if (uses_template_parms (friend_type))
  		new_friend_type = tsubst (friend_type, args,
  					  tf_error | tf_warning, NULL_TREE);
+ 	      else if (CLASSTYPE_USE_TEMPLATE (friend_type))
+ 		new_friend_type = friend_type;
  	      else 
  		{
  		  tree ns = decl_namespace_context (TYPE_MAIN_DECL (friend_type));
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/friend19.C gcc-main-new/gcc/testsuite/g++.dg/template/friend19.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/friend19.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/friend19.C	Tue Jul  8 20:04:00 2003
***************
*** 0 ****
--- 1,28 ----
+ // { dg-do compile }
+ 
+ // Origin: Benjamin Li <benxbli@yahoo.com>
+ 
+ // PR c++/11030: Template substition of friend class that is
+ // a specialization.
+ 
+ template <int S>
+ struct A
+ {
+   void func(void);
+ };
+ 
+ template <class T>
+ class C
+ {
+   static void private_func(void) {}
+ public:
+   friend class A<512>;
+ };
+ 
+ template <int S>
+ void A<S>::func(void)
+ {
+   C<void>::private_func();
+ }
+ 
+ template class A<512>;



More information about the Gcc-patches mailing list