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.3/trunk] Fix PR10940 regression (specialization ofstatic member function)


Hi

This patch fixes a regression in 3.3/trunk.  Inside
'check_explicit_specialization', when a specialization of a member
template of a template class is encountered, we currently
return the specialization template immediately.  However
we forget to update 'last_function_parms' to get rid of the 'this'
pointer in case of a static function is specialized.  So later
in 'start_function', the 'this' parameter remains despite being
a static function.

This patch reorder the code in 'check_explicit_specialization'
so that static-ness is checked and last_function_parms is modified
before returning the template.

Patch tested on i686-pc-linux.  OK for 3.3 branch and trunk?

--Kriang


2003-06-02  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/10940
	* pt.c (check_explicit_specialization): Check for 'static'
	earlier.

2003-06-02  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/10940
	* g++.dg/template/spec10.C: New test.


diff -cprN gcc-33-save/gcc/cp/pt.c gcc-33-new/gcc/cp/pt.c
*** gcc-33-save/gcc/cp/pt.c	Sun Jun  1 00:25:35 2003
--- gcc-33-new/gcc/cp/pt.c	Sun Jun  1 00:21:42 2003
*************** check_explicit_specialization (declarato
*** 1811,1816 ****
--- 1811,1828 ----
  	      return instantiate_template (tmpl, targs);
  	    }
  
+ 	  /* If we thought that the DECL was a member function, but it
+ 	     turns out to be specializing a static member function,
+ 	     make DECL a static member function as well.  We also have
+ 	     to adjust last_function_parms to avoid confusing
+ 	     start_function later.  */
+ 	  if (DECL_STATIC_FUNCTION_P (tmpl)
+ 	      && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl))
+ 	    {
+ 	      revert_static_member_fn (decl);
+ 	      last_function_parms = TREE_CHAIN (last_function_parms);
+ 	    }
+ 
  	  /* If this is a specialization of a member template of a
  	     template class.  In we want to return the TEMPLATE_DECL,
  	     not the specialization of it.  */
*************** check_explicit_specialization (declarato
*** 1821,1836 ****
  	      return tmpl;
  	    }
  
- 	  /* If we thought that the DECL was a member function, but it
- 	     turns out to be specializing a static member function,
- 	     make DECL a static member function as well.  */
- 	  if (DECL_STATIC_FUNCTION_P (tmpl)
- 	      && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl))
- 	    {
- 	      revert_static_member_fn (decl);
- 	      last_function_parms = TREE_CHAIN (last_function_parms);
- 	    }
- 
  	  /* Set up the DECL_TEMPLATE_INFO for DECL.  */
  	  DECL_TEMPLATE_INFO (decl) = tree_cons (tmpl, targs, NULL_TREE);
  
--- 1833,1838 ----
diff -cprN gcc-33-save/gcc/testsuite/g++.dg/template/spec10.C gcc-33-new/gcc/testsuite/g++.dg/template/spec10.C
*** gcc-33-save/gcc/testsuite/g++.dg/template/spec10.C	Thu Jan  1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/template/spec10.C	Sun Jun  1 00:36:51 2003
***************
*** 0 ****
--- 1,27 ----
+ // { dg-do run }
+ 
+ // Origin: Lynn Akers <lakers@peachtree.com>
+ 
+ // PR c++/10940: Problem handling parameter list for static member
+ // that is a specialization of a member template of a template class.
+ 
+ template<int b>
+ class o
+ {
+ public:
+ 	template<typename T> static void do_add(T* p, T v);
+ };
+ 
+ template<>
+ template<typename T>
+ inline void o<32>::do_add(T* p, T v)
+ {
+ 	*p += v;
+ }
+ 
+ int main()
+ {
+ 	int a = 0x1000;
+ 	o<32>().do_add<int>(&a, 0x2000);
+ 	return a;
+ }


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