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 maybe_handle_ref_bind
PROTO((tree
*, tree
*));
91 static void maybe_handle_implicit_object
PROTO((tree
*));
92 static struct z_candidate
* add_candidate
PROTO((struct z_candidate
*,
94 static tree source_type
PROTO((tree
));
95 static void add_warning
PROTO((struct z_candidate
*, struct z_candidate
*));
98 build_vfield_ref (datum
, type
)
103 if (datum
== error_mark_node
)
104 return error_mark_node
;
106 if (TREE_CODE (TREE_TYPE (datum
)) == REFERENCE_TYPE
)
107 datum
= convert_from_reference (datum
);
109 if (! TYPE_USES_COMPLEX_INHERITANCE (type
))
110 rval
= build (COMPONENT_REF
, TREE_TYPE (CLASSTYPE_VFIELD (type
)),
111 datum
, CLASSTYPE_VFIELD (type
));
113 rval
= build_component_ref (datum
, DECL_NAME (CLASSTYPE_VFIELD (type
)), NULL_TREE
, 0);
118 /* Build a call to a member of an object. I.e., one that overloads
119 operator ()(), or is a pointer-to-function or pointer-to-method. */
122 build_field_call (basetype_path
, instance_ptr
, name
, parms
)
123 tree basetype_path
, instance_ptr
, name
, parms
;
125 tree field
, instance
;
127 if (name
== ctor_identifier
|| name
== dtor_identifier
)
130 /* Speed up the common case. */
131 if (instance_ptr
== current_class_ptr
132 && IDENTIFIER_CLASS_VALUE (name
) == NULL_TREE
)
135 field
= lookup_field (basetype_path
, name
, 1, 0);
137 if (field
== error_mark_node
|| field
== NULL_TREE
)
140 if (TREE_CODE (field
) == FIELD_DECL
|| TREE_CODE (field
) == VAR_DECL
)
142 /* If it's a field, try overloading operator (),
143 or calling if the field is a pointer-to-function. */
144 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
145 instance
= build_component_ref_1 (instance
, field
, 0);
147 if (instance
== error_mark_node
)
148 return error_mark_node
;
150 if (IS_AGGR_TYPE (TREE_TYPE (instance
)))
151 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
,
152 instance
, parms
, NULL_TREE
);
153 else if (TREE_CODE (TREE_TYPE (instance
)) == POINTER_TYPE
)
155 if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == FUNCTION_TYPE
)
156 return build_function_call (instance
, parms
);
157 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
)))
159 return build_function_call
160 (instance
, expr_tree_cons (NULL_TREE
, instance_ptr
, parms
));
168 find_scoped_type (type
, inner_name
, inner_types
)
169 tree type
, inner_name
, inner_types
;
171 tree tags
= CLASSTYPE_TAGS (type
);
175 /* The TREE_PURPOSE of an enum tag (which becomes a member of the
176 enclosing class) is set to the name for the enum type. So, if
177 inner_name is `bar', and we strike `baz' for `enum bar { baz }',
178 then this test will be true. */
179 if (TREE_PURPOSE (tags
) == inner_name
)
181 if (inner_types
== NULL_TREE
)
182 return TYPE_MAIN_DECL (TREE_VALUE (tags
));
183 return resolve_scope_to_name (TREE_VALUE (tags
), inner_types
);
185 tags
= TREE_CHAIN (tags
);
188 /* Look for a TYPE_DECL. */
189 for (tags
= TYPE_FIELDS (type
); tags
; tags
= TREE_CHAIN (tags
))
190 if (TREE_CODE (tags
) == TYPE_DECL
&& DECL_NAME (tags
) == inner_name
)
192 /* Code by raeburn. */
193 if (inner_types
== NULL_TREE
)
195 return resolve_scope_to_name (TREE_TYPE (tags
), inner_types
);
201 /* Resolve an expression NAME1::NAME2::...::NAMEn to
202 the name that names the above nested type. INNER_TYPES
203 is a chain of nested type names (held together by SCOPE_REFs);
204 OUTER_TYPE is the type we know to enclose INNER_TYPES.
205 Returns NULL_TREE if there is an error. */
208 resolve_scope_to_name (outer_type
, inner_stuff
)
209 tree outer_type
, inner_stuff
;
212 tree inner_name
, inner_type
;
214 if (outer_type
== NULL_TREE
&& current_class_type
!= NULL_TREE
)
216 /* We first try to look for a nesting in our current class context,
217 then try any enclosing classes. */
218 tree type
= current_class_type
;
220 while (type
&& (TREE_CODE (type
) == RECORD_TYPE
221 || TREE_CODE (type
) == UNION_TYPE
))
223 tree rval
= resolve_scope_to_name (type
, inner_stuff
);
225 if (rval
!= NULL_TREE
)
227 type
= DECL_CONTEXT (TYPE_MAIN_DECL (type
));
231 if (TREE_CODE (inner_stuff
) == SCOPE_REF
)
233 inner_name
= TREE_OPERAND (inner_stuff
, 0);
234 inner_type
= TREE_OPERAND (inner_stuff
, 1);
238 inner_name
= inner_stuff
;
239 inner_type
= NULL_TREE
;
242 if (outer_type
== NULL_TREE
)
245 /* If we have something that's already a type by itself,
247 if (IDENTIFIER_HAS_TYPE_VALUE (inner_name
))
250 return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name
),
255 x
= lookup_name (inner_name
, 0);
257 if (x
&& TREE_CODE (x
) == NAMESPACE_DECL
)
259 x
= lookup_namespace_name (x
, inner_type
);
265 if (! IS_AGGR_TYPE (outer_type
))
268 /* Look for member classes or enums. */
269 tmp
= find_scoped_type (outer_type
, inner_name
, inner_type
);
271 /* If it's not a type in this class, then go down into the
272 base classes and search there. */
273 if (! tmp
&& TYPE_BINFO (outer_type
))
275 tree binfos
= TYPE_BINFO_BASETYPES (outer_type
);
276 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
278 for (i
= 0; i
< n_baselinks
; i
++)
280 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
281 tmp
= resolve_scope_to_name (BINFO_TYPE (base_binfo
), inner_stuff
);
291 /* Returns nonzero iff the destructor name specified in NAME
292 (a BIT_NOT_EXPR) matches BASETYPE. The operand of NAME can take many
296 check_dtor_name (basetype
, name
)
299 name
= TREE_OPERAND (name
, 0);
301 /* Just accept something we've already complained about. */
302 if (name
== error_mark_node
)
305 if (TREE_CODE (name
) == TYPE_DECL
)
306 name
= TREE_TYPE (name
);
307 else if (TREE_CODE_CLASS (TREE_CODE (name
)) == 't')
309 else if (TREE_CODE (name
) == IDENTIFIER_NODE
)
311 if ((IS_AGGR_TYPE (basetype
) && name
== constructor_name (basetype
))
312 || (TREE_CODE (basetype
) == ENUMERAL_TYPE
313 && name
== TYPE_IDENTIFIER (basetype
)))
316 name
= get_type_value (name
);
319 my_friendly_abort (980605);
321 if (name
&& TYPE_MAIN_VARIANT (basetype
) == TYPE_MAIN_VARIANT (name
))
326 /* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'.
327 This is how virtual function calls are avoided. */
330 build_scoped_method_call (exp
, basetype
, name
, parms
)
331 tree exp
, basetype
, name
, parms
;
333 /* Because this syntactic form does not allow
334 a pointer to a base class to be `stolen',
335 we need not protect the derived->base conversion
338 @@ But we do have to check access privileges later. */
340 tree type
= TREE_TYPE (exp
);
342 if (type
== error_mark_node
343 || basetype
== error_mark_node
)
344 return error_mark_node
;
346 if (processing_template_decl
)
348 if (TREE_CODE (name
) == BIT_NOT_EXPR
349 && TREE_CODE (TREE_OPERAND (name
, 0)) == IDENTIFIER_NODE
)
351 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 0);
353 name
= build_min_nt (BIT_NOT_EXPR
, type
);
355 name
= build_min_nt (SCOPE_REF
, basetype
, name
);
356 return build_min_nt (METHOD_CALL_EXPR
, name
, exp
, parms
, NULL_TREE
);
359 if (TREE_CODE (type
) == REFERENCE_TYPE
)
360 type
= TREE_TYPE (type
);
362 if (TREE_CODE (basetype
) == TREE_VEC
)
365 basetype
= BINFO_TYPE (binfo
);
370 /* Check the destructor call syntax. */
371 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
373 /* We can get here if someone writes their destructor call like
374 `obj.NS::~T()'; this isn't really a scoped method call, so hand
376 if (TREE_CODE (basetype
) == NAMESPACE_DECL
)
377 return build_method_call (exp
, name
, parms
, NULL_TREE
, LOOKUP_NORMAL
);
379 if (! check_dtor_name (basetype
, name
))
380 cp_error ("qualified type `%T' does not match destructor name `~%T'",
381 basetype
, TREE_OPERAND (name
, 0));
383 /* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
384 that explicit ~int is caught in the parser; this deals with typedefs
385 and template parms. */
386 if (! IS_AGGR_TYPE (basetype
))
388 if (TYPE_MAIN_VARIANT (type
) != TYPE_MAIN_VARIANT (basetype
))
389 cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
390 exp
, basetype
, type
);
392 return cp_convert (void_type_node
, exp
);
396 if (! is_aggr_type (basetype
, 1))
397 return error_mark_node
;
399 if (! IS_AGGR_TYPE (type
))
401 cp_error ("base object `%E' of scoped method call is of non-aggregate type `%T'",
403 return error_mark_node
;
408 binfo
= get_binfo (basetype
, type
, 1);
409 if (binfo
== error_mark_node
)
410 return error_mark_node
;
412 error_not_base_type (basetype
, type
);
417 if (TREE_CODE (exp
) == INDIRECT_REF
)
418 decl
= build_indirect_ref
419 (convert_pointer_to_real
420 (binfo
, build_unary_op (ADDR_EXPR
, exp
, 0)), NULL_PTR
);
422 decl
= build_scoped_ref (exp
, basetype
);
424 /* Call to a destructor. */
425 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
427 if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl
)))
428 return cp_convert (void_type_node
, exp
);
430 return build_delete (TREE_TYPE (decl
), decl
, integer_two_node
,
431 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
,
435 /* Call to a method. */
436 return build_method_call (decl
, name
, parms
, binfo
,
437 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
);
439 return error_mark_node
;
442 /* We want the address of a function or method. We avoid creating a
443 pointer-to-member function. */
446 build_addr_func (function
)
449 tree type
= TREE_TYPE (function
);
451 /* We have to do these by hand to avoid real pointer to member
453 if (TREE_CODE (type
) == METHOD_TYPE
)
457 type
= build_pointer_type (type
);
459 if (mark_addressable (function
) == 0)
460 return error_mark_node
;
462 addr
= build1 (ADDR_EXPR
, type
, function
);
464 /* Address of a static or external variable or function counts
466 if (staticp (function
))
467 TREE_CONSTANT (addr
) = 1;
472 function
= default_conversion (function
);
477 /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
478 POINTER_TYPE to those. Note, pointer to member function types
479 (TYPE_PTRMEMFUNC_P) must be handled by our callers. */
482 build_call (function
, result_type
, parms
)
483 tree function
, result_type
, parms
;
485 int is_constructor
= 0;
489 function
= build_addr_func (function
);
491 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
493 sorry ("unable to call pointer to member function here");
494 return error_mark_node
;
497 if (TREE_CODE (function
) == ADDR_EXPR
498 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
)
499 decl
= TREE_OPERAND (function
, 0);
503 if (decl
&& DECL_CONSTRUCTOR_P (decl
))
507 my_friendly_assert (TREE_USED (decl
), 990125);
509 /* Don't pass empty class objects by value. This is useful
510 for tags in STL, which are used to control overload resolution.
511 We don't need to handle other cases of copying empty classes. */
512 if (! decl
|| ! DECL_BUILT_IN (decl
))
513 for (tmp
= parms
; tmp
; tmp
= TREE_CHAIN (tmp
))
514 if (is_empty_class (TREE_TYPE (TREE_VALUE (tmp
)))
515 && ! TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (tmp
))))
517 tree t
= make_node (RTL_EXPR
);
518 TREE_TYPE (t
) = TREE_TYPE (TREE_VALUE (tmp
));
519 RTL_EXPR_RTL (t
) = const0_rtx
;
520 RTL_EXPR_SEQUENCE (t
) = NULL_RTX
;
521 TREE_VALUE (tmp
) = build (COMPOUND_EXPR
, TREE_TYPE (t
),
522 TREE_VALUE (tmp
), t
);
525 function
= build_nt (CALL_EXPR
, function
, parms
, NULL_TREE
);
526 TREE_HAS_CONSTRUCTOR (function
) = is_constructor
;
527 TREE_TYPE (function
) = result_type
;
528 TREE_SIDE_EFFECTS (function
) = 1;
533 /* Build something of the form ptr->method (args)
534 or object.method (args). This can also build
535 calls to constructors, and find friends.
537 Member functions always take their class variable
540 INSTANCE is a class instance.
542 NAME is the name of the method desired, usually an IDENTIFIER_NODE.
544 PARMS help to figure out what that NAME really refers to.
546 BASETYPE_PATH, if non-NULL, contains a chain from the type of INSTANCE
547 down to the real instance type to use for access checking. We need this
548 information to get protected accesses correct. This parameter is used
549 by build_member_call.
551 FLAGS is the logical disjunction of zero or more LOOKUP_
552 flags. See cp-tree.h for more info.
554 If this is all OK, calls build_function_call with the resolved
557 This function must also handle being called to perform
558 initialization, promotion/coercion of arguments, and
559 instantiation of default parameters.
561 Note that NAME may refer to an instance variable name. If
562 `operator()()' is defined for the type of that field, then we return
566 build_method_call (instance
, name
, parms
, basetype_path
, flags
)
567 tree instance
, name
, parms
, basetype_path
;
570 tree basetype
, instance_ptr
;
572 #ifdef GATHER_STATISTICS
573 n_build_method_call
++;
576 if (instance
== error_mark_node
577 || name
== error_mark_node
578 || parms
== error_mark_node
579 || (instance
!= NULL_TREE
&& TREE_TYPE (instance
) == error_mark_node
))
580 return error_mark_node
;
582 if (processing_template_decl
)
584 /* We need to process template parm names here so that tsubst catches
585 them properly. Other type names can wait. */
586 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
588 tree type
= NULL_TREE
;
590 if (TREE_CODE (TREE_OPERAND (name
, 0)) == IDENTIFIER_NODE
)
591 type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 0);
592 else if (TREE_CODE (TREE_OPERAND (name
, 0)) == TYPE_DECL
)
593 type
= TREE_TYPE (TREE_OPERAND (name
, 0));
595 if (type
&& TREE_CODE (type
) == TEMPLATE_TYPE_PARM
)
596 name
= build_min_nt (BIT_NOT_EXPR
, type
);
599 return build_min_nt (METHOD_CALL_EXPR
, name
, instance
, parms
, NULL_TREE
);
602 /* This is the logic that magically deletes the second argument to
603 operator delete, if it is not needed. */
604 if (name
== ansi_opname
[(int) DELETE_EXPR
] && list_length (parms
)==2)
606 tree save_last
= TREE_CHAIN (parms
);
608 /* get rid of unneeded argument */
609 TREE_CHAIN (parms
) = NULL_TREE
;
610 if (build_method_call (instance
, name
, parms
, basetype_path
,
611 (LOOKUP_SPECULATIVELY
|flags
) & ~LOOKUP_COMPLAIN
))
613 /* If it finds a match, return it. */
614 return build_method_call (instance
, name
, parms
, basetype_path
, flags
);
616 /* If it doesn't work, two argument delete must work */
617 TREE_CHAIN (parms
) = save_last
;
619 /* We already know whether it's needed or not for vec delete. */
620 else if (name
== ansi_opname
[(int) VEC_DELETE_EXPR
]
621 && TYPE_LANG_SPECIFIC (TREE_TYPE (instance
))
622 && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance
)))
623 TREE_CHAIN (parms
) = NULL_TREE
;
625 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
628 error ("destructors take no parameters");
629 basetype
= TREE_TYPE (instance
);
630 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
631 basetype
= TREE_TYPE (basetype
);
633 if (! check_dtor_name (basetype
, name
))
635 ("destructor name `~%T' does not match type `%T' of expression",
636 TREE_OPERAND (name
, 0), basetype
);
638 if (! TYPE_HAS_DESTRUCTOR (complete_type (basetype
)))
639 return cp_convert (void_type_node
, instance
);
640 instance
= default_conversion (instance
);
641 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
642 return build_delete (build_pointer_type (basetype
),
643 instance_ptr
, integer_two_node
,
644 LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
, 0);
647 return build_new_method_call (instance
, name
, parms
, basetype_path
, flags
);
650 /* New overloading code. */
660 struct z_candidate
*next
;
663 #define IDENTITY_RANK 0
669 #define ELLIPSIS_RANK 6
672 #define ICS_RANK(NODE) \
673 (ICS_BAD_FLAG (NODE) ? BAD_RANK \
674 : ICS_ELLIPSIS_FLAG (NODE) ? ELLIPSIS_RANK \
675 : ICS_USER_FLAG (NODE) ? USER_RANK \
676 : ICS_STD_RANK (NODE))
678 #define ICS_STD_RANK(NODE) TREE_COMPLEXITY (NODE)
680 #define ICS_USER_FLAG(NODE) TREE_LANG_FLAG_0 (NODE)
681 #define ICS_ELLIPSIS_FLAG(NODE) TREE_LANG_FLAG_1 (NODE)
682 #define ICS_THIS_FLAG(NODE) TREE_LANG_FLAG_2 (NODE)
683 #define ICS_BAD_FLAG(NODE) TREE_LANG_FLAG_3 (NODE)
685 #define USER_CONV_CAND(NODE) \
686 ((struct z_candidate *)WRAPPER_PTR (TREE_OPERAND (NODE, 1)))
687 #define USER_CONV_FN(NODE) (USER_CONV_CAND (NODE)->fn)
694 || (integer_zerop (t
) && TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
))
700 build_conv (code
, type
, from
)
704 tree t
= build1 (code
, type
, from
);
705 int rank
= ICS_STD_RANK (from
);
717 if (rank
< EXACT_RANK
)
723 ICS_STD_RANK (t
) = rank
;
724 ICS_USER_FLAG (t
) = ICS_USER_FLAG (from
);
725 ICS_BAD_FLAG (t
) = ICS_BAD_FLAG (from
);
733 if (TREE_CODE (t
) == REFERENCE_TYPE
)
742 if (TREE_CODE (t
) == ARRAY_TYPE
)
744 return TYPE_MAIN_VARIANT (t
);
747 /* Returns the standard conversion path (see [conv]) from type FROM to type
748 TO, if any. For proper handling of null pointer constants, you must
749 also pass the expression EXPR to convert from. */
752 standard_conversion (to
, from
, expr
)
755 enum tree_code fcode
, tcode
;
759 if (TREE_CODE (to
) == REFERENCE_TYPE
)
761 if (TREE_CODE (from
) == REFERENCE_TYPE
)
764 from
= TREE_TYPE (from
);
766 to
= strip_top_quals (to
);
767 from
= strip_top_quals (from
);
769 if ((TYPE_PTRFN_P (to
) || TYPE_PTRMEMFUNC_P (to
))
770 && expr
&& type_unknown_p (expr
))
772 expr
= instantiate_type (to
, expr
, 0);
773 if (expr
== error_mark_node
)
775 from
= TREE_TYPE (expr
);
778 fcode
= TREE_CODE (from
);
779 tcode
= TREE_CODE (to
);
781 conv
= build1 (IDENTITY_CONV
, from
, expr
);
783 if (fcode
== FUNCTION_TYPE
)
785 from
= build_pointer_type (from
);
786 fcode
= TREE_CODE (from
);
787 conv
= build_conv (LVALUE_CONV
, from
, conv
);
789 else if (fcode
== ARRAY_TYPE
)
791 from
= build_pointer_type (TREE_TYPE (from
));
792 fcode
= TREE_CODE (from
);
793 conv
= build_conv (LVALUE_CONV
, from
, conv
);
795 else if (fromref
|| (expr
&& real_lvalue_p (expr
)))
796 conv
= build_conv (RVALUE_CONV
, from
, conv
);
801 if ((tcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (to
))
802 && expr
&& null_ptr_cst_p (expr
))
804 conv
= build_conv (STD_CONV
, to
, conv
);
806 else if (tcode
== POINTER_TYPE
&& fcode
== POINTER_TYPE
)
808 enum tree_code ufcode
= TREE_CODE (TREE_TYPE (from
));
809 enum tree_code utcode
= TREE_CODE (TREE_TYPE (to
));
811 if (same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (from
)),
812 TYPE_MAIN_VARIANT (TREE_TYPE (to
))))
814 else if (utcode
== VOID_TYPE
&& ufcode
!= OFFSET_TYPE
815 && ufcode
!= FUNCTION_TYPE
)
817 from
= build_pointer_type
818 (cp_build_qualified_type (void_type_node
,
819 CP_TYPE_QUALS (TREE_TYPE (from
))));
820 conv
= build_conv (PTR_CONV
, from
, conv
);
822 else if (ufcode
== OFFSET_TYPE
&& utcode
== OFFSET_TYPE
)
824 tree fbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from
));
825 tree tbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to
));
827 if (DERIVED_FROM_P (fbase
, tbase
)
829 (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (from
))),
830 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (to
))))))
832 from
= build_offset_type (tbase
, TREE_TYPE (TREE_TYPE (from
)));
833 from
= build_pointer_type (from
);
834 conv
= build_conv (PMEM_CONV
, from
, conv
);
837 else if (IS_AGGR_TYPE (TREE_TYPE (from
))
838 && IS_AGGR_TYPE (TREE_TYPE (to
)))
840 if (DERIVED_FROM_P (TREE_TYPE (to
), TREE_TYPE (from
)))
843 cp_build_qualified_type (TREE_TYPE (to
),
844 CP_TYPE_QUALS (TREE_TYPE (from
)));
845 from
= build_pointer_type (from
);
846 conv
= build_conv (PTR_CONV
, from
, conv
);
850 if (same_type_p (from
, to
))
852 else if (comp_ptr_ttypes (TREE_TYPE (to
), TREE_TYPE (from
)))
853 conv
= build_conv (QUAL_CONV
, to
, conv
);
854 else if (expr
&& string_conv_p (to
, expr
, 0))
855 /* converting from string constant to char *. */
856 conv
= build_conv (QUAL_CONV
, to
, conv
);
857 else if (ptr_reasonably_similar (TREE_TYPE (to
), TREE_TYPE (from
)))
859 conv
= build_conv (PTR_CONV
, to
, conv
);
860 ICS_BAD_FLAG (conv
) = 1;
867 else if (TYPE_PTRMEMFUNC_P (to
) && TYPE_PTRMEMFUNC_P (from
))
869 tree fromfn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from
));
870 tree tofn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to
));
871 tree fbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn
)));
872 tree tbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn
)));
874 if (! DERIVED_FROM_P (fbase
, tbase
)
875 || ! same_type_p (TREE_TYPE (fromfn
), TREE_TYPE (tofn
))
876 || ! compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)),
877 TREE_CHAIN (TYPE_ARG_TYPES (tofn
)))
878 || CP_TYPE_QUALS (fbase
) != CP_TYPE_QUALS (tbase
))
881 from
= cp_build_qualified_type (tbase
, CP_TYPE_QUALS (fbase
));
882 from
= build_cplus_method_type (from
, TREE_TYPE (fromfn
),
883 TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)));
884 from
= build_ptrmemfunc_type (build_pointer_type (from
));
885 conv
= build_conv (PMEM_CONV
, from
, conv
);
887 else if (tcode
== BOOLEAN_TYPE
)
889 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
890 || fcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (from
)))
893 conv
= build_conv (STD_CONV
, to
, conv
);
894 if (fcode
== POINTER_TYPE
895 || (TYPE_PTRMEMFUNC_P (from
) && ICS_STD_RANK (conv
) < PBOOL_RANK
))
896 ICS_STD_RANK (conv
) = PBOOL_RANK
;
898 /* We don't check for ENUMERAL_TYPE here because there are no standard
899 conversions to enum type. */
900 else if (tcode
== INTEGER_TYPE
|| tcode
== BOOLEAN_TYPE
901 || tcode
== REAL_TYPE
)
903 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
))
905 conv
= build_conv (STD_CONV
, to
, conv
);
907 /* Give this a better rank if it's a promotion. */
908 if (to
== type_promotes_to (from
)
909 && ICS_STD_RANK (TREE_OPERAND (conv
, 0)) <= PROMO_RANK
)
910 ICS_STD_RANK (conv
) = PROMO_RANK
;
912 else if (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
913 && DERIVED_FROM_P (to
, from
))
915 if (TREE_CODE (conv
) == RVALUE_CONV
)
916 conv
= TREE_OPERAND (conv
, 0);
917 conv
= build_conv (BASE_CONV
, to
, conv
);
925 /* Returns the conversion path from type FROM to reference type TO for
926 purposes of reference binding. For lvalue binding, either pass a
927 reference type to FROM or an lvalue expression to EXPR.
929 Currently does not distinguish in the generated trees between binding to
930 an lvalue and a temporary. Should it? */
933 reference_binding (rto
, rfrom
, expr
, flags
)
934 tree rto
, rfrom
, expr
;
939 tree to
= TREE_TYPE (rto
);
943 if (TREE_CODE (to
) == FUNCTION_TYPE
&& expr
&& type_unknown_p (expr
))
945 expr
= instantiate_type (to
, expr
, 0);
946 if (expr
== error_mark_node
)
948 from
= TREE_TYPE (expr
);
951 if (TREE_CODE (from
) == REFERENCE_TYPE
)
952 from
= TREE_TYPE (from
);
953 else if (! expr
|| ! real_lvalue_p (expr
))
956 related
= (same_type_p (TYPE_MAIN_VARIANT (to
),
957 TYPE_MAIN_VARIANT (from
))
958 || (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
959 && DERIVED_FROM_P (to
, from
)));
961 if (lvalue
&& related
&& at_least_as_qualified_p (to
, from
))
963 conv
= build1 (IDENTITY_CONV
, from
, expr
);
965 if (same_type_p (TYPE_MAIN_VARIANT (to
),
966 TYPE_MAIN_VARIANT (from
)))
967 conv
= build_conv (REF_BIND
, rto
, conv
);
970 conv
= build_conv (REF_BIND
, rto
, conv
);
971 ICS_STD_RANK (conv
) = STD_RANK
;
979 conv
= standard_conversion (to
, rfrom
, expr
);
982 conv
= build_conv (REF_BIND
, rto
, conv
);
984 /* Bind directly to a base subobject of a class rvalue. Do it
985 after building the conversion for proper handling of ICS_RANK. */
986 if (TREE_CODE (TREE_OPERAND (conv
, 0)) == BASE_CONV
)
987 TREE_OPERAND (conv
, 0) = TREE_OPERAND (TREE_OPERAND (conv
, 0), 0);
990 && ((! (CP_TYPE_CONST_NON_VOLATILE_P (to
)
991 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0))
992 /* If T1 is reference-related to T2, cv1 must be the same
993 cv-qualification as, or greater cv-qualification than,
994 cv2; otherwise, the program is ill-formed. */
995 || (related
&& !at_least_as_qualified_p (to
, from
))))
996 ICS_BAD_FLAG (conv
) = 1;
1002 /* Returns the implicit conversion sequence (see [over.ics]) from type FROM
1003 to type TO. The optional expression EXPR may affect the conversion.
1004 FLAGS are the usual overloading flags. Only LOOKUP_NO_CONVERSION is
1008 implicit_conversion (to
, from
, expr
, flags
)
1009 tree to
, from
, expr
;
1013 struct z_candidate
*cand
;
1015 if (TREE_CODE (to
) == REFERENCE_TYPE
)
1016 conv
= reference_binding (to
, from
, expr
, flags
);
1018 conv
= standard_conversion (to
, from
, expr
);
1022 else if (expr
!= NULL_TREE
1023 && (IS_AGGR_TYPE (non_reference (from
))
1024 || IS_AGGR_TYPE (non_reference (to
)))
1025 && (flags
& LOOKUP_NO_CONVERSION
) == 0)
1027 cand
= build_user_type_conversion_1
1028 (to
, expr
, LOOKUP_ONLYCONVERTING
);
1030 conv
= cand
->second_conv
;
1031 if ((! conv
|| ICS_BAD_FLAG (conv
))
1032 && TREE_CODE (to
) == REFERENCE_TYPE
1033 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0)
1035 cand
= build_user_type_conversion_1
1036 (TYPE_MAIN_VARIANT (TREE_TYPE (to
)), expr
, LOOKUP_ONLYCONVERTING
);
1039 if (!CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (to
)))
1040 ICS_BAD_FLAG (cand
->second_conv
) = 1;
1041 if (!conv
|| (ICS_BAD_FLAG (conv
)
1042 > ICS_BAD_FLAG (cand
->second_conv
)))
1043 conv
= build_conv (REF_BIND
, to
, cand
->second_conv
);
1051 /* Add a new entry to the list of candidates. Used by the add_*_candidate
1054 static struct z_candidate
*
1055 add_candidate (candidates
, fn
, convs
, viable
)
1056 struct z_candidate
*candidates
;
1060 struct z_candidate
*cand
1061 = (struct z_candidate
*) scratchalloc (sizeof (struct z_candidate
));
1064 cand
->convs
= convs
;
1065 cand
->second_conv
= NULL_TREE
;
1066 cand
->viable
= viable
;
1067 cand
->basetype_path
= NULL_TREE
;
1068 cand
->template = NULL_TREE
;
1069 cand
->warnings
= NULL_TREE
;
1070 cand
->next
= candidates
;
1075 /* Create an overload candidate for the function or method FN called with
1076 the argument list ARGLIST and add it to CANDIDATES. FLAGS is passed on
1077 to implicit_conversion. */
1079 static struct z_candidate
*
1080 add_function_candidate (candidates
, fn
, arglist
, flags
)
1081 struct z_candidate
*candidates
;
1085 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1088 tree parmnode
, argnode
;
1091 /* The `this' and `in_chrg' arguments to constructors are not considered
1092 in overload resolution. */
1093 if (DECL_CONSTRUCTOR_P (fn
))
1095 parmlist
= TREE_CHAIN (parmlist
);
1096 arglist
= TREE_CHAIN (arglist
);
1097 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
1099 parmlist
= TREE_CHAIN (parmlist
);
1100 arglist
= TREE_CHAIN (arglist
);
1104 len
= list_length (arglist
);
1105 convs
= make_scratch_vec (len
);
1107 /* 13.3.2 - Viable functions [over.match.viable]
1108 First, to be a viable function, a candidate function shall have enough
1109 parameters to agree in number with the arguments in the list.
1111 We need to check this first; otherwise, checking the ICSes might cause
1112 us to produce an ill-formed template instantiation. */
1114 parmnode
= parmlist
;
1115 for (i
= 0; i
< len
; ++i
)
1117 if (parmnode
== NULL_TREE
|| parmnode
== void_list_node
)
1119 parmnode
= TREE_CHAIN (parmnode
);
1122 if (i
< len
&& parmnode
)
1125 /* Make sure there are default args for the rest of the parms. */
1126 else for (; parmnode
&& parmnode
!= void_list_node
;
1127 parmnode
= TREE_CHAIN (parmnode
))
1128 if (! TREE_PURPOSE (parmnode
))
1137 /* Second, for F to be a viable function, there shall exist for each
1138 argument an implicit conversion sequence that converts that argument
1139 to the corresponding parameter of F. */
1141 parmnode
= parmlist
;
1144 for (i
= 0; i
< len
; ++i
)
1146 tree arg
= TREE_VALUE (argnode
);
1147 tree argtype
= lvalue_type (arg
);
1150 if (parmnode
== void_list_node
)
1155 tree parmtype
= TREE_VALUE (parmnode
);
1157 /* [over.match.funcs] For conversion functions, the function is
1158 considered to be a member of the class of the implicit object
1159 argument for the purpose of defining the type of the implicit
1162 Since build_over_call ignores the ICS for the `this' parameter,
1163 we can just change the parm type. */
1164 if (DECL_CONV_FN_P (fn
) && i
== 0)
1167 = build_qualified_type (TREE_TYPE (argtype
),
1168 TYPE_QUALS (TREE_TYPE (parmtype
)));
1169 parmtype
= build_pointer_type (parmtype
);
1172 t
= implicit_conversion (parmtype
, argtype
, arg
, flags
);
1176 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
1177 ICS_ELLIPSIS_FLAG (t
) = 1;
1180 if (i
== 0 && t
&& TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
1181 && ! DECL_CONSTRUCTOR_P (fn
))
1182 ICS_THIS_FLAG (t
) = 1;
1184 TREE_VEC_ELT (convs
, i
) = t
;
1191 if (ICS_BAD_FLAG (t
))
1195 parmnode
= TREE_CHAIN (parmnode
);
1196 argnode
= TREE_CHAIN (argnode
);
1200 return add_candidate (candidates
, fn
, convs
, viable
);
1203 /* Create an overload candidate for the conversion function FN which will
1204 be invoked for expression OBJ, producing a pointer-to-function which
1205 will in turn be called with the argument list ARGLIST, and add it to
1206 CANDIDATES. FLAGS is passed on to implicit_conversion.
1208 Actually, we don't really care about FN; we care about the type it
1209 converts to. There may be multiple conversion functions that will
1210 convert to that type, and we rely on build_user_type_conversion_1 to
1211 choose the best one; so when we create our candidate, we record the type
1212 instead of the function. */
1214 static struct z_candidate
*
1215 add_conv_candidate (candidates
, fn
, obj
, arglist
)
1216 struct z_candidate
*candidates
;
1217 tree fn
, obj
, arglist
;
1219 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
1220 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (totype
));
1221 int i
, len
= list_length (arglist
) + 1;
1222 tree convs
= make_scratch_vec (len
);
1223 tree parmnode
= parmlist
;
1224 tree argnode
= arglist
;
1226 int flags
= LOOKUP_NORMAL
;
1228 /* Don't bother looking up the same type twice. */
1229 if (candidates
&& candidates
->fn
== totype
)
1232 for (i
= 0; i
< len
; ++i
)
1234 tree arg
= i
== 0 ? obj
: TREE_VALUE (argnode
);
1235 tree argtype
= lvalue_type (arg
);
1239 t
= implicit_conversion (totype
, argtype
, arg
, flags
);
1240 else if (parmnode
== void_list_node
)
1243 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
1246 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
1247 ICS_ELLIPSIS_FLAG (t
) = 1;
1250 TREE_VEC_ELT (convs
, i
) = t
;
1254 if (ICS_BAD_FLAG (t
))
1261 parmnode
= TREE_CHAIN (parmnode
);
1262 argnode
= TREE_CHAIN (argnode
);
1268 for (; parmnode
&& parmnode
!= void_list_node
;
1269 parmnode
= TREE_CHAIN (parmnode
))
1270 if (! TREE_PURPOSE (parmnode
))
1276 return add_candidate (candidates
, totype
, convs
, viable
);
1279 static struct z_candidate
*
1280 build_builtin_candidate (candidates
, fnname
, type1
, type2
,
1281 args
, argtypes
, flags
)
1282 struct z_candidate
*candidates
;
1283 tree fnname
, type1
, type2
, *args
, *argtypes
;
1294 convs
= make_scratch_vec (args
[2] ? 3 : (args
[1] ? 2 : 1));
1296 for (i
= 0; i
< 2; ++i
)
1301 t
= implicit_conversion (types
[i
], argtypes
[i
], args
[i
], flags
);
1305 /* We need something for printing the candidate. */
1306 t
= build1 (IDENTITY_CONV
, types
[i
], NULL_TREE
);
1308 else if (ICS_BAD_FLAG (t
))
1310 TREE_VEC_ELT (convs
, i
) = t
;
1313 /* For COND_EXPR we rearranged the arguments; undo that now. */
1316 TREE_VEC_ELT (convs
, 2) = TREE_VEC_ELT (convs
, 1);
1317 TREE_VEC_ELT (convs
, 1) = TREE_VEC_ELT (convs
, 0);
1318 t
= implicit_conversion (boolean_type_node
, argtypes
[2], args
[2], flags
);
1320 TREE_VEC_ELT (convs
, 0) = t
;
1325 return add_candidate (candidates
, fnname
, convs
, viable
);
1332 return TYPE_SIZE (complete_type (t
)) != NULL_TREE
;
1335 /* Create any builtin operator overload candidates for the operator in
1336 question given the converted operand types TYPE1 and TYPE2. The other
1337 args are passed through from add_builtin_candidates to
1338 build_builtin_candidate. */
1340 static struct z_candidate
*
1341 add_builtin_candidate (candidates
, code
, code2
, fnname
, type1
, type2
,
1342 args
, argtypes
, flags
)
1343 struct z_candidate
*candidates
;
1344 enum tree_code code
, code2
;
1345 tree fnname
, type1
, type2
, *args
, *argtypes
;
1350 case POSTINCREMENT_EXPR
:
1351 case POSTDECREMENT_EXPR
:
1352 args
[1] = integer_zero_node
;
1353 type2
= integer_type_node
;
1362 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
1363 and VQ is either volatile or empty, there exist candidate operator
1364 functions of the form
1365 VQ T& operator++(VQ T&);
1366 T operator++(VQ T&, int);
1367 5 For every pair T, VQ), where T is an enumeration type or an arithmetic
1368 type other than bool, and VQ is either volatile or empty, there exist
1369 candidate operator functions of the form
1370 VQ T& operator--(VQ T&);
1371 T operator--(VQ T&, int);
1372 6 For every pair T, VQ), where T is a cv-qualified or cv-unqualified
1373 complete object type, and VQ is either volatile or empty, there exist
1374 candidate operator functions of the form
1375 T*VQ& operator++(T*VQ&);
1376 T*VQ& operator--(T*VQ&);
1377 T* operator++(T*VQ&, int);
1378 T* operator--(T*VQ&, int); */
1380 case POSTDECREMENT_EXPR
:
1381 case PREDECREMENT_EXPR
:
1382 if (TREE_CODE (type1
) == BOOLEAN_TYPE
)
1384 case POSTINCREMENT_EXPR
:
1385 case PREINCREMENT_EXPR
:
1386 if ((ARITHMETIC_TYPE_P (type1
) && TREE_CODE (type1
) != ENUMERAL_TYPE
)
1387 || TYPE_PTROB_P (type1
))
1389 type1
= build_reference_type (type1
);
1394 /* 7 For every cv-qualified or cv-unqualified complete object type T, there
1395 exist candidate operator functions of the form
1399 8 For every function type T, there exist candidate operator functions of
1401 T& operator*(T*); */
1404 if (TREE_CODE (type1
) == POINTER_TYPE
1405 && (TYPE_PTROB_P (type1
)
1406 || TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
))
1410 /* 9 For every type T, there exist candidate operator functions of the form
1413 10For every promoted arithmetic type T, there exist candidate operator
1414 functions of the form
1418 case CONVERT_EXPR
: /* unary + */
1419 if (TREE_CODE (type1
) == POINTER_TYPE
1420 && TREE_CODE (TREE_TYPE (type1
)) != OFFSET_TYPE
)
1423 if (ARITHMETIC_TYPE_P (type1
))
1427 /* 11For every promoted integral type T, there exist candidate operator
1428 functions of the form
1432 if (INTEGRAL_TYPE_P (type1
))
1436 /* 12For every quintuple C1, C2, T, CV1, CV2), where C2 is a class type, C1
1437 is the same type as C2 or is a derived class of C2, T is a complete
1438 object type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
1439 there exist candidate operator functions of the form
1440 CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
1441 where CV12 is the union of CV1 and CV2. */
1444 if (TREE_CODE (type1
) == POINTER_TYPE
1445 && (TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
)))
1447 tree c1
= TREE_TYPE (type1
);
1448 tree c2
= (TYPE_PTRMEMFUNC_P (type2
)
1449 ? TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type2
)))
1450 : TYPE_OFFSET_BASETYPE (TREE_TYPE (type2
)));
1452 if (IS_AGGR_TYPE (c1
) && DERIVED_FROM_P (c2
, c1
)
1453 && (TYPE_PTRMEMFUNC_P (type2
)
1454 || is_complete (TREE_TYPE (TREE_TYPE (type2
)))))
1459 /* 13For every pair of promoted arithmetic types L and R, there exist can-
1460 didate operator functions of the form
1465 bool operator<(L, R);
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 where LR is the result of the usual arithmetic conversions between
1474 14For every pair of types T and I, where T is a cv-qualified or cv-
1475 unqualified complete object type and I is a promoted integral type,
1476 there exist candidate operator functions of the form
1477 T* operator+(T*, I);
1478 T& operator[](T*, I);
1479 T* operator-(T*, I);
1480 T* operator+(I, T*);
1481 T& operator[](I, T*);
1483 15For every T, where T is a pointer to complete object type, there exist
1484 candidate operator functions of the form112)
1485 ptrdiff_t operator-(T, T);
1487 16For every pointer type T, there exist candidate operator functions of
1489 bool operator<(T, T);
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);
1496 17For every pointer to member type T, there exist candidate operator
1497 functions of the form
1498 bool operator==(T, T);
1499 bool operator!=(T, T); */
1502 if (TYPE_PTROB_P (type1
) && TYPE_PTROB_P (type2
))
1504 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
1506 type2
= ptrdiff_type_node
;
1510 case TRUNC_DIV_EXPR
:
1511 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1517 if ((TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
))
1518 || (TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
)))
1520 if ((TYPE_PTRMEMFUNC_P (type1
) || TYPE_PTRMEM_P (type1
))
1521 && null_ptr_cst_p (args
[1]))
1526 if ((TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
))
1527 && null_ptr_cst_p (args
[0]))
1538 if ((ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1539 || (TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
)))
1541 if (TYPE_PTR_P (type1
) && null_ptr_cst_p (args
[1]))
1546 if (null_ptr_cst_p (args
[0]) && TYPE_PTR_P (type2
))
1554 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1557 if (INTEGRAL_TYPE_P (type1
) && TYPE_PTROB_P (type2
))
1559 type1
= ptrdiff_type_node
;
1562 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
1564 type2
= ptrdiff_type_node
;
1569 /* 18For every pair of promoted integral types L and R, there exist candi-
1570 date operator functions of the form
1577 where LR is the result of the usual arithmetic conversions between
1580 case TRUNC_MOD_EXPR
:
1586 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
1590 /* 19For every triple L, VQ, R), where L is an arithmetic or enumeration
1591 type, VQ is either volatile or empty, and R is a promoted arithmetic
1592 type, there exist candidate operator functions of the form
1593 VQ L& operator=(VQ L&, R);
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);
1599 20For every pair T, VQ), where T is any type and VQ is either volatile
1600 or empty, there exist candidate operator functions of the form
1601 T*VQ& operator=(T*VQ&, T*);
1603 21For every pair T, VQ), where T is a pointer to member type and VQ is
1604 either volatile or empty, there exist candidate operator functions of
1606 VQ T& operator=(VQ T&, T);
1608 22For every triple T, VQ, I), where T is a cv-qualified or cv-
1609 unqualified complete object type, VQ is either volatile or empty, and
1610 I is a promoted integral type, there exist candidate operator func-
1612 T*VQ& operator+=(T*VQ&, I);
1613 T*VQ& operator-=(T*VQ&, I);
1615 23For every triple L, VQ, R), where L is an integral or enumeration
1616 type, VQ is either volatile or empty, and R is a promoted integral
1617 type, there exist candidate operator functions of the form
1619 VQ L& operator%=(VQ L&, R);
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); */
1631 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
1633 type2
= ptrdiff_type_node
;
1637 case TRUNC_DIV_EXPR
:
1638 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1642 case TRUNC_MOD_EXPR
:
1648 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
1653 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1655 if ((TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
))
1656 || (TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
1657 || (TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
))
1658 || ((TYPE_PTRMEMFUNC_P (type1
)
1659 || TREE_CODE (type1
) == POINTER_TYPE
)
1660 && null_ptr_cst_p (args
[1])))
1668 my_friendly_abort (367);
1670 type1
= build_reference_type (type1
);
1674 /* Kludge around broken overloading rules whereby
1675 bool ? const char& : enum is ambiguous
1676 (between int and const char&). */
1677 flags
|= LOOKUP_NO_TEMP_BIND
;
1679 /* Extension: Support ?: of enumeral type. Hopefully this will not
1680 be an extension for long. */
1681 if (TREE_CODE (type1
) == ENUMERAL_TYPE
&& type1
== type2
)
1683 else if (TREE_CODE (type1
) == ENUMERAL_TYPE
1684 || TREE_CODE (type2
) == ENUMERAL_TYPE
)
1686 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1688 if (TREE_CODE (type1
) == TREE_CODE (type2
)
1689 && (TREE_CODE (type1
) == REFERENCE_TYPE
1690 || TREE_CODE (type1
) == POINTER_TYPE
1691 || TYPE_PTRMEMFUNC_P (type1
)
1692 || IS_AGGR_TYPE (type1
)))
1694 if (TREE_CODE (type1
) == REFERENCE_TYPE
1695 || TREE_CODE (type2
) == REFERENCE_TYPE
)
1697 if (((TYPE_PTRMEMFUNC_P (type1
) || TREE_CODE (type1
) == POINTER_TYPE
)
1698 && null_ptr_cst_p (args
[1]))
1699 || IS_AGGR_TYPE (type1
))
1704 if (((TYPE_PTRMEMFUNC_P (type2
) || TREE_CODE (type2
) == POINTER_TYPE
)
1705 && null_ptr_cst_p (args
[0]))
1706 || IS_AGGR_TYPE (type2
))
1714 my_friendly_abort (367);
1717 /* If we're dealing with two pointer types, we need candidates
1718 for both of them. */
1719 if (type2
&& type1
!= type2
1720 && TREE_CODE (type1
) == TREE_CODE (type2
)
1721 && (TREE_CODE (type1
) == REFERENCE_TYPE
1722 || (TREE_CODE (type1
) == POINTER_TYPE
1723 && TYPE_PTRMEM_P (type1
) == TYPE_PTRMEM_P (type2
))
1724 || TYPE_PTRMEMFUNC_P (type1
)
1725 || IS_AGGR_TYPE (type1
)))
1727 candidates
= build_builtin_candidate
1728 (candidates
, fnname
, type1
, type1
, args
, argtypes
, flags
);
1729 return build_builtin_candidate
1730 (candidates
, fnname
, type2
, type2
, args
, argtypes
, flags
);
1733 return build_builtin_candidate
1734 (candidates
, fnname
, type1
, type2
, args
, argtypes
, flags
);
1738 type_decays_to (type
)
1741 if (TREE_CODE (type
) == ARRAY_TYPE
)
1742 return build_pointer_type (TREE_TYPE (type
));
1743 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1744 return build_pointer_type (type
);
1748 /* There are three conditions of builtin candidates:
1750 1) bool-taking candidates. These are the same regardless of the input.
1751 2) pointer-pair taking candidates. These are generated for each type
1752 one of the input types converts to.
1753 3) arithmetic candidates. According to the WP, we should generate
1754 all of these, but I'm trying not to... */
1756 static struct z_candidate
*
1757 add_builtin_candidates (candidates
, code
, code2
, fnname
, args
, flags
)
1758 struct z_candidate
*candidates
;
1759 enum tree_code code
, code2
;
1764 tree type
, argtypes
[3], types
[2];
1766 for (i
= 0; i
< 3; ++i
)
1769 argtypes
[i
] = lvalue_type (args
[i
]);
1771 argtypes
[i
] = NULL_TREE
;
1776 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
1777 and VQ is either volatile or empty, there exist candidate operator
1778 functions of the form
1779 VQ T& operator++(VQ T&); */
1781 case POSTINCREMENT_EXPR
:
1782 case PREINCREMENT_EXPR
:
1783 case POSTDECREMENT_EXPR
:
1784 case PREDECREMENT_EXPR
:
1789 /* 24There also exist candidate operator functions of the form
1790 bool operator!(bool);
1791 bool operator&&(bool, bool);
1792 bool operator||(bool, bool); */
1794 case TRUTH_NOT_EXPR
:
1795 return build_builtin_candidate
1796 (candidates
, fnname
, boolean_type_node
,
1797 NULL_TREE
, args
, argtypes
, flags
);
1799 case TRUTH_ORIF_EXPR
:
1800 case TRUTH_ANDIF_EXPR
:
1801 return build_builtin_candidate
1802 (candidates
, fnname
, boolean_type_node
,
1803 boolean_type_node
, args
, argtypes
, flags
);
1814 types
[0] = types
[1] = NULL_TREE
;
1816 for (i
= 0; i
< 2; ++i
)
1820 else if (IS_AGGR_TYPE (argtypes
[i
]))
1824 if (i
== 0 && code
== MODIFY_EXPR
&& code2
== NOP_EXPR
)
1827 convs
= lookup_conversions (argtypes
[i
]);
1829 if (code
== COND_EXPR
)
1831 if (real_lvalue_p (args
[i
]))
1832 types
[i
] = scratch_tree_cons
1833 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
1835 types
[i
] = scratch_tree_cons
1836 (NULL_TREE
, TYPE_MAIN_VARIANT (argtypes
[i
]), types
[i
]);
1842 for (; convs
; convs
= TREE_CHAIN (convs
))
1844 type
= TREE_TYPE (TREE_TYPE (OVL_CURRENT (TREE_VALUE (convs
))));
1847 && (TREE_CODE (type
) != REFERENCE_TYPE
1848 || CP_TYPE_CONST_P (TREE_TYPE (type
))))
1851 if (code
== COND_EXPR
&& TREE_CODE (type
) == REFERENCE_TYPE
)
1852 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1854 type
= non_reference (type
);
1855 if (i
!= 0 || ! ref1
)
1857 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
1858 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
1859 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1860 if (INTEGRAL_TYPE_P (type
))
1861 type
= type_promotes_to (type
);
1864 if (! value_member (type
, types
[i
]))
1865 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1870 if (code
== COND_EXPR
&& real_lvalue_p (args
[i
]))
1871 types
[i
] = scratch_tree_cons
1872 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
1873 type
= non_reference (argtypes
[i
]);
1874 if (i
!= 0 || ! ref1
)
1876 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
1877 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
1878 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1879 if (INTEGRAL_TYPE_P (type
))
1880 type
= type_promotes_to (type
);
1882 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1886 for (; types
[0]; types
[0] = TREE_CHAIN (types
[0]))
1889 for (type
= types
[1]; type
; type
= TREE_CHAIN (type
))
1890 candidates
= add_builtin_candidate
1891 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
1892 TREE_VALUE (type
), args
, argtypes
, flags
);
1894 candidates
= add_builtin_candidate
1895 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
1896 NULL_TREE
, args
, argtypes
, flags
);
1903 /* If TMPL can be successfully instantiated as indicated by
1904 EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
1906 TMPL is the template. EXPLICIT_TARGS are any explicit template
1907 arguments. ARGLIST is the arguments provided at the call-site.
1908 The RETURN_TYPE is the desired type for conversion operators. If
1909 OBJ is NULL_TREE, FLAGS are as for add_function_candidate. If an
1910 OBJ is supplied, FLAGS are ignored, and OBJ is as for
1911 add_conv_candidate. */
1913 static struct z_candidate
*
1914 add_template_candidate_real (candidates
, tmpl
, explicit_targs
,
1915 arglist
, return_type
, flags
,
1917 struct z_candidate
*candidates
;
1918 tree tmpl
, explicit_targs
, arglist
, return_type
;
1921 unification_kind_t strict
;
1923 int ntparms
= DECL_NTPARMS (tmpl
);
1924 tree targs
= make_scratch_vec (ntparms
);
1925 struct z_candidate
*cand
;
1929 i
= fn_type_unification (tmpl
, explicit_targs
, targs
, arglist
,
1930 return_type
, strict
);
1935 fn
= instantiate_template (tmpl
, targs
);
1936 if (fn
== error_mark_node
)
1939 if (obj
!= NULL_TREE
)
1940 /* Aha, this is a conversion function. */
1941 cand
= add_conv_candidate (candidates
, fn
, obj
, arglist
);
1943 cand
= add_function_candidate (candidates
, fn
, arglist
, flags
);
1944 if (DECL_TI_TEMPLATE (fn
) != tmpl
)
1945 /* This situation can occur if a member template of a template
1946 class is specialized. Then, instantiate_template might return
1947 an instantiation of the specialization, in which case the
1948 DECL_TI_TEMPLATE field will point at the original
1949 specialization. For example:
1951 template <class T> struct S { template <class U> void f(U);
1952 template <> void f(int) {}; };
1956 Here, TMPL will be template <class U> S<double>::f(U).
1957 And, instantiate template will give us the specialization
1958 template <> S<double>::f(int). But, the DECL_TI_TEMPLATE field
1959 for this will point at template <class T> template <> S<T>::f(int),
1960 so that we can find the definition. For the purposes of
1961 overload resolution, however, we want the original TMPL. */
1962 cand
->template = tree_cons (tmpl
, targs
, NULL_TREE
);
1964 cand
->template = DECL_TEMPLATE_INFO (fn
);
1970 static struct z_candidate
*
1971 add_template_candidate (candidates
, tmpl
, explicit_targs
,
1972 arglist
, return_type
, flags
, strict
)
1973 struct z_candidate
*candidates
;
1974 tree tmpl
, explicit_targs
, arglist
, return_type
;
1976 unification_kind_t strict
;
1979 add_template_candidate_real (candidates
, tmpl
, explicit_targs
,
1980 arglist
, return_type
, flags
,
1985 static struct z_candidate
*
1986 add_template_conv_candidate (candidates
, tmpl
, obj
, arglist
, return_type
)
1987 struct z_candidate
*candidates
;
1988 tree tmpl
, obj
, arglist
, return_type
;
1991 add_template_candidate_real (candidates
, tmpl
, NULL_TREE
, arglist
,
1992 return_type
, 0, obj
, DEDUCE_CONV
);
1998 struct z_candidate
*cands
;
2000 for (; cands
; cands
= cands
->next
)
2001 if (pedantic
? cands
->viable
== 1 : cands
->viable
)
2006 static struct z_candidate
*
2007 splice_viable (cands
)
2008 struct z_candidate
*cands
;
2010 struct z_candidate
**p
= &cands
;
2014 if (pedantic
? (*p
)->viable
== 1 : (*p
)->viable
)
2027 /* Fix this to work on non-lvalues. */
2028 if (IS_SIGNATURE_POINTER (TREE_TYPE (obj
))
2029 || IS_SIGNATURE_REFERENCE (TREE_TYPE (obj
)))
2032 return build_unary_op (ADDR_EXPR
, obj
, 0);
2036 print_z_candidates (candidates
)
2037 struct z_candidate
*candidates
;
2039 const char *str
= "candidates are:";
2040 for (; candidates
; candidates
= candidates
->next
)
2042 if (TREE_CODE (candidates
->fn
) == IDENTIFIER_NODE
)
2044 if (candidates
->fn
== ansi_opname
[COND_EXPR
])
2045 cp_error ("%s %D(%T, %T, %T) <builtin>", str
, candidates
->fn
,
2046 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
2047 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)),
2048 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 2)));
2049 else if (TREE_VEC_LENGTH (candidates
->convs
) == 2)
2050 cp_error ("%s %D(%T, %T) <builtin>", str
, candidates
->fn
,
2051 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
2052 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)));
2054 cp_error ("%s %D(%T) <builtin>", str
, candidates
->fn
,
2055 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)));
2057 else if (TYPE_P (candidates
->fn
))
2058 cp_error ("%s %T <conversion>", str
, candidates
->fn
);
2060 cp_error_at ("%s %+#D%s", str
, candidates
->fn
,
2061 candidates
->viable
== -1 ? " <near match>" : "");
2066 /* Returns the best overload candidate to perform the requested
2067 conversion. This function is used for three the overloading situations
2068 described in [over.match.copy], [over.match.conv], and [over.match.ref].
2069 If TOTYPE is a REFERENCE_TYPE, we're trying to find an lvalue binding as
2070 per [dcl.init.ref], so we ignore temporary bindings. */
2072 static struct z_candidate
*
2073 build_user_type_conversion_1 (totype
, expr
, flags
)
2077 struct z_candidate
*candidates
, *cand
;
2078 tree fromtype
= TREE_TYPE (expr
);
2079 tree ctors
= NULL_TREE
, convs
= NULL_TREE
, *p
;
2080 tree args
= NULL_TREE
;
2081 tree templates
= NULL_TREE
;
2083 if (IS_AGGR_TYPE (totype
))
2084 ctors
= lookup_fnfields (TYPE_BINFO (totype
), ctor_identifier
, 0);
2085 if (IS_AGGR_TYPE (fromtype
)
2086 && (! IS_AGGR_TYPE (totype
) || ! DERIVED_FROM_P (totype
, fromtype
)))
2087 convs
= lookup_conversions (fromtype
);
2090 flags
|= LOOKUP_NO_CONVERSION
;
2094 tree t
= build_int_2 (0, 0);
2095 TREE_TYPE (t
) = build_pointer_type (totype
);
2096 args
= build_scratch_list (NULL_TREE
, expr
);
2097 if (TYPE_USES_VIRTUAL_BASECLASSES (totype
))
2098 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
2099 args
= scratch_tree_cons (NULL_TREE
, t
, args
);
2101 ctors
= TREE_VALUE (ctors
);
2103 for (; ctors
; ctors
= OVL_NEXT (ctors
))
2105 tree ctor
= OVL_CURRENT (ctors
);
2106 if (DECL_NONCONVERTING_P (ctor
))
2109 if (TREE_CODE (ctor
) == TEMPLATE_DECL
)
2111 templates
= scratch_tree_cons (NULL_TREE
, ctor
, templates
);
2113 add_template_candidate (candidates
, ctor
,
2114 NULL_TREE
, args
, NULL_TREE
, flags
,
2118 candidates
= add_function_candidate (candidates
, ctor
,
2123 candidates
->second_conv
= build1 (IDENTITY_CONV
, totype
, NULL_TREE
);
2124 candidates
->basetype_path
= TYPE_BINFO (totype
);
2129 args
= build_scratch_list (NULL_TREE
, build_this (expr
));
2131 for (; convs
; convs
= TREE_CHAIN (convs
))
2133 tree fns
= TREE_VALUE (convs
);
2134 int convflags
= LOOKUP_NO_CONVERSION
;
2137 /* If we are called to convert to a reference type, we are trying to
2138 find an lvalue binding, so don't even consider temporaries. If
2139 we don't find an lvalue binding, the caller will try again to
2140 look for a temporary binding. */
2141 if (TREE_CODE (totype
) == REFERENCE_TYPE
)
2142 convflags
|= LOOKUP_NO_TEMP_BIND
;
2144 if (TREE_CODE (OVL_CURRENT (fns
)) != TEMPLATE_DECL
)
2145 ics
= implicit_conversion
2146 (totype
, TREE_TYPE (TREE_TYPE (OVL_CURRENT (fns
))), 0, convflags
);
2148 /* We can't compute this yet. */
2149 ics
= error_mark_node
;
2151 if (TREE_CODE (totype
) == REFERENCE_TYPE
&& ics
&& ICS_BAD_FLAG (ics
))
2152 /* ignore the near match. */;
2154 for (; fns
; fns
= OVL_NEXT (fns
))
2156 tree fn
= OVL_CURRENT (fns
);
2157 struct z_candidate
*old_candidates
= candidates
;
2159 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2161 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2163 add_template_candidate (candidates
, fn
, NULL_TREE
,
2164 args
, totype
, flags
,
2168 candidates
= add_function_candidate (candidates
, fn
,
2171 if (candidates
!= old_candidates
)
2173 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2174 ics
= implicit_conversion
2175 (totype
, TREE_TYPE (TREE_TYPE (candidates
->fn
)),
2178 candidates
->second_conv
= ics
;
2179 candidates
->basetype_path
= TREE_PURPOSE (convs
);
2181 if (ics
== NULL_TREE
)
2182 candidates
->viable
= 0;
2183 else if (candidates
->viable
== 1 && ICS_BAD_FLAG (ics
))
2184 candidates
->viable
= -1;
2189 if (! any_viable (candidates
))
2192 if (flags
& LOOKUP_COMPLAIN
)
2194 if (candidates
&& ! candidates
->next
)
2195 /* say why this one won't work or try to be loose */;
2197 cp_error ("no viable candidates");
2204 candidates
= splice_viable (candidates
);
2205 cand
= tourney (candidates
);
2209 if (flags
& LOOKUP_COMPLAIN
)
2211 cp_error ("conversion from `%T' to `%T' is ambiguous",
2213 print_z_candidates (candidates
);
2216 cand
= candidates
; /* any one will do */
2217 cand
->second_conv
= build1 (AMBIG_CONV
, totype
, expr
);
2218 ICS_USER_FLAG (cand
->second_conv
) = 1;
2219 ICS_BAD_FLAG (cand
->second_conv
) = 1;
2224 for (p
= &(cand
->second_conv
); TREE_CODE (*p
) != IDENTITY_CONV
; )
2225 p
= &(TREE_OPERAND (*p
, 0));
2227 /* Pedantically, normal function declarations are never considered
2228 to refer to template instantiations, so we only do this with
2230 if (flag_guiding_decls
&& templates
&& ! cand
->template
2231 && !DECL_INITIAL (cand
->fn
)
2232 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
2233 add_maybe_template (cand
->fn
, templates
);
2237 (DECL_CONSTRUCTOR_P (cand
->fn
)
2238 ? totype
: non_reference (TREE_TYPE (TREE_TYPE (cand
->fn
)))),
2239 expr
, build_expr_ptr_wrapper (cand
));
2240 ICS_USER_FLAG (cand
->second_conv
) = 1;
2241 if (cand
->viable
== -1)
2242 ICS_BAD_FLAG (cand
->second_conv
) = 1;
2248 build_user_type_conversion (totype
, expr
, flags
)
2252 struct z_candidate
*cand
2253 = build_user_type_conversion_1 (totype
, expr
, flags
);
2257 if (TREE_CODE (cand
->second_conv
) == AMBIG_CONV
)
2258 return error_mark_node
;
2259 return convert_from_reference (convert_like (cand
->second_conv
, expr
));
2264 /* Do any initial processing on the arguments to a function call. */
2271 for (t
= args
; t
; t
= TREE_CHAIN (t
))
2273 if (TREE_VALUE (t
) == error_mark_node
)
2274 return error_mark_node
;
2275 else if (TREE_CODE (TREE_TYPE (TREE_VALUE (t
))) == VOID_TYPE
)
2277 error ("invalid use of void expression");
2278 return error_mark_node
;
2280 else if (TREE_CODE (TREE_VALUE (t
)) == OFFSET_REF
)
2281 TREE_VALUE (t
) = resolve_offset_ref (TREE_VALUE (t
));
2287 build_new_function_call (fn
, args
)
2290 struct z_candidate
*candidates
= 0, *cand
;
2291 tree explicit_targs
= NULL_TREE
;
2292 int template_only
= 0;
2294 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2296 explicit_targs
= TREE_OPERAND (fn
, 1);
2297 fn
= TREE_OPERAND (fn
, 0);
2301 if (really_overloaded_fn (fn
))
2304 tree templates
= NULL_TREE
;
2306 args
= resolve_args (args
);
2308 if (args
== error_mark_node
)
2309 return error_mark_node
;
2311 for (t1
= fn
; t1
; t1
= OVL_CHAIN (t1
))
2313 tree t
= OVL_FUNCTION (t1
);
2314 struct z_candidate
*old_candidates
= candidates
;
2316 if (TREE_CODE (t
) == TEMPLATE_DECL
)
2318 templates
= scratch_tree_cons (NULL_TREE
, t
, templates
);
2319 candidates
= add_template_candidate
2320 (candidates
, t
, explicit_targs
, args
, NULL_TREE
,
2321 LOOKUP_NORMAL
, DEDUCE_CALL
);
2323 else if (! template_only
)
2324 candidates
= add_function_candidate
2325 (candidates
, t
, args
, LOOKUP_NORMAL
);
2327 if (candidates
!= old_candidates
)
2328 candidates
->basetype_path
= DECL_REAL_CONTEXT (t
);
2331 if (! any_viable (candidates
))
2333 if (candidates
&& ! candidates
->next
)
2334 return build_function_call (candidates
->fn
, args
);
2335 cp_error ("no matching function for call to `%D (%A)'",
2336 DECL_NAME (OVL_FUNCTION (fn
)), args
);
2338 print_z_candidates (candidates
);
2339 return error_mark_node
;
2341 candidates
= splice_viable (candidates
);
2342 cand
= tourney (candidates
);
2346 cp_error ("call of overloaded `%D (%A)' is ambiguous",
2347 DECL_NAME (OVL_FUNCTION (fn
)), args
);
2348 print_z_candidates (candidates
);
2349 return error_mark_node
;
2352 /* Pedantically, normal function declarations are never considered
2353 to refer to template instantiations, so we only do this with
2355 if (flag_guiding_decls
&& templates
&& ! cand
->template
2356 && ! DECL_INITIAL (cand
->fn
))
2357 add_maybe_template (cand
->fn
, templates
);
2359 return build_over_call (cand
, args
, LOOKUP_NORMAL
);
2362 /* This is not really overloaded. */
2363 fn
= OVL_CURRENT (fn
);
2365 return build_function_call (fn
, args
);
2369 build_object_call (obj
, args
)
2372 struct z_candidate
*candidates
= 0, *cand
;
2373 tree fns
, convs
, mem_args
= NULL_TREE
;
2374 tree type
= TREE_TYPE (obj
);
2376 if (TYPE_PTRMEMFUNC_P (type
))
2378 /* It's no good looking for an overloaded operator() on a
2379 pointer-to-member-function. */
2380 cp_error ("pointer-to-member function %E cannot be called", obj
);
2381 cp_error ("without an object; consider using .* or ->*");
2382 return error_mark_node
;
2385 fns
= lookup_fnfields (TYPE_BINFO (type
), ansi_opname
[CALL_EXPR
], 1);
2386 if (fns
== error_mark_node
)
2387 return error_mark_node
;
2389 args
= resolve_args (args
);
2391 if (args
== error_mark_node
)
2392 return error_mark_node
;
2396 tree base
= TREE_PURPOSE (fns
);
2397 mem_args
= scratch_tree_cons (NULL_TREE
, build_this (obj
), args
);
2399 for (fns
= TREE_VALUE (fns
); fns
; fns
= OVL_NEXT (fns
))
2401 tree fn
= OVL_CURRENT (fns
);
2402 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2405 = add_template_candidate (candidates
, fn
, NULL_TREE
,
2406 mem_args
, NULL_TREE
,
2407 LOOKUP_NORMAL
, DEDUCE_CALL
);
2410 candidates
= add_function_candidate
2411 (candidates
, fn
, mem_args
, LOOKUP_NORMAL
);
2414 candidates
->basetype_path
= base
;
2418 convs
= lookup_conversions (type
);
2420 for (; convs
; convs
= TREE_CHAIN (convs
))
2422 tree fns
= TREE_VALUE (convs
);
2423 tree totype
= TREE_TYPE (TREE_TYPE (OVL_CURRENT (fns
)));
2425 if ((TREE_CODE (totype
) == POINTER_TYPE
2426 || TREE_CODE (totype
) == REFERENCE_TYPE
)
2427 && TREE_CODE (TREE_TYPE (totype
)) == FUNCTION_TYPE
)
2428 for (; fns
; fns
= OVL_NEXT (fns
))
2430 tree fn
= OVL_CURRENT (fns
);
2431 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2433 candidates
= add_template_conv_candidate (candidates
,
2440 candidates
= add_conv_candidate (candidates
, fn
, obj
, args
);
2443 candidates
->basetype_path
= TREE_PURPOSE (convs
);
2447 if (! any_viable (candidates
))
2449 cp_error ("no match for call to `(%T) (%A)'", TREE_TYPE (obj
), args
);
2450 print_z_candidates (candidates
);
2451 return error_mark_node
;
2454 candidates
= splice_viable (candidates
);
2455 cand
= tourney (candidates
);
2459 cp_error ("call of `(%T) (%A)' is ambiguous", TREE_TYPE (obj
), args
);
2460 print_z_candidates (candidates
);
2461 return error_mark_node
;
2464 if (DECL_NAME (cand
->fn
) == ansi_opname
[CALL_EXPR
])
2465 return build_over_call (cand
, mem_args
, LOOKUP_NORMAL
);
2467 obj
= convert_like (TREE_VEC_ELT (cand
->convs
, 0), obj
);
2470 return build_function_call (obj
, args
);
2474 op_error (code
, code2
, arg1
, arg2
, arg3
, problem
)
2475 enum tree_code code
, code2
;
2476 tree arg1
, arg2
, arg3
;
2477 const char *problem
;
2480 = (code
== MODIFY_EXPR
? assignop_tab
[code2
] : opname_tab
[code
]);
2485 cp_error ("%s for `%T ? %T : %T'", problem
,
2486 error_type (arg1
), error_type (arg2
), error_type (arg3
));
2488 case POSTINCREMENT_EXPR
:
2489 case POSTDECREMENT_EXPR
:
2490 cp_error ("%s for `%T%s'", problem
, error_type (arg1
), opname
);
2493 cp_error ("%s for `%T[%T]'", problem
,
2494 error_type (arg1
), error_type (arg2
));
2498 cp_error ("%s for `%T %s %T'", problem
,
2499 error_type (arg1
), opname
, error_type (arg2
));
2501 cp_error ("%s for `%s%T'", problem
, opname
, error_type (arg1
));
2506 build_new_op (code
, flags
, arg1
, arg2
, arg3
)
2507 enum tree_code code
;
2509 tree arg1
, arg2
, arg3
;
2511 struct z_candidate
*candidates
= 0, *cand
;
2512 tree fns
, mem_arglist
= NULL_TREE
, arglist
, fnname
;
2513 enum tree_code code2
= NOP_EXPR
;
2514 tree templates
= NULL_TREE
;
2517 if (arg1
== error_mark_node
2518 || arg2
== error_mark_node
2519 || arg3
== error_mark_node
)
2520 return error_mark_node
;
2522 /* This can happen if a template takes all non-type parameters, e.g.
2523 undeclared_template<1, 5, 72>a; */
2524 if (code
== LT_EXPR
&& TREE_CODE (arg1
) == TEMPLATE_DECL
)
2526 cp_error ("`%D' must be declared before use", arg1
);
2527 return error_mark_node
;
2530 if (code
== MODIFY_EXPR
)
2532 code2
= TREE_CODE (arg3
);
2534 fnname
= ansi_assopname
[code2
];
2537 fnname
= ansi_opname
[code
];
2543 case VEC_DELETE_EXPR
:
2545 /* Use build_op_new_call and build_op_delete_call instead. */
2546 my_friendly_abort (981018);
2549 return build_object_call (arg1
, arg2
);
2555 /* The comma operator can have void args. */
2556 if (TREE_CODE (arg1
) == OFFSET_REF
)
2557 arg1
= resolve_offset_ref (arg1
);
2558 if (arg2
&& TREE_CODE (arg2
) == OFFSET_REF
)
2559 arg2
= resolve_offset_ref (arg2
);
2560 if (arg3
&& TREE_CODE (arg3
) == OFFSET_REF
)
2561 arg3
= resolve_offset_ref (arg3
);
2563 if (code
== COND_EXPR
)
2565 if (arg2
== NULL_TREE
2566 || TREE_CODE (TREE_TYPE (arg2
)) == VOID_TYPE
2567 || TREE_CODE (TREE_TYPE (arg3
)) == VOID_TYPE
2568 || (! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))
2569 && ! IS_OVERLOAD_TYPE (TREE_TYPE (arg3
))))
2572 else if (! IS_OVERLOAD_TYPE (TREE_TYPE (arg1
))
2573 && (! arg2
|| ! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))))
2576 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
2577 arg2
= integer_zero_node
;
2580 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, scratch_tree_cons
2581 (NULL_TREE
, arg2
, build_scratch_list (NULL_TREE
, arg3
)));
2583 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, build_scratch_list (NULL_TREE
, arg2
));
2585 arglist
= build_scratch_list (NULL_TREE
, arg1
);
2587 fns
= lookup_function_nonclass (fnname
, arglist
);
2589 if (fns
&& TREE_CODE (fns
) == TREE_LIST
)
2590 fns
= TREE_VALUE (fns
);
2591 for (; fns
; fns
= OVL_NEXT (fns
))
2593 tree fn
= OVL_CURRENT (fns
);
2594 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2596 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2598 = add_template_candidate (candidates
, fn
, NULL_TREE
,
2599 arglist
, TREE_TYPE (fnname
),
2600 flags
, DEDUCE_CALL
);
2603 candidates
= add_function_candidate (candidates
, fn
, arglist
, flags
);
2606 if (IS_AGGR_TYPE (TREE_TYPE (arg1
)))
2608 fns
= lookup_fnfields (TYPE_BINFO (TREE_TYPE (arg1
)), fnname
, 1);
2609 if (fns
== error_mark_node
)
2617 tree basetype
= TREE_PURPOSE (fns
);
2618 mem_arglist
= scratch_tree_cons (NULL_TREE
, build_this (arg1
), TREE_CHAIN (arglist
));
2619 for (fns
= TREE_VALUE (fns
); fns
; fns
= OVL_NEXT (fns
))
2621 tree fn
= OVL_CURRENT (fns
);
2624 if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
2625 this_arglist
= mem_arglist
;
2627 this_arglist
= arglist
;
2629 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2631 /* A member template. */
2632 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2634 = add_template_candidate (candidates
, fn
, NULL_TREE
,
2635 this_arglist
, TREE_TYPE (fnname
),
2636 flags
, DEDUCE_CALL
);
2639 candidates
= add_function_candidate
2640 (candidates
, fn
, this_arglist
, flags
);
2643 candidates
->basetype_path
= basetype
;
2650 /* Rearrange the arguments for ?: so that add_builtin_candidate only has
2651 to know about two args; a builtin candidate will always have a first
2652 parameter of type bool. We'll handle that in
2653 build_builtin_candidate. */
2654 if (code
== COND_EXPR
)
2664 args
[2] = NULL_TREE
;
2667 candidates
= add_builtin_candidates
2668 (candidates
, code
, code2
, fnname
, args
, flags
);
2671 if (! any_viable (candidates
))
2675 case POSTINCREMENT_EXPR
:
2676 case POSTDECREMENT_EXPR
:
2677 /* Look for an `operator++ (int)'. If they didn't have
2678 one, then we fall back to the old way of doing things. */
2679 if (flags
& LOOKUP_COMPLAIN
)
2680 cp_pedwarn ("no `%D (int)' declared for postfix `%s', trying prefix operator instead",
2681 fnname
, opname_tab
[code
]);
2682 if (code
== POSTINCREMENT_EXPR
)
2683 code
= PREINCREMENT_EXPR
;
2685 code
= PREDECREMENT_EXPR
;
2686 return build_new_op (code
, flags
, arg1
, NULL_TREE
, NULL_TREE
);
2688 /* The caller will deal with these. */
2697 if (flags
& LOOKUP_COMPLAIN
)
2699 op_error (code
, code2
, arg1
, arg2
, arg3
, "no match");
2700 print_z_candidates (candidates
);
2702 return error_mark_node
;
2704 candidates
= splice_viable (candidates
);
2705 cand
= tourney (candidates
);
2709 if (flags
& LOOKUP_COMPLAIN
)
2711 op_error (code
, code2
, arg1
, arg2
, arg3
, "ambiguous overload");
2712 print_z_candidates (candidates
);
2714 return error_mark_node
;
2717 if (TREE_CODE (cand
->fn
) == FUNCTION_DECL
)
2719 extern int warn_synth
;
2721 && fnname
== ansi_opname
[MODIFY_EXPR
]
2722 && DECL_ARTIFICIAL (cand
->fn
)
2724 && ! candidates
->next
->next
)
2726 cp_warning ("using synthesized `%#D' for copy assignment",
2728 cp_warning_at (" where cfront would use `%#D'",
2730 ? candidates
->next
->fn
2734 /* Pedantically, normal function declarations are never considered
2735 to refer to template instantiations, so we only do this with
2737 if (flag_guiding_decls
&& templates
&& ! cand
->template
2738 && ! DECL_INITIAL (cand
->fn
)
2739 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
2740 add_maybe_template (cand
->fn
, templates
);
2742 return build_over_call
2744 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
2745 ? mem_arglist
: arglist
,
2749 /* Check for comparison of different enum types. */
2758 if (TREE_CODE (TREE_TYPE (arg1
)) == ENUMERAL_TYPE
2759 && TREE_CODE (TREE_TYPE (arg2
)) == ENUMERAL_TYPE
2760 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg1
))
2761 != TYPE_MAIN_VARIANT (TREE_TYPE (arg2
))))
2763 cp_warning ("comparison between `%#T' and `%#T'",
2764 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
2771 /* We need to strip any leading REF_BIND so that bitfields don't cause
2772 errors. This should not remove any important conversions, because
2773 builtins don't apply to class objects directly. */
2774 conv
= TREE_VEC_ELT (cand
->convs
, 0);
2775 if (TREE_CODE (conv
) == REF_BIND
)
2776 conv
= TREE_OPERAND (conv
, 0);
2777 arg1
= convert_like (conv
, arg1
);
2779 arg2
= convert_like (TREE_VEC_ELT (cand
->convs
, 1), arg2
);
2781 arg3
= convert_like (TREE_VEC_ELT (cand
->convs
, 2), arg3
);
2787 return build_modify_expr (arg1
, code2
, arg2
);
2790 return build_indirect_ref (arg1
, "unary *");
2795 case TRUNC_DIV_EXPR
:
2806 case TRUNC_MOD_EXPR
:
2810 case TRUTH_ANDIF_EXPR
:
2811 case TRUTH_ORIF_EXPR
:
2812 return build_binary_op_nodefault (code
, arg1
, arg2
, code
);
2817 case TRUTH_NOT_EXPR
:
2818 case PREINCREMENT_EXPR
:
2819 case POSTINCREMENT_EXPR
:
2820 case PREDECREMENT_EXPR
:
2821 case POSTDECREMENT_EXPR
:
2824 return build_unary_op (code
, arg1
, candidates
!= 0);
2827 return build_array_ref (arg1
, arg2
);
2830 return build_conditional_expr (arg1
, arg2
, arg3
);
2833 return build_m_component_ref
2834 (build_indirect_ref (arg1
, NULL_PTR
), arg2
);
2836 /* The caller will deal with these. */
2843 my_friendly_abort (367);
2848 /* Build up a call to operator new. This has to be handled differently
2849 from other operators in the way lookup is handled; first members are
2850 considered, then globals. CODE is either NEW_EXPR or VEC_NEW_EXPR.
2851 TYPE is the type to be created. ARGS are any new-placement args.
2852 FLAGS are the usual overloading flags. */
2855 build_op_new_call (code
, type
, args
, flags
)
2856 enum tree_code code
;
2860 tree fnname
= ansi_opname
[code
];
2862 if (IS_AGGR_TYPE (type
) && ! (flags
& LOOKUP_GLOBAL
)
2863 && (TYPE_GETS_NEW (type
) & (1 << (code
== VEC_NEW_EXPR
))))
2865 return build_method_call (build_dummy_object (type
),
2866 fnname
, args
, NULL_TREE
, flags
);
2869 return build_new_function_call
2870 (lookup_function_nonclass (fnname
, args
), args
);
2873 /* Build a call to operator delete. This has to be handled very specially,
2874 because the restrictions on what signatures match are different from all
2875 other call instances. For a normal delete, only a delete taking (void *)
2876 or (void *, size_t) is accepted. For a placement delete, only an exact
2877 match with the placement new is accepted.
2879 CODE is either DELETE_EXPR or VEC_DELETE_EXPR.
2880 ADDR is the pointer to be deleted. For placement delete, it is also
2881 used to determine what the corresponding new looked like.
2882 SIZE is the size of the memory block to be deleted.
2883 FLAGS are the usual overloading flags.
2884 PLACEMENT is the corresponding placement new call, or 0. */
2887 build_op_delete_call (code
, addr
, size
, flags
, placement
)
2888 enum tree_code code
;
2889 tree addr
, size
, placement
;
2892 tree fn
, fns
, fnname
, fntype
, argtypes
, args
, type
;
2894 if (addr
== error_mark_node
)
2895 return error_mark_node
;
2897 type
= TREE_TYPE (TREE_TYPE (addr
));
2898 fnname
= ansi_opname
[code
];
2900 if (IS_AGGR_TYPE (type
) && ! (flags
& LOOKUP_GLOBAL
))
2903 If the result of the lookup is ambiguous or inaccessible, or if
2904 the lookup selects a placement deallocation function, the
2905 program is ill-formed.
2907 Therefore, we ask lookup_fnfields to complain ambout ambiguity. */
2909 fns
= lookup_fnfields (TYPE_BINFO (type
), fnname
, 1);
2910 if (fns
== error_mark_node
)
2911 return error_mark_node
;
2916 if (fns
== NULL_TREE
)
2917 fns
= lookup_name_nonclass (fnname
);
2921 /* placement is a CALL_EXPR around an ADDR_EXPR around a function. */
2923 /* Extract the function. */
2924 argtypes
= TREE_OPERAND (TREE_OPERAND (placement
, 0), 0);
2925 /* Then the second parm type. */
2926 argtypes
= TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (argtypes
)));
2928 /* Also the second argument. */
2929 args
= TREE_CHAIN (TREE_OPERAND (placement
, 1));
2933 /* First try it without the size argument. */
2934 argtypes
= void_list_node
;
2938 argtypes
= tree_cons (NULL_TREE
, ptr_type_node
, argtypes
);
2939 fntype
= build_function_type (void_type_node
, argtypes
);
2941 /* Strip const and volatile from addr. */
2942 if (type
!= TYPE_MAIN_VARIANT (type
))
2943 addr
= cp_convert (build_pointer_type (TYPE_MAIN_VARIANT (type
)), addr
);
2945 fn
= instantiate_type (fntype
, fns
, 0);
2947 if (fn
!= error_mark_node
)
2949 if (TREE_CODE (fns
) == TREE_LIST
)
2950 /* Member functions. */
2951 enforce_access (TREE_PURPOSE (fns
), fn
);
2952 return build_function_call (fn
, expr_tree_cons (NULL_TREE
, addr
, args
));
2955 /* If we are doing placement delete we do nothing if we don't find a
2956 matching op delete. */
2960 /* Normal delete; now try to find a match including the size argument. */
2961 argtypes
= tree_cons (NULL_TREE
, ptr_type_node
,
2962 tree_cons (NULL_TREE
, sizetype
, void_list_node
));
2963 fntype
= build_function_type (void_type_node
, argtypes
);
2965 fn
= instantiate_type (fntype
, fns
, 0);
2967 if (fn
!= error_mark_node
)
2969 if (TREE_CODE (fns
) == TREE_LIST
)
2970 /* Member functions. */
2971 enforce_access (TREE_PURPOSE (fns
), fn
);
2972 return build_function_call
2973 (fn
, expr_tree_cons (NULL_TREE
, addr
,
2974 build_expr_list (NULL_TREE
, size
)));
2977 /* finish_function passes LOOKUP_SPECULATIVELY if we're in a
2978 destructor, in which case the error should be deferred
2979 until someone actually tries to delete one of these. */
2980 if (flags
& LOOKUP_SPECULATIVELY
)
2983 cp_error ("no suitable operator delete for `%T'", type
);
2984 return error_mark_node
;
2987 /* If the current scope isn't allowed to access DECL along
2988 BASETYPE_PATH, give an error. The most derived class in
2989 BASETYPE_PATH is the one used to qualify DECL. */
2992 enforce_access (basetype_path
, decl
)
2998 accessible
= accessible_p (basetype_path
, decl
);
3001 if (TREE_PRIVATE (decl
))
3002 cp_error_at ("`%+#D' is private", decl
);
3003 else if (TREE_PROTECTED (decl
))
3004 cp_error_at ("`%+#D' is protected", decl
);
3006 cp_error_at ("`%+#D' is inaccessible", decl
);
3007 cp_error ("within this context");
3014 /* Perform the conversions in CONVS on the expression EXPR. */
3017 convert_like (convs
, expr
)
3020 if (ICS_BAD_FLAG (convs
)
3021 && TREE_CODE (convs
) != USER_CONV
3022 && TREE_CODE (convs
) != AMBIG_CONV
)
3025 for (; t
; t
= TREE_OPERAND (t
, 0))
3027 if (TREE_CODE (t
) == USER_CONV
)
3029 expr
= convert_like (t
, expr
);
3032 else if (TREE_CODE (t
) == AMBIG_CONV
)
3033 return convert_like (t
, expr
);
3034 else if (TREE_CODE (t
) == IDENTITY_CONV
)
3037 return convert_for_initialization
3038 (NULL_TREE
, TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
,
3039 "conversion", NULL_TREE
, 0);
3042 switch (TREE_CODE (convs
))
3046 struct z_candidate
*cand
3047 = WRAPPER_PTR (TREE_OPERAND (convs
, 1));
3051 if (DECL_CONSTRUCTOR_P (fn
))
3053 tree t
= build_int_2 (0, 0);
3054 TREE_TYPE (t
) = build_pointer_type (DECL_CONTEXT (fn
));
3056 args
= build_scratch_list (NULL_TREE
, expr
);
3057 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3058 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
3059 args
= scratch_tree_cons (NULL_TREE
, t
, args
);
3062 args
= build_this (expr
);
3063 expr
= build_over_call (cand
, args
, LOOKUP_NORMAL
);
3065 /* If this is a constructor or a function returning an aggr type,
3066 we need to build up a TARGET_EXPR. */
3067 if (DECL_CONSTRUCTOR_P (fn
))
3068 expr
= build_cplus_new (TREE_TYPE (convs
), expr
);
3073 if (type_unknown_p (expr
))
3074 expr
= instantiate_type (TREE_TYPE (convs
), expr
, 1);
3075 if (TREE_READONLY_DECL_P (expr
))
3076 expr
= decl_constant_value (expr
);
3079 /* Call build_user_type_conversion again for the error. */
3080 return build_user_type_conversion
3081 (TREE_TYPE (convs
), TREE_OPERAND (convs
, 0), LOOKUP_NORMAL
);
3087 expr
= convert_like (TREE_OPERAND (convs
, 0), expr
);
3088 if (expr
== error_mark_node
)
3089 return error_mark_node
;
3091 switch (TREE_CODE (convs
))
3094 if (! IS_AGGR_TYPE (TREE_TYPE (convs
)))
3096 /* else fall through */
3099 tree cvt_expr
= build_user_type_conversion
3100 (TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
);
3103 /* This can occur if, for example, the EXPR has incomplete
3104 type. We can't check for that before attempting the
3105 conversion because the type might be an incomplete
3106 array type, which is OK if some constructor for the
3107 destination type takes a pointer argument. */
3108 if (TYPE_SIZE (TREE_TYPE (expr
)) == 0)
3110 if (same_type_p (TREE_TYPE (expr
), TREE_TYPE (convs
)))
3111 incomplete_type_error (expr
, TREE_TYPE (expr
));
3113 cp_error ("could not convert `%E' (with incomplete type `%T') to `%T'",
3114 expr
, TREE_TYPE (expr
), TREE_TYPE (convs
));
3117 cp_error ("could not convert `%E' to `%T'",
3118 expr
, TREE_TYPE (convs
));
3119 return error_mark_node
;
3125 return convert_to_reference
3126 (TREE_TYPE (convs
), expr
,
3127 CONV_IMPLICIT
, LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
,
3130 return decay_conversion (expr
);
3133 /* Warn about deprecated conversion if appropriate. */
3134 string_conv_p (TREE_TYPE (convs
), expr
, 1);
3140 return ocp_convert (TREE_TYPE (convs
), expr
, CONV_IMPLICIT
,
3141 LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
);
3144 /* ARG is being passed to a varargs function. Perform any conversions
3145 required. Return the converted value. */
3148 convert_arg_to_ellipsis (arg
)
3151 if (TREE_CODE (TREE_TYPE (arg
)) == REAL_TYPE
3152 && (TYPE_PRECISION (TREE_TYPE (arg
))
3153 < TYPE_PRECISION (double_type_node
)))
3154 /* Convert `float' to `double'. */
3155 arg
= cp_convert (double_type_node
, arg
);
3156 else if (IS_AGGR_TYPE (TREE_TYPE (arg
))
3157 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (arg
)))
3158 cp_warning ("cannot pass objects of type `%T' through `...'",
3161 /* Convert `short' and `char' to full-size `int'. */
3162 arg
= default_conversion (arg
);
3164 arg
= require_complete_type (arg
);
3169 /* ARG is a default argument expression being passed to a parameter of
3170 the indicated TYPE, which is a parameter to FN. Do any required
3171 conversions. Return the converted value. */
3174 convert_default_arg (type
, arg
, fn
)
3179 if (fn
&& DECL_TEMPLATE_INFO (fn
))
3181 /* This default argument came from a template. Instantiate the
3182 default argument here, not in tsubst. In the case of
3191 we must be careful to do name lookup in the scope of S<T>,
3192 rather than in the current class. */
3193 if (DECL_CLASS_SCOPE_P (fn
))
3194 pushclass (DECL_REAL_CONTEXT (fn
), 2);
3196 arg
= tsubst_expr (arg
, DECL_TI_ARGS (fn
), /*complain=*/1, NULL_TREE
);
3198 if (DECL_CLASS_SCOPE_P (fn
))
3201 /* Make sure the default argument is reasonable. */
3202 arg
= check_default_argument (type
, arg
);
3205 arg
= break_out_target_exprs (arg
);
3207 if (TREE_CODE (arg
) == CONSTRUCTOR
)
3209 arg
= digest_init (type
, arg
, 0);
3210 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
3211 "default argument", 0, 0);
3215 /* This could get clobbered by the following call. */
3216 if (TREE_HAS_CONSTRUCTOR (arg
))
3217 arg
= copy_node (arg
);
3219 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
3220 "default argument", 0, 0);
3221 #ifdef PROMOTE_PROTOTYPES
3222 if ((TREE_CODE (type
) == INTEGER_TYPE
3223 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3224 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
3225 arg
= default_conversion (arg
);
3233 build_over_call (cand
, args
, flags
)
3234 struct z_candidate
*cand
;
3239 tree convs
= cand
->convs
;
3240 tree converted_args
= NULL_TREE
;
3241 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
3242 tree conv
, arg
, val
;
3246 /* Give any warnings we noticed during overload resolution. */
3248 for (val
= cand
->warnings
; val
; val
= TREE_CHAIN (val
))
3249 joust (cand
, WRAPPER_PTR (TREE_VALUE (val
)), 1);
3251 if (DECL_FUNCTION_MEMBER_P (fn
))
3252 enforce_access (cand
->basetype_path
, fn
);
3254 if (args
&& TREE_CODE (args
) != TREE_LIST
)
3255 args
= build_scratch_list (NULL_TREE
, args
);
3258 /* The implicit parameters to a constructor are not considered by overload
3259 resolution, and must be of the proper type. */
3260 if (DECL_CONSTRUCTOR_P (fn
))
3262 converted_args
= expr_tree_cons (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
3263 arg
= TREE_CHAIN (arg
);
3264 parm
= TREE_CHAIN (parm
);
3265 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3267 converted_args
= expr_tree_cons
3268 (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
3269 arg
= TREE_CHAIN (arg
);
3270 parm
= TREE_CHAIN (parm
);
3273 /* Bypass access control for 'this' parameter. */
3274 else if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
3276 tree parmtype
= TREE_VALUE (parm
);
3277 tree argtype
= TREE_TYPE (TREE_VALUE (arg
));
3279 if (ICS_BAD_FLAG (TREE_VEC_ELT (convs
, i
)))
3280 cp_pedwarn ("passing `%T' as `this' argument of `%#D' discards qualifiers",
3281 TREE_TYPE (argtype
), fn
);
3283 /* [class.mfct.nonstatic]: If a nonstatic member function of a class
3284 X is called for an object that is not of type X, or of a type
3285 derived from X, the behavior is undefined.
3287 So we can assume that anything passed as 'this' is non-null, and
3288 optimize accordingly. */
3289 if (TREE_CODE (parmtype
) == POINTER_TYPE
)
3290 t
= convert_pointer_to_real (TREE_TYPE (parmtype
), TREE_VALUE (arg
));
3292 /* This happens with signatures. */
3293 t
= convert_force (parmtype
, TREE_VALUE (arg
), CONV_C_CAST
);
3294 converted_args
= expr_tree_cons (NULL_TREE
, t
, converted_args
);
3295 parm
= TREE_CHAIN (parm
);
3296 arg
= TREE_CHAIN (arg
);
3302 parm
= TREE_CHAIN (parm
), arg
= TREE_CHAIN (arg
), ++i
)
3304 tree type
= TREE_VALUE (parm
);
3306 conv
= TREE_VEC_ELT (convs
, i
);
3307 if (ICS_BAD_FLAG (conv
))
3310 val
= TREE_VALUE (arg
);
3312 for (; t
; t
= TREE_OPERAND (t
, 0))
3314 if (TREE_CODE (t
) == USER_CONV
3315 || TREE_CODE (t
) == AMBIG_CONV
)
3317 val
= convert_like (t
, val
);
3320 else if (TREE_CODE (t
) == IDENTITY_CONV
)
3323 val
= convert_for_initialization
3324 (NULL_TREE
, type
, val
, LOOKUP_NORMAL
,
3325 "argument passing", fn
, i
- is_method
);
3329 /* Issue warnings about peculiar, but legal, uses of NULL. */
3330 if (ARITHMETIC_TYPE_P (TREE_VALUE (parm
))
3331 && TREE_VALUE (arg
) == null_node
)
3332 cp_warning ("converting NULL to non-pointer type");
3334 val
= convert_like (conv
, TREE_VALUE (arg
));
3337 #ifdef PROMOTE_PROTOTYPES
3338 if ((TREE_CODE (type
) == INTEGER_TYPE
3339 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3340 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
3341 val
= default_conversion (val
);
3343 converted_args
= expr_tree_cons (NULL_TREE
, val
, converted_args
);
3346 /* Default arguments */
3347 for (; parm
&& parm
!= void_list_node
; parm
= TREE_CHAIN (parm
))
3349 = expr_tree_cons (NULL_TREE
,
3350 convert_default_arg (TREE_VALUE (parm
),
3351 TREE_PURPOSE (parm
),
3356 for (; arg
; arg
= TREE_CHAIN (arg
))
3358 = expr_tree_cons (NULL_TREE
,
3359 convert_arg_to_ellipsis (TREE_VALUE (arg
)),
3362 converted_args
= nreverse (converted_args
);
3364 if (warn_format
&& (DECL_NAME (fn
) || DECL_ASSEMBLER_NAME (fn
)))
3365 check_function_format (DECL_NAME (fn
), DECL_ASSEMBLER_NAME (fn
),
3368 /* Avoid actually calling copy constructors and copy assignment operators,
3371 if (! flag_elide_constructors
)
3372 /* Do things the hard way. */;
3373 else if (DECL_CONSTRUCTOR_P (fn
)
3374 && TREE_VEC_LENGTH (convs
) == 1
3375 && copy_args_p (fn
))
3378 arg
= TREE_CHAIN (converted_args
);
3379 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3380 arg
= TREE_CHAIN (arg
);
3381 arg
= TREE_VALUE (arg
);
3383 /* Pull out the real argument, disregarding const-correctness. */
3385 while (TREE_CODE (targ
) == NOP_EXPR
3386 || TREE_CODE (targ
) == NON_LVALUE_EXPR
3387 || TREE_CODE (targ
) == CONVERT_EXPR
)
3388 targ
= TREE_OPERAND (targ
, 0);
3389 if (TREE_CODE (targ
) == ADDR_EXPR
)
3391 targ
= TREE_OPERAND (targ
, 0);
3392 if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg
))),
3393 TYPE_MAIN_VARIANT (TREE_TYPE (targ
))))
3402 arg
= build_indirect_ref (arg
, 0);
3404 /* [class.copy]: the copy constructor is implicitly defined even if
3405 the implementation elided its use. */
3406 if (TYPE_HAS_COMPLEX_INIT_REF (DECL_CONTEXT (fn
)))
3409 /* If we're creating a temp and we already have one, don't create a
3410 new one. If we're not creating a temp but we get one, use
3411 INIT_EXPR to collapse the temp into our target. Otherwise, if the
3412 ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
3413 temp or an INIT_EXPR otherwise. */
3414 if (integer_zerop (TREE_VALUE (args
)))
3416 if (! real_lvalue_p (arg
))
3418 else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
3420 val
= build_decl (VAR_DECL
, NULL_TREE
, DECL_CONTEXT (fn
));
3421 val
= build (TARGET_EXPR
, DECL_CONTEXT (fn
), val
, arg
, 0, 0);
3422 TREE_SIDE_EFFECTS (val
) = 1;
3426 else if (! real_lvalue_p (arg
)
3427 || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
3429 tree to
= stabilize_reference
3430 (build_indirect_ref (TREE_VALUE (args
), 0));
3432 /* Don't copy the padding byte; it might not have been allocated
3433 if to is a base subobject. */
3434 if (is_empty_class (DECL_CLASS_CONTEXT (fn
)))
3435 return build_unary_op
3436 (ADDR_EXPR
, build (COMPOUND_EXPR
, TREE_TYPE (to
),
3437 cp_convert (void_type_node
, arg
), to
),
3440 val
= build (INIT_EXPR
, DECL_CONTEXT (fn
), to
, arg
);
3441 TREE_SIDE_EFFECTS (val
) = 1;
3442 return build_unary_op (ADDR_EXPR
, val
, 0);
3445 else if (DECL_NAME (fn
) == ansi_opname
[MODIFY_EXPR
]
3447 && TYPE_HAS_TRIVIAL_ASSIGN_REF (DECL_CLASS_CONTEXT (fn
)))
3449 tree to
= stabilize_reference
3450 (build_indirect_ref (TREE_VALUE (converted_args
), 0));
3452 arg
= build_indirect_ref (TREE_VALUE (TREE_CHAIN (converted_args
)), 0);
3454 /* Don't copy the padding byte; it might not have been allocated
3455 if to is a base subobject. */
3456 if (is_empty_class (DECL_CLASS_CONTEXT (fn
)))
3457 return build (COMPOUND_EXPR
, TREE_TYPE (to
),
3458 cp_convert (void_type_node
, arg
), to
);
3460 val
= build (MODIFY_EXPR
, TREE_TYPE (to
), to
, arg
);
3461 TREE_SIDE_EFFECTS (val
) = 1;
3467 if (DECL_CLASS_SCOPE_P (fn
) && IS_SIGNATURE (DECL_CONTEXT (fn
)))
3468 return build_signature_method_call (fn
, converted_args
);
3469 else if (DECL_VINDEX (fn
) && (flags
& LOOKUP_NONVIRTUAL
) == 0)
3471 tree t
, *p
= &TREE_VALUE (converted_args
);
3472 tree binfo
= get_binfo
3473 (DECL_CONTEXT (fn
), TREE_TYPE (TREE_TYPE (*p
)), 0);
3474 *p
= convert_pointer_to_real (binfo
, *p
);
3475 if (TREE_SIDE_EFFECTS (*p
))
3476 *p
= save_expr (*p
);
3477 t
= build_pointer_type (TREE_TYPE (fn
));
3478 fn
= build_vfn_ref (p
, build_indirect_ref (*p
, 0), DECL_VINDEX (fn
));
3481 else if (DECL_INLINE (fn
))
3482 fn
= inline_conversion (fn
);
3484 fn
= build_addr_func (fn
);
3486 /* Recognize certain built-in functions so we can make tree-codes
3487 other than CALL_EXPR. We do this when it enables fold-const.c
3488 to do something useful. */
3490 if (TREE_CODE (fn
) == ADDR_EXPR
3491 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
3492 && DECL_BUILT_IN (TREE_OPERAND (fn
, 0)))
3493 switch (DECL_FUNCTION_CODE (TREE_OPERAND (fn
, 0)))
3498 if (converted_args
== 0)
3499 return integer_zero_node
;
3500 return build_unary_op (ABS_EXPR
, TREE_VALUE (converted_args
), 0);
3505 fn
= build_call (fn
, TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))), converted_args
);
3506 if (TREE_CODE (TREE_TYPE (fn
)) == VOID_TYPE
)
3508 fn
= require_complete_type (fn
);
3509 if (IS_AGGR_TYPE (TREE_TYPE (fn
)))
3510 fn
= build_cplus_new (TREE_TYPE (fn
), fn
);
3511 return convert_from_reference (fn
);
3515 build_new_method_call (instance
, name
, args
, basetype_path
, flags
)
3516 tree instance
, name
, args
, basetype_path
;
3519 struct z_candidate
*candidates
= 0, *cand
;
3520 tree explicit_targs
= NULL_TREE
;
3521 tree basetype
, mem_args
= NULL_TREE
, fns
, instance_ptr
;
3523 tree user_args
= args
;
3524 tree templates
= NULL_TREE
;
3525 int template_only
= 0;
3527 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
3529 explicit_targs
= TREE_OPERAND (name
, 1);
3530 name
= TREE_OPERAND (name
, 0);
3531 if (TREE_CODE_CLASS (TREE_CODE (name
)) == 'd')
3532 name
= DECL_NAME (name
);
3535 if (TREE_CODE (name
) == COMPONENT_REF
)
3536 name
= TREE_OPERAND (name
, 1);
3537 if (TREE_CODE (name
) == OVERLOAD
)
3538 name
= DECL_NAME (OVL_CURRENT (name
));
3544 /* If there is an extra argument for controlling virtual bases,
3545 remove it for error reporting. */
3546 if (flags
& LOOKUP_HAS_IN_CHARGE
)
3547 user_args
= TREE_CHAIN (args
);
3549 args
= resolve_args (args
);
3551 if (args
== error_mark_node
)
3552 return error_mark_node
;
3554 if (instance
== NULL_TREE
)
3555 basetype
= BINFO_TYPE (basetype_path
);
3558 if (TREE_CODE (instance
) == OFFSET_REF
)
3559 instance
= resolve_offset_ref (instance
);
3560 if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
3561 instance
= convert_from_reference (instance
);
3562 basetype
= TREE_TYPE (instance
);
3564 /* XXX this should be handled before we get here. */
3565 if (! IS_AGGR_TYPE (basetype
)
3566 && ! (TYPE_LANG_SPECIFIC (basetype
)
3567 && (IS_SIGNATURE_POINTER (basetype
)
3568 || IS_SIGNATURE_REFERENCE (basetype
))))
3570 if ((flags
& LOOKUP_COMPLAIN
) && basetype
!= error_mark_node
)
3571 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
3572 name
, instance
, basetype
);
3574 return error_mark_node
;
3577 /* If `instance' is a signature pointer/reference and `name' is
3578 not a constructor, we are calling a signature member function.
3579 In that case set the `basetype' to the signature type. */
3580 if ((IS_SIGNATURE_POINTER (basetype
)
3581 || IS_SIGNATURE_REFERENCE (basetype
))
3582 && TYPE_IDENTIFIER (basetype
) != name
)
3583 basetype
= SIGNATURE_TYPE (basetype
);
3586 if (basetype_path
== NULL_TREE
)
3587 basetype_path
= TYPE_BINFO (basetype
);
3591 instance_ptr
= build_this (instance
);
3593 if (! template_only
)
3595 /* XXX this should be handled before we get here. */
3596 fns
= build_field_call (basetype_path
, instance_ptr
, name
, args
);
3603 instance_ptr
= build_int_2 (0, 0);
3604 TREE_TYPE (instance_ptr
) = build_pointer_type (basetype
);
3608 = (name
== ctor_identifier
? constructor_name (basetype
) : name
);
3610 fns
= lookup_fnfields (basetype_path
, name
, 1);
3612 if (fns
== error_mark_node
)
3613 return error_mark_node
;
3616 tree fn
= TREE_VALUE (fns
);
3617 if (name
== ctor_identifier
&& TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
3618 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
3620 flags
|= LOOKUP_HAS_IN_CHARGE
;
3621 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
3623 mem_args
= scratch_tree_cons (NULL_TREE
, instance_ptr
, args
);
3624 for (; fn
; fn
= OVL_NEXT (fn
))
3626 tree t
= OVL_CURRENT (fn
);
3629 /* We can end up here for copy-init of same or base class. */
3630 if (name
== ctor_identifier
3631 && (flags
& LOOKUP_ONLYCONVERTING
)
3632 && DECL_NONCONVERTING_P (t
))
3634 if (TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)
3635 this_arglist
= mem_args
;
3637 this_arglist
= args
;
3639 if (TREE_CODE (t
) == TEMPLATE_DECL
)
3641 /* A member template. */
3642 templates
= scratch_tree_cons (NULL_TREE
, t
, templates
);
3644 add_template_candidate (candidates
, t
, explicit_targs
,
3646 TREE_TYPE (name
), flags
, DEDUCE_CALL
);
3648 else if (! template_only
)
3649 candidates
= add_function_candidate (candidates
, t
,
3650 this_arglist
, flags
);
3653 candidates
->basetype_path
= TREE_PURPOSE (fns
);
3657 if (! any_viable (candidates
))
3659 /* XXX will LOOKUP_SPECULATIVELY be needed when this is done? */
3660 if (flags
& LOOKUP_SPECULATIVELY
)
3662 if (TYPE_SIZE (basetype
) == 0)
3663 incomplete_type_error (instance_ptr
, basetype
);
3665 cp_error ("no matching function for call to `%T::%D (%A)%V'",
3666 basetype
, pretty_name
, user_args
,
3667 TREE_TYPE (TREE_TYPE (instance_ptr
)));
3668 print_z_candidates (candidates
);
3669 return error_mark_node
;
3671 candidates
= splice_viable (candidates
);
3672 cand
= tourney (candidates
);
3676 cp_error ("call of overloaded `%D(%A)' is ambiguous", pretty_name
,
3678 print_z_candidates (candidates
);
3679 return error_mark_node
;
3682 if (DECL_ABSTRACT_VIRTUAL_P (cand
->fn
)
3683 && instance
== current_class_ref
3684 && DECL_CONSTRUCTOR_P (current_function_decl
)
3685 && ! (flags
& LOOKUP_NONVIRTUAL
)
3686 && value_member (cand
->fn
, CLASSTYPE_ABSTRACT_VIRTUALS (basetype
)))
3687 cp_error ("abstract virtual `%#D' called from constructor", cand
->fn
);
3688 if (TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
3689 && is_dummy_object (instance_ptr
))
3691 cp_error ("cannot call member function `%D' without object", cand
->fn
);
3692 return error_mark_node
;
3695 if (DECL_VINDEX (cand
->fn
) && ! (flags
& LOOKUP_NONVIRTUAL
)
3696 && ((instance
== current_class_ref
&& (dtor_label
|| ctor_label
))
3697 || resolves_to_fixed_type_p (instance
, 0)))
3698 flags
|= LOOKUP_NONVIRTUAL
;
3700 /* Pedantically, normal function declarations are never considered
3701 to refer to template instantiations, so we only do this with
3703 if (flag_guiding_decls
&& templates
&& ! cand
->template
3704 && ! DECL_INITIAL (cand
->fn
))
3705 add_maybe_template (cand
->fn
, templates
);
3707 return build_over_call
3709 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
? mem_args
: args
,
3713 /* Returns non-zero iff standard conversion sequence ICS1 is a proper
3714 subsequence of ICS2. */
3717 is_subseq (ics1
, ics2
)
3720 /* We can assume that a conversion of the same code
3721 between the same types indicates a subsequence since we only get
3722 here if the types we are converting from are the same. */
3724 while (TREE_CODE (ics1
) == RVALUE_CONV
3725 || TREE_CODE (ics1
) == LVALUE_CONV
)
3726 ics1
= TREE_OPERAND (ics1
, 0);
3730 while (TREE_CODE (ics2
) == RVALUE_CONV
3731 || TREE_CODE (ics2
) == LVALUE_CONV
)
3732 ics2
= TREE_OPERAND (ics2
, 0);
3734 if (TREE_CODE (ics2
) == USER_CONV
3735 || TREE_CODE (ics2
) == AMBIG_CONV
3736 || TREE_CODE (ics2
) == IDENTITY_CONV
)
3737 /* At this point, ICS1 cannot be a proper subsequence of
3738 ICS2. We can get a USER_CONV when we are comparing the
3739 second standard conversion sequence of two user conversion
3743 ics2
= TREE_OPERAND (ics2
, 0);
3745 if (TREE_CODE (ics2
) == TREE_CODE (ics1
)
3746 && same_type_p (TREE_TYPE (ics2
), TREE_TYPE (ics1
))
3747 && same_type_p (TREE_TYPE (TREE_OPERAND (ics2
, 0)),
3748 TREE_TYPE (TREE_OPERAND (ics1
, 0))))
3753 /* Returns non-zero iff DERIVED is derived from BASE. The inputs may
3754 be any _TYPE nodes. */
3757 is_properly_derived_from (derived
, base
)
3761 if (!IS_AGGR_TYPE_CODE (TREE_CODE (derived
))
3762 || !IS_AGGR_TYPE_CODE (TREE_CODE (base
)))
3765 /* We only allow proper derivation here. The DERIVED_FROM_P macro
3766 considers every class derived from itself. */
3767 return (!same_type_p (TYPE_MAIN_VARIANT (derived
),
3768 TYPE_MAIN_VARIANT (base
))
3769 && DERIVED_FROM_P (base
, derived
));
3772 /* We build the ICS for an implicit object parameter as a pointer
3773 conversion sequence. However, such a sequence should be compared
3774 as if it were a reference conversion sequence. If ICS is the
3775 implicit conversion sequence for an implicit object parameter,
3776 modify it accordingly. */
3779 maybe_handle_implicit_object (ics
)
3782 if (ICS_THIS_FLAG (*ics
))
3784 /* [over.match.funcs]
3786 For non-static member functions, the type of the
3787 implicit object parameter is "reference to cv X"
3788 where X is the class of which the function is a
3789 member and cv is the cv-qualification on the member
3790 function declaration. */
3792 if (TREE_CODE (t
) == QUAL_CONV
)
3793 t
= TREE_OPERAND (t
, 0);
3794 if (TREE_CODE (t
) == PTR_CONV
)
3795 t
= TREE_OPERAND (t
, 0);
3796 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
3797 t
= build_conv (REF_BIND
,
3798 build_reference_type (TREE_TYPE (TREE_TYPE (*ics
))),
3800 ICS_STD_RANK (t
) = ICS_STD_RANK (*ics
);
3805 /* If ICS is a REF_BIND, modify it appropriately, set TARGET_TYPE
3806 to the type the reference originally referred to, and return 1.
3807 Otherwise, return 0. */
3810 maybe_handle_ref_bind (ics
, target_type
)
3814 if (TREE_CODE (*ics
) == REF_BIND
)
3818 When a parameter of reference type binds directly
3819 (_dcl.init.ref_) to an argument expression, the implicit
3820 conversion sequence is the identity conversion, unless the
3821 argument expression has a type that is a derived class of the
3822 parameter type, in which case the implicit conversion
3823 sequence is a derived-to-base Conversion.
3825 If the parameter binds directly to the result of applying a
3826 conversion function to the argument expression, the implicit
3827 conversion sequence is a user-defined conversion sequence
3828 (_over.ics.user_), with the second standard conversion
3829 sequence either an identity conversion or, if the conversion
3830 function returns an entity of a type that is a derived class
3831 of the parameter type, a derived-to-base Conversion.
3833 When a parameter of reference type is not bound directly to
3834 an argument expression, the conversion sequence is the one
3835 required to convert the argument expression to the underlying
3836 type of the reference according to _over.best.ics_.
3837 Conceptually, this conversion sequence corresponds to
3838 copy-initializing a temporary of the underlying type with the
3839 argument expression. Any difference in top-level
3840 cv-qualification is subsumed by the initialization itself and
3841 does not constitute a conversion. */
3843 tree old_ics
= *ics
;
3845 *target_type
= TREE_TYPE (TREE_TYPE (*ics
));
3846 *ics
= TREE_OPERAND (*ics
, 0);
3847 if (TREE_CODE (*ics
) == IDENTITY_CONV
3848 && is_properly_derived_from (TREE_TYPE (*ics
), *target_type
))
3849 *ics
= build_conv (BASE_CONV
, *target_type
, *ics
);
3850 ICS_USER_FLAG (*ics
) = ICS_USER_FLAG (old_ics
);
3851 ICS_BAD_FLAG (*ics
) = ICS_BAD_FLAG (old_ics
);
3859 /* Compare two implicit conversion sequences according to the rules set out in
3860 [over.ics.rank]. Return values:
3862 1: ics1 is better than ics2
3863 -1: ics2 is better than ics1
3864 0: ics1 and ics2 are indistinguishable */
3867 compare_ics (ics1
, ics2
)
3874 tree deref_from_type1
= NULL_TREE
;
3875 tree deref_from_type2
= NULL_TREE
;
3876 tree deref_to_type1
= NULL_TREE
;
3877 tree deref_to_type2
= NULL_TREE
;
3879 /* REF_BINDING is non-zero if the result of the conversion sequence
3880 is a reference type. In that case TARGET_TYPE is the
3881 type referred to by the reference. */
3887 /* Handle implicit object parameters. */
3888 maybe_handle_implicit_object (&ics1
);
3889 maybe_handle_implicit_object (&ics2
);
3891 /* Handle reference parameters. */
3892 ref_binding1
= maybe_handle_ref_bind (&ics1
, &target_type1
);
3893 ref_binding2
= maybe_handle_ref_bind (&ics2
, &target_type2
);
3897 When comparing the basic forms of implicit conversion sequences (as
3898 defined in _over.best.ics_)
3900 --a standard conversion sequence (_over.ics.scs_) is a better
3901 conversion sequence than a user-defined conversion sequence
3902 or an ellipsis conversion sequence, and
3904 --a user-defined conversion sequence (_over.ics.user_) is a
3905 better conversion sequence than an ellipsis conversion sequence
3906 (_over.ics.ellipsis_). */
3907 if (ICS_RANK (ics1
) > ICS_RANK (ics2
))
3909 else if (ICS_RANK (ics1
) < ICS_RANK (ics2
))
3912 if (ICS_RANK (ics1
) == BAD_RANK
)
3914 /* Both ICS are bad. We try to make a decision based on what
3915 would have happenned if they'd been good. */
3916 if (ICS_USER_FLAG (ics1
) > ICS_USER_FLAG (ics2
)
3917 || ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
3919 else if (ICS_USER_FLAG (ics1
) < ICS_USER_FLAG (ics2
)
3920 || ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
3923 /* We couldn't make up our minds; try to figure it out below. */
3926 if (ICS_ELLIPSIS_FLAG (ics1
))
3927 /* Both conversions are ellipsis conversions. */
3930 /* User-defined conversion sequence U1 is a better conversion sequence
3931 than another user-defined conversion sequence U2 if they contain the
3932 same user-defined conversion operator or constructor and if the sec-
3933 ond standard conversion sequence of U1 is better than the second
3934 standard conversion sequence of U2. */
3936 if (ICS_USER_FLAG (ics1
))
3940 for (t1
= ics1
; TREE_CODE (t1
) != USER_CONV
; t1
= TREE_OPERAND (t1
, 0))
3941 if (TREE_CODE (t1
) == AMBIG_CONV
)
3943 for (t2
= ics2
; TREE_CODE (t2
) != USER_CONV
; t2
= TREE_OPERAND (t2
, 0))
3944 if (TREE_CODE (t2
) == AMBIG_CONV
)
3947 if (USER_CONV_FN (t1
) != USER_CONV_FN (t2
))
3950 /* We can just fall through here, after setting up
3951 FROM_TYPE1 and FROM_TYPE2. */
3952 from_type1
= TREE_TYPE (t1
);
3953 from_type2
= TREE_TYPE (t2
);
3957 /* We're dealing with two standard conversion sequences.
3961 Standard conversion sequence S1 is a better conversion
3962 sequence than standard conversion sequence S2 if
3964 --S1 is a proper subsequence of S2 (comparing the conversion
3965 sequences in the canonical form defined by _over.ics.scs_,
3966 excluding any Lvalue Transformation; the identity
3967 conversion sequence is considered to be a subsequence of
3968 any non-identity conversion sequence */
3971 while (TREE_CODE (from_type1
) != IDENTITY_CONV
)
3972 from_type1
= TREE_OPERAND (from_type1
, 0);
3973 from_type1
= TREE_TYPE (from_type1
);
3976 while (TREE_CODE (from_type2
) != IDENTITY_CONV
)
3977 from_type2
= TREE_OPERAND (from_type2
, 0);
3978 from_type2
= TREE_TYPE (from_type2
);
3981 if (same_type_p (from_type1
, from_type2
))
3983 if (is_subseq (ics1
, ics2
))
3985 if (is_subseq (ics2
, ics1
))
3988 /* Otherwise, one sequence cannot be a subsequence of the other; they
3989 don't start with the same type. This can happen when comparing the
3990 second standard conversion sequence in two user-defined conversion
3997 --the rank of S1 is better than the rank of S2 (by the rules
4000 Standard conversion sequences are ordered by their ranks: an Exact
4001 Match is a better conversion than a Promotion, which is a better
4002 conversion than a Conversion.
4004 Two conversion sequences with the same rank are indistinguishable
4005 unless one of the following rules applies:
4007 --A conversion that is not a conversion of a pointer, or pointer
4008 to member, to bool is better than another conversion that is such
4011 The ICS_STD_RANK automatically handles the pointer-to-bool rule,
4012 so that we do not have to check it explicitly. */
4013 if (ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
4015 else if (ICS_STD_RANK (ics2
) < ICS_STD_RANK (ics1
))
4018 to_type1
= TREE_TYPE (ics1
);
4019 to_type2
= TREE_TYPE (ics2
);
4021 if (TYPE_PTR_P (from_type1
)
4022 && TYPE_PTR_P (from_type2
)
4023 && TYPE_PTR_P (to_type1
)
4024 && TYPE_PTR_P (to_type2
))
4026 deref_from_type1
= TREE_TYPE (from_type1
);
4027 deref_from_type2
= TREE_TYPE (from_type2
);
4028 deref_to_type1
= TREE_TYPE (to_type1
);
4029 deref_to_type2
= TREE_TYPE (to_type2
);
4031 /* The rules for pointers to members A::* are just like the rules
4032 for pointers A*, except opposite: if B is derived from A then
4033 A::* converts to B::*, not vice versa. For that reason, we
4034 switch the from_ and to_ variables here. */
4035 else if (TYPE_PTRMEM_P (from_type1
)
4036 && TYPE_PTRMEM_P (from_type2
)
4037 && TYPE_PTRMEM_P (to_type1
)
4038 && TYPE_PTRMEM_P (to_type2
))
4040 deref_to_type1
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from_type1
));
4041 deref_to_type2
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from_type2
));
4042 deref_from_type1
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to_type1
));
4043 deref_from_type2
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to_type2
));
4045 else if (TYPE_PTRMEMFUNC_P (from_type1
)
4046 && TYPE_PTRMEMFUNC_P (from_type2
)
4047 && TYPE_PTRMEMFUNC_P (to_type1
)
4048 && TYPE_PTRMEMFUNC_P (to_type2
))
4050 deref_to_type1
= TYPE_PTRMEMFUNC_OBJECT_TYPE (from_type1
);
4051 deref_to_type2
= TYPE_PTRMEMFUNC_OBJECT_TYPE (from_type2
);
4052 deref_from_type1
= TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type1
);
4053 deref_from_type2
= TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type2
);
4056 if (deref_from_type1
!= NULL_TREE
4057 && IS_AGGR_TYPE_CODE (TREE_CODE (deref_from_type1
))
4058 && IS_AGGR_TYPE_CODE (TREE_CODE (deref_from_type2
)))
4060 /* This was one of the pointer or pointer-like conversions.
4064 --If class B is derived directly or indirectly from class A,
4065 conversion of B* to A* is better than conversion of B* to
4066 void*, and conversion of A* to void* is better than
4067 conversion of B* to void*. */
4068 if (TREE_CODE (deref_to_type1
) == VOID_TYPE
4069 && TREE_CODE (deref_to_type2
) == VOID_TYPE
)
4071 if (is_properly_derived_from (deref_from_type1
,
4074 else if (is_properly_derived_from (deref_from_type2
,
4078 else if (TREE_CODE (deref_to_type1
) == VOID_TYPE
4079 || TREE_CODE (deref_to_type2
) == VOID_TYPE
)
4081 if (same_type_p (deref_from_type1
, deref_from_type2
))
4083 if (TREE_CODE (deref_to_type2
) == VOID_TYPE
)
4085 if (is_properly_derived_from (deref_from_type1
,
4089 /* We know that DEREF_TO_TYPE1 is `void' here. */
4090 else if (is_properly_derived_from (deref_from_type1
,
4095 else if (IS_AGGR_TYPE_CODE (TREE_CODE (deref_to_type1
))
4096 && IS_AGGR_TYPE_CODE (TREE_CODE (deref_to_type2
)))
4100 --If class B is derived directly or indirectly from class A
4101 and class C is derived directly or indirectly from B,
4103 --conversion of C* to B* is better than conversion of C* to
4106 --conversion of B* to A* is better than conversion of C* to
4108 if (same_type_p (deref_from_type1
, deref_from_type2
))
4110 if (is_properly_derived_from (deref_to_type1
,
4113 else if (is_properly_derived_from (deref_to_type2
,
4117 else if (same_type_p (deref_to_type1
, deref_to_type2
))
4119 if (is_properly_derived_from (deref_from_type2
,
4122 else if (is_properly_derived_from (deref_from_type1
,
4128 else if (IS_AGGR_TYPE_CODE (TREE_CODE (from_type1
))
4129 && same_type_p (from_type1
, from_type2
))
4133 --binding of an expression of type C to a reference of type
4134 B& is better than binding an expression of type C to a
4135 reference of type A&
4137 --conversion of C to B is better than conversion of C to A, */
4138 if (is_properly_derived_from (from_type1
, to_type1
)
4139 && is_properly_derived_from (from_type1
, to_type2
))
4141 if (is_properly_derived_from (to_type1
, to_type2
))
4143 else if (is_properly_derived_from (to_type2
, to_type1
))
4147 else if (IS_AGGR_TYPE_CODE (TREE_CODE (to_type1
))
4148 && same_type_p (to_type1
, to_type2
))
4152 --binding of an expression of type B to a reference of type
4153 A& is better than binding an expression of type C to a
4154 reference of type A&,
4156 --onversion of B to A is better than conversion of C to A */
4157 if (is_properly_derived_from (from_type1
, to_type1
)
4158 && is_properly_derived_from (from_type2
, to_type1
))
4160 if (is_properly_derived_from (from_type2
, from_type1
))
4162 else if (is_properly_derived_from (from_type1
, from_type2
))
4169 --S1 and S2 differ only in their qualification conversion and yield
4170 similar types T1 and T2 (_conv.qual_), respectively, and the cv-
4171 qualification signature of type T1 is a proper subset of the cv-
4172 qualification signature of type T2 */
4173 if (TREE_CODE (ics1
) == QUAL_CONV
4174 && TREE_CODE (ics2
) == QUAL_CONV
4175 && same_type_p (from_type1
, from_type2
))
4176 return comp_cv_qual_signature (to_type1
, to_type2
);
4180 --S1 and S2 are reference bindings (_dcl.init.ref_), and the
4181 types to which the references refer are the same type except for
4182 top-level cv-qualifiers, and the type to which the reference
4183 initialized by S2 refers is more cv-qualified than the type to
4184 which the reference initialized by S1 refers */
4186 if (ref_binding1
&& ref_binding2
4187 && same_type_p (TYPE_MAIN_VARIANT (to_type1
),
4188 TYPE_MAIN_VARIANT (to_type2
)))
4189 return comp_cv_qualification (target_type2
, target_type1
);
4191 /* Neither conversion sequence is better than the other. */
4195 /* The source type for this standard conversion sequence. */
4201 for (;; t
= TREE_OPERAND (t
, 0))
4203 if (TREE_CODE (t
) == USER_CONV
4204 || TREE_CODE (t
) == AMBIG_CONV
4205 || TREE_CODE (t
) == IDENTITY_CONV
)
4206 return TREE_TYPE (t
);
4208 my_friendly_abort (1823);
4211 /* Note a warning about preferring WINNER to LOSER. We do this by storing
4212 a pointer to LOSER and re-running joust to produce the warning if WINNER
4213 is actually used. */
4216 add_warning (winner
, loser
)
4217 struct z_candidate
*winner
, *loser
;
4219 winner
->warnings
= expr_tree_cons (NULL_PTR
,
4220 build_expr_ptr_wrapper (loser
),
4224 /* Compare two candidates for overloading as described in
4225 [over.match.best]. Return values:
4227 1: cand1 is better than cand2
4228 -1: cand2 is better than cand1
4229 0: cand1 and cand2 are indistinguishable */
4232 joust (cand1
, cand2
, warn
)
4233 struct z_candidate
*cand1
, *cand2
;
4237 int i
, off1
= 0, off2
= 0, len
;
4239 /* Candidates that involve bad conversions are always worse than those
4241 if (cand1
->viable
> cand2
->viable
)
4243 if (cand1
->viable
< cand2
->viable
)
4246 /* If we have two pseudo-candidates for conversions to the same type,
4247 arbitrarily pick one. */
4248 if (TYPE_P (cand1
->fn
) && cand1
->fn
== cand2
->fn
)
4251 /* a viable function F1
4252 is defined to be a better function than another viable function F2 if
4253 for all arguments i, ICSi(F1) is not a worse conversion sequence than
4254 ICSi(F2), and then */
4256 /* for some argument j, ICSj(F1) is a better conversion sequence than
4259 /* For comparing static and non-static member functions, we ignore the
4260 implicit object parameter of the non-static function. The WP says to
4261 pretend that the static function has an object parm, but that won't
4262 work with operator overloading. */
4263 len
= TREE_VEC_LENGTH (cand1
->convs
);
4264 if (len
!= TREE_VEC_LENGTH (cand2
->convs
))
4266 if (DECL_STATIC_FUNCTION_P (cand1
->fn
)
4267 && ! DECL_STATIC_FUNCTION_P (cand2
->fn
))
4269 else if (! DECL_STATIC_FUNCTION_P (cand1
->fn
)
4270 && DECL_STATIC_FUNCTION_P (cand2
->fn
))
4276 my_friendly_abort (42);
4279 for (i
= 0; i
< len
; ++i
)
4281 tree t1
= TREE_VEC_ELT (cand1
->convs
, i
+off1
);
4282 tree t2
= TREE_VEC_ELT (cand2
->convs
, i
+off2
);
4283 int comp
= compare_ics (t1
, t2
);
4288 && ICS_RANK (t1
) + ICS_RANK (t2
) == STD_RANK
+ PROMO_RANK
4289 && TREE_CODE (t1
) == STD_CONV
4290 && TREE_CODE (t2
) == STD_CONV
4291 && TREE_CODE (TREE_TYPE (t1
)) == INTEGER_TYPE
4292 && TREE_CODE (TREE_TYPE (t2
)) == INTEGER_TYPE
4293 && (TYPE_PRECISION (TREE_TYPE (t1
))
4294 == TYPE_PRECISION (TREE_TYPE (t2
)))
4295 && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (t1
, 0)))
4296 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (t1
, 0)))
4299 tree type
= TREE_TYPE (TREE_OPERAND (t1
, 0));
4301 struct z_candidate
*w
, *l
;
4303 type1
= TREE_TYPE (t1
), type2
= TREE_TYPE (t2
),
4304 w
= cand1
, l
= cand2
;
4306 type1
= TREE_TYPE (t2
), type2
= TREE_TYPE (t1
),
4307 w
= cand2
, l
= cand1
;
4311 cp_warning ("passing `%T' chooses `%T' over `%T'",
4312 type
, type1
, type2
);
4313 cp_warning (" in call to `%D'", w
->fn
);
4319 if (winner
&& comp
!= winner
)
4328 /* warn about confusing overload resolution for user-defined conversions,
4329 either between a constructor and a conversion op, or between two
4331 if (winner
&& cand1
->second_conv
4332 && ((DECL_CONSTRUCTOR_P (cand1
->fn
)
4333 != DECL_CONSTRUCTOR_P (cand2
->fn
))
4334 /* Don't warn if the two conv ops convert to the same type... */
4335 || (! DECL_CONSTRUCTOR_P (cand1
->fn
)
4336 && ! same_type_p (TREE_TYPE (cand1
->second_conv
),
4337 TREE_TYPE (cand2
->second_conv
)))))
4339 int comp
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
4342 struct z_candidate
*w
, *l
;
4344 w
= cand1
, l
= cand2
;
4346 w
= cand2
, l
= cand1
;
4349 tree source
= source_type (TREE_VEC_ELT (w
->convs
, 0));
4350 if (! DECL_CONSTRUCTOR_P (w
->fn
))
4351 source
= TREE_TYPE (source
);
4352 cp_warning ("choosing `%D' over `%D'", w
->fn
, l
->fn
);
4353 cp_warning (" for conversion from `%T' to `%T'",
4354 source
, TREE_TYPE (w
->second_conv
));
4355 cp_warning (" because conversion sequence for the argument is better");
4366 F1 is a non-template function and F2 is a template function */
4368 if (! cand1
->template && cand2
->template)
4370 else if (cand1
->template && ! cand2
->template)
4372 else if (cand1
->template && cand2
->template)
4373 winner
= more_specialized
4374 (TI_TEMPLATE (cand1
->template), TI_TEMPLATE (cand2
->template),
4378 the context is an initialization by user-defined conversion (see
4379 _dcl.init_ and _over.match.user_) and the standard conversion
4380 sequence from the return type of F1 to the destination type (i.e.,
4381 the type of the entity being initialized) is a better conversion
4382 sequence than the standard conversion sequence from the return type
4383 of F2 to the destination type. */
4385 if (! winner
&& cand1
->second_conv
)
4386 winner
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
4388 /* If the built-in candidates are the same, arbitrarily pick one. */
4389 if (! winner
&& cand1
->fn
== cand2
->fn
4390 && TREE_CODE (cand1
->fn
) == IDENTIFIER_NODE
)
4392 for (i
= 0; i
< len
; ++i
)
4393 if (!same_type_p (TREE_TYPE (TREE_VEC_ELT (cand1
->convs
, i
)),
4394 TREE_TYPE (TREE_VEC_ELT (cand2
->convs
, i
))))
4396 if (i
== TREE_VEC_LENGTH (cand1
->convs
))
4399 /* Kludge around broken overloading rules whereby
4400 Integer a, b; test ? a : b; is ambiguous, since there's a builtin
4401 that takes references and another that takes values. */
4402 if (cand1
->fn
== ansi_opname
[COND_EXPR
])
4404 tree c1
= TREE_VEC_ELT (cand1
->convs
, 1);
4405 tree c2
= TREE_VEC_ELT (cand2
->convs
, 1);
4406 tree t1
= strip_top_quals (non_reference (TREE_TYPE (c1
)));
4407 tree t2
= strip_top_quals (non_reference (TREE_TYPE (c2
)));
4409 if (same_type_p (t1
, t2
))
4411 if (TREE_CODE (c1
) == REF_BIND
&& TREE_CODE (c2
) != REF_BIND
)
4413 if (TREE_CODE (c1
) != REF_BIND
&& TREE_CODE (c2
) == REF_BIND
)
4421 /* Extension: If the worst conversion for one candidate is worse than the
4422 worst conversion for the other, take the first. */
4423 if (! winner
&& ! pedantic
)
4425 int rank1
= IDENTITY_RANK
, rank2
= IDENTITY_RANK
;
4427 for (i
= 0; i
< len
; ++i
)
4429 if (ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
)) > rank1
)
4430 rank1
= ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
));
4431 if (ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
)) > rank2
)
4432 rank2
= ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
));
4444 /* Given a list of candidates for overloading, find the best one, if any.
4445 This algorithm has a worst case of O(2n) (winner is last), and a best
4446 case of O(n/2) (totally ambiguous); much better than a sorting
4449 static struct z_candidate
*
4450 tourney (candidates
)
4451 struct z_candidate
*candidates
;
4453 struct z_candidate
*champ
= candidates
, *challenger
;
4455 int champ_compared_to_predecessor
= 0;
4457 /* Walk through the list once, comparing each current champ to the next
4458 candidate, knocking out a candidate or two with each comparison. */
4460 for (challenger
= champ
->next
; challenger
; )
4462 fate
= joust (champ
, challenger
, 0);
4464 challenger
= challenger
->next
;
4469 champ
= challenger
->next
;
4472 champ_compared_to_predecessor
= 0;
4477 champ_compared_to_predecessor
= 1;
4480 challenger
= champ
->next
;
4484 /* Make sure the champ is better than all the candidates it hasn't yet
4485 been compared to. */
4487 for (challenger
= candidates
;
4489 && !(champ_compared_to_predecessor
&& challenger
->next
== champ
);
4490 challenger
= challenger
->next
)
4492 fate
= joust (champ
, challenger
, 0);
4501 can_convert (to
, from
)
4504 tree t
= implicit_conversion (to
, from
, NULL_TREE
, LOOKUP_NORMAL
);
4505 return (t
&& ! ICS_BAD_FLAG (t
));
4509 can_convert_arg (to
, from
, arg
)
4512 tree t
= implicit_conversion (to
, from
, arg
, LOOKUP_NORMAL
);
4513 return (t
&& ! ICS_BAD_FLAG (t
));