contrib/gcc-4.4/gcc/cp/call.c
/* If TMPL can be successfully instantiated as indicated by
   EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.

   TMPL is the template.  EXPLICIT_TARGS are any explicit template
   arguments.  ARGLIST is the arguments provided at the call-site.
   The RETURN_TYPE is the desired type for conversion operators.  If
   OBJ is NULL_TREE, FLAGS and CTYPE are as for add_function_candidate.
   If an OBJ is supplied, FLAGS and CTYPE are ignored, and OBJ is as for
   add_conv_candidate.  */
If TMPL can be successfully instantiated as indicated by
EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.

TMPL is the template.  EXPLICIT_TARGS are any explicit template
arguments.  ARGLIST is the arguments provided at the call-site.
The RETURN_TYPE is the desired type for conversion operators.  If
OBJ is NULL_TREE, FLAGS and CTYPE are as for add_function_candidate.
If an OBJ is supplied, FLAGS and CTYPE are ignored, and OBJ is as for
add_conv_candidate.
If TMPL can be successfully instantiated as indicated by EXPLICIT_TARGS and ARGLIST adds the instantiation to CANDIDATES . TMPL is the template . EXPLICIT_TARGS are any explicit template arguments . ARGLIST is the arguments provided at the call - site . The RETURN_TYPE is the desired type for conversion operators . If OBJ is NULL_TREE FLAGS and CTYPE are as for add_function_candidate . If an OBJ is supplied FLAGS and CTYPE are ignored and OBJ is as for add_conv_candidate .
static struct z_candidate*
add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
			     tree ctype, tree explicit_targs, tree arglist,
			     tree return_type, tree access_path,
			     tree conversion_path, int flags, tree obj,
			     unification_kind_t strict)
{
  int ntparms = DECL_NTPARMS (tmpl);
  tree targs = make_tree_vec (ntparms);
  tree args_without_in_chrg = arglist;
  struct z_candidate *cand;
  int i;
  tree fn;
  if (DECL_NONSTATIC_MEMBER_FUNCTION_P (tmpl))
    args_without_in_chrg = TREE_CHAIN (args_without_in_chrg);
  if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
       || DECL_BASE_CONSTRUCTOR_P (tmpl))
      && CLASSTYPE_VBASECLASSES (DECL_CONTEXT (tmpl)))
    args_without_in_chrg = TREE_CHAIN (args_without_in_chrg);
  i = fn_type_unification (tmpl, explicit_targs, targs,
			   args_without_in_chrg,
			   return_type, strict, flags);
  if (i != 0)
    return NULL;
  fn = instantiate_template (tmpl, targs, tf_none);
  if (fn == error_mark_node)
    return NULL;
  if (DECL_CONSTRUCTOR_P (fn) && list_length (arglist) == 2)
    {
      tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
      if (arg_types && same_type_p (TYPE_MAIN_VARIANT (TREE_VALUE (arg_types)),
				    ctype))
	return NULL;
    }
  if (obj != NULL_TREE)
    cand = add_conv_candidate (candidates, fn, obj, access_path,
			       conversion_path, arglist);
  else
    cand = add_function_candidate (candidates, fn, ctype,
				   arglist, access_path,
				   conversion_path, flags);
  if (DECL_TI_TEMPLATE (fn) != tmpl)
    cand->template_decl = tree_cons (tmpl, targs, NULL_TREE);
  else
    cand->template_decl = DECL_TEMPLATE_INFO (fn);
  return cand;
}
static struct z_candidate * add_template_candidate_real ( struct z_candidate * * candidates , tree tmpl , tree ctype , tree explicit_targs , tree arglist , tree return_type , tree access_path , tree conversion_path , int flags , tree obj , unification_kind_t strict ) { int ntparms = DECL_NTPARMS ( tmpl ) ; tree targs = make_tree_vec ( ntparms ) ; tree args_without_in_chrg = arglist ; struct z_candidate * cand ; int i ; tree fn ; if ( DECL_NONSTATIC_MEMBER_FUNCTION_P ( tmpl ) ) args_without_in_chrg = TREE_CHAIN ( args_without_in_chrg ) ; if ( ( DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P ( tmpl ) || DECL_BASE_CONSTRUCTOR_P ( tmpl ) ) && CLASSTYPE_VBASECLASSES ( DECL_CONTEXT ( tmpl ) ) ) args_without_in_chrg = TREE_CHAIN ( args_without_in_chrg ) ; i = fn_type_unification ( tmpl , explicit_targs , targs , args_without_in_chrg , return_type , strict , flags ) ; if ( i != 0 ) return NULL ; fn = instantiate_template ( tmpl , targs , tf_none ) ; if ( fn == error_mark_node ) return NULL ; if ( DECL_CONSTRUCTOR_P ( fn ) && list_length ( arglist ) == 2 ) { tree arg_types = FUNCTION_FIRST_USER_PARMTYPE ( fn ) ; if ( arg_types && same_type_p ( TYPE_MAIN_VARIANT ( TREE_VALUE ( arg_types ) ) , ctype ) ) return NULL ; } if ( obj != NULL_TREE ) cand = add_conv_candidate ( candidates , fn , obj , access_path , conversion_path , arglist ) ; else cand = add_function_candidate ( candidates , fn , ctype , arglist , access_path , conversion_path , flags ) ; if ( DECL_TI_TEMPLATE ( fn ) != tmpl ) cand -> template_decl = tree_cons ( tmpl , targs , NULL_TREE ) ; else cand -> template_decl = DECL_TEMPLATE_INFO ( fn ) ; return cand ; }
If TMPL can be successfully instantiated as indicated by
EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
If TMPL can be successfully instantiated as indicated by EXPLICIT_TARGS and ARGLIST adds the instantiation to CANDIDATES .
/* We don't do deduction on the in-charge parameter, the VTT
     parameter or 'this'.  */ /* In [class.copy]:

       A member function template is never instantiated to perform the
       copy of a class object to an object of its class type.

     It's a little unclear what this means; the standard explicitly
     does allow a template to be used to copy a class.  For example,
     in:

       struct A {
	 A(A&);
	 template <class T> A(const T&);
       };
       const A f ();
       void g () { A a (f ()); }

     the member template will be used to make the copy.  The section
     quoted above appears in the paragraph that forbids constructors
     whose only parameter is (a possibly cv-qualified variant of) the
     class type, and a logical interpretation is that the intent was
     to forbid the instantiation of member templates which would then
     have that form.  */ /* Aha, this is a conversion function.  */ /* This situation can occur if a member template of a template
       class is specialized.  Then, instantiate_template might return
       an instantiation of the specialization, in which case the
       DECL_TI_TEMPLATE field will point at the original
       specialization.  For example:

	 template <class T> struct S { template <class U> void f(U);
				       template <> void f(int) {}; };
	 S<double> sd;
	 sd.f(3);

       Here, TMPL will be template <class U> S<double>::f(U).
       And, instantiate template will give us the specialization
       template <> S<double>::f(int).  But, the DECL_TI_TEMPLATE field
       for this will point at template <class T> template <> S<T>::f(int),
       so that we can find the definition.  For the purposes of
       overload resolution, however, we want the original TMPL.  */