If the target type is of reference kind (see line 1106 in implicit_conversion ), it is the case of reference binding specified by [3], clause 13.3.3.1.4 “Reference binding” [over.ics.ref ].
1. When a parameter of reference type binds directly (8.5.3) to an argument expression, the implicit conversion sequence is the identity conversion, unless the argument expression has a type that is a derived class of the parameter type, in which case the implicit conversion sequence is a derived-to-base Conversion (13.3.3.1). [Example: struct A {}; struct B : public A {} b; int f(A&); int f(B&); int i = f(b); // Calls f(B&), an exact match, rather than // f(A&), a conversion —end example ] If the parameter binds directly to the result of applying a conversion function to the argument expression, the implicit conversion sequence is a user-defined conversion sequence (13.3.3.1.2), with the second standard conversion sequence either an identity conversion or, if the conversion function returns an entity of a type that is a derived class of the parameter type, a derived-to-base Conversion. 2. When a parameter of reference type is not bound directly to an argument expression, the conversion sequence is the one required to convert the argument expression to the underlying type of the reference according to 13.3.3.1 (i.e., implicit conversion sequence). Conceptually, this conversion sequence corresponds to copy-initializing a temporary of the underlying type with the argument expression. Any difference in top-level cv-qualification is subsumed by the initialization itself and does not constitute a conversion. 3. A standard conversion sequence cannot be formed if it requires binding a reference to non-const to an rvalue (except when binding an implicit object parameter; see the special rules for that case in 13.3.1). [Note: this means, for example, that a candidate function cannot be a viable function if it has a non-const reference parameter (other than the implicit object parameter) and the corresponding argument is a temporary or would require one to be created to initialize the reference (see 8.5.3).] 4. Other restrictions on binding a reference to a particular argument do not affect the formation of a standard conversion sequence, however. [Example: a function with a “reference to int” parameter can be a viable candidate even if the corresponding argument is an int bit-field. The formation of implicit conversion sequences treats the int bit-field as an int lvalue and finds an exact match with the parameter. If the function is selected by overload resolution, the call will nonetheless be ill-formed because of the prohibition on binding a non-const reference to a bit-field (8.5.3). ] 5. The binding of a reference to an expression that is reference-compatible with added qualification influences the rank of a standard conversion; see 13.3.3.2 and 8.5.3. |
940 static tree
941 reference_binding (tree rto, tree rfrom, tree expr, int flags) in call.c
942 {
943 tree conv = NULL_TREE;
944 tree to = TREE_TYPE (rto);
945 tree from = rfrom;
946 bool related_p;
947 bool compatible_p;
948 cp_lvalue_kind lvalue_p = clk_none;
949
950 if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
951 {
952 expr = instantiate_type (to, expr, tf_none);
953 if (expr == error_mark_node)
954 return NULL_TREE;
955 from = TREE_TYPE (expr);
956 }
If the target type referred is a type of function or method, and argument expression passed is an overloaded function/method whose type is unknown_type_node and makes type_unknown_p holds (it may be a baselink or template-id). It needs determine the right candidate for the argument.
Below function will instantiate the type of the expression given in rhs to match the type given by lhstype .
6001 tree
6002 instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags) in class.c
6003 {
6004 tsubst_flags_t flags_in = flags;
6005
6006 flags &= ~tf_ptrmem_ok;
6007
6008 if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
6009 {
6010 if (flags & tf_error)
6011 error ("not enough type information");
6012 return error_mark_node;
6013 }
6014
6015 if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
6016 {
6017 if (same_type_p (lhstype, TREE_TYPE (rhs)))
6018 return rhs;
6019 if (flag_ms_extensions
6020 && TYPE_PTRMEMFUNC_P (lhstype)
6021 && !TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs)))
6022 /* Microsoft allows `A::f' to be resolved to a
6023 pointer-to-member. */
6024 ;
6025 else
6026 {
6027 if (flags & tf_error)
6028 error ("argument of type `%T' does not match `%T'",
6029 TREE_TYPE (rhs), lhstype);
6030 return error_mark_node;
6031 }
6032 }
See that condition at line 6015 if satisfied the type of rhs is known for certainty, which must be same as the target type (lhstype ); otherwise the unmatched types of rhs and lhs leads to an error. If rhs has unknown_type_node or NULL in TREE_TYPE, it means multiple expressions can fit in rhs , the final one should be determined by the type of lhs .
As comment at line 6042 mentions, the SWITCH block begins at line 6047 is used for distingishing what sort of a pointer (in fact includes reference too).
Note NOP_EXPR below at line 6072, it is used to represent conversions that do not require any code-generation. For example, conversion of a `char*' to an `int*' does not require any code be generated; such a conversion is represented by a NOP_EXPR. The single operand is the expression to be converted. The conversion from a pointer to a reference is also represented with a NOP_EXPR. If we arrive at this branch, the TREE_TYPE of NOP_EXPR must be NULL or unknown_type_node indicating the multiple choices. After stripping this top NOP_EXPR, it needs keep this information of uncertainty by setting unknown_type_node in the TREE_TYPE of its operand.
instantiate_type (continue)
6034 if (TREE_CODE (rhs) == BASELINK)
6035 rhs = BASELINK_FUNCTIONS (rhs);
6036
6037 /* We don't overwrite rhs if it is an overloaded function.
6038 Copying it would destroy the tree link. */
6039 if (TREE_CODE (rhs) != OVERLOAD)
6040 rhs = copy_node (rhs);
6041
6042 /* This should really only be used when attempting to distinguish
6043 what sort of a pointer to function we have. For now, any
6044 arithmetic operation which is not supported on pointers
6045 is rejected as an error. */
6046
6047 switch (TREE_CODE (rhs))
6048 {
6049 case TYPE_EXPR:
6050 case CONVERT_EXPR:
6051 case SAVE_EXPR:
6052 case CONSTRUCTOR:
6053 case BUFFER_REF:
6054 abort ();
6055 return error_mark_node;
6056
6057 case INDIRECT_REF:
6058 case ARRAY_REF:
6059 {
6060 tree new_rhs;
6061
6062 new_rhs = instantiate_type (build_pointer_type (lhstype),
6063 TREE_OPERAND (rhs, 0), flags);
6064 if (new_rhs == error_mark_node)
6065 return error_mark_node;
6066
6067 TREE_TYPE (rhs) = lhstype;
6068 TREE_OPERAND (rhs, 0) = new_rhs;
6069 return rhs;
6070 }
6071
6072 case NOP_EXPR:
6073 rhs = copy_node (TREE_OPERAND (rhs, 0));
6074 TREE_TYPE (rhs) = unknown_type_node;
6075 return instantiate_type (lhstype, rhs, flags);
6076
6077 case COMPONENT_REF:
6078 {
6079 tree addr = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
6080
6081 if (addr != error_mark_node
6082 && TREE_SIDE_EFFECTS (TREE_OPERAND (rhs, 0)))
6083 /* Do not lose object's side effects. */
6084 addr = build (COMPOUND_EXPR, TREE_TYPE (addr),
6085 TREE_OPERAND (rhs, 0), addr);
6086 return addr;
6087 }
6088
6089 case OFFSET_REF:
6090 rhs = TREE_OPERAND (rhs, 1);
6091 if (BASELINK_P (rhs))
6092 return instantiate_type (lhstype, BASELINK_FUNCTIONS (rhs), flags_in);
6093
6094 /* This can happen if we are forming a pointer-to-member for a
6095 member template. */
6096 my_friendly_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR, 0);
6097
6098 /* Fall through. */
6099
6100 case TEMPLATE_ID_EXPR:
6101 {
6102 tree fns = TREE_OPERAND (rhs, 0);
6103 tree args = TREE_OPERAND (rhs, 1);
6104
6105 return
6106 resolve_address_of_overloaded_function (lhstype, fns, flags_in,
6107 /*template_only=*/ true,
6108 args);
6109 }
6110
6111 case OVERLOAD:
6112 case FUNCTION_DECL:
6113 return
6114 resolve_address_of_overloaded_function (lhstype, rhs, flags_in,
6115 /*template_only=*/ false,
6116 /*explicit_targs=*/ NULL_TREE);
6117
6118 case TREE_LIST:
6119 /* Now we should have a baselink. */
6120 my_friendly_assert (BASELINK_P (rhs), 990412);
6121
6122 return instantiate_type (lhstype, BASELINK_FUNCTIONS (rhs), flags);
6123
6124 case CALL_EXPR:
6125 /* This is too hard for now. */
6126 abort ();
6127 return error_mark_node;
6128
6129 case PLUS_EXPR:
6130 case MINUS_EXPR:
6131 case COMPOUND_EXPR:
6132 TREE_OPERAND (rhs, 0)
6133 = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
6134 if (TREE_OPERAND (rhs, 0) == error_mark_node)
6135 return error_mark_node;
6136 TREE_OPERAND (rhs, 1)
6137 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
6138 if (TREE_OPERAND (rhs, 1) == error_mark_node)
6139 return error_mark_node;
6140
6141 TREE_TYPE (rhs) = lhstype;
6142 return rhs;
6143
6144 case MULT_EXPR:
6145 case TRUNC_DIV_EXPR:
6146 case FLOOR_DIV_EXPR:
6147 case CEIL_DIV_EXPR:
6148 case ROUND_DIV_EXPR:
6149 case RDIV_EXPR:
6150 case TRUNC_MOD_EXPR:
6151 case FLOOR_MOD_EXPR:
6152 case CEIL_MOD_EXPR:
6153 case ROUND_MOD_EXPR:
6154 case FIX_ROUND_EXPR:
6155 case FIX_FLOOR_EXPR:
6156 case FIX_CEIL_EXPR:
6157 case FIX_TRUNC_EXPR:
6158 case FLOAT_EXPR:
6159 case NEGATE_EXPR:
6160 case ABS_EXPR:
6161 case MAX_EXPR:
6162 case MIN_EXPR:
6163
6164 case BIT_AND_EXPR:
6165 case BIT_IOR_EXPR:
6166 case BIT_XOR_EXPR:
6167 case LSHIFT_EXPR:
6168 case RSHIFT_EXPR:
6169 case LROTATE_EXPR:
6170 case RROTATE_EXPR:
6171
6172 case PREINCREMENT_EXPR:
6173 case PREDECREMENT_EXPR:
6174 case POSTINCREMENT_EXPR:
6175 case POSTDECREMENT_EXPR:
6176 if (flags & tf_error)
6177 error ("invalid operation on uninstantiated type");
6178 return error_mark_node;
6179
6180 case TRUTH_AND_EXPR:
6181 case TRUTH_OR_EXPR:
6182 case TRUTH_XOR_EXPR:
6183 case LT_EXPR:
6184 case LE_EXPR:
6185 case GT_EXPR:
6186 case GE_EXPR:
6187 case EQ_EXPR:
6188 case NE_EXPR:
6189 case TRUTH_ANDIF_EXPR:
6190 case TRUTH_ORIF_EXPR:
6191 case TRUTH_NOT_EXPR:
6192 if (flags & tf_error)
6193 error ("not enough type information");
6194 return error_mark_node;
6195
6196 case COND_EXPR:
6197 if (type_unknown_p (TREE_OPERAND (rhs, 0)))
6198 {
6199 if (flags & tf_error)
6200 error ("not enough type information");
6201 return error_mark_node;
6202 }
6203 TREE_OPERAND (rhs, 1)
6204 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
6205 if (TREE_OPERAND (rhs, 1) == error_mark_node)
6206 return error_mark_node;
6207 TREE_OPERAND (rhs, 2)
6208 = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), flags);
6209 if (TREE_OPERAND (rhs, 2) == error_mark_node)
6210 return error_mark_node;
6211
6212 TREE_TYPE (rhs) = lhstype;
6213 return rhs;
6214
6215 case MODIFY_EXPR:
6216 TREE_OPERAND (rhs, 1)
6217 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
6218 if (TREE_OPERAND (rhs, 1) == error_mark_node)
6219 return error_mark_node;
6220
6221 TREE_TYPE (rhs) = lhstype;
6222 return rhs;
6223
6224 case ADDR_EXPR:
6225 {
6226 if (PTRMEM_OK_P (rhs))
6227 flags |= tf_ptrmem_ok;
6228
6229 return instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
6230 }
6231 case ENTRY_VALUE_EXPR:
6232 abort ();
6233 return error_mark_node;
6234
6235 case ERROR_MARK:
6236 return error_mark_node;
6237
6238 default :
6239 abort ();
6240 return error_mark_node;
6241 }
6242 }
Above code shows clearly which operand of the node of specified kind is concerned (functions for building tree node for expressions, for example, build_binary_op would synchronize operands with the same type. So for expression “ptr+5” (ptr is type of “int*”), the expression building function will promote ‘5’ to the type of “int*”).
Then if the overload is legal (either TEMPLATE_ID_EXPR, or FUNCITON_DECL, or OVERLOAD), it should be resolved and finds out overload that matching; and of course, more than 1 matching causes problem of ambiguity. See below argument explicit_targs is only used for template matching, which holds the explictly given template arguments.
Besides the comment at line 5730, in [3], clause 13.4 “Address of overloaded function” ([over.over]), also gives the meaning and usage of this syntax element pluses examples.
1. A use of an overloaded function name without arguments is resolved in certain contexts to a function, a pointer to function or a pointer to member function for a specific function from the overload set. A function template name is considered to name a set of overloaded functions in such contexts. The function selected is the one whose type matches the target type required in the context. The target can be — an object or reference being initialized (8.5, 8.5.3), — the left side of an assignment (5.17), — a parameter of a function (5.2.2), — a parameter of a user-defined operator (13.5), — the return value of a function, operator function, or conversion (6.6.3), — an explicit type conversion (5.2.3, 5.2.9, 5.4), or — a non-type template-parameter (14.3.2). The overloaded function name can be preceded by the & operator. An overloaded function name shall not be used without arguments in contexts other than those listed. [Note: any redundant set of parentheses surrounding the overloaded function name is ignored (5.1). ] 2~4 … same as comment 5. [Example: int f(double); int f(int); int (*pfd)(double) = &f; // selects f(double) int (*pfi)(int) = &f; // selects f(int) int (*pfe)(...) = &f; // error: type mismatch int (&rfi)(int) = f; // selects f(int) int (&rfd)(double) = f; // selects f(double) void g() { (int (*)(int))&f; // cast expression as selector } The initialization of pfe is ill-formed because no f() with type int(...) has been defined, and not because of any ambiguity. For another example, struct X { int f(int); static int f(long); }; int (X::*p1)(int) = &X::f; // OK int (*p2)(int) = &X::f; // error: mismatch int (*p3)(long) = &X::f; // OK int (X::*p4)(long) = &X::f; // error: mismatch int (X::*p5)(int) = &(X::f); // error: wrong syntax for pointer to member int (*p6)(long) = &(X::f); // OK —end example ] 6. [Note: if f() and g() are both overloaded functions, the cross product of possibilities must be considered to resolve f(&g), or the equivalent expression f(g). ] 7. [Note: there are no standard conversions (clause 4) of one pointer-to-function type into another. In particular, even if B is a public base of D, we have D* f(); B* (*p1)() = &f; // error void g(D*); void (*p2)(B*) = &g; // error —end note ] |
5723 static tree
5724 resolve_address_of_overloaded_function (tree target_type, in class.c
5725 tree overload,
5726 tsubst_flags_t flags,
5727 bool template_only,
5728 tree explicit_targs)
5729 {
5730 /* Here's what the standard says:
5731
5732 [over.over]
5733
5734 If the name is a function template, template argument deduction
5735 is done, and if the argument deduction succeeds, the deduced
5736 arguments are used to generate a single template function, which
5737 is added to the set of overloaded functions considered.
5738
5739 Non-member functions and static member functions match targets of
5740 type "pointer-to-function" or "reference-to-function." Nonstatic
5741 member functions match targets of type "pointer-to-member
5742 function;" the function type of the pointer to member is used to
5743 select the member function from the set of overloaded member
5744 functions. If a nonstatic member function is selected, the
5745 reference to the overloaded function name is required to have the
5746 form of a pointer to member as described in 5.3.1.
5747
5748 If more than one function is selected, any template functions in
5749 the set are eliminated if the set also contains a non-template
5750 function, and any given template function is eliminated if the
5751 set contains a second template function that is more specialized
5752 than the first according to the partial ordering rules 14.5.5.2.
5753 After such eliminations, if any, there shall remain exactly one
5754 selected function. */
5755
5756 int is_ptrmem = 0;
5757 int is_reference = 0;
5758 /* We store the matches in a TREE_LIST rooted here. The functions
5759 are the TREE_PURPOSE, not the TREE_VALUE, in this list, for easy
5760 interoperability with most_specialized_instantiation. */
5761 tree matches = NULL_TREE;
5762 tree fn;
5763
5764 /* By the time we get here, we should be seeing only real
5765 pointer-to-member types, not the internal POINTER_TYPE to
5766 METHOD_TYPE representation. */
5767 my_friendly_assert (!(TREE_CODE (target_type) == POINTER_TYPE
5768 && (TREE_CODE (TREE_TYPE (target_type))
5769 == METHOD_TYPE)), 0);
5770
5771 my_friendly_assert (is_overloaded_fn (overload), 20030910);
5772
5773 /* Check that the TARGET_TYPE is reasonable. */
5774 if (TYPE_PTRFN_P (target_type))
5775 /* This is OK. */ ;
5776 else if (TYPE_PTRMEMFUNC_P (target_type))
5777 /* This is OK, too. */
5778 is_ptrmem = 1;
5779 else if (TREE_CODE (target_type) == FUNCTION_TYPE)
5780 {
5781 /* This is OK, too. This comes from a conversion to reference
5782 type. */
5783 target_type = build_reference_type (target_type);
5784 is_reference = 1;
5785 }
5786 else
5787 {
5788 if (flags & tf_error)
5789 error ("/
5790 cannot resolve overloaded function `%D' based on conversion to type `%T'",
5791 DECL_NAME (OVL_FUNCTION (overload)), target_type);
5792 return error_mark_node;
5793 }
5794
5795 /* If we can find a non-template function that matches, we can just
5796 use it. There's no point in generating template instantiations
5797 if we're just going to throw them out anyhow. But, of course, we
5798 can only do this when we don't *need* a template function. */
5799 if (!template_only)
5800 {
5801 tree fns;
5802
5803 for (fns = overload; fns; fns = OVL_NEXT (fns))
5804 {
5805 tree fn = OVL_CURRENT (fns);
5806 tree fntype;
5807
5808 if (TREE_CODE (fn) == TEMPLATE_DECL)
5809 /* We're not looking for templates just yet. */
5810 continue ;
5811
5812 if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
5813 != is_ptrmem)
5814 /* We're looking for a non-static member, and this isn't
5815 one, or vice versa. */
5816 continue ;
5817
5818 /* Ignore anticipated decls of undeclared builtins. */
5819 if (DECL_ANTICIPATED (fn))
5820 continue ;
5821
5822 /* See if there's a match. */
5823 fntype = TREE_TYPE (fn);
5824 if (is_ptrmem)
5825 fntype = build_ptrmemfunc_type (build_pointer_type (fntype));
5826 else if (!is_reference)
5827 fntype = build_pointer_type (fntype);
5828
5829 if (can_convert_arg (target_type, fntype, fn))
5830 matches = tree_cons (fn, NULL_TREE, matches);
5831 }
5832 }
Remember overloads are chained in a list with node of OVERLOAD at head, but after this head, the nodes contain nodes of FUNCTION_DECL respectively, which is fetched at line 5805 by OVL_CURRENT. Then, fntype at line 5823 would be FUNCTION_TYPE with certainty instead of unknown_type_node . So the pointer type is built from it. For the types, can_convert_arg would checks if the type can be implicitly converted to target_type , and in standard_conversion handling this pointer conversion, at line 619, we can see pointer-to-function requires exactly matching as above example shows.
And among overloads, non-template is superior to template, and if non-template matching is found, the templates will be ignored. If we can’t find non-template matching, then we are just searching for template matching, we will enter the IF block below at line 5837.
resolve_address_of_overloaded_function (continue)
5834 /* Now, if we've already got a match (or matches), there's no need
5835 to proceed to the template functions. But, if we don't have a
5836 match we need to look at them, too. */
5837 if (!matches)
5838 {
5839 tree target_fn_type;
5840 tree target_arg_types;
5841 tree target_ret_type;
5842 tree fns;
5843
5844 if (is_ptrmem)
5845 target_fn_type
5846 = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (target_type));
5847 else
5848 target_fn_type = TREE_TYPE (target_type);
5849 target_arg_types = TYPE_ARG_TYPES (target_fn_type);
5850 target_ret_type = TREE_TYPE (target_fn_type);
5851
5852 /* Never do unification on the 'this' parameter. */
5853 if (TREE_CODE (target_fn_type) == METHOD_TYPE)
5854 target_arg_types = TREE_CHAIN (target_arg_types);
5855
5856 for (fns = overload; fns; fns = OVL_NEXT (fns))
5857 {
5858 tree fn = OVL_CURRENT (fns);
5859 tree instantiation;
5860 tree instantiation_type;
5861 tree targs;
5862
5863 if (TREE_CODE (fn) != TEMPLATE_DECL)
5864 /* We're only looking for templates. */
5865 continue ;
5866
5867 if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
5868 != is_ptrmem)
5869 /* We're not looking for a non-static member, and this is
5870 one, or vice versa. */
5871 continue ;
5872
5873 /* Try to do argument deduction. */
5874 targs = make_tree_vec (DECL_NTPARMS (fn));
5875 if (fn_type_unification (fn, explicit_targs, targs,
5876 target_arg_types, target_ret_type,
5877 DEDUCE_EXACT, -1) != 0)
5878 /* Argument deduction failed. */
5879 continue ;
5880
5881 /* Instantiate the template. */
5882 instantiation = instantiate_template (fn, targs, flags);
5883 if (instantiation == error_mark_node)
5884 /* Instantiation failed. */
5885 continue ;
5886
5887 /* See if there's a match. */
5888 instantiation_type = TREE_TYPE (instantiation);
5889 if (is_ptrmem)
5890 instantiation_type =
5891 build_ptrmemfunc_type (build_pointer_type (instantiation_type));
5892 else if (!is_reference)
5893 instantiation_type = build_pointer_type (instantiation_type);
5894 if (can_convert_arg (target_type, instantiation_type, instantiation))
5895 matches = tree_cons (instantiation, fn, matches);
5896 }
5897
5898 /* Now, remove all but the most specialized of the matches. */
5899 if (matches)
5900 {
5901 tree match = most_specialized_instantiation (matches);
5902
5903 if (match != error_mark_node)
5904 matches = tree_cons (match, NULL_TREE, NULL_TREE);
5905 }
5906 }
We have seen the procedure of deducting template arguments in previous section. We don’t take the trouble to look them again.
resolve_address_of_overloaded_function (continue)
5908 Now we should have exactly one function in MATCHES. */
5909 if (matches == NULL_TREE)
5910 {
5911 /* There were *no* matches. */
5912 if (flags & tf_error)
5913 {
5914 error ("no matches converting function `%D' to type `%#T'",
5915 DECL_NAME (OVL_FUNCTION (overload)),
5916 target_type);
5917
5918 /* print_candidates expects a chain with the functions in
5919 TREE_VALUE slots, so we cons one up here (we're losing anyway,
5920 so why be clever?). */
5921 for (; overload; overload = OVL_NEXT (overload))
5922 matches = tree_cons (NULL_TREE, OVL_CURRENT (overload),
5923 matches);
5924
5925 print_candidates (matches);
5926 }
5927 return error_mark_node;
5928 }
5929 else if (TREE_CHAIN (matches))
5930 {
5931 /* There were too many matches. */
5932
5933 if (flags & tf_error)
5934 {
5935 tree match;
5936
5937 error ("converting overloaded function `%D' to type `%#T' is ambiguous",
5938 DECL_NAME (OVL_FUNCTION (overload)),
5939 target_type);
5940
5941 /* Since print_candidates expects the functions in the
5942 TREE_VALUE slot, we flip them here. */
5943 for (match = matches; match; match = TREE_CHAIN (match))
5944 TREE_VALUE (match) = TREE_PURPOSE (match);
5945
5946 print_candidates (matches);
5947 }
5948
5949 return error_mark_node;
5950 }
5951
5952 /* Good, exactly one match. Now, convert it to the correct type. */
5953 fn = TREE_PURPOSE (matches);
5954
5955 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
5956 && !(flags & tf_ptrmem_ok) && !flag_ms_extensions )
5957 {
5958 static int explained;
5959
5960 if (!(flags & tf_error))
5961 return error_mark_node;
5962
5963 pedwarn ("assuming pointer to member `%D'", fn);
5964 if (!explained)
5965 {
5966 pedwarn ("(a pointer to member can only be formed with `&%E')", fn);
5967 explained = 1;
5968 }
5969 }
5970
5971 /* If we're doing overload resolution purely for the purpose of
5972 determining conversion sequences, we should not consider the
5973 function used. If this conversion sequence is selected, the
5974 function will be marked as used at this point. */
5975 if (!(flags & tf_conv))
5976 mark_used (fn);
5977
5978 if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
5979 return build_unary_op (ADDR_EXPR, fn, 0);
5980 else
5981 {
5982 /* The target must be a REFERENCE_TYPE. Above, build_unary_op
5983 will mark the function as addressed, but here we must do it
5984 explicitly. */
5985 cxx_mark_addressable (fn);
5986
5987 return fn;
5988 }
5989 }
At last, it needs mark the qualified found result as addressable, which is the information important to code generation. And fn returned by the function is the overload found matching. And this returned value is stored in expr at line 952. And from is updated to its type at line 955.