C++ PATCH: More specialization stuff

Mark Mitchell mark@codesourcery.com
Tue Jun 6 12:56:00 GMT 2000


This fixes the remaining bugs in g++.pt/memtemp96.C.  I love it when a
bug fix consists just of removing code. :-)

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-06-06  Mark Mitchell  <mark@codesourcery.com>

	* decl.c (redeclaration_error_message): If two TEMPLATE_DECLs have
	the same DECL_RESULT, it's not a redefinition.
	* pt.c (tsubst_decl): Remove code to handle illegal
	specializations.

Index: decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.626
diff -c -p -r1.626 decl.c
*** decl.c	2000/06/05 10:49:11	1.626
--- decl.c	2000/06/06 19:53:24
*************** redeclaration_error_message (newdecl, ol
*** 4729,4734 ****
--- 4729,4736 ----
    else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
      {
        if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL
+ 	   && (DECL_TEMPLATE_RESULT (newdecl) 
+ 	       != DECL_TEMPLATE_RESULT (olddecl))
  	   && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl))
  	   && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)))
  	  || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL
Index: pt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/pt.c,v
retrieving revision 1.434
diff -c -p -r1.434 pt.c
*** pt.c	2000/06/06 00:12:40	1.434
--- pt.c	2000/06/06 19:53:34
*************** tsubst_decl (t, args, type, in_decl)
*** 5569,5629 ****
  	if (TREE_CODE (decl) == TYPE_DECL)
  	  break;
  
- 	for (spec = DECL_TEMPLATE_SPECIALIZATIONS (t);
- 	     spec != NULL_TREE;
- 	     spec = TREE_CHAIN (spec))
- 	  {
- 	    /* It helps to consider example here.  Consider:
- 
- 	       template <class T>
- 	       struct S {
- 	         template <class U>
- 		 void f(U u);
- 
- 		 template <>
- 		 void f(T* t) {}
- 	       };
- 	       
- 	       Now, for example, we are instantiating S<int>::f(U u).  
- 	       We want to make a template:
- 
- 	       template <class U>
- 	       void S<int>::f(U);
- 
- 	       It will have a specialization, for the case U = int*, of
- 	       the form:
- 
- 	       template <>
- 	       void S<int>::f<int*>(int*);
- 
- 	       This specialization will be an instantiation of
- 	       the specialization given in the declaration of S, with
- 	       argument list int*.  */
- 
- 	    tree fn = TREE_VALUE (spec);
- 	    tree spec_args;
- 	    tree new_fn;
- 
- 	    if (!DECL_TEMPLATE_SPECIALIZATION (fn))
- 	      /* Instantiations are on the same list, but they're of
- 		 no concern to us.  */
- 	      continue;
- 
- 	    if (TREE_CODE (fn) != TEMPLATE_DECL)
- 	      /* A full specialization.  There's no need to record
- 		 that here.  */
- 	      continue;
- 
- 	    spec_args = tsubst (DECL_TI_ARGS (fn), args,
- 				/*complain=*/1, in_decl); 
- 	    new_fn
- 	      = tsubst (DECL_TEMPLATE_RESULT (most_general_template (fn)), 
- 			spec_args, /*complain=*/1, in_decl); 
- 	    DECL_TI_TEMPLATE (new_fn) = fn;
- 	    register_specialization (new_fn, r, 
- 				     INNERMOST_TEMPLATE_ARGS (spec_args));
- 	  }
- 
  	/* Record this partial instantiation.  */
  	register_specialization (r, t, 
  				 DECL_TI_ARGS (DECL_TEMPLATE_RESULT (r)));
--- 5569,5574 ----


More information about the Gcc-patches mailing list