1 /* Functions related to invoking methods and overloaded functions.
2 Copyright (C) 1987, 92-97, 1998, 1999 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com) and
4 modified by Brendan Kehoe (brendan@cygnus.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 /* High-level class interface. */
36 #define obstack_chunk_alloc xmalloc
37 #define obstack_chunk_free free
39 extern int inhibit_warnings
;
40 extern tree ctor_label
, dtor_label
;
42 static tree build_new_method_call
PROTO((tree
, tree
, tree
, tree
, int));
44 static tree build_field_call
PROTO((tree
, tree
, tree
, tree
));
45 static tree find_scoped_type
PROTO((tree
, tree
, tree
));
46 static struct z_candidate
* tourney
PROTO((struct z_candidate
*));
47 static int joust
PROTO((struct z_candidate
*, struct z_candidate
*, int));
48 static int compare_ics
PROTO((tree
, tree
));
49 static tree build_over_call
PROTO((struct z_candidate
*, tree
, int));
50 static tree convert_like
PROTO((tree
, tree
));
51 static void op_error
PROTO((enum tree_code
, enum tree_code
, tree
, tree
,
53 static tree build_object_call
PROTO((tree
, tree
));
54 static tree resolve_args
PROTO((tree
));
55 static struct z_candidate
* build_user_type_conversion_1
56 PROTO ((tree
, tree
, int));
57 static void print_z_candidates
PROTO((struct z_candidate
*));
58 static tree build_this
PROTO((tree
));
59 static struct z_candidate
* splice_viable
PROTO((struct z_candidate
*));
60 static int any_viable
PROTO((struct z_candidate
*));
61 static struct z_candidate
* add_template_candidate
62 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
, int,
64 static struct z_candidate
* add_template_candidate_real
65 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
, int,
66 tree
, unification_kind_t
));
67 static struct z_candidate
* add_template_conv_candidate
68 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
));
69 static struct z_candidate
* add_builtin_candidates
70 PROTO((struct z_candidate
*, enum tree_code
, enum tree_code
,
72 static struct z_candidate
* add_builtin_candidate
73 PROTO((struct z_candidate
*, enum tree_code
, enum tree_code
,
74 tree
, tree
, tree
, tree
*, tree
*, int));
75 static int is_complete
PROTO((tree
));
76 static struct z_candidate
* build_builtin_candidate
77 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
*, tree
*,
79 static struct z_candidate
* add_conv_candidate
80 PROTO((struct z_candidate
*, tree
, tree
, tree
));
81 static struct z_candidate
* add_function_candidate
82 PROTO((struct z_candidate
*, tree
, tree
, int));
83 static tree implicit_conversion
PROTO((tree
, tree
, tree
, int));
84 static tree standard_conversion
PROTO((tree
, tree
, tree
));
85 static tree reference_binding
PROTO((tree
, tree
, tree
, int));
86 static tree strip_top_quals
PROTO((tree
));
87 static tree non_reference
PROTO((tree
));
88 static tree build_conv
PROTO((enum tree_code
, tree
, tree
));
89 static int is_subseq
PROTO((tree
, tree
));
90 static int is_properly_derived_from
PROTO((tree
, tree
));
91 static int maybe_handle_ref_bind
PROTO((tree
*, tree
*));
92 static void maybe_handle_implicit_object
PROTO((tree
*));
93 static struct z_candidate
* add_candidate
PROTO((struct z_candidate
*,
95 static tree source_type
PROTO((tree
));
96 static void add_warning
PROTO((struct z_candidate
*, struct z_candidate
*));
99 build_vfield_ref (datum
, type
)
104 if (datum
== error_mark_node
)
105 return error_mark_node
;
107 if (TREE_CODE (TREE_TYPE (datum
)) == REFERENCE_TYPE
)
108 datum
= convert_from_reference (datum
);
110 if (! TYPE_USES_COMPLEX_INHERITANCE (type
))
111 rval
= build (COMPONENT_REF
, TREE_TYPE (CLASSTYPE_VFIELD (type
)),
112 datum
, CLASSTYPE_VFIELD (type
));
114 rval
= build_component_ref (datum
, DECL_NAME (CLASSTYPE_VFIELD (type
)), NULL_TREE
, 0);
119 /* Build a call to a member of an object. I.e., one that overloads
120 operator ()(), or is a pointer-to-function or pointer-to-method. */
123 build_field_call (basetype_path
, instance_ptr
, name
, parms
)
124 tree basetype_path
, instance_ptr
, name
, parms
;
126 tree field
, instance
;
128 if (name
== ctor_identifier
|| name
== dtor_identifier
)
131 /* Speed up the common case. */
132 if (instance_ptr
== current_class_ptr
133 && IDENTIFIER_CLASS_VALUE (name
) == NULL_TREE
)
136 field
= lookup_field (basetype_path
, name
, 1, 0);
138 if (field
== error_mark_node
|| field
== NULL_TREE
)
141 if (TREE_CODE (field
) == FIELD_DECL
|| TREE_CODE (field
) == VAR_DECL
)
143 /* If it's a field, try overloading operator (),
144 or calling if the field is a pointer-to-function. */
145 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
146 instance
= build_component_ref_1 (instance
, field
, 0);
148 if (instance
== error_mark_node
)
149 return error_mark_node
;
151 if (IS_AGGR_TYPE (TREE_TYPE (instance
)))
152 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
,
153 instance
, parms
, NULL_TREE
);
154 else if (TREE_CODE (TREE_TYPE (instance
)) == POINTER_TYPE
)
156 if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == FUNCTION_TYPE
)
157 return build_function_call (instance
, parms
);
158 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
)))
160 return build_function_call
161 (instance
, expr_tree_cons (NULL_TREE
, instance_ptr
, parms
));
169 find_scoped_type (type
, inner_name
, inner_types
)
170 tree type
, inner_name
, inner_types
;
172 tree tags
= CLASSTYPE_TAGS (type
);
176 /* The TREE_PURPOSE of an enum tag (which becomes a member of the
177 enclosing class) is set to the name for the enum type. So, if
178 inner_name is `bar', and we strike `baz' for `enum bar { baz }',
179 then this test will be true. */
180 if (TREE_PURPOSE (tags
) == inner_name
)
182 if (inner_types
== NULL_TREE
)
183 return TYPE_MAIN_DECL (TREE_VALUE (tags
));
184 return resolve_scope_to_name (TREE_VALUE (tags
), inner_types
);
186 tags
= TREE_CHAIN (tags
);
189 /* Look for a TYPE_DECL. */
190 for (tags
= TYPE_FIELDS (type
); tags
; tags
= TREE_CHAIN (tags
))
191 if (TREE_CODE (tags
) == TYPE_DECL
&& DECL_NAME (tags
) == inner_name
)
193 /* Code by raeburn. */
194 if (inner_types
== NULL_TREE
)
196 return resolve_scope_to_name (TREE_TYPE (tags
), inner_types
);
202 /* Resolve an expression NAME1::NAME2::...::NAMEn to
203 the name that names the above nested type. INNER_TYPES
204 is a chain of nested type names (held together by SCOPE_REFs);
205 OUTER_TYPE is the type we know to enclose INNER_TYPES.
206 Returns NULL_TREE if there is an error. */
209 resolve_scope_to_name (outer_type
, inner_stuff
)
210 tree outer_type
, inner_stuff
;
213 tree inner_name
, inner_type
;
215 if (outer_type
== NULL_TREE
&& current_class_type
!= NULL_TREE
)
217 /* We first try to look for a nesting in our current class context,
218 then try any enclosing classes. */
219 tree type
= current_class_type
;
221 while (type
&& (TREE_CODE (type
) == RECORD_TYPE
222 || TREE_CODE (type
) == UNION_TYPE
))
224 tree rval
= resolve_scope_to_name (type
, inner_stuff
);
226 if (rval
!= NULL_TREE
)
228 type
= DECL_CONTEXT (TYPE_MAIN_DECL (type
));
232 if (TREE_CODE (inner_stuff
) == SCOPE_REF
)
234 inner_name
= TREE_OPERAND (inner_stuff
, 0);
235 inner_type
= TREE_OPERAND (inner_stuff
, 1);
239 inner_name
= inner_stuff
;
240 inner_type
= NULL_TREE
;
243 if (outer_type
== NULL_TREE
)
246 /* If we have something that's already a type by itself,
248 if (IDENTIFIER_HAS_TYPE_VALUE (inner_name
))
251 return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name
),
256 x
= lookup_name (inner_name
, 0);
258 if (x
&& TREE_CODE (x
) == NAMESPACE_DECL
)
260 x
= lookup_namespace_name (x
, inner_type
);
266 if (! IS_AGGR_TYPE (outer_type
))
269 /* Look for member classes or enums. */
270 tmp
= find_scoped_type (outer_type
, inner_name
, inner_type
);
272 /* If it's not a type in this class, then go down into the
273 base classes and search there. */
274 if (! tmp
&& TYPE_BINFO (outer_type
))
276 tree binfos
= TYPE_BINFO_BASETYPES (outer_type
);
277 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
279 for (i
= 0; i
< n_baselinks
; i
++)
281 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
282 tmp
= resolve_scope_to_name (BINFO_TYPE (base_binfo
), inner_stuff
);
292 /* Returns nonzero iff the destructor name specified in NAME
293 (a BIT_NOT_EXPR) matches BASETYPE. The operand of NAME can take many
297 check_dtor_name (basetype
, name
)
300 name
= TREE_OPERAND (name
, 0);
302 /* Just accept something we've already complained about. */
303 if (name
== error_mark_node
)
306 if (TREE_CODE (name
) == TYPE_DECL
)
307 name
= TREE_TYPE (name
);
308 else if (TREE_CODE_CLASS (TREE_CODE (name
)) == 't')
310 else if (TREE_CODE (name
) == IDENTIFIER_NODE
)
312 if ((IS_AGGR_TYPE (basetype
) && name
== constructor_name (basetype
))
313 || (TREE_CODE (basetype
) == ENUMERAL_TYPE
314 && name
== TYPE_IDENTIFIER (basetype
)))
317 name
= get_type_value (name
);
320 my_friendly_abort (980605);
322 if (name
&& TYPE_MAIN_VARIANT (basetype
) == TYPE_MAIN_VARIANT (name
))
327 /* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'.
328 This is how virtual function calls are avoided. */
331 build_scoped_method_call (exp
, basetype
, name
, parms
)
332 tree exp
, basetype
, name
, parms
;
334 /* Because this syntactic form does not allow
335 a pointer to a base class to be `stolen',
336 we need not protect the derived->base conversion
339 @@ But we do have to check access privileges later. */
341 tree type
= TREE_TYPE (exp
);
343 if (type
== error_mark_node
344 || basetype
== error_mark_node
)
345 return error_mark_node
;
347 if (processing_template_decl
)
349 if (TREE_CODE (name
) == BIT_NOT_EXPR
350 && TREE_CODE (TREE_OPERAND (name
, 0)) == IDENTIFIER_NODE
)
352 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 0);
354 name
= build_min_nt (BIT_NOT_EXPR
, type
);
356 name
= build_min_nt (SCOPE_REF
, basetype
, name
);
357 return build_min_nt (METHOD_CALL_EXPR
, name
, exp
, parms
, NULL_TREE
);
360 if (TREE_CODE (type
) == REFERENCE_TYPE
)
361 type
= TREE_TYPE (type
);
363 if (TREE_CODE (basetype
) == TREE_VEC
)
366 basetype
= BINFO_TYPE (binfo
);
371 /* Check the destructor call syntax. */
372 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
374 /* We can get here if someone writes their destructor call like
375 `obj.NS::~T()'; this isn't really a scoped method call, so hand
377 if (TREE_CODE (basetype
) == NAMESPACE_DECL
)
378 return build_method_call (exp
, name
, parms
, NULL_TREE
, LOOKUP_NORMAL
);
380 if (! check_dtor_name (basetype
, name
))
381 cp_error ("qualified type `%T' does not match destructor name `~%T'",
382 basetype
, TREE_OPERAND (name
, 0));
384 /* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
385 that explicit ~int is caught in the parser; this deals with typedefs
386 and template parms. */
387 if (! IS_AGGR_TYPE (basetype
))
389 if (TYPE_MAIN_VARIANT (type
) != TYPE_MAIN_VARIANT (basetype
))
390 cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
391 exp
, basetype
, type
);
393 return cp_convert (void_type_node
, exp
);
397 if (! is_aggr_type (basetype
, 1))
398 return error_mark_node
;
400 if (! IS_AGGR_TYPE (type
))
402 cp_error ("base object `%E' of scoped method call is of non-aggregate type `%T'",
404 return error_mark_node
;
409 binfo
= get_binfo (basetype
, type
, 1);
410 if (binfo
== error_mark_node
)
411 return error_mark_node
;
413 error_not_base_type (basetype
, type
);
418 if (TREE_CODE (exp
) == INDIRECT_REF
)
419 decl
= build_indirect_ref
420 (convert_pointer_to_real
421 (binfo
, build_unary_op (ADDR_EXPR
, exp
, 0)), NULL_PTR
);
423 decl
= build_scoped_ref (exp
, basetype
);
425 /* Call to a destructor. */
426 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
428 if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl
)))
429 return cp_convert (void_type_node
, exp
);
431 return build_delete (TREE_TYPE (decl
), decl
, integer_two_node
,
432 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
,
436 /* Call to a method. */
437 return build_method_call (decl
, name
, parms
, binfo
,
438 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
);
440 return error_mark_node
;
443 /* We want the address of a function or method. We avoid creating a
444 pointer-to-member function. */
447 build_addr_func (function
)
450 tree type
= TREE_TYPE (function
);
452 /* We have to do these by hand to avoid real pointer to member
454 if (TREE_CODE (type
) == METHOD_TYPE
)
458 type
= build_pointer_type (type
);
460 if (mark_addressable (function
) == 0)
461 return error_mark_node
;
463 addr
= build1 (ADDR_EXPR
, type
, function
);
465 /* Address of a static or external variable or function counts
467 if (staticp (function
))
468 TREE_CONSTANT (addr
) = 1;
473 function
= default_conversion (function
);
478 /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
479 POINTER_TYPE to those. Note, pointer to member function types
480 (TYPE_PTRMEMFUNC_P) must be handled by our callers. */
483 build_call (function
, result_type
, parms
)
484 tree function
, result_type
, parms
;
486 int is_constructor
= 0;
490 function
= build_addr_func (function
);
492 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
494 sorry ("unable to call pointer to member function here");
495 return error_mark_node
;
498 if (TREE_CODE (function
) == ADDR_EXPR
499 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
)
500 decl
= TREE_OPERAND (function
, 0);
504 if (decl
&& DECL_CONSTRUCTOR_P (decl
))
508 my_friendly_assert (TREE_USED (decl
), 990125);
510 /* Don't pass empty class objects by value. This is useful
511 for tags in STL, which are used to control overload resolution.
512 We don't need to handle other cases of copying empty classes. */
513 if (! decl
|| ! DECL_BUILT_IN (decl
))
514 for (tmp
= parms
; tmp
; tmp
= TREE_CHAIN (tmp
))
515 if (is_empty_class (TREE_TYPE (TREE_VALUE (tmp
)))
516 && ! TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (tmp
))))
518 tree t
= make_node (RTL_EXPR
);
519 TREE_TYPE (t
) = TREE_TYPE (TREE_VALUE (tmp
));
520 RTL_EXPR_RTL (t
) = const0_rtx
;
521 RTL_EXPR_SEQUENCE (t
) = NULL_RTX
;
522 TREE_VALUE (tmp
) = build (COMPOUND_EXPR
, TREE_TYPE (t
),
523 TREE_VALUE (tmp
), t
);
526 function
= build_nt (CALL_EXPR
, function
, parms
, NULL_TREE
);
527 TREE_HAS_CONSTRUCTOR (function
) = is_constructor
;
528 TREE_TYPE (function
) = result_type
;
529 TREE_SIDE_EFFECTS (function
) = 1;
534 /* Build something of the form ptr->method (args)
535 or object.method (args). This can also build
536 calls to constructors, and find friends.
538 Member functions always take their class variable
541 INSTANCE is a class instance.
543 NAME is the name of the method desired, usually an IDENTIFIER_NODE.
545 PARMS help to figure out what that NAME really refers to.
547 BASETYPE_PATH, if non-NULL, contains a chain from the type of INSTANCE
548 down to the real instance type to use for access checking. We need this
549 information to get protected accesses correct. This parameter is used
550 by build_member_call.
552 FLAGS is the logical disjunction of zero or more LOOKUP_
553 flags. See cp-tree.h for more info.
555 If this is all OK, calls build_function_call with the resolved
558 This function must also handle being called to perform
559 initialization, promotion/coercion of arguments, and
560 instantiation of default parameters.
562 Note that NAME may refer to an instance variable name. If
563 `operator()()' is defined for the type of that field, then we return
567 build_method_call (instance
, name
, parms
, basetype_path
, flags
)
568 tree instance
, name
, parms
, basetype_path
;
571 tree basetype
, instance_ptr
;
573 #ifdef GATHER_STATISTICS
574 n_build_method_call
++;
577 if (instance
== error_mark_node
578 || name
== error_mark_node
579 || parms
== error_mark_node
580 || (instance
!= NULL_TREE
&& TREE_TYPE (instance
) == error_mark_node
))
581 return error_mark_node
;
583 if (processing_template_decl
)
585 /* We need to process template parm names here so that tsubst catches
586 them properly. Other type names can wait. */
587 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
589 tree type
= NULL_TREE
;
591 if (TREE_CODE (TREE_OPERAND (name
, 0)) == IDENTIFIER_NODE
)
592 type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 0);
593 else if (TREE_CODE (TREE_OPERAND (name
, 0)) == TYPE_DECL
)
594 type
= TREE_TYPE (TREE_OPERAND (name
, 0));
596 if (type
&& TREE_CODE (type
) == TEMPLATE_TYPE_PARM
)
597 name
= build_min_nt (BIT_NOT_EXPR
, type
);
600 return build_min_nt (METHOD_CALL_EXPR
, name
, instance
, parms
, NULL_TREE
);
603 /* This is the logic that magically deletes the second argument to
604 operator delete, if it is not needed. */
605 if (name
== ansi_opname
[(int) DELETE_EXPR
] && list_length (parms
)==2)
607 tree save_last
= TREE_CHAIN (parms
);
609 /* get rid of unneeded argument */
610 TREE_CHAIN (parms
) = NULL_TREE
;
611 if (build_method_call (instance
, name
, parms
, basetype_path
,
612 (LOOKUP_SPECULATIVELY
|flags
) & ~LOOKUP_COMPLAIN
))
614 /* If it finds a match, return it. */
615 return build_method_call (instance
, name
, parms
, basetype_path
, flags
);
617 /* If it doesn't work, two argument delete must work */
618 TREE_CHAIN (parms
) = save_last
;
620 /* We already know whether it's needed or not for vec delete. */
621 else if (name
== ansi_opname
[(int) VEC_DELETE_EXPR
]
622 && TYPE_LANG_SPECIFIC (TREE_TYPE (instance
))
623 && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance
)))
624 TREE_CHAIN (parms
) = NULL_TREE
;
626 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
629 error ("destructors take no parameters");
630 basetype
= TREE_TYPE (instance
);
631 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
632 basetype
= TREE_TYPE (basetype
);
634 if (! check_dtor_name (basetype
, name
))
636 ("destructor name `~%T' does not match type `%T' of expression",
637 TREE_OPERAND (name
, 0), basetype
);
639 if (! TYPE_HAS_DESTRUCTOR (complete_type (basetype
)))
640 return cp_convert (void_type_node
, instance
);
641 instance
= default_conversion (instance
);
642 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
643 return build_delete (build_pointer_type (basetype
),
644 instance_ptr
, integer_two_node
,
645 LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
, 0);
648 return build_new_method_call (instance
, name
, parms
, basetype_path
, flags
);
651 /* New overloading code. */
661 struct z_candidate
*next
;
664 #define IDENTITY_RANK 0
670 #define ELLIPSIS_RANK 6
673 #define ICS_RANK(NODE) \
674 (ICS_BAD_FLAG (NODE) ? BAD_RANK \
675 : ICS_ELLIPSIS_FLAG (NODE) ? ELLIPSIS_RANK \
676 : ICS_USER_FLAG (NODE) ? USER_RANK \
677 : ICS_STD_RANK (NODE))
679 #define ICS_STD_RANK(NODE) TREE_COMPLEXITY (NODE)
681 #define ICS_USER_FLAG(NODE) TREE_LANG_FLAG_0 (NODE)
682 #define ICS_ELLIPSIS_FLAG(NODE) TREE_LANG_FLAG_1 (NODE)
683 #define ICS_THIS_FLAG(NODE) TREE_LANG_FLAG_2 (NODE)
684 #define ICS_BAD_FLAG(NODE) TREE_LANG_FLAG_3 (NODE)
686 #define USER_CONV_CAND(NODE) \
687 ((struct z_candidate *)WRAPPER_PTR (TREE_OPERAND (NODE, 1)))
688 #define USER_CONV_FN(NODE) (USER_CONV_CAND (NODE)->fn)
695 || (integer_zerop (t
) && TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
))
701 build_conv (code
, type
, from
)
705 tree t
= build1 (code
, type
, from
);
706 int rank
= ICS_STD_RANK (from
);
718 if (rank
< EXACT_RANK
)
724 ICS_STD_RANK (t
) = rank
;
725 ICS_USER_FLAG (t
) = ICS_USER_FLAG (from
);
726 ICS_BAD_FLAG (t
) = ICS_BAD_FLAG (from
);
734 if (TREE_CODE (t
) == REFERENCE_TYPE
)
743 if (TREE_CODE (t
) == ARRAY_TYPE
)
745 return TYPE_MAIN_VARIANT (t
);
748 /* Returns the standard conversion path (see [conv]) from type FROM to type
749 TO, if any. For proper handling of null pointer constants, you must
750 also pass the expression EXPR to convert from. */
753 standard_conversion (to
, from
, expr
)
756 enum tree_code fcode
, tcode
;
760 if (TREE_CODE (to
) == REFERENCE_TYPE
)
762 if (TREE_CODE (from
) == REFERENCE_TYPE
)
765 from
= TREE_TYPE (from
);
767 to
= strip_top_quals (to
);
768 from
= strip_top_quals (from
);
770 if ((TYPE_PTRFN_P (to
) || TYPE_PTRMEMFUNC_P (to
))
771 && expr
&& type_unknown_p (expr
))
773 expr
= instantiate_type (to
, expr
, 0);
774 if (expr
== error_mark_node
)
776 from
= TREE_TYPE (expr
);
779 fcode
= TREE_CODE (from
);
780 tcode
= TREE_CODE (to
);
782 conv
= build1 (IDENTITY_CONV
, from
, expr
);
784 if (fcode
== FUNCTION_TYPE
)
786 from
= build_pointer_type (from
);
787 fcode
= TREE_CODE (from
);
788 conv
= build_conv (LVALUE_CONV
, from
, conv
);
790 else if (fcode
== ARRAY_TYPE
)
792 from
= build_pointer_type (TREE_TYPE (from
));
793 fcode
= TREE_CODE (from
);
794 conv
= build_conv (LVALUE_CONV
, from
, conv
);
796 else if (fromref
|| (expr
&& real_lvalue_p (expr
)))
797 conv
= build_conv (RVALUE_CONV
, from
, conv
);
802 if ((tcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (to
))
803 && expr
&& null_ptr_cst_p (expr
))
805 conv
= build_conv (STD_CONV
, to
, conv
);
807 else if (tcode
== POINTER_TYPE
&& fcode
== POINTER_TYPE
)
809 enum tree_code ufcode
= TREE_CODE (TREE_TYPE (from
));
810 enum tree_code utcode
= TREE_CODE (TREE_TYPE (to
));
812 if (same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (from
)),
813 TYPE_MAIN_VARIANT (TREE_TYPE (to
))))
815 else if (utcode
== VOID_TYPE
&& ufcode
!= OFFSET_TYPE
816 && ufcode
!= FUNCTION_TYPE
)
818 from
= build_pointer_type
819 (cp_build_qualified_type (void_type_node
,
820 CP_TYPE_QUALS (TREE_TYPE (from
))));
821 conv
= build_conv (PTR_CONV
, from
, conv
);
823 else if (ufcode
== OFFSET_TYPE
&& utcode
== OFFSET_TYPE
)
825 tree fbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from
));
826 tree tbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to
));
828 if (DERIVED_FROM_P (fbase
, tbase
)
830 (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (from
))),
831 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (to
))))))
833 from
= build_offset_type (tbase
, TREE_TYPE (TREE_TYPE (from
)));
834 from
= build_pointer_type (from
);
835 conv
= build_conv (PMEM_CONV
, from
, conv
);
838 else if (IS_AGGR_TYPE (TREE_TYPE (from
))
839 && IS_AGGR_TYPE (TREE_TYPE (to
)))
841 if (DERIVED_FROM_P (TREE_TYPE (to
), TREE_TYPE (from
)))
844 cp_build_qualified_type (TREE_TYPE (to
),
845 CP_TYPE_QUALS (TREE_TYPE (from
)));
846 from
= build_pointer_type (from
);
847 conv
= build_conv (PTR_CONV
, from
, conv
);
851 if (same_type_p (from
, to
))
853 else if (comp_ptr_ttypes (TREE_TYPE (to
), TREE_TYPE (from
)))
854 conv
= build_conv (QUAL_CONV
, to
, conv
);
855 else if (expr
&& string_conv_p (to
, expr
, 0))
856 /* converting from string constant to char *. */
857 conv
= build_conv (QUAL_CONV
, to
, conv
);
858 else if (ptr_reasonably_similar (TREE_TYPE (to
), TREE_TYPE (from
)))
860 conv
= build_conv (PTR_CONV
, to
, conv
);
861 ICS_BAD_FLAG (conv
) = 1;
868 else if (TYPE_PTRMEMFUNC_P (to
) && TYPE_PTRMEMFUNC_P (from
))
870 tree fromfn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from
));
871 tree tofn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to
));
872 tree fbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn
)));
873 tree tbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn
)));
875 if (! DERIVED_FROM_P (fbase
, tbase
)
876 || ! same_type_p (TREE_TYPE (fromfn
), TREE_TYPE (tofn
))
877 || ! compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)),
878 TREE_CHAIN (TYPE_ARG_TYPES (tofn
)))
879 || CP_TYPE_QUALS (fbase
) != CP_TYPE_QUALS (tbase
))
882 from
= cp_build_qualified_type (tbase
, CP_TYPE_QUALS (fbase
));
883 from
= build_cplus_method_type (from
, TREE_TYPE (fromfn
),
884 TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)));
885 from
= build_ptrmemfunc_type (build_pointer_type (from
));
886 conv
= build_conv (PMEM_CONV
, from
, conv
);
888 else if (tcode
== BOOLEAN_TYPE
)
890 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
891 || fcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (from
)))
894 conv
= build_conv (STD_CONV
, to
, conv
);
895 if (fcode
== POINTER_TYPE
896 || (TYPE_PTRMEMFUNC_P (from
) && ICS_STD_RANK (conv
) < PBOOL_RANK
))
897 ICS_STD_RANK (conv
) = PBOOL_RANK
;
899 /* We don't check for ENUMERAL_TYPE here because there are no standard
900 conversions to enum type. */
901 else if (tcode
== INTEGER_TYPE
|| tcode
== BOOLEAN_TYPE
902 || tcode
== REAL_TYPE
)
904 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
))
906 conv
= build_conv (STD_CONV
, to
, conv
);
908 /* Give this a better rank if it's a promotion. */
909 if (to
== type_promotes_to (from
)
910 && ICS_STD_RANK (TREE_OPERAND (conv
, 0)) <= PROMO_RANK
)
911 ICS_STD_RANK (conv
) = PROMO_RANK
;
913 else if (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
914 && DERIVED_FROM_P (to
, from
))
916 if (TREE_CODE (conv
) == RVALUE_CONV
)
917 conv
= TREE_OPERAND (conv
, 0);
918 conv
= build_conv (BASE_CONV
, to
, conv
);
926 /* Returns the conversion path from type FROM to reference type TO for
927 purposes of reference binding. For lvalue binding, either pass a
928 reference type to FROM or an lvalue expression to EXPR.
930 Currently does not distinguish in the generated trees between binding to
931 an lvalue and a temporary. Should it? */
934 reference_binding (rto
, rfrom
, expr
, flags
)
935 tree rto
, rfrom
, expr
;
940 tree to
= TREE_TYPE (rto
);
944 if (TREE_CODE (to
) == FUNCTION_TYPE
&& expr
&& type_unknown_p (expr
))
946 expr
= instantiate_type (to
, expr
, 0);
947 if (expr
== error_mark_node
)
949 from
= TREE_TYPE (expr
);
952 if (TREE_CODE (from
) == REFERENCE_TYPE
)
953 from
= TREE_TYPE (from
);
954 else if (! expr
|| ! real_lvalue_p (expr
))
957 related
= (same_type_p (TYPE_MAIN_VARIANT (to
),
958 TYPE_MAIN_VARIANT (from
))
959 || (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
960 && DERIVED_FROM_P (to
, from
)));
962 if (lvalue
&& related
&& at_least_as_qualified_p (to
, from
))
964 conv
= build1 (IDENTITY_CONV
, from
, expr
);
966 if (same_type_p (TYPE_MAIN_VARIANT (to
),
967 TYPE_MAIN_VARIANT (from
)))
968 conv
= build_conv (REF_BIND
, rto
, conv
);
971 conv
= build_conv (REF_BIND
, rto
, conv
);
972 ICS_STD_RANK (conv
) = STD_RANK
;
980 conv
= standard_conversion (to
, rfrom
, expr
);
983 conv
= build_conv (REF_BIND
, rto
, conv
);
985 /* Bind directly to a base subobject of a class rvalue. Do it
986 after building the conversion for proper handling of ICS_RANK. */
987 if (TREE_CODE (TREE_OPERAND (conv
, 0)) == BASE_CONV
)
988 TREE_OPERAND (conv
, 0) = TREE_OPERAND (TREE_OPERAND (conv
, 0), 0);
991 && ((! (CP_TYPE_CONST_NON_VOLATILE_P (to
)
992 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0))
993 /* If T1 is reference-related to T2, cv1 must be the same
994 cv-qualification as, or greater cv-qualification than,
995 cv2; otherwise, the program is ill-formed. */
996 || (related
&& !at_least_as_qualified_p (to
, from
))))
997 ICS_BAD_FLAG (conv
) = 1;
1003 /* Returns the implicit conversion sequence (see [over.ics]) from type FROM
1004 to type TO. The optional expression EXPR may affect the conversion.
1005 FLAGS are the usual overloading flags. Only LOOKUP_NO_CONVERSION is
1009 implicit_conversion (to
, from
, expr
, flags
)
1010 tree to
, from
, expr
;
1014 struct z_candidate
*cand
;
1016 if (TREE_CODE (to
) == REFERENCE_TYPE
)
1017 conv
= reference_binding (to
, from
, expr
, flags
);
1019 conv
= standard_conversion (to
, from
, expr
);
1023 else if (expr
!= NULL_TREE
1024 && (IS_AGGR_TYPE (non_reference (from
))
1025 || IS_AGGR_TYPE (non_reference (to
)))
1026 && (flags
& LOOKUP_NO_CONVERSION
) == 0)
1028 cand
= build_user_type_conversion_1
1029 (to
, expr
, LOOKUP_ONLYCONVERTING
);
1031 conv
= cand
->second_conv
;
1032 if ((! conv
|| ICS_BAD_FLAG (conv
))
1033 && TREE_CODE (to
) == REFERENCE_TYPE
1034 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0)
1036 cand
= build_user_type_conversion_1
1037 (TYPE_MAIN_VARIANT (TREE_TYPE (to
)), expr
, LOOKUP_ONLYCONVERTING
);
1040 if (!CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (to
)))
1041 ICS_BAD_FLAG (cand
->second_conv
) = 1;
1042 if (!conv
|| (ICS_BAD_FLAG (conv
)
1043 > ICS_BAD_FLAG (cand
->second_conv
)))
1044 conv
= build_conv (REF_BIND
, to
, cand
->second_conv
);
1052 /* Add a new entry to the list of candidates. Used by the add_*_candidate
1055 static struct z_candidate
*
1056 add_candidate (candidates
, fn
, convs
, viable
)
1057 struct z_candidate
*candidates
;
1061 struct z_candidate
*cand
1062 = (struct z_candidate
*) scratchalloc (sizeof (struct z_candidate
));
1065 cand
->convs
= convs
;
1066 cand
->second_conv
= NULL_TREE
;
1067 cand
->viable
= viable
;
1068 cand
->basetype_path
= NULL_TREE
;
1069 cand
->template = NULL_TREE
;
1070 cand
->warnings
= NULL_TREE
;
1071 cand
->next
= candidates
;
1076 /* Create an overload candidate for the function or method FN called with
1077 the argument list ARGLIST and add it to CANDIDATES. FLAGS is passed on
1078 to implicit_conversion. */
1080 static struct z_candidate
*
1081 add_function_candidate (candidates
, fn
, arglist
, flags
)
1082 struct z_candidate
*candidates
;
1086 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1089 tree parmnode
, argnode
;
1092 /* The `this' and `in_chrg' arguments to constructors are not considered
1093 in overload resolution. */
1094 if (DECL_CONSTRUCTOR_P (fn
))
1096 parmlist
= TREE_CHAIN (parmlist
);
1097 arglist
= TREE_CHAIN (arglist
);
1098 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
1100 parmlist
= TREE_CHAIN (parmlist
);
1101 arglist
= TREE_CHAIN (arglist
);
1105 len
= list_length (arglist
);
1106 convs
= make_scratch_vec (len
);
1108 /* 13.3.2 - Viable functions [over.match.viable]
1109 First, to be a viable function, a candidate function shall have enough
1110 parameters to agree in number with the arguments in the list.
1112 We need to check this first; otherwise, checking the ICSes might cause
1113 us to produce an ill-formed template instantiation. */
1115 parmnode
= parmlist
;
1116 for (i
= 0; i
< len
; ++i
)
1118 if (parmnode
== NULL_TREE
|| parmnode
== void_list_node
)
1120 parmnode
= TREE_CHAIN (parmnode
);
1123 if (i
< len
&& parmnode
)
1126 /* Make sure there are default args for the rest of the parms. */
1127 else for (; parmnode
&& parmnode
!= void_list_node
;
1128 parmnode
= TREE_CHAIN (parmnode
))
1129 if (! TREE_PURPOSE (parmnode
))
1138 /* Second, for F to be a viable function, there shall exist for each
1139 argument an implicit conversion sequence that converts that argument
1140 to the corresponding parameter of F. */
1142 parmnode
= parmlist
;
1145 for (i
= 0; i
< len
; ++i
)
1147 tree arg
= TREE_VALUE (argnode
);
1148 tree argtype
= lvalue_type (arg
);
1151 if (parmnode
== void_list_node
)
1156 tree parmtype
= TREE_VALUE (parmnode
);
1158 /* [over.match.funcs] For conversion functions, the function is
1159 considered to be a member of the class of the implicit object
1160 argument for the purpose of defining the type of the implicit
1163 Since build_over_call ignores the ICS for the `this' parameter,
1164 we can just change the parm type. */
1165 if (DECL_CONV_FN_P (fn
) && i
== 0)
1168 = build_qualified_type (TREE_TYPE (argtype
),
1169 TYPE_QUALS (TREE_TYPE (parmtype
)));
1170 parmtype
= build_pointer_type (parmtype
);
1173 t
= implicit_conversion (parmtype
, argtype
, arg
, flags
);
1177 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
1178 ICS_ELLIPSIS_FLAG (t
) = 1;
1181 if (i
== 0 && t
&& TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
1182 && ! DECL_CONSTRUCTOR_P (fn
))
1183 ICS_THIS_FLAG (t
) = 1;
1185 TREE_VEC_ELT (convs
, i
) = t
;
1192 if (ICS_BAD_FLAG (t
))
1196 parmnode
= TREE_CHAIN (parmnode
);
1197 argnode
= TREE_CHAIN (argnode
);
1201 return add_candidate (candidates
, fn
, convs
, viable
);
1204 /* Create an overload candidate for the conversion function FN which will
1205 be invoked for expression OBJ, producing a pointer-to-function which
1206 will in turn be called with the argument list ARGLIST, and add it to
1207 CANDIDATES. FLAGS is passed on to implicit_conversion.
1209 Actually, we don't really care about FN; we care about the type it
1210 converts to. There may be multiple conversion functions that will
1211 convert to that type, and we rely on build_user_type_conversion_1 to
1212 choose the best one; so when we create our candidate, we record the type
1213 instead of the function. */
1215 static struct z_candidate
*
1216 add_conv_candidate (candidates
, fn
, obj
, arglist
)
1217 struct z_candidate
*candidates
;
1218 tree fn
, obj
, arglist
;
1220 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
1221 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (totype
));
1222 int i
, len
= list_length (arglist
) + 1;
1223 tree convs
= make_scratch_vec (len
);
1224 tree parmnode
= parmlist
;
1225 tree argnode
= arglist
;
1227 int flags
= LOOKUP_NORMAL
;
1229 /* Don't bother looking up the same type twice. */
1230 if (candidates
&& candidates
->fn
== totype
)
1233 for (i
= 0; i
< len
; ++i
)
1235 tree arg
= i
== 0 ? obj
: TREE_VALUE (argnode
);
1236 tree argtype
= lvalue_type (arg
);
1240 t
= implicit_conversion (totype
, argtype
, arg
, flags
);
1241 else if (parmnode
== void_list_node
)
1244 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
1247 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
1248 ICS_ELLIPSIS_FLAG (t
) = 1;
1251 TREE_VEC_ELT (convs
, i
) = t
;
1255 if (ICS_BAD_FLAG (t
))
1262 parmnode
= TREE_CHAIN (parmnode
);
1263 argnode
= TREE_CHAIN (argnode
);
1269 for (; parmnode
&& parmnode
!= void_list_node
;
1270 parmnode
= TREE_CHAIN (parmnode
))
1271 if (! TREE_PURPOSE (parmnode
))
1277 return add_candidate (candidates
, totype
, convs
, viable
);
1280 static struct z_candidate
*
1281 build_builtin_candidate (candidates
, fnname
, type1
, type2
,
1282 args
, argtypes
, flags
)
1283 struct z_candidate
*candidates
;
1284 tree fnname
, type1
, type2
, *args
, *argtypes
;
1295 convs
= make_scratch_vec (args
[2] ? 3 : (args
[1] ? 2 : 1));
1297 for (i
= 0; i
< 2; ++i
)
1302 t
= implicit_conversion (types
[i
], argtypes
[i
], args
[i
], flags
);
1306 /* We need something for printing the candidate. */
1307 t
= build1 (IDENTITY_CONV
, types
[i
], NULL_TREE
);
1309 else if (ICS_BAD_FLAG (t
))
1311 TREE_VEC_ELT (convs
, i
) = t
;
1314 /* For COND_EXPR we rearranged the arguments; undo that now. */
1317 TREE_VEC_ELT (convs
, 2) = TREE_VEC_ELT (convs
, 1);
1318 TREE_VEC_ELT (convs
, 1) = TREE_VEC_ELT (convs
, 0);
1319 t
= implicit_conversion (boolean_type_node
, argtypes
[2], args
[2], flags
);
1321 TREE_VEC_ELT (convs
, 0) = t
;
1326 return add_candidate (candidates
, fnname
, convs
, viable
);
1333 return TYPE_SIZE (complete_type (t
)) != NULL_TREE
;
1336 /* Create any builtin operator overload candidates for the operator in
1337 question given the converted operand types TYPE1 and TYPE2. The other
1338 args are passed through from add_builtin_candidates to
1339 build_builtin_candidate. */
1341 static struct z_candidate
*
1342 add_builtin_candidate (candidates
, code
, code2
, fnname
, type1
, type2
,
1343 args
, argtypes
, flags
)
1344 struct z_candidate
*candidates
;
1345 enum tree_code code
, code2
;
1346 tree fnname
, type1
, type2
, *args
, *argtypes
;
1351 case POSTINCREMENT_EXPR
:
1352 case POSTDECREMENT_EXPR
:
1353 args
[1] = integer_zero_node
;
1354 type2
= integer_type_node
;
1363 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
1364 and VQ is either volatile or empty, there exist candidate operator
1365 functions of the form
1366 VQ T& operator++(VQ T&);
1367 T operator++(VQ T&, int);
1368 5 For every pair T, VQ), where T is an enumeration type or an arithmetic
1369 type other than bool, and VQ is either volatile or empty, there exist
1370 candidate operator functions of the form
1371 VQ T& operator--(VQ T&);
1372 T operator--(VQ T&, int);
1373 6 For every pair T, VQ), where T is a cv-qualified or cv-unqualified
1374 complete object type, and VQ is either volatile or empty, there exist
1375 candidate operator functions of the form
1376 T*VQ& operator++(T*VQ&);
1377 T*VQ& operator--(T*VQ&);
1378 T* operator++(T*VQ&, int);
1379 T* operator--(T*VQ&, int); */
1381 case POSTDECREMENT_EXPR
:
1382 case PREDECREMENT_EXPR
:
1383 if (TREE_CODE (type1
) == BOOLEAN_TYPE
)
1385 case POSTINCREMENT_EXPR
:
1386 case PREINCREMENT_EXPR
:
1387 if ((ARITHMETIC_TYPE_P (type1
) && TREE_CODE (type1
) != ENUMERAL_TYPE
)
1388 || TYPE_PTROB_P (type1
))
1390 type1
= build_reference_type (type1
);
1395 /* 7 For every cv-qualified or cv-unqualified complete object type T, there
1396 exist candidate operator functions of the form
1400 8 For every function type T, there exist candidate operator functions of
1402 T& operator*(T*); */
1405 if (TREE_CODE (type1
) == POINTER_TYPE
1406 && (TYPE_PTROB_P (type1
)
1407 || TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
))
1411 /* 9 For every type T, there exist candidate operator functions of the form
1414 10For every promoted arithmetic type T, there exist candidate operator
1415 functions of the form
1419 case CONVERT_EXPR
: /* unary + */
1420 if (TREE_CODE (type1
) == POINTER_TYPE
1421 && TREE_CODE (TREE_TYPE (type1
)) != OFFSET_TYPE
)
1424 if (ARITHMETIC_TYPE_P (type1
))
1428 /* 11For every promoted integral type T, there exist candidate operator
1429 functions of the form
1433 if (INTEGRAL_TYPE_P (type1
))
1437 /* 12For every quintuple C1, C2, T, CV1, CV2), where C2 is a class type, C1
1438 is the same type as C2 or is a derived class of C2, T is a complete
1439 object type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
1440 there exist candidate operator functions of the form
1441 CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
1442 where CV12 is the union of CV1 and CV2. */
1445 if (TREE_CODE (type1
) == POINTER_TYPE
1446 && (TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
)))
1448 tree c1
= TREE_TYPE (type1
);
1449 tree c2
= (TYPE_PTRMEMFUNC_P (type2
)
1450 ? TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type2
)))
1451 : TYPE_OFFSET_BASETYPE (TREE_TYPE (type2
)));
1453 if (IS_AGGR_TYPE (c1
) && DERIVED_FROM_P (c2
, c1
)
1454 && (TYPE_PTRMEMFUNC_P (type2
)
1455 || is_complete (TREE_TYPE (TREE_TYPE (type2
)))))
1460 /* 13For every pair of promoted arithmetic types L and R, there exist can-
1461 didate operator functions of the form
1466 bool operator<(L, R);
1467 bool operator>(L, R);
1468 bool operator<=(L, R);
1469 bool operator>=(L, R);
1470 bool operator==(L, R);
1471 bool operator!=(L, R);
1472 where LR is the result of the usual arithmetic conversions between
1475 14For every pair of types T and I, where T is a cv-qualified or cv-
1476 unqualified complete object type and I is a promoted integral type,
1477 there exist candidate operator functions of the form
1478 T* operator+(T*, I);
1479 T& operator[](T*, I);
1480 T* operator-(T*, I);
1481 T* operator+(I, T*);
1482 T& operator[](I, T*);
1484 15For every T, where T is a pointer to complete object type, there exist
1485 candidate operator functions of the form112)
1486 ptrdiff_t operator-(T, T);
1488 16For every pointer type T, there exist candidate operator functions of
1490 bool operator<(T, T);
1491 bool operator>(T, T);
1492 bool operator<=(T, T);
1493 bool operator>=(T, T);
1494 bool operator==(T, T);
1495 bool operator!=(T, T);
1497 17For every pointer to member type T, there exist candidate operator
1498 functions of the form
1499 bool operator==(T, T);
1500 bool operator!=(T, T); */
1503 if (TYPE_PTROB_P (type1
) && TYPE_PTROB_P (type2
))
1505 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
1507 type2
= ptrdiff_type_node
;
1511 case TRUNC_DIV_EXPR
:
1512 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1518 if ((TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
))
1519 || (TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
)))
1521 if ((TYPE_PTRMEMFUNC_P (type1
) || TYPE_PTRMEM_P (type1
))
1522 && null_ptr_cst_p (args
[1]))
1527 if ((TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
))
1528 && null_ptr_cst_p (args
[0]))
1539 if ((ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1540 || (TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
)))
1542 if (TYPE_PTR_P (type1
) && null_ptr_cst_p (args
[1]))
1547 if (null_ptr_cst_p (args
[0]) && TYPE_PTR_P (type2
))
1555 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1558 if (INTEGRAL_TYPE_P (type1
) && TYPE_PTROB_P (type2
))
1560 type1
= ptrdiff_type_node
;
1563 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
1565 type2
= ptrdiff_type_node
;
1570 /* 18For every pair of promoted integral types L and R, there exist candi-
1571 date operator functions of the form
1578 where LR is the result of the usual arithmetic conversions between
1581 case TRUNC_MOD_EXPR
:
1587 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
1591 /* 19For every triple L, VQ, R), where L is an arithmetic or enumeration
1592 type, VQ is either volatile or empty, and R is a promoted arithmetic
1593 type, there exist candidate operator functions of the form
1594 VQ L& operator=(VQ L&, R);
1595 VQ L& operator*=(VQ L&, R);
1596 VQ L& operator/=(VQ L&, R);
1597 VQ L& operator+=(VQ L&, R);
1598 VQ L& operator-=(VQ L&, R);
1600 20For every pair T, VQ), where T is any type and VQ is either volatile
1601 or empty, there exist candidate operator functions of the form
1602 T*VQ& operator=(T*VQ&, T*);
1604 21For every pair T, VQ), where T is a pointer to member type and VQ is
1605 either volatile or empty, there exist candidate operator functions of
1607 VQ T& operator=(VQ T&, T);
1609 22For every triple T, VQ, I), where T is a cv-qualified or cv-
1610 unqualified complete object type, VQ is either volatile or empty, and
1611 I is a promoted integral type, there exist candidate operator func-
1613 T*VQ& operator+=(T*VQ&, I);
1614 T*VQ& operator-=(T*VQ&, I);
1616 23For every triple L, VQ, R), where L is an integral or enumeration
1617 type, VQ is either volatile or empty, and R is a promoted integral
1618 type, there exist candidate operator functions of the form
1620 VQ L& operator%=(VQ L&, R);
1621 VQ L& operator<<=(VQ L&, R);
1622 VQ L& operator>>=(VQ L&, R);
1623 VQ L& operator&=(VQ L&, R);
1624 VQ L& operator^=(VQ L&, R);
1625 VQ L& operator|=(VQ L&, R); */
1632 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
1634 type2
= ptrdiff_type_node
;
1638 case TRUNC_DIV_EXPR
:
1639 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1643 case TRUNC_MOD_EXPR
:
1649 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
1654 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1656 if ((TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
))
1657 || (TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
1658 || (TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
))
1659 || ((TYPE_PTRMEMFUNC_P (type1
)
1660 || TREE_CODE (type1
) == POINTER_TYPE
)
1661 && null_ptr_cst_p (args
[1])))
1669 my_friendly_abort (367);
1671 type1
= build_reference_type (type1
);
1675 /* Kludge around broken overloading rules whereby
1676 bool ? const char& : enum is ambiguous
1677 (between int and const char&). */
1678 flags
|= LOOKUP_NO_TEMP_BIND
;
1680 /* Extension: Support ?: of enumeral type. Hopefully this will not
1681 be an extension for long. */
1682 if (TREE_CODE (type1
) == ENUMERAL_TYPE
&& type1
== type2
)
1684 else if (TREE_CODE (type1
) == ENUMERAL_TYPE
1685 || TREE_CODE (type2
) == ENUMERAL_TYPE
)
1687 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1689 if (TREE_CODE (type1
) == TREE_CODE (type2
)
1690 && (TREE_CODE (type1
) == REFERENCE_TYPE
1691 || TREE_CODE (type1
) == POINTER_TYPE
1692 || TYPE_PTRMEMFUNC_P (type1
)
1693 || IS_AGGR_TYPE (type1
)))
1695 if (TREE_CODE (type1
) == REFERENCE_TYPE
1696 || TREE_CODE (type2
) == REFERENCE_TYPE
)
1698 if (((TYPE_PTRMEMFUNC_P (type1
) || TREE_CODE (type1
) == POINTER_TYPE
)
1699 && null_ptr_cst_p (args
[1]))
1700 || IS_AGGR_TYPE (type1
))
1705 if (((TYPE_PTRMEMFUNC_P (type2
) || TREE_CODE (type2
) == POINTER_TYPE
)
1706 && null_ptr_cst_p (args
[0]))
1707 || IS_AGGR_TYPE (type2
))
1715 my_friendly_abort (367);
1718 /* If we're dealing with two pointer types, we need candidates
1719 for both of them. */
1720 if (type2
&& type1
!= type2
1721 && TREE_CODE (type1
) == TREE_CODE (type2
)
1722 && (TREE_CODE (type1
) == REFERENCE_TYPE
1723 || (TREE_CODE (type1
) == POINTER_TYPE
1724 && TYPE_PTRMEM_P (type1
) == TYPE_PTRMEM_P (type2
))
1725 || TYPE_PTRMEMFUNC_P (type1
)
1726 || IS_AGGR_TYPE (type1
)))
1728 candidates
= build_builtin_candidate
1729 (candidates
, fnname
, type1
, type1
, args
, argtypes
, flags
);
1730 return build_builtin_candidate
1731 (candidates
, fnname
, type2
, type2
, args
, argtypes
, flags
);
1734 return build_builtin_candidate
1735 (candidates
, fnname
, type1
, type2
, args
, argtypes
, flags
);
1739 type_decays_to (type
)
1742 if (TREE_CODE (type
) == ARRAY_TYPE
)
1743 return build_pointer_type (TREE_TYPE (type
));
1744 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1745 return build_pointer_type (type
);
1749 /* There are three conditions of builtin candidates:
1751 1) bool-taking candidates. These are the same regardless of the input.
1752 2) pointer-pair taking candidates. These are generated for each type
1753 one of the input types converts to.
1754 3) arithmetic candidates. According to the WP, we should generate
1755 all of these, but I'm trying not to... */
1757 static struct z_candidate
*
1758 add_builtin_candidates (candidates
, code
, code2
, fnname
, args
, flags
)
1759 struct z_candidate
*candidates
;
1760 enum tree_code code
, code2
;
1765 tree type
, argtypes
[3], types
[2];
1767 for (i
= 0; i
< 3; ++i
)
1770 argtypes
[i
] = lvalue_type (args
[i
]);
1772 argtypes
[i
] = NULL_TREE
;
1777 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
1778 and VQ is either volatile or empty, there exist candidate operator
1779 functions of the form
1780 VQ T& operator++(VQ T&); */
1782 case POSTINCREMENT_EXPR
:
1783 case PREINCREMENT_EXPR
:
1784 case POSTDECREMENT_EXPR
:
1785 case PREDECREMENT_EXPR
:
1790 /* 24There also exist candidate operator functions of the form
1791 bool operator!(bool);
1792 bool operator&&(bool, bool);
1793 bool operator||(bool, bool); */
1795 case TRUTH_NOT_EXPR
:
1796 return build_builtin_candidate
1797 (candidates
, fnname
, boolean_type_node
,
1798 NULL_TREE
, args
, argtypes
, flags
);
1800 case TRUTH_ORIF_EXPR
:
1801 case TRUTH_ANDIF_EXPR
:
1802 return build_builtin_candidate
1803 (candidates
, fnname
, boolean_type_node
,
1804 boolean_type_node
, args
, argtypes
, flags
);
1815 types
[0] = types
[1] = NULL_TREE
;
1817 for (i
= 0; i
< 2; ++i
)
1821 else if (IS_AGGR_TYPE (argtypes
[i
]))
1825 if (i
== 0 && code
== MODIFY_EXPR
&& code2
== NOP_EXPR
)
1828 convs
= lookup_conversions (argtypes
[i
]);
1830 if (code
== COND_EXPR
)
1832 if (real_lvalue_p (args
[i
]))
1833 types
[i
] = scratch_tree_cons
1834 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
1836 types
[i
] = scratch_tree_cons
1837 (NULL_TREE
, TYPE_MAIN_VARIANT (argtypes
[i
]), types
[i
]);
1843 for (; convs
; convs
= TREE_CHAIN (convs
))
1845 type
= TREE_TYPE (TREE_TYPE (OVL_CURRENT (TREE_VALUE (convs
))));
1848 && (TREE_CODE (type
) != REFERENCE_TYPE
1849 || CP_TYPE_CONST_P (TREE_TYPE (type
))))
1852 if (code
== COND_EXPR
&& TREE_CODE (type
) == REFERENCE_TYPE
)
1853 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1855 type
= non_reference (type
);
1856 if (i
!= 0 || ! ref1
)
1858 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
1859 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
1860 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1861 if (INTEGRAL_TYPE_P (type
))
1862 type
= type_promotes_to (type
);
1865 if (! value_member (type
, types
[i
]))
1866 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1871 if (code
== COND_EXPR
&& real_lvalue_p (args
[i
]))
1872 types
[i
] = scratch_tree_cons
1873 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
1874 type
= non_reference (argtypes
[i
]);
1875 if (i
!= 0 || ! ref1
)
1877 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
1878 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
1879 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1880 if (INTEGRAL_TYPE_P (type
))
1881 type
= type_promotes_to (type
);
1883 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1887 for (; types
[0]; types
[0] = TREE_CHAIN (types
[0]))
1890 for (type
= types
[1]; type
; type
= TREE_CHAIN (type
))
1891 candidates
= add_builtin_candidate
1892 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
1893 TREE_VALUE (type
), args
, argtypes
, flags
);
1895 candidates
= add_builtin_candidate
1896 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
1897 NULL_TREE
, args
, argtypes
, flags
);
1904 /* If TMPL can be successfully instantiated as indicated by
1905 EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
1907 TMPL is the template. EXPLICIT_TARGS are any explicit template
1908 arguments. ARGLIST is the arguments provided at the call-site.
1909 The RETURN_TYPE is the desired type for conversion operators. If
1910 OBJ is NULL_TREE, FLAGS are as for add_function_candidate. If an
1911 OBJ is supplied, FLAGS are ignored, and OBJ is as for
1912 add_conv_candidate. */
1914 static struct z_candidate
*
1915 add_template_candidate_real (candidates
, tmpl
, explicit_targs
,
1916 arglist
, return_type
, flags
,
1918 struct z_candidate
*candidates
;
1919 tree tmpl
, explicit_targs
, arglist
, return_type
;
1922 unification_kind_t strict
;
1924 int ntparms
= DECL_NTPARMS (tmpl
);
1925 tree targs
= make_scratch_vec (ntparms
);
1926 struct z_candidate
*cand
;
1930 i
= fn_type_unification (tmpl
, explicit_targs
, targs
, arglist
,
1931 return_type
, strict
);
1936 fn
= instantiate_template (tmpl
, targs
);
1937 if (fn
== error_mark_node
)
1940 if (obj
!= NULL_TREE
)
1941 /* Aha, this is a conversion function. */
1942 cand
= add_conv_candidate (candidates
, fn
, obj
, arglist
);
1944 cand
= add_function_candidate (candidates
, fn
, arglist
, flags
);
1945 if (DECL_TI_TEMPLATE (fn
) != tmpl
)
1946 /* This situation can occur if a member template of a template
1947 class is specialized. Then, instantiate_template might return
1948 an instantiation of the specialization, in which case the
1949 DECL_TI_TEMPLATE field will point at the original
1950 specialization. For example:
1952 template <class T> struct S { template <class U> void f(U);
1953 template <> void f(int) {}; };
1957 Here, TMPL will be template <class U> S<double>::f(U).
1958 And, instantiate template will give us the specialization
1959 template <> S<double>::f(int). But, the DECL_TI_TEMPLATE field
1960 for this will point at template <class T> template <> S<T>::f(int),
1961 so that we can find the definition. For the purposes of
1962 overload resolution, however, we want the original TMPL. */
1963 cand
->template = tree_cons (tmpl
, targs
, NULL_TREE
);
1965 cand
->template = DECL_TEMPLATE_INFO (fn
);
1971 static struct z_candidate
*
1972 add_template_candidate (candidates
, tmpl
, explicit_targs
,
1973 arglist
, return_type
, flags
, strict
)
1974 struct z_candidate
*candidates
;
1975 tree tmpl
, explicit_targs
, arglist
, return_type
;
1977 unification_kind_t strict
;
1980 add_template_candidate_real (candidates
, tmpl
, explicit_targs
,
1981 arglist
, return_type
, flags
,
1986 static struct z_candidate
*
1987 add_template_conv_candidate (candidates
, tmpl
, obj
, arglist
, return_type
)
1988 struct z_candidate
*candidates
;
1989 tree tmpl
, obj
, arglist
, return_type
;
1992 add_template_candidate_real (candidates
, tmpl
, NULL_TREE
, arglist
,
1993 return_type
, 0, obj
, DEDUCE_CONV
);
1999 struct z_candidate
*cands
;
2001 for (; cands
; cands
= cands
->next
)
2002 if (pedantic
? cands
->viable
== 1 : cands
->viable
)
2007 static struct z_candidate
*
2008 splice_viable (cands
)
2009 struct z_candidate
*cands
;
2011 struct z_candidate
**p
= &cands
;
2015 if (pedantic
? (*p
)->viable
== 1 : (*p
)->viable
)
2028 /* Fix this to work on non-lvalues. */
2029 if (IS_SIGNATURE_POINTER (TREE_TYPE (obj
))
2030 || IS_SIGNATURE_REFERENCE (TREE_TYPE (obj
)))
2033 return build_unary_op (ADDR_EXPR
, obj
, 0);
2037 print_z_candidates (candidates
)
2038 struct z_candidate
*candidates
;
2040 const char *str
= "candidates are:";
2041 for (; candidates
; candidates
= candidates
->next
)
2043 if (TREE_CODE (candidates
->fn
) == IDENTIFIER_NODE
)
2045 if (candidates
->fn
== ansi_opname
[COND_EXPR
])
2046 cp_error ("%s %D(%T, %T, %T) <builtin>", str
, candidates
->fn
,
2047 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
2048 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)),
2049 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 2)));
2050 else if (TREE_VEC_LENGTH (candidates
->convs
) == 2)
2051 cp_error ("%s %D(%T, %T) <builtin>", str
, candidates
->fn
,
2052 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
2053 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)));
2055 cp_error ("%s %D(%T) <builtin>", str
, candidates
->fn
,
2056 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)));
2058 else if (TYPE_P (candidates
->fn
))
2059 cp_error ("%s %T <conversion>", str
, candidates
->fn
);
2061 cp_error_at ("%s %+#D%s", str
, candidates
->fn
,
2062 candidates
->viable
== -1 ? " <near match>" : "");
2067 /* Returns the best overload candidate to perform the requested
2068 conversion. This function is used for three the overloading situations
2069 described in [over.match.copy], [over.match.conv], and [over.match.ref].
2070 If TOTYPE is a REFERENCE_TYPE, we're trying to find an lvalue binding as
2071 per [dcl.init.ref], so we ignore temporary bindings. */
2073 static struct z_candidate
*
2074 build_user_type_conversion_1 (totype
, expr
, flags
)
2078 struct z_candidate
*candidates
, *cand
;
2079 tree fromtype
= TREE_TYPE (expr
);
2080 tree ctors
= NULL_TREE
, convs
= NULL_TREE
, *p
;
2081 tree args
= NULL_TREE
;
2082 tree templates
= NULL_TREE
;
2084 if (IS_AGGR_TYPE (totype
))
2085 ctors
= lookup_fnfields (TYPE_BINFO (totype
), ctor_identifier
, 0);
2086 if (IS_AGGR_TYPE (fromtype
)
2087 && (! IS_AGGR_TYPE (totype
) || ! DERIVED_FROM_P (totype
, fromtype
)))
2088 convs
= lookup_conversions (fromtype
);
2091 flags
|= LOOKUP_NO_CONVERSION
;
2095 tree t
= build_int_2 (0, 0);
2096 TREE_TYPE (t
) = build_pointer_type (totype
);
2097 args
= build_scratch_list (NULL_TREE
, expr
);
2098 if (TYPE_USES_VIRTUAL_BASECLASSES (totype
))
2099 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
2100 args
= scratch_tree_cons (NULL_TREE
, t
, args
);
2102 ctors
= TREE_VALUE (ctors
);
2104 for (; ctors
; ctors
= OVL_NEXT (ctors
))
2106 tree ctor
= OVL_CURRENT (ctors
);
2107 if (DECL_NONCONVERTING_P (ctor
))
2110 if (TREE_CODE (ctor
) == TEMPLATE_DECL
)
2112 templates
= scratch_tree_cons (NULL_TREE
, ctor
, templates
);
2114 add_template_candidate (candidates
, ctor
,
2115 NULL_TREE
, args
, NULL_TREE
, flags
,
2119 candidates
= add_function_candidate (candidates
, ctor
,
2124 candidates
->second_conv
= build1 (IDENTITY_CONV
, totype
, NULL_TREE
);
2125 candidates
->basetype_path
= TYPE_BINFO (totype
);
2130 args
= build_scratch_list (NULL_TREE
, build_this (expr
));
2132 for (; convs
; convs
= TREE_CHAIN (convs
))
2134 tree fns
= TREE_VALUE (convs
);
2135 int convflags
= LOOKUP_NO_CONVERSION
;
2138 /* If we are called to convert to a reference type, we are trying to
2139 find an lvalue binding, so don't even consider temporaries. If
2140 we don't find an lvalue binding, the caller will try again to
2141 look for a temporary binding. */
2142 if (TREE_CODE (totype
) == REFERENCE_TYPE
)
2143 convflags
|= LOOKUP_NO_TEMP_BIND
;
2145 if (TREE_CODE (OVL_CURRENT (fns
)) != TEMPLATE_DECL
)
2146 ics
= implicit_conversion
2147 (totype
, TREE_TYPE (TREE_TYPE (OVL_CURRENT (fns
))), 0, convflags
);
2149 /* We can't compute this yet. */
2150 ics
= error_mark_node
;
2152 if (TREE_CODE (totype
) == REFERENCE_TYPE
&& ics
&& ICS_BAD_FLAG (ics
))
2153 /* ignore the near match. */;
2155 for (; fns
; fns
= OVL_NEXT (fns
))
2157 tree fn
= OVL_CURRENT (fns
);
2158 struct z_candidate
*old_candidates
= candidates
;
2160 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2162 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2164 add_template_candidate (candidates
, fn
, NULL_TREE
,
2165 args
, totype
, flags
,
2169 candidates
= add_function_candidate (candidates
, fn
,
2172 if (candidates
!= old_candidates
)
2174 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2175 ics
= implicit_conversion
2176 (totype
, TREE_TYPE (TREE_TYPE (candidates
->fn
)),
2179 candidates
->second_conv
= ics
;
2180 candidates
->basetype_path
= TREE_PURPOSE (convs
);
2182 if (ics
== NULL_TREE
)
2183 candidates
->viable
= 0;
2184 else if (candidates
->viable
== 1 && ICS_BAD_FLAG (ics
))
2185 candidates
->viable
= -1;
2190 if (! any_viable (candidates
))
2193 if (flags
& LOOKUP_COMPLAIN
)
2195 if (candidates
&& ! candidates
->next
)
2196 /* say why this one won't work or try to be loose */;
2198 cp_error ("no viable candidates");
2205 candidates
= splice_viable (candidates
);
2206 cand
= tourney (candidates
);
2210 if (flags
& LOOKUP_COMPLAIN
)
2212 cp_error ("conversion from `%T' to `%T' is ambiguous",
2214 print_z_candidates (candidates
);
2217 cand
= candidates
; /* any one will do */
2218 cand
->second_conv
= build1 (AMBIG_CONV
, totype
, expr
);
2219 ICS_USER_FLAG (cand
->second_conv
) = 1;
2220 ICS_BAD_FLAG (cand
->second_conv
) = 1;
2225 for (p
= &(cand
->second_conv
); TREE_CODE (*p
) != IDENTITY_CONV
; )
2226 p
= &(TREE_OPERAND (*p
, 0));
2228 /* Pedantically, normal function declarations are never considered
2229 to refer to template instantiations, so we only do this with
2231 if (flag_guiding_decls
&& templates
&& ! cand
->template
2232 && !DECL_INITIAL (cand
->fn
)
2233 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
2234 add_maybe_template (cand
->fn
, templates
);
2238 (DECL_CONSTRUCTOR_P (cand
->fn
)
2239 ? totype
: non_reference (TREE_TYPE (TREE_TYPE (cand
->fn
)))),
2240 expr
, build_expr_ptr_wrapper (cand
));
2241 ICS_USER_FLAG (cand
->second_conv
) = 1;
2242 if (cand
->viable
== -1)
2243 ICS_BAD_FLAG (cand
->second_conv
) = 1;
2249 build_user_type_conversion (totype
, expr
, flags
)
2253 struct z_candidate
*cand
2254 = build_user_type_conversion_1 (totype
, expr
, flags
);
2258 if (TREE_CODE (cand
->second_conv
) == AMBIG_CONV
)
2259 return error_mark_node
;
2260 return convert_from_reference (convert_like (cand
->second_conv
, expr
));
2265 /* Do any initial processing on the arguments to a function call. */
2272 for (t
= args
; t
; t
= TREE_CHAIN (t
))
2274 if (TREE_VALUE (t
) == error_mark_node
)
2275 return error_mark_node
;
2276 else if (TREE_CODE (TREE_TYPE (TREE_VALUE (t
))) == VOID_TYPE
)
2278 error ("invalid use of void expression");
2279 return error_mark_node
;
2281 else if (TREE_CODE (TREE_VALUE (t
)) == OFFSET_REF
)
2282 TREE_VALUE (t
) = resolve_offset_ref (TREE_VALUE (t
));
2288 build_new_function_call (fn
, args
)
2291 struct z_candidate
*candidates
= 0, *cand
;
2292 tree explicit_targs
= NULL_TREE
;
2293 int template_only
= 0;
2295 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2297 explicit_targs
= TREE_OPERAND (fn
, 1);
2298 fn
= TREE_OPERAND (fn
, 0);
2302 if (really_overloaded_fn (fn
))
2305 tree templates
= NULL_TREE
;
2307 args
= resolve_args (args
);
2309 if (args
== error_mark_node
)
2310 return error_mark_node
;
2312 for (t1
= fn
; t1
; t1
= OVL_CHAIN (t1
))
2314 tree t
= OVL_FUNCTION (t1
);
2315 if (TREE_CODE (t
) == TEMPLATE_DECL
)
2317 templates
= scratch_tree_cons (NULL_TREE
, t
, templates
);
2318 candidates
= add_template_candidate
2319 (candidates
, t
, explicit_targs
, args
, NULL_TREE
,
2320 LOOKUP_NORMAL
, DEDUCE_CALL
);
2322 else if (! template_only
)
2323 candidates
= add_function_candidate
2324 (candidates
, t
, args
, LOOKUP_NORMAL
);
2327 if (! any_viable (candidates
))
2329 if (candidates
&& ! candidates
->next
)
2330 return build_function_call (candidates
->fn
, args
);
2331 cp_error ("no matching function for call to `%D (%A)'",
2332 DECL_NAME (OVL_FUNCTION (fn
)), args
);
2334 print_z_candidates (candidates
);
2335 return error_mark_node
;
2337 candidates
= splice_viable (candidates
);
2338 cand
= tourney (candidates
);
2342 cp_error ("call of overloaded `%D (%A)' is ambiguous",
2343 DECL_NAME (OVL_FUNCTION (fn
)), args
);
2344 print_z_candidates (candidates
);
2345 return error_mark_node
;
2348 /* Pedantically, normal function declarations are never considered
2349 to refer to template instantiations, so we only do this with
2351 if (flag_guiding_decls
&& templates
&& ! cand
->template
2352 && ! DECL_INITIAL (cand
->fn
))
2353 add_maybe_template (cand
->fn
, templates
);
2355 return build_over_call (cand
, args
, LOOKUP_NORMAL
);
2358 /* This is not really overloaded. */
2359 fn
= OVL_CURRENT (fn
);
2361 return build_function_call (fn
, args
);
2365 build_object_call (obj
, args
)
2368 struct z_candidate
*candidates
= 0, *cand
;
2369 tree fns
, convs
, mem_args
= NULL_TREE
;
2370 tree type
= TREE_TYPE (obj
);
2372 if (TYPE_PTRMEMFUNC_P (type
))
2374 /* It's no good looking for an overloaded operator() on a
2375 pointer-to-member-function. */
2376 cp_error ("pointer-to-member function %E cannot be called", obj
);
2377 cp_error ("without an object; consider using .* or ->*");
2378 return error_mark_node
;
2381 fns
= lookup_fnfields (TYPE_BINFO (type
), ansi_opname
[CALL_EXPR
], 1);
2382 if (fns
== error_mark_node
)
2383 return error_mark_node
;
2385 args
= resolve_args (args
);
2387 if (args
== error_mark_node
)
2388 return error_mark_node
;
2392 tree base
= TREE_PURPOSE (fns
);
2393 mem_args
= scratch_tree_cons (NULL_TREE
, build_this (obj
), args
);
2395 for (fns
= TREE_VALUE (fns
); fns
; fns
= OVL_NEXT (fns
))
2397 tree fn
= OVL_CURRENT (fns
);
2398 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2401 = add_template_candidate (candidates
, fn
, NULL_TREE
,
2402 mem_args
, NULL_TREE
,
2403 LOOKUP_NORMAL
, DEDUCE_CALL
);
2406 candidates
= add_function_candidate
2407 (candidates
, fn
, mem_args
, LOOKUP_NORMAL
);
2410 candidates
->basetype_path
= base
;
2414 convs
= lookup_conversions (type
);
2416 for (; convs
; convs
= TREE_CHAIN (convs
))
2418 tree fns
= TREE_VALUE (convs
);
2419 tree totype
= TREE_TYPE (TREE_TYPE (OVL_CURRENT (fns
)));
2421 if ((TREE_CODE (totype
) == POINTER_TYPE
2422 || TREE_CODE (totype
) == REFERENCE_TYPE
)
2423 && TREE_CODE (TREE_TYPE (totype
)) == FUNCTION_TYPE
)
2424 for (; fns
; fns
= OVL_NEXT (fns
))
2426 tree fn
= OVL_CURRENT (fns
);
2427 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2429 candidates
= add_template_conv_candidate (candidates
,
2436 candidates
= add_conv_candidate (candidates
, fn
, obj
, args
);
2439 candidates
->basetype_path
= TREE_PURPOSE (convs
);
2443 if (! any_viable (candidates
))
2445 cp_error ("no match for call to `(%T) (%A)'", TREE_TYPE (obj
), args
);
2446 print_z_candidates (candidates
);
2447 return error_mark_node
;
2450 candidates
= splice_viable (candidates
);
2451 cand
= tourney (candidates
);
2455 cp_error ("call of `(%T) (%A)' is ambiguous", TREE_TYPE (obj
), args
);
2456 print_z_candidates (candidates
);
2457 return error_mark_node
;
2460 if (DECL_NAME (cand
->fn
) == ansi_opname
[CALL_EXPR
])
2461 return build_over_call (cand
, mem_args
, LOOKUP_NORMAL
);
2463 obj
= convert_like (TREE_VEC_ELT (cand
->convs
, 0), obj
);
2466 return build_function_call (obj
, args
);
2470 op_error (code
, code2
, arg1
, arg2
, arg3
, problem
)
2471 enum tree_code code
, code2
;
2472 tree arg1
, arg2
, arg3
;
2473 const char *problem
;
2476 = (code
== MODIFY_EXPR
? assignop_tab
[code2
] : opname_tab
[code
]);
2481 cp_error ("%s for `%T ? %T : %T'", problem
,
2482 error_type (arg1
), error_type (arg2
), error_type (arg3
));
2484 case POSTINCREMENT_EXPR
:
2485 case POSTDECREMENT_EXPR
:
2486 cp_error ("%s for `%T%s'", problem
, error_type (arg1
), opname
);
2489 cp_error ("%s for `%T[%T]'", problem
,
2490 error_type (arg1
), error_type (arg2
));
2494 cp_error ("%s for `%T %s %T'", problem
,
2495 error_type (arg1
), opname
, error_type (arg2
));
2497 cp_error ("%s for `%s%T'", problem
, opname
, error_type (arg1
));
2502 build_new_op (code
, flags
, arg1
, arg2
, arg3
)
2503 enum tree_code code
;
2505 tree arg1
, arg2
, arg3
;
2507 struct z_candidate
*candidates
= 0, *cand
;
2508 tree fns
, mem_arglist
= NULL_TREE
, arglist
, fnname
;
2509 enum tree_code code2
= NOP_EXPR
;
2510 tree templates
= NULL_TREE
;
2513 if (arg1
== error_mark_node
2514 || arg2
== error_mark_node
2515 || arg3
== error_mark_node
)
2516 return error_mark_node
;
2518 /* This can happen if a template takes all non-type parameters, e.g.
2519 undeclared_template<1, 5, 72>a; */
2520 if (code
== LT_EXPR
&& TREE_CODE (arg1
) == TEMPLATE_DECL
)
2522 cp_error ("`%D' must be declared before use", arg1
);
2523 return error_mark_node
;
2526 if (code
== MODIFY_EXPR
)
2528 code2
= TREE_CODE (arg3
);
2530 fnname
= ansi_assopname
[code2
];
2533 fnname
= ansi_opname
[code
];
2539 case VEC_DELETE_EXPR
:
2541 /* Use build_op_new_call and build_op_delete_call instead. */
2542 my_friendly_abort (981018);
2545 return build_object_call (arg1
, arg2
);
2551 /* The comma operator can have void args. */
2552 if (TREE_CODE (arg1
) == OFFSET_REF
)
2553 arg1
= resolve_offset_ref (arg1
);
2554 if (arg2
&& TREE_CODE (arg2
) == OFFSET_REF
)
2555 arg2
= resolve_offset_ref (arg2
);
2556 if (arg3
&& TREE_CODE (arg3
) == OFFSET_REF
)
2557 arg3
= resolve_offset_ref (arg3
);
2559 if (code
== COND_EXPR
)
2561 if (arg2
== NULL_TREE
2562 || TREE_CODE (TREE_TYPE (arg2
)) == VOID_TYPE
2563 || TREE_CODE (TREE_TYPE (arg3
)) == VOID_TYPE
2564 || (! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))
2565 && ! IS_OVERLOAD_TYPE (TREE_TYPE (arg3
))))
2568 else if (! IS_OVERLOAD_TYPE (TREE_TYPE (arg1
))
2569 && (! arg2
|| ! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))))
2572 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
2573 arg2
= integer_zero_node
;
2576 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, scratch_tree_cons
2577 (NULL_TREE
, arg2
, build_scratch_list (NULL_TREE
, arg3
)));
2579 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, build_scratch_list (NULL_TREE
, arg2
));
2581 arglist
= build_scratch_list (NULL_TREE
, arg1
);
2583 fns
= lookup_function_nonclass (fnname
, arglist
);
2585 if (fns
&& TREE_CODE (fns
) == TREE_LIST
)
2586 fns
= TREE_VALUE (fns
);
2587 for (; fns
; fns
= OVL_NEXT (fns
))
2589 tree fn
= OVL_CURRENT (fns
);
2590 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2592 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2594 = add_template_candidate (candidates
, fn
, NULL_TREE
,
2595 arglist
, TREE_TYPE (fnname
),
2596 flags
, DEDUCE_CALL
);
2599 candidates
= add_function_candidate (candidates
, fn
, arglist
, flags
);
2602 if (IS_AGGR_TYPE (TREE_TYPE (arg1
)))
2604 fns
= lookup_fnfields (TYPE_BINFO (TREE_TYPE (arg1
)), fnname
, 1);
2605 if (fns
== error_mark_node
)
2613 tree basetype
= TREE_PURPOSE (fns
);
2614 mem_arglist
= scratch_tree_cons (NULL_TREE
, build_this (arg1
), TREE_CHAIN (arglist
));
2615 for (fns
= TREE_VALUE (fns
); fns
; fns
= OVL_NEXT (fns
))
2617 tree fn
= OVL_CURRENT (fns
);
2620 if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
2621 this_arglist
= mem_arglist
;
2623 this_arglist
= arglist
;
2625 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2627 /* A member template. */
2628 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2630 = add_template_candidate (candidates
, fn
, NULL_TREE
,
2631 this_arglist
, TREE_TYPE (fnname
),
2632 flags
, DEDUCE_CALL
);
2635 candidates
= add_function_candidate
2636 (candidates
, fn
, this_arglist
, flags
);
2639 candidates
->basetype_path
= basetype
;
2646 /* Rearrange the arguments for ?: so that add_builtin_candidate only has
2647 to know about two args; a builtin candidate will always have a first
2648 parameter of type bool. We'll handle that in
2649 build_builtin_candidate. */
2650 if (code
== COND_EXPR
)
2660 args
[2] = NULL_TREE
;
2663 candidates
= add_builtin_candidates
2664 (candidates
, code
, code2
, fnname
, args
, flags
);
2667 if (! any_viable (candidates
))
2671 case POSTINCREMENT_EXPR
:
2672 case POSTDECREMENT_EXPR
:
2673 /* Look for an `operator++ (int)'. If they didn't have
2674 one, then we fall back to the old way of doing things. */
2675 if (flags
& LOOKUP_COMPLAIN
)
2676 cp_pedwarn ("no `%D (int)' declared for postfix `%s', trying prefix operator instead",
2677 fnname
, opname_tab
[code
]);
2678 if (code
== POSTINCREMENT_EXPR
)
2679 code
= PREINCREMENT_EXPR
;
2681 code
= PREDECREMENT_EXPR
;
2682 return build_new_op (code
, flags
, arg1
, NULL_TREE
, NULL_TREE
);
2684 /* The caller will deal with these. */
2693 if (flags
& LOOKUP_COMPLAIN
)
2695 op_error (code
, code2
, arg1
, arg2
, arg3
, "no match");
2696 print_z_candidates (candidates
);
2698 return error_mark_node
;
2700 candidates
= splice_viable (candidates
);
2701 cand
= tourney (candidates
);
2705 if (flags
& LOOKUP_COMPLAIN
)
2707 op_error (code
, code2
, arg1
, arg2
, arg3
, "ambiguous overload");
2708 print_z_candidates (candidates
);
2710 return error_mark_node
;
2713 if (TREE_CODE (cand
->fn
) == FUNCTION_DECL
)
2715 extern int warn_synth
;
2717 && fnname
== ansi_opname
[MODIFY_EXPR
]
2718 && DECL_ARTIFICIAL (cand
->fn
)
2720 && ! candidates
->next
->next
)
2722 cp_warning ("using synthesized `%#D' for copy assignment",
2724 cp_warning_at (" where cfront would use `%#D'",
2726 ? candidates
->next
->fn
2730 /* Pedantically, normal function declarations are never considered
2731 to refer to template instantiations, so we only do this with
2733 if (flag_guiding_decls
&& templates
&& ! cand
->template
2734 && ! DECL_INITIAL (cand
->fn
)
2735 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
2736 add_maybe_template (cand
->fn
, templates
);
2738 return build_over_call
2740 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
2741 ? mem_arglist
: arglist
,
2745 /* Check for comparison of different enum types. */
2754 if (TREE_CODE (TREE_TYPE (arg1
)) == ENUMERAL_TYPE
2755 && TREE_CODE (TREE_TYPE (arg2
)) == ENUMERAL_TYPE
2756 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg1
))
2757 != TYPE_MAIN_VARIANT (TREE_TYPE (arg2
))))
2759 cp_warning ("comparison between `%#T' and `%#T'",
2760 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
2767 /* We need to strip any leading REF_BIND so that bitfields don't cause
2768 errors. This should not remove any important conversions, because
2769 builtins don't apply to class objects directly. */
2770 conv
= TREE_VEC_ELT (cand
->convs
, 0);
2771 if (TREE_CODE (conv
) == REF_BIND
)
2772 conv
= TREE_OPERAND (conv
, 0);
2773 arg1
= convert_like (conv
, arg1
);
2775 arg2
= convert_like (TREE_VEC_ELT (cand
->convs
, 1), arg2
);
2777 arg3
= convert_like (TREE_VEC_ELT (cand
->convs
, 2), arg3
);
2783 return build_modify_expr (arg1
, code2
, arg2
);
2786 return build_indirect_ref (arg1
, "unary *");
2791 case TRUNC_DIV_EXPR
:
2802 case TRUNC_MOD_EXPR
:
2806 case TRUTH_ANDIF_EXPR
:
2807 case TRUTH_ORIF_EXPR
:
2808 return build_binary_op_nodefault (code
, arg1
, arg2
, code
);
2813 case TRUTH_NOT_EXPR
:
2814 case PREINCREMENT_EXPR
:
2815 case POSTINCREMENT_EXPR
:
2816 case PREDECREMENT_EXPR
:
2817 case POSTDECREMENT_EXPR
:
2820 return build_unary_op (code
, arg1
, candidates
!= 0);
2823 return build_array_ref (arg1
, arg2
);
2826 return build_conditional_expr (arg1
, arg2
, arg3
);
2829 return build_m_component_ref
2830 (build_indirect_ref (arg1
, NULL_PTR
), arg2
);
2832 /* The caller will deal with these. */
2839 my_friendly_abort (367);
2844 /* Build up a call to operator new. This has to be handled differently
2845 from other operators in the way lookup is handled; first members are
2846 considered, then globals. CODE is either NEW_EXPR or VEC_NEW_EXPR.
2847 TYPE is the type to be created. ARGS are any new-placement args.
2848 FLAGS are the usual overloading flags. */
2851 build_op_new_call (code
, type
, args
, flags
)
2852 enum tree_code code
;
2856 tree fnname
= ansi_opname
[code
];
2858 if (IS_AGGR_TYPE (type
) && ! (flags
& LOOKUP_GLOBAL
)
2859 && (TYPE_GETS_NEW (type
) & (1 << (code
== VEC_NEW_EXPR
))))
2861 return build_method_call (build_dummy_object (type
),
2862 fnname
, args
, NULL_TREE
, flags
);
2865 return build_new_function_call
2866 (lookup_function_nonclass (fnname
, args
), args
);
2869 /* Build a call to operator delete. This has to be handled very specially,
2870 because the restrictions on what signatures match are different from all
2871 other call instances. For a normal delete, only a delete taking (void *)
2872 or (void *, size_t) is accepted. For a placement delete, only an exact
2873 match with the placement new is accepted.
2875 CODE is either DELETE_EXPR or VEC_DELETE_EXPR.
2876 ADDR is the pointer to be deleted. For placement delete, it is also
2877 used to determine what the corresponding new looked like.
2878 SIZE is the size of the memory block to be deleted.
2879 FLAGS are the usual overloading flags.
2880 PLACEMENT is the corresponding placement new call, or 0. */
2883 build_op_delete_call (code
, addr
, size
, flags
, placement
)
2884 enum tree_code code
;
2885 tree addr
, size
, placement
;
2888 tree fn
, fns
, fnname
, fntype
, argtypes
, args
, type
;
2890 if (addr
== error_mark_node
)
2891 return error_mark_node
;
2893 type
= TREE_TYPE (TREE_TYPE (addr
));
2894 fnname
= ansi_opname
[code
];
2896 if (IS_AGGR_TYPE (type
) && ! (flags
& LOOKUP_GLOBAL
))
2899 If the result of the lookup is ambiguous or inaccessible, or if
2900 the lookup selects a placement deallocation function, the
2901 program is ill-formed.
2903 Therefore, we ask lookup_fnfields to complain ambout ambiguity. */
2905 fns
= lookup_fnfields (TYPE_BINFO (type
), fnname
, 1);
2906 if (fns
== error_mark_node
)
2907 return error_mark_node
;
2912 if (fns
== NULL_TREE
)
2913 fns
= lookup_name_nonclass (fnname
);
2917 /* placement is a CALL_EXPR around an ADDR_EXPR around a function. */
2919 /* Extract the function. */
2920 argtypes
= TREE_OPERAND (TREE_OPERAND (placement
, 0), 0);
2921 /* Then the second parm type. */
2922 argtypes
= TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (argtypes
)));
2924 /* Also the second argument. */
2925 args
= TREE_CHAIN (TREE_OPERAND (placement
, 1));
2929 /* First try it without the size argument. */
2930 argtypes
= void_list_node
;
2934 argtypes
= tree_cons (NULL_TREE
, ptr_type_node
, argtypes
);
2935 fntype
= build_function_type (void_type_node
, argtypes
);
2937 /* Strip const and volatile from addr. */
2938 if (type
!= TYPE_MAIN_VARIANT (type
))
2939 addr
= cp_convert (build_pointer_type (TYPE_MAIN_VARIANT (type
)), addr
);
2941 fn
= instantiate_type (fntype
, fns
, 0);
2943 if (fn
!= error_mark_node
)
2945 if (TREE_CODE (fns
) == TREE_LIST
)
2946 /* Member functions. */
2947 enforce_access (TREE_PURPOSE (fns
), fn
);
2948 return build_function_call (fn
, expr_tree_cons (NULL_TREE
, addr
, args
));
2951 /* If we are doing placement delete we do nothing if we don't find a
2952 matching op delete. */
2956 /* Normal delete; now try to find a match including the size argument. */
2957 argtypes
= tree_cons (NULL_TREE
, ptr_type_node
,
2958 tree_cons (NULL_TREE
, sizetype
, void_list_node
));
2959 fntype
= build_function_type (void_type_node
, argtypes
);
2961 fn
= instantiate_type (fntype
, fns
, 0);
2963 if (fn
!= error_mark_node
)
2965 if (TREE_CODE (fns
) == TREE_LIST
)
2966 /* Member functions. */
2967 enforce_access (TREE_PURPOSE (fns
), fn
);
2968 return build_function_call
2969 (fn
, expr_tree_cons (NULL_TREE
, addr
,
2970 build_expr_list (NULL_TREE
, size
)));
2973 /* finish_function passes LOOKUP_SPECULATIVELY if we're in a
2974 destructor, in which case the error should be deferred
2975 until someone actually tries to delete one of these. */
2976 if (flags
& LOOKUP_SPECULATIVELY
)
2979 cp_error ("no suitable operator delete for `%T'", type
);
2980 return error_mark_node
;
2983 /* If the current scope isn't allowed to access DECL along
2984 BASETYPE_PATH, give an error. The most derived class in
2985 BASETYPE_PATH is the one used to qualify DECL. */
2988 enforce_access (basetype_path
, decl
)
2994 accessible
= accessible_p (basetype_path
, decl
);
2997 if (TREE_PRIVATE (decl
))
2998 cp_error_at ("`%+#D' is private", decl
);
2999 else if (TREE_PROTECTED (decl
))
3000 cp_error_at ("`%+#D' is protected", decl
);
3002 cp_error_at ("`%+#D' is inaccessible", decl
);
3003 cp_error ("within this context");
3010 /* Perform the conversions in CONVS on the expression EXPR. */
3013 convert_like (convs
, expr
)
3016 if (ICS_BAD_FLAG (convs
)
3017 && TREE_CODE (convs
) != USER_CONV
3018 && TREE_CODE (convs
) != AMBIG_CONV
)
3021 for (; t
; t
= TREE_OPERAND (t
, 0))
3023 if (TREE_CODE (t
) == USER_CONV
)
3025 expr
= convert_like (t
, expr
);
3028 else if (TREE_CODE (t
) == AMBIG_CONV
)
3029 return convert_like (t
, expr
);
3030 else if (TREE_CODE (t
) == IDENTITY_CONV
)
3033 return convert_for_initialization
3034 (NULL_TREE
, TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
,
3035 "conversion", NULL_TREE
, 0);
3038 switch (TREE_CODE (convs
))
3042 struct z_candidate
*cand
3043 = WRAPPER_PTR (TREE_OPERAND (convs
, 1));
3047 if (DECL_CONSTRUCTOR_P (fn
))
3049 tree t
= build_int_2 (0, 0);
3050 TREE_TYPE (t
) = build_pointer_type (DECL_CONTEXT (fn
));
3052 args
= build_scratch_list (NULL_TREE
, expr
);
3053 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3054 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
3055 args
= scratch_tree_cons (NULL_TREE
, t
, args
);
3058 args
= build_this (expr
);
3059 expr
= build_over_call (cand
, args
, LOOKUP_NORMAL
);
3061 /* If this is a constructor or a function returning an aggr type,
3062 we need to build up a TARGET_EXPR. */
3063 if (DECL_CONSTRUCTOR_P (fn
))
3064 expr
= build_cplus_new (TREE_TYPE (convs
), expr
);
3069 if (type_unknown_p (expr
))
3070 expr
= instantiate_type (TREE_TYPE (convs
), expr
, 1);
3071 if (TREE_READONLY_DECL_P (expr
))
3072 expr
= decl_constant_value (expr
);
3075 /* Call build_user_type_conversion again for the error. */
3076 return build_user_type_conversion
3077 (TREE_TYPE (convs
), TREE_OPERAND (convs
, 0), LOOKUP_NORMAL
);
3083 expr
= convert_like (TREE_OPERAND (convs
, 0), expr
);
3084 if (expr
== error_mark_node
)
3085 return error_mark_node
;
3087 switch (TREE_CODE (convs
))
3090 if (! IS_AGGR_TYPE (TREE_TYPE (convs
)))
3092 /* else fall through */
3095 tree cvt_expr
= build_user_type_conversion
3096 (TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
);
3099 /* This can occur if, for example, the EXPR has incomplete
3100 type. We can't check for that before attempting the
3101 conversion because the type might be an incomplete
3102 array type, which is OK if some constructor for the
3103 destination type takes a pointer argument. */
3104 if (TYPE_SIZE (TREE_TYPE (expr
)) == 0)
3106 if (same_type_p (TREE_TYPE (expr
), TREE_TYPE (convs
)))
3107 incomplete_type_error (expr
, TREE_TYPE (expr
));
3109 cp_error ("could not convert `%E' (with incomplete type `%T') to `%T'",
3110 expr
, TREE_TYPE (expr
), TREE_TYPE (convs
));
3113 cp_error ("could not convert `%E' to `%T'",
3114 expr
, TREE_TYPE (convs
));
3115 return error_mark_node
;
3121 return convert_to_reference
3122 (TREE_TYPE (convs
), expr
,
3123 CONV_IMPLICIT
, LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
,
3126 return decay_conversion (expr
);
3129 /* Warn about deprecated conversion if appropriate. */
3130 string_conv_p (TREE_TYPE (convs
), expr
, 1);
3136 return ocp_convert (TREE_TYPE (convs
), expr
, CONV_IMPLICIT
,
3137 LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
);
3140 /* ARG is being passed to a varargs function. Perform any conversions
3141 required. Return the converted value. */
3144 convert_arg_to_ellipsis (arg
)
3147 if (TREE_CODE (TREE_TYPE (arg
)) == REAL_TYPE
3148 && (TYPE_PRECISION (TREE_TYPE (arg
))
3149 < TYPE_PRECISION (double_type_node
)))
3150 /* Convert `float' to `double'. */
3151 arg
= cp_convert (double_type_node
, arg
);
3152 else if (IS_AGGR_TYPE (TREE_TYPE (arg
))
3153 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (arg
)))
3154 cp_warning ("cannot pass objects of type `%T' through `...'",
3157 /* Convert `short' and `char' to full-size `int'. */
3158 arg
= default_conversion (arg
);
3160 arg
= require_complete_type (arg
);
3165 /* ARG is a default argument expression being passed to a parameter of
3166 the indicated TYPE, which is a parameter to FN. Do any required
3167 conversions. Return the converted value. */
3170 convert_default_arg (type
, arg
, fn
)
3175 if (fn
&& DECL_TEMPLATE_INFO (fn
))
3177 /* This default argument came from a template. Instantiate the
3178 default argument here, not in tsubst. In the case of
3187 we must be careful to do name lookup in the scope of S<T>,
3188 rather than in the current class. */
3189 if (DECL_CLASS_SCOPE_P (fn
))
3190 pushclass (DECL_REAL_CONTEXT (fn
), 2);
3192 arg
= tsubst_expr (arg
, DECL_TI_ARGS (fn
), /*complain=*/1, NULL_TREE
);
3194 if (DECL_CLASS_SCOPE_P (fn
))
3197 /* Make sure the default argument is reasonable. */
3198 arg
= check_default_argument (type
, arg
);
3201 arg
= break_out_target_exprs (arg
);
3203 if (TREE_CODE (arg
) == CONSTRUCTOR
)
3205 arg
= digest_init (type
, arg
, 0);
3206 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
3207 "default argument", 0, 0);
3211 /* This could get clobbered by the following call. */
3212 if (TREE_HAS_CONSTRUCTOR (arg
))
3213 arg
= copy_node (arg
);
3215 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
3216 "default argument", 0, 0);
3217 #ifdef PROMOTE_PROTOTYPES
3218 if ((TREE_CODE (type
) == INTEGER_TYPE
3219 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3220 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
3221 arg
= default_conversion (arg
);
3229 build_over_call (cand
, args
, flags
)
3230 struct z_candidate
*cand
;
3235 tree convs
= cand
->convs
;
3236 tree converted_args
= NULL_TREE
;
3237 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
3238 tree conv
, arg
, val
;
3242 /* Give any warnings we noticed during overload resolution. */
3244 for (val
= cand
->warnings
; val
; val
= TREE_CHAIN (val
))
3245 joust (cand
, WRAPPER_PTR (TREE_VALUE (val
)), 1);
3247 if (DECL_FUNCTION_MEMBER_P (fn
))
3248 enforce_access (cand
->basetype_path
, fn
);
3250 if (args
&& TREE_CODE (args
) != TREE_LIST
)
3251 args
= build_scratch_list (NULL_TREE
, args
);
3254 /* The implicit parameters to a constructor are not considered by overload
3255 resolution, and must be of the proper type. */
3256 if (DECL_CONSTRUCTOR_P (fn
))
3258 converted_args
= expr_tree_cons (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
3259 arg
= TREE_CHAIN (arg
);
3260 parm
= TREE_CHAIN (parm
);
3261 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3263 converted_args
= expr_tree_cons
3264 (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
3265 arg
= TREE_CHAIN (arg
);
3266 parm
= TREE_CHAIN (parm
);
3269 /* Bypass access control for 'this' parameter. */
3270 else if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
3272 tree parmtype
= TREE_VALUE (parm
);
3273 tree argtype
= TREE_TYPE (TREE_VALUE (arg
));
3275 if (ICS_BAD_FLAG (TREE_VEC_ELT (convs
, i
)))
3276 cp_pedwarn ("passing `%T' as `this' argument of `%#D' discards qualifiers",
3277 TREE_TYPE (argtype
), fn
);
3279 /* [class.mfct.nonstatic]: If a nonstatic member function of a class
3280 X is called for an object that is not of type X, or of a type
3281 derived from X, the behavior is undefined.
3283 So we can assume that anything passed as 'this' is non-null, and
3284 optimize accordingly. */
3285 if (TREE_CODE (parmtype
) == POINTER_TYPE
)
3286 t
= convert_pointer_to_real (TREE_TYPE (parmtype
), TREE_VALUE (arg
));
3288 /* This happens with signatures. */
3289 t
= convert_force (parmtype
, TREE_VALUE (arg
), CONV_C_CAST
);
3290 converted_args
= expr_tree_cons (NULL_TREE
, t
, converted_args
);
3291 parm
= TREE_CHAIN (parm
);
3292 arg
= TREE_CHAIN (arg
);
3298 parm
= TREE_CHAIN (parm
), arg
= TREE_CHAIN (arg
), ++i
)
3300 tree type
= TREE_VALUE (parm
);
3302 conv
= TREE_VEC_ELT (convs
, i
);
3303 if (ICS_BAD_FLAG (conv
))
3306 val
= TREE_VALUE (arg
);
3308 for (; t
; t
= TREE_OPERAND (t
, 0))
3310 if (TREE_CODE (t
) == USER_CONV
3311 || TREE_CODE (t
) == AMBIG_CONV
)
3313 val
= convert_like (t
, val
);
3316 else if (TREE_CODE (t
) == IDENTITY_CONV
)
3319 val
= convert_for_initialization
3320 (NULL_TREE
, type
, val
, LOOKUP_NORMAL
,
3321 "argument passing", fn
, i
- is_method
);
3325 /* Issue warnings about peculiar, but legal, uses of NULL. */
3326 if (ARITHMETIC_TYPE_P (TREE_VALUE (parm
))
3327 && TREE_VALUE (arg
) == null_node
)
3328 cp_warning ("converting NULL to non-pointer type");
3330 val
= convert_like (conv
, TREE_VALUE (arg
));
3333 #ifdef PROMOTE_PROTOTYPES
3334 if ((TREE_CODE (type
) == INTEGER_TYPE
3335 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3336 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
3337 val
= default_conversion (val
);
3339 converted_args
= expr_tree_cons (NULL_TREE
, val
, converted_args
);
3342 /* Default arguments */
3343 for (; parm
&& parm
!= void_list_node
; parm
= TREE_CHAIN (parm
))
3345 = expr_tree_cons (NULL_TREE
,
3346 convert_default_arg (TREE_VALUE (parm
),
3347 TREE_PURPOSE (parm
),
3352 for (; arg
; arg
= TREE_CHAIN (arg
))
3354 = expr_tree_cons (NULL_TREE
,
3355 convert_arg_to_ellipsis (TREE_VALUE (arg
)),
3358 converted_args
= nreverse (converted_args
);
3360 if (warn_format
&& (DECL_NAME (fn
) || DECL_ASSEMBLER_NAME (fn
)))
3361 check_function_format (DECL_NAME (fn
), DECL_ASSEMBLER_NAME (fn
),
3364 /* Avoid actually calling copy constructors and copy assignment operators,
3367 if (! flag_elide_constructors
)
3368 /* Do things the hard way. */;
3369 else if (DECL_CONSTRUCTOR_P (fn
)
3370 && TREE_VEC_LENGTH (convs
) == 1
3371 && copy_args_p (fn
))
3374 arg
= TREE_CHAIN (converted_args
);
3375 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3376 arg
= TREE_CHAIN (arg
);
3377 arg
= TREE_VALUE (arg
);
3379 /* Pull out the real argument, disregarding const-correctness. */
3381 while (TREE_CODE (targ
) == NOP_EXPR
3382 || TREE_CODE (targ
) == NON_LVALUE_EXPR
3383 || TREE_CODE (targ
) == CONVERT_EXPR
)
3384 targ
= TREE_OPERAND (targ
, 0);
3385 if (TREE_CODE (targ
) == ADDR_EXPR
)
3387 targ
= TREE_OPERAND (targ
, 0);
3388 if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg
))),
3389 TYPE_MAIN_VARIANT (TREE_TYPE (targ
))))
3398 arg
= build_indirect_ref (arg
, 0);
3400 /* [class.copy]: the copy constructor is implicitly defined even if
3401 the implementation elided its use. */
3402 if (TYPE_HAS_COMPLEX_INIT_REF (DECL_CONTEXT (fn
)))
3405 /* If we're creating a temp and we already have one, don't create a
3406 new one. If we're not creating a temp but we get one, use
3407 INIT_EXPR to collapse the temp into our target. Otherwise, if the
3408 ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
3409 temp or an INIT_EXPR otherwise. */
3410 if (integer_zerop (TREE_VALUE (args
)))
3412 if (! real_lvalue_p (arg
))
3414 else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
3416 val
= build_decl (VAR_DECL
, NULL_TREE
, DECL_CONTEXT (fn
));
3417 val
= build (TARGET_EXPR
, DECL_CONTEXT (fn
), val
, arg
, 0, 0);
3418 TREE_SIDE_EFFECTS (val
) = 1;
3422 else if (! real_lvalue_p (arg
)
3423 || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
3425 tree to
= stabilize_reference
3426 (build_indirect_ref (TREE_VALUE (args
), 0));
3428 /* Don't copy the padding byte; it might not have been allocated
3429 if to is a base subobject. */
3430 if (is_empty_class (DECL_CLASS_CONTEXT (fn
)))
3431 return build_unary_op
3432 (ADDR_EXPR
, build (COMPOUND_EXPR
, TREE_TYPE (to
),
3433 cp_convert (void_type_node
, arg
), to
),
3436 val
= build (INIT_EXPR
, DECL_CONTEXT (fn
), to
, arg
);
3437 TREE_SIDE_EFFECTS (val
) = 1;
3438 return build_unary_op (ADDR_EXPR
, val
, 0);
3441 else if (DECL_NAME (fn
) == ansi_opname
[MODIFY_EXPR
]
3443 && TYPE_HAS_TRIVIAL_ASSIGN_REF (DECL_CLASS_CONTEXT (fn
)))
3445 tree to
= stabilize_reference
3446 (build_indirect_ref (TREE_VALUE (converted_args
), 0));
3448 arg
= build_indirect_ref (TREE_VALUE (TREE_CHAIN (converted_args
)), 0);
3450 /* Don't copy the padding byte; it might not have been allocated
3451 if to is a base subobject. */
3452 if (is_empty_class (DECL_CLASS_CONTEXT (fn
)))
3453 return build (COMPOUND_EXPR
, TREE_TYPE (to
),
3454 cp_convert (void_type_node
, arg
), to
);
3456 val
= build (MODIFY_EXPR
, TREE_TYPE (to
), to
, arg
);
3457 TREE_SIDE_EFFECTS (val
) = 1;
3463 if (DECL_CLASS_SCOPE_P (fn
) && IS_SIGNATURE (DECL_CONTEXT (fn
)))
3464 return build_signature_method_call (fn
, converted_args
);
3465 else if (DECL_VINDEX (fn
) && (flags
& LOOKUP_NONVIRTUAL
) == 0)
3467 tree t
, *p
= &TREE_VALUE (converted_args
);
3468 tree binfo
= get_binfo
3469 (DECL_CONTEXT (fn
), TREE_TYPE (TREE_TYPE (*p
)), 0);
3470 *p
= convert_pointer_to_real (binfo
, *p
);
3471 if (TREE_SIDE_EFFECTS (*p
))
3472 *p
= save_expr (*p
);
3473 t
= build_pointer_type (TREE_TYPE (fn
));
3474 fn
= build_vfn_ref (p
, build_indirect_ref (*p
, 0), DECL_VINDEX (fn
));
3477 else if (DECL_INLINE (fn
))
3478 fn
= inline_conversion (fn
);
3480 fn
= build_addr_func (fn
);
3482 /* Recognize certain built-in functions so we can make tree-codes
3483 other than CALL_EXPR. We do this when it enables fold-const.c
3484 to do something useful. */
3486 if (TREE_CODE (fn
) == ADDR_EXPR
3487 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
3488 && DECL_BUILT_IN (TREE_OPERAND (fn
, 0)))
3489 switch (DECL_FUNCTION_CODE (TREE_OPERAND (fn
, 0)))
3494 if (converted_args
== 0)
3495 return integer_zero_node
;
3496 return build_unary_op (ABS_EXPR
, TREE_VALUE (converted_args
), 0);
3501 fn
= build_call (fn
, TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))), converted_args
);
3502 if (TREE_CODE (TREE_TYPE (fn
)) == VOID_TYPE
)
3504 fn
= require_complete_type (fn
);
3505 if (IS_AGGR_TYPE (TREE_TYPE (fn
)))
3506 fn
= build_cplus_new (TREE_TYPE (fn
), fn
);
3507 return convert_from_reference (fn
);
3511 build_new_method_call (instance
, name
, args
, basetype_path
, flags
)
3512 tree instance
, name
, args
, basetype_path
;
3515 struct z_candidate
*candidates
= 0, *cand
;
3516 tree explicit_targs
= NULL_TREE
;
3517 tree basetype
, mem_args
= NULL_TREE
, fns
, instance_ptr
;
3519 tree user_args
= args
;
3520 tree templates
= NULL_TREE
;
3521 int template_only
= 0;
3523 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
3525 explicit_targs
= TREE_OPERAND (name
, 1);
3526 name
= TREE_OPERAND (name
, 0);
3527 if (TREE_CODE (name
) == TEMPLATE_DECL
)
3528 name
= DECL_NAME (name
);
3532 /* If there is an extra argument for controlling virtual bases,
3533 remove it for error reporting. */
3534 if (flags
& LOOKUP_HAS_IN_CHARGE
)
3535 user_args
= TREE_CHAIN (args
);
3537 args
= resolve_args (args
);
3539 if (args
== error_mark_node
)
3540 return error_mark_node
;
3542 if (instance
== NULL_TREE
)
3543 basetype
= BINFO_TYPE (basetype_path
);
3546 if (TREE_CODE (instance
) == OFFSET_REF
)
3547 instance
= resolve_offset_ref (instance
);
3548 if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
3549 instance
= convert_from_reference (instance
);
3550 basetype
= TREE_TYPE (instance
);
3552 /* XXX this should be handled before we get here. */
3553 if (! IS_AGGR_TYPE (basetype
)
3554 && ! (TYPE_LANG_SPECIFIC (basetype
)
3555 && (IS_SIGNATURE_POINTER (basetype
)
3556 || IS_SIGNATURE_REFERENCE (basetype
))))
3558 if ((flags
& LOOKUP_COMPLAIN
) && basetype
!= error_mark_node
)
3559 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
3560 name
, instance
, basetype
);
3562 return error_mark_node
;
3565 /* If `instance' is a signature pointer/reference and `name' is
3566 not a constructor, we are calling a signature member function.
3567 In that case set the `basetype' to the signature type. */
3568 if ((IS_SIGNATURE_POINTER (basetype
)
3569 || IS_SIGNATURE_REFERENCE (basetype
))
3570 && TYPE_IDENTIFIER (basetype
) != name
)
3571 basetype
= SIGNATURE_TYPE (basetype
);
3574 if (basetype_path
== NULL_TREE
)
3575 basetype_path
= TYPE_BINFO (basetype
);
3579 instance_ptr
= build_this (instance
);
3581 if (! template_only
)
3583 /* XXX this should be handled before we get here. */
3584 fns
= build_field_call (basetype_path
, instance_ptr
, name
, args
);
3591 instance_ptr
= build_int_2 (0, 0);
3592 TREE_TYPE (instance_ptr
) = build_pointer_type (basetype
);
3596 = (name
== ctor_identifier
? constructor_name (basetype
) : name
);
3598 fns
= lookup_fnfields (basetype_path
, name
, 1);
3600 if (fns
== error_mark_node
)
3601 return error_mark_node
;
3604 tree fn
= TREE_VALUE (fns
);
3605 if (name
== ctor_identifier
&& TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
3606 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
3608 flags
|= LOOKUP_HAS_IN_CHARGE
;
3609 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
3611 mem_args
= scratch_tree_cons (NULL_TREE
, instance_ptr
, args
);
3612 for (; fn
; fn
= OVL_NEXT (fn
))
3614 tree t
= OVL_CURRENT (fn
);
3617 /* We can end up here for copy-init of same or base class. */
3618 if (name
== ctor_identifier
3619 && (flags
& LOOKUP_ONLYCONVERTING
)
3620 && DECL_NONCONVERTING_P (t
))
3622 if (TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)
3623 this_arglist
= mem_args
;
3625 this_arglist
= args
;
3627 if (TREE_CODE (t
) == TEMPLATE_DECL
)
3629 /* A member template. */
3630 templates
= scratch_tree_cons (NULL_TREE
, t
, templates
);
3632 add_template_candidate (candidates
, t
, explicit_targs
,
3634 TREE_TYPE (name
), flags
, DEDUCE_CALL
);
3636 else if (! template_only
)
3637 candidates
= add_function_candidate (candidates
, t
,
3638 this_arglist
, flags
);
3641 candidates
->basetype_path
= TREE_PURPOSE (fns
);
3645 if (! any_viable (candidates
))
3647 /* XXX will LOOKUP_SPECULATIVELY be needed when this is done? */
3648 if (flags
& LOOKUP_SPECULATIVELY
)
3650 if (TYPE_SIZE (basetype
) == 0)
3651 incomplete_type_error (instance_ptr
, basetype
);
3653 cp_error ("no matching function for call to `%T::%D (%A)%V'",
3654 basetype
, pretty_name
, user_args
,
3655 TREE_TYPE (TREE_TYPE (instance_ptr
)));
3656 print_z_candidates (candidates
);
3657 return error_mark_node
;
3659 candidates
= splice_viable (candidates
);
3660 cand
= tourney (candidates
);
3664 cp_error ("call of overloaded `%D(%A)' is ambiguous", pretty_name
,
3666 print_z_candidates (candidates
);
3667 return error_mark_node
;
3670 if (DECL_ABSTRACT_VIRTUAL_P (cand
->fn
)
3671 && instance
== current_class_ref
3672 && DECL_CONSTRUCTOR_P (current_function_decl
)
3673 && ! (flags
& LOOKUP_NONVIRTUAL
)
3674 && value_member (cand
->fn
, CLASSTYPE_ABSTRACT_VIRTUALS (basetype
)))
3675 cp_error ("abstract virtual `%#D' called from constructor", cand
->fn
);
3676 if (TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
3677 && is_dummy_object (instance_ptr
))
3678 cp_error ("cannot call member function `%D' without object", cand
->fn
);
3680 if (DECL_VINDEX (cand
->fn
) && ! (flags
& LOOKUP_NONVIRTUAL
)
3681 && ((instance
== current_class_ref
&& (dtor_label
|| ctor_label
))
3682 || resolves_to_fixed_type_p (instance
, 0)))
3683 flags
|= LOOKUP_NONVIRTUAL
;
3685 /* Pedantically, normal function declarations are never considered
3686 to refer to template instantiations, so we only do this with
3688 if (flag_guiding_decls
&& templates
&& ! cand
->template
3689 && ! DECL_INITIAL (cand
->fn
))
3690 add_maybe_template (cand
->fn
, templates
);
3692 return build_over_call
3694 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
? mem_args
: args
,
3698 /* Returns non-zero iff standard conversion sequence ICS1 is a proper
3699 subsequence of ICS2. */
3702 is_subseq (ics1
, ics2
)
3705 /* We can assume that a conversion of the same code
3706 between the same types indicates a subsequence since we only get
3707 here if the types we are converting from are the same. */
3709 while (TREE_CODE (ics1
) == RVALUE_CONV
3710 || TREE_CODE (ics1
) == LVALUE_CONV
)
3711 ics1
= TREE_OPERAND (ics1
, 0);
3715 while (TREE_CODE (ics2
) == RVALUE_CONV
3716 || TREE_CODE (ics2
) == LVALUE_CONV
)
3717 ics2
= TREE_OPERAND (ics2
, 0);
3719 if (TREE_CODE (ics2
) == USER_CONV
3720 || TREE_CODE (ics2
) == AMBIG_CONV
3721 || TREE_CODE (ics2
) == IDENTITY_CONV
)
3722 /* At this point, ICS1 cannot be a proper subsequence of
3723 ICS2. We can get a USER_CONV when we are comparing the
3724 second standard conversion sequence of two user conversion
3728 ics2
= TREE_OPERAND (ics2
, 0);
3730 if (TREE_CODE (ics2
) == TREE_CODE (ics1
)
3731 && same_type_p (TREE_TYPE (ics2
), TREE_TYPE (ics1
))
3732 && same_type_p (TREE_TYPE (TREE_OPERAND (ics2
, 0)),
3733 TREE_TYPE (TREE_OPERAND (ics1
, 0))))
3738 /* Returns non-zero iff DERIVED is derived from BASE. The inputs may
3739 be any _TYPE nodes. */
3742 is_properly_derived_from (derived
, base
)
3746 if (!IS_AGGR_TYPE_CODE (TREE_CODE (derived
))
3747 || !IS_AGGR_TYPE_CODE (TREE_CODE (base
)))
3750 /* We only allow proper derivation here. The DERIVED_FROM_P macro
3751 considers every class derived from itself. */
3752 return (!same_type_p (TYPE_MAIN_VARIANT (derived
),
3753 TYPE_MAIN_VARIANT (base
))
3754 && DERIVED_FROM_P (base
, derived
));
3757 /* We build the ICS for an implicit object parameter as a pointer
3758 conversion sequence. However, such a sequence should be compared
3759 as if it were a reference conversion sequence. If ICS is the
3760 implicit conversion sequence for an implicit object parameter,
3761 modify it accordingly. */
3764 maybe_handle_implicit_object (ics
)
3767 if (ICS_THIS_FLAG (*ics
))
3769 /* [over.match.funcs]
3771 For non-static member functions, the type of the
3772 implicit object parameter is "reference to cv X"
3773 where X is the class of which the function is a
3774 member and cv is the cv-qualification on the member
3775 function declaration. */
3777 if (TREE_CODE (t
) == QUAL_CONV
)
3778 t
= TREE_OPERAND (t
, 0);
3779 if (TREE_CODE (t
) == PTR_CONV
)
3780 t
= TREE_OPERAND (t
, 0);
3781 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
3782 t
= build_conv (REF_BIND
,
3783 build_reference_type (TREE_TYPE (TREE_TYPE (*ics
))),
3785 ICS_STD_RANK (t
) = ICS_STD_RANK (*ics
);
3790 /* If ICS is a REF_BIND, modify it appropriately, set TARGET_TYPE
3791 to the type the reference originally referred to, and return 1.
3792 Otherwise, return 0. */
3795 maybe_handle_ref_bind (ics
, target_type
)
3799 if (TREE_CODE (*ics
) == REF_BIND
)
3803 When a parameter of reference type binds directly
3804 (_dcl.init.ref_) to an argument expression, the implicit
3805 conversion sequence is the identity conversion, unless the
3806 argument expression has a type that is a derived class of the
3807 parameter type, in which case the implicit conversion
3808 sequence is a derived-to-base Conversion.
3810 If the parameter binds directly to the result of applying a
3811 conversion function to the argument expression, the implicit
3812 conversion sequence is a user-defined conversion sequence
3813 (_over.ics.user_), with the second standard conversion
3814 sequence either an identity conversion or, if the conversion
3815 function returns an entity of a type that is a derived class
3816 of the parameter type, a derived-to-base Conversion.
3818 When a parameter of reference type is not bound directly to
3819 an argument expression, the conversion sequence is the one
3820 required to convert the argument expression to the underlying
3821 type of the reference according to _over.best.ics_.
3822 Conceptually, this conversion sequence corresponds to
3823 copy-initializing a temporary of the underlying type with the
3824 argument expression. Any difference in top-level
3825 cv-qualification is subsumed by the initialization itself and
3826 does not constitute a conversion. */
3828 tree old_ics
= *ics
;
3830 *target_type
= TREE_TYPE (TREE_TYPE (*ics
));
3831 *ics
= TREE_OPERAND (*ics
, 0);
3832 if (TREE_CODE (*ics
) == IDENTITY_CONV
3833 && is_properly_derived_from (TREE_TYPE (*ics
), *target_type
))
3834 *ics
= build_conv (BASE_CONV
, *target_type
, *ics
);
3835 ICS_USER_FLAG (*ics
) = ICS_USER_FLAG (old_ics
);
3836 ICS_BAD_FLAG (*ics
) = ICS_BAD_FLAG (old_ics
);
3844 /* Compare two implicit conversion sequences according to the rules set out in
3845 [over.ics.rank]. Return values:
3847 1: ics1 is better than ics2
3848 -1: ics2 is better than ics1
3849 0: ics1 and ics2 are indistinguishable */
3852 compare_ics (ics1
, ics2
)
3859 tree deref_from_type1
= NULL_TREE
;
3860 tree deref_from_type2
= NULL_TREE
;
3861 tree deref_to_type1
= NULL_TREE
;
3862 tree deref_to_type2
= NULL_TREE
;
3864 /* REF_BINDING is non-zero if the result of the conversion sequence
3865 is a reference type. In that case TARGET_TYPE is the
3866 type referred to by the reference. */
3872 /* Handle implicit object parameters. */
3873 maybe_handle_implicit_object (&ics1
);
3874 maybe_handle_implicit_object (&ics2
);
3876 /* Handle reference parameters. */
3877 ref_binding1
= maybe_handle_ref_bind (&ics1
, &target_type1
);
3878 ref_binding2
= maybe_handle_ref_bind (&ics2
, &target_type2
);
3882 When comparing the basic forms of implicit conversion sequences (as
3883 defined in _over.best.ics_)
3885 --a standard conversion sequence (_over.ics.scs_) is a better
3886 conversion sequence than a user-defined conversion sequence
3887 or an ellipsis conversion sequence, and
3889 --a user-defined conversion sequence (_over.ics.user_) is a
3890 better conversion sequence than an ellipsis conversion sequence
3891 (_over.ics.ellipsis_). */
3892 if (ICS_RANK (ics1
) > ICS_RANK (ics2
))
3894 else if (ICS_RANK (ics1
) < ICS_RANK (ics2
))
3897 if (ICS_RANK (ics1
) == BAD_RANK
)
3899 /* Both ICS are bad. We try to make a decision based on what
3900 would have happenned if they'd been good. */
3901 if (ICS_USER_FLAG (ics1
) > ICS_USER_FLAG (ics2
)
3902 || ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
3904 else if (ICS_USER_FLAG (ics1
) < ICS_USER_FLAG (ics2
)
3905 || ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
3908 /* We couldn't make up our minds; try to figure it out below. */
3911 if (ICS_ELLIPSIS_FLAG (ics1
))
3912 /* Both conversions are ellipsis conversions. */
3915 /* User-defined conversion sequence U1 is a better conversion sequence
3916 than another user-defined conversion sequence U2 if they contain the
3917 same user-defined conversion operator or constructor and if the sec-
3918 ond standard conversion sequence of U1 is better than the second
3919 standard conversion sequence of U2. */
3921 if (ICS_USER_FLAG (ics1
))
3925 for (t1
= ics1
; TREE_CODE (t1
) != USER_CONV
; t1
= TREE_OPERAND (t1
, 0))
3926 if (TREE_CODE (t1
) == AMBIG_CONV
)
3928 for (t2
= ics2
; TREE_CODE (t2
) != USER_CONV
; t2
= TREE_OPERAND (t2
, 0))
3929 if (TREE_CODE (t2
) == AMBIG_CONV
)
3932 if (USER_CONV_FN (t1
) != USER_CONV_FN (t2
))
3935 /* We can just fall through here, after setting up
3936 FROM_TYPE1 and FROM_TYPE2. */
3937 from_type1
= TREE_TYPE (t1
);
3938 from_type2
= TREE_TYPE (t2
);
3942 /* We're dealing with two standard conversion sequences.
3946 Standard conversion sequence S1 is a better conversion
3947 sequence than standard conversion sequence S2 if
3949 --S1 is a proper subsequence of S2 (comparing the conversion
3950 sequences in the canonical form defined by _over.ics.scs_,
3951 excluding any Lvalue Transformation; the identity
3952 conversion sequence is considered to be a subsequence of
3953 any non-identity conversion sequence */
3956 while (TREE_CODE (from_type1
) != IDENTITY_CONV
)
3957 from_type1
= TREE_OPERAND (from_type1
, 0);
3958 from_type1
= TREE_TYPE (from_type1
);
3961 while (TREE_CODE (from_type2
) != IDENTITY_CONV
)
3962 from_type2
= TREE_OPERAND (from_type2
, 0);
3963 from_type2
= TREE_TYPE (from_type2
);
3966 if (same_type_p (from_type1
, from_type2
))
3968 if (is_subseq (ics1
, ics2
))
3970 if (is_subseq (ics2
, ics1
))
3973 /* Otherwise, one sequence cannot be a subsequence of the other; they
3974 don't start with the same type. This can happen when comparing the
3975 second standard conversion sequence in two user-defined conversion
3982 --the rank of S1 is better than the rank of S2 (by the rules
3985 Standard conversion sequences are ordered by their ranks: an Exact
3986 Match is a better conversion than a Promotion, which is a better
3987 conversion than a Conversion.
3989 Two conversion sequences with the same rank are indistinguishable
3990 unless one of the following rules applies:
3992 --A conversion that is not a conversion of a pointer, or pointer
3993 to member, to bool is better than another conversion that is such
3996 The ICS_STD_RANK automatically handles the pointer-to-bool rule,
3997 so that we do not have to check it explicitly. */
3998 if (ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
4000 else if (ICS_STD_RANK (ics2
) < ICS_STD_RANK (ics1
))
4003 to_type1
= TREE_TYPE (ics1
);
4004 to_type2
= TREE_TYPE (ics2
);
4006 if (TYPE_PTR_P (from_type1
)
4007 && TYPE_PTR_P (from_type2
)
4008 && TYPE_PTR_P (to_type1
)
4009 && TYPE_PTR_P (to_type2
))
4011 deref_from_type1
= TREE_TYPE (from_type1
);
4012 deref_from_type2
= TREE_TYPE (from_type2
);
4013 deref_to_type1
= TREE_TYPE (to_type1
);
4014 deref_to_type2
= TREE_TYPE (to_type2
);
4016 /* The rules for pointers to members A::* are just like the rules
4017 for pointers A*, except opposite: if B is derived from A then
4018 A::* converts to B::*, not vice versa. For that reason, we
4019 switch the from_ and to_ variables here. */
4020 else if (TYPE_PTRMEM_P (from_type1
)
4021 && TYPE_PTRMEM_P (from_type2
)
4022 && TYPE_PTRMEM_P (to_type1
)
4023 && TYPE_PTRMEM_P (to_type2
))
4025 deref_to_type1
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from_type1
));
4026 deref_to_type2
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from_type2
));
4027 deref_from_type1
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to_type1
));
4028 deref_from_type2
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to_type2
));
4030 else if (TYPE_PTRMEMFUNC_P (from_type1
)
4031 && TYPE_PTRMEMFUNC_P (from_type2
)
4032 && TYPE_PTRMEMFUNC_P (to_type1
)
4033 && TYPE_PTRMEMFUNC_P (to_type2
))
4035 deref_to_type1
= TYPE_PTRMEMFUNC_OBJECT_TYPE (from_type1
);
4036 deref_to_type2
= TYPE_PTRMEMFUNC_OBJECT_TYPE (from_type2
);
4037 deref_from_type1
= TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type1
);
4038 deref_from_type2
= TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type2
);
4041 if (deref_from_type1
!= NULL_TREE
4042 && IS_AGGR_TYPE_CODE (TREE_CODE (deref_from_type1
))
4043 && IS_AGGR_TYPE_CODE (TREE_CODE (deref_from_type2
)))
4045 /* This was one of the pointer or pointer-like conversions.
4049 --If class B is derived directly or indirectly from class A,
4050 conversion of B* to A* is better than conversion of B* to
4051 void*, and conversion of A* to void* is better than
4052 conversion of B* to void*. */
4053 if (TREE_CODE (deref_to_type1
) == VOID_TYPE
4054 && TREE_CODE (deref_to_type2
) == VOID_TYPE
)
4056 if (is_properly_derived_from (deref_from_type1
,
4059 else if (is_properly_derived_from (deref_from_type2
,
4063 else if (TREE_CODE (deref_to_type1
) == VOID_TYPE
4064 || TREE_CODE (deref_to_type2
) == VOID_TYPE
)
4066 if (same_type_p (deref_from_type1
, deref_from_type2
))
4068 if (TREE_CODE (deref_to_type2
) == VOID_TYPE
)
4070 if (is_properly_derived_from (deref_from_type1
,
4074 /* We know that DEREF_TO_TYPE1 is `void' here. */
4075 else if (is_properly_derived_from (deref_from_type1
,
4080 else if (IS_AGGR_TYPE_CODE (TREE_CODE (deref_to_type1
))
4081 && IS_AGGR_TYPE_CODE (TREE_CODE (deref_to_type2
)))
4085 --If class B is derived directly or indirectly from class A
4086 and class C is derived directly or indirectly from B,
4088 --conversion of C* to B* is better than conversion of C* to
4091 --conversion of B* to A* is better than conversion of C* to
4093 if (same_type_p (deref_from_type1
, deref_from_type2
))
4095 if (is_properly_derived_from (deref_to_type1
,
4098 else if (is_properly_derived_from (deref_to_type2
,
4102 else if (same_type_p (deref_to_type1
, deref_to_type2
))
4104 if (is_properly_derived_from (deref_from_type2
,
4107 else if (is_properly_derived_from (deref_from_type1
,
4113 else if (IS_AGGR_TYPE_CODE (TREE_CODE (from_type1
))
4114 && same_type_p (from_type1
, from_type2
))
4118 --binding of an expression of type C to a reference of type
4119 B& is better than binding an expression of type C to a
4120 reference of type A&
4122 --conversion of C to B is better than conversion of C to A, */
4123 if (is_properly_derived_from (from_type1
, to_type1
)
4124 && is_properly_derived_from (from_type1
, to_type2
))
4126 if (is_properly_derived_from (to_type1
, to_type2
))
4128 else if (is_properly_derived_from (to_type2
, to_type1
))
4132 else if (IS_AGGR_TYPE_CODE (TREE_CODE (to_type1
))
4133 && same_type_p (to_type1
, to_type2
))
4137 --binding of an expression of type B to a reference of type
4138 A& is better than binding an expression of type C to a
4139 reference of type A&,
4141 --onversion of B to A is better than conversion of C to A */
4142 if (is_properly_derived_from (from_type1
, to_type1
)
4143 && is_properly_derived_from (from_type2
, to_type1
))
4145 if (is_properly_derived_from (from_type2
, from_type1
))
4147 else if (is_properly_derived_from (from_type1
, from_type2
))
4154 --S1 and S2 differ only in their qualification conversion and yield
4155 similar types T1 and T2 (_conv.qual_), respectively, and the cv-
4156 qualification signature of type T1 is a proper subset of the cv-
4157 qualification signature of type T2 */
4158 if (TREE_CODE (ics1
) == QUAL_CONV
4159 && TREE_CODE (ics2
) == QUAL_CONV
4160 && same_type_p (from_type1
, from_type2
))
4161 return comp_cv_qual_signature (to_type1
, to_type2
);
4165 --S1 and S2 are reference bindings (_dcl.init.ref_), and the
4166 types to which the references refer are the same type except for
4167 top-level cv-qualifiers, and the type to which the reference
4168 initialized by S2 refers is more cv-qualified than the type to
4169 which the reference initialized by S1 refers */
4171 if (ref_binding1
&& ref_binding2
4172 && same_type_p (TYPE_MAIN_VARIANT (to_type1
),
4173 TYPE_MAIN_VARIANT (to_type2
)))
4174 return comp_cv_qualification (target_type2
, target_type1
);
4176 /* Neither conversion sequence is better than the other. */
4180 /* The source type for this standard conversion sequence. */
4186 for (;; t
= TREE_OPERAND (t
, 0))
4188 if (TREE_CODE (t
) == USER_CONV
4189 || TREE_CODE (t
) == AMBIG_CONV
4190 || TREE_CODE (t
) == IDENTITY_CONV
)
4191 return TREE_TYPE (t
);
4193 my_friendly_abort (1823);
4196 /* Note a warning about preferring WINNER to LOSER. We do this by storing
4197 a pointer to LOSER and re-running joust to produce the warning if WINNER
4198 is actually used. */
4201 add_warning (winner
, loser
)
4202 struct z_candidate
*winner
, *loser
;
4204 winner
->warnings
= expr_tree_cons (NULL_PTR
,
4205 build_expr_ptr_wrapper (loser
),
4209 /* Compare two candidates for overloading as described in
4210 [over.match.best]. Return values:
4212 1: cand1 is better than cand2
4213 -1: cand2 is better than cand1
4214 0: cand1 and cand2 are indistinguishable */
4217 joust (cand1
, cand2
, warn
)
4218 struct z_candidate
*cand1
, *cand2
;
4222 int i
, off1
= 0, off2
= 0, len
;
4224 /* Candidates that involve bad conversions are always worse than those
4226 if (cand1
->viable
> cand2
->viable
)
4228 if (cand1
->viable
< cand2
->viable
)
4231 /* If we have two pseudo-candidates for conversions to the same type,
4232 arbitrarily pick one. */
4233 if (TYPE_P (cand1
->fn
) && cand1
->fn
== cand2
->fn
)
4236 /* a viable function F1
4237 is defined to be a better function than another viable function F2 if
4238 for all arguments i, ICSi(F1) is not a worse conversion sequence than
4239 ICSi(F2), and then */
4241 /* for some argument j, ICSj(F1) is a better conversion sequence than
4244 /* For comparing static and non-static member functions, we ignore the
4245 implicit object parameter of the non-static function. The WP says to
4246 pretend that the static function has an object parm, but that won't
4247 work with operator overloading. */
4248 len
= TREE_VEC_LENGTH (cand1
->convs
);
4249 if (len
!= TREE_VEC_LENGTH (cand2
->convs
))
4251 if (DECL_STATIC_FUNCTION_P (cand1
->fn
)
4252 && ! DECL_STATIC_FUNCTION_P (cand2
->fn
))
4254 else if (! DECL_STATIC_FUNCTION_P (cand1
->fn
)
4255 && DECL_STATIC_FUNCTION_P (cand2
->fn
))
4261 my_friendly_abort (42);
4264 for (i
= 0; i
< len
; ++i
)
4266 tree t1
= TREE_VEC_ELT (cand1
->convs
, i
+off1
);
4267 tree t2
= TREE_VEC_ELT (cand2
->convs
, i
+off2
);
4268 int comp
= compare_ics (t1
, t2
);
4273 && ICS_RANK (t1
) + ICS_RANK (t2
) == STD_RANK
+ PROMO_RANK
4274 && TREE_CODE (t1
) == STD_CONV
4275 && TREE_CODE (t2
) == STD_CONV
4276 && TREE_CODE (TREE_TYPE (t1
)) == INTEGER_TYPE
4277 && TREE_CODE (TREE_TYPE (t2
)) == INTEGER_TYPE
4278 && (TYPE_PRECISION (TREE_TYPE (t1
))
4279 == TYPE_PRECISION (TREE_TYPE (t2
)))
4280 && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (t1
, 0)))
4281 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (t1
, 0)))
4284 tree type
= TREE_TYPE (TREE_OPERAND (t1
, 0));
4286 struct z_candidate
*w
, *l
;
4288 type1
= TREE_TYPE (t1
), type2
= TREE_TYPE (t2
),
4289 w
= cand1
, l
= cand2
;
4291 type1
= TREE_TYPE (t2
), type2
= TREE_TYPE (t1
),
4292 w
= cand2
, l
= cand1
;
4296 cp_warning ("passing `%T' chooses `%T' over `%T'",
4297 type
, type1
, type2
);
4298 cp_warning (" in call to `%D'", w
->fn
);
4304 if (winner
&& comp
!= winner
)
4313 /* warn about confusing overload resolution for user-defined conversions,
4314 either between a constructor and a conversion op, or between two
4316 if (winner
&& cand1
->second_conv
4317 && ((DECL_CONSTRUCTOR_P (cand1
->fn
)
4318 != DECL_CONSTRUCTOR_P (cand2
->fn
))
4319 /* Don't warn if the two conv ops convert to the same type... */
4320 || (! DECL_CONSTRUCTOR_P (cand1
->fn
)
4321 && ! same_type_p (TREE_TYPE (cand1
->second_conv
),
4322 TREE_TYPE (cand2
->second_conv
)))))
4324 int comp
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
4327 struct z_candidate
*w
, *l
;
4329 w
= cand1
, l
= cand2
;
4331 w
= cand2
, l
= cand1
;
4334 tree source
= source_type (TREE_VEC_ELT (w
->convs
, 0));
4335 if (! DECL_CONSTRUCTOR_P (w
->fn
))
4336 source
= TREE_TYPE (source
);
4337 cp_warning ("choosing `%D' over `%D'", w
->fn
, l
->fn
);
4338 cp_warning (" for conversion from `%T' to `%T'",
4339 source
, TREE_TYPE (w
->second_conv
));
4340 cp_warning (" because conversion sequence for the argument is better");
4351 F1 is a non-template function and F2 is a template function */
4353 if (! cand1
->template && cand2
->template)
4355 else if (cand1
->template && ! cand2
->template)
4357 else if (cand1
->template && cand2
->template)
4358 winner
= more_specialized
4359 (TI_TEMPLATE (cand1
->template), TI_TEMPLATE (cand2
->template),
4363 the context is an initialization by user-defined conversion (see
4364 _dcl.init_ and _over.match.user_) and the standard conversion
4365 sequence from the return type of F1 to the destination type (i.e.,
4366 the type of the entity being initialized) is a better conversion
4367 sequence than the standard conversion sequence from the return type
4368 of F2 to the destination type. */
4370 if (! winner
&& cand1
->second_conv
)
4371 winner
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
4373 /* If the built-in candidates are the same, arbitrarily pick one. */
4374 if (! winner
&& cand1
->fn
== cand2
->fn
4375 && TREE_CODE (cand1
->fn
) == IDENTIFIER_NODE
)
4377 for (i
= 0; i
< len
; ++i
)
4378 if (!same_type_p (TREE_TYPE (TREE_VEC_ELT (cand1
->convs
, i
)),
4379 TREE_TYPE (TREE_VEC_ELT (cand2
->convs
, i
))))
4381 if (i
== TREE_VEC_LENGTH (cand1
->convs
))
4384 /* Kludge around broken overloading rules whereby
4385 Integer a, b; test ? a : b; is ambiguous, since there's a builtin
4386 that takes references and another that takes values. */
4387 if (cand1
->fn
== ansi_opname
[COND_EXPR
])
4389 tree c1
= TREE_VEC_ELT (cand1
->convs
, 1);
4390 tree c2
= TREE_VEC_ELT (cand2
->convs
, 1);
4391 tree t1
= strip_top_quals (non_reference (TREE_TYPE (c1
)));
4392 tree t2
= strip_top_quals (non_reference (TREE_TYPE (c2
)));
4394 if (same_type_p (t1
, t2
))
4396 if (TREE_CODE (c1
) == REF_BIND
&& TREE_CODE (c2
) != REF_BIND
)
4398 if (TREE_CODE (c1
) != REF_BIND
&& TREE_CODE (c2
) == REF_BIND
)
4406 /* Extension: If the worst conversion for one candidate is worse than the
4407 worst conversion for the other, take the first. */
4408 if (! winner
&& ! pedantic
)
4410 int rank1
= IDENTITY_RANK
, rank2
= IDENTITY_RANK
;
4412 for (i
= 0; i
< len
; ++i
)
4414 if (ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
)) > rank1
)
4415 rank1
= ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
));
4416 if (ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
)) > rank2
)
4417 rank2
= ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
));
4429 /* Given a list of candidates for overloading, find the best one, if any.
4430 This algorithm has a worst case of O(2n) (winner is last), and a best
4431 case of O(n/2) (totally ambiguous); much better than a sorting
4434 static struct z_candidate
*
4435 tourney (candidates
)
4436 struct z_candidate
*candidates
;
4438 struct z_candidate
*champ
= candidates
, *challenger
;
4440 int champ_compared_to_predecessor
= 0;
4442 /* Walk through the list once, comparing each current champ to the next
4443 candidate, knocking out a candidate or two with each comparison. */
4445 for (challenger
= champ
->next
; challenger
; )
4447 fate
= joust (champ
, challenger
, 0);
4449 challenger
= challenger
->next
;
4454 champ
= challenger
->next
;
4457 champ_compared_to_predecessor
= 0;
4462 champ_compared_to_predecessor
= 1;
4465 challenger
= champ
->next
;
4469 /* Make sure the champ is better than all the candidates it hasn't yet
4470 been compared to. */
4472 for (challenger
= candidates
;
4474 && !(champ_compared_to_predecessor
&& challenger
->next
== champ
);
4475 challenger
= challenger
->next
)
4477 fate
= joust (champ
, challenger
, 0);
4486 can_convert (to
, from
)
4489 tree t
= implicit_conversion (to
, from
, NULL_TREE
, LOOKUP_NORMAL
);
4490 return (t
&& ! ICS_BAD_FLAG (t
));
4494 can_convert_arg (to
, from
, arg
)
4497 tree t
= implicit_conversion (to
, from
, arg
, LOOKUP_NORMAL
);
4498 return (t
&& ! ICS_BAD_FLAG (t
));