1 /* Functions related to invoking methods and overloaded functions.
2 Copyright (C) 1987, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com) and
4 hacked 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. */
38 #define obstack_chunk_alloc xmalloc
39 #define obstack_chunk_free free
41 extern int inhibit_warnings;
42 extern tree ctor_label, dtor_label;
44 static tree build_new_method_call PROTO((tree, tree, tree, tree, int));
46 static tree build_field_call PROTO((tree, tree, tree, tree));
47 static tree find_scoped_type PROTO((tree, tree, tree));
48 static struct z_candidate * tourney PROTO((struct z_candidate *));
49 static int joust PROTO((struct z_candidate *, struct z_candidate *));
50 static int compare_qual PROTO((tree, tree));
51 static int compare_ics PROTO((tree, tree));
52 static tree build_over_call PROTO((tree, tree, tree, int));
53 static tree convert_default_arg PROTO((tree, tree));
54 static void enforce_access PROTO((tree, tree));
55 static tree convert_like PROTO((tree, tree));
56 static void op_error PROTO((enum tree_code, enum tree_code, tree, tree,
58 static tree build_object_call PROTO((tree, tree));
59 static tree resolve_args PROTO((tree));
60 static struct z_candidate * build_user_type_conversion_1
61 PROTO ((tree, tree, int));
62 static void print_z_candidates PROTO((struct z_candidate *));
63 static tree build_this PROTO((tree));
64 static struct z_candidate * splice_viable PROTO((struct z_candidate *));
65 static int any_viable PROTO((struct z_candidate *));
66 static struct z_candidate * add_template_candidate
67 PROTO((struct z_candidate *, tree, tree, tree, tree, int));
68 static struct z_candidate * add_template_conv_candidate
69 PROTO((struct z_candidate *, tree, tree, tree, tree));
70 static struct z_candidate * add_builtin_candidates
71 PROTO((struct z_candidate *, enum tree_code, enum tree_code,
73 static struct z_candidate * add_builtin_candidate
74 PROTO((struct z_candidate *, enum tree_code, enum tree_code,
75 tree, tree, tree, tree *, tree *, int));
76 static int is_complete PROTO((tree));
77 static struct z_candidate * build_builtin_candidate
78 PROTO((struct z_candidate *, tree, tree, tree, tree *, tree *,
80 static struct z_candidate * add_conv_candidate
81 PROTO((struct z_candidate *, tree, tree, tree));
82 static struct z_candidate * add_function_candidate
83 PROTO((struct z_candidate *, tree, tree, int));
84 static tree implicit_conversion PROTO((tree, tree, tree, int));
85 static tree standard_conversion PROTO((tree, tree, tree));
86 static tree reference_binding PROTO((tree, tree, tree, int));
87 static tree strip_top_quals PROTO((tree));
88 static tree non_reference PROTO((tree));
89 static tree build_conv PROTO((enum tree_code, tree, tree));
90 static int is_subseq PROTO((tree, tree));
93 build_vfield_ref (datum, type)
97 int old_assume_nonnull_objects = flag_assume_nonnull_objects;
99 if (datum == error_mark_node)
100 return error_mark_node;
102 /* Vtable references are always made from non-null objects. */
103 flag_assume_nonnull_objects = 1;
104 if (TREE_CODE (TREE_TYPE (datum)) == REFERENCE_TYPE)
105 datum = convert_from_reference (datum);
107 if (! TYPE_USES_COMPLEX_INHERITANCE (type))
108 rval = build (COMPONENT_REF, TREE_TYPE (CLASSTYPE_VFIELD (type)),
109 datum, CLASSTYPE_VFIELD (type));
111 rval = build_component_ref (datum, DECL_NAME (CLASSTYPE_VFIELD (type)), NULL_TREE, 0);
112 flag_assume_nonnull_objects = old_assume_nonnull_objects;
117 /* Build a call to a member of an object. I.e., one that overloads
118 operator ()(), or is a pointer-to-function or pointer-to-method. */
121 build_field_call (basetype_path, instance_ptr, name, parms)
122 tree basetype_path, instance_ptr, name, parms;
124 tree field, instance;
126 if (name == ctor_identifier || name == dtor_identifier)
129 if (instance_ptr == current_class_ptr)
131 /* Check to see if we really have a reference to an instance variable
132 with `operator()()' overloaded. */
133 field = IDENTIFIER_CLASS_VALUE (name);
135 if (field == NULL_TREE)
137 cp_error ("`this' has no member named `%D'", name);
138 return error_mark_node;
141 if (TREE_CODE (field) == FIELD_DECL)
143 /* If it's a field, try overloading operator (),
144 or calling if the field is a pointer-to-function. */
145 instance = build_component_ref_1 (current_class_ref, field, 0);
146 if (instance == error_mark_node)
147 return error_mark_node;
149 if (TYPE_LANG_SPECIFIC (TREE_TYPE (instance)))
150 return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, instance, parms, NULL_TREE);
152 if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE)
154 if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == FUNCTION_TYPE)
155 return build_function_call (instance, parms);
156 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == METHOD_TYPE)
157 return build_function_call (instance, expr_tree_cons (NULL_TREE, current_class_ptr, parms));
163 /* Check to see if this is not really a reference to an instance variable
164 with `operator()()' overloaded. */
165 field = lookup_field (basetype_path, name, 1, 0);
167 /* This can happen if the reference was ambiguous or for access
169 if (field == error_mark_node)
170 return error_mark_node;
175 tree ftype = TREE_TYPE (field);
177 if (TREE_CODE (ftype) == REFERENCE_TYPE)
178 ftype = TREE_TYPE (ftype);
180 if (TYPE_LANG_SPECIFIC (ftype))
182 /* Make the next search for this field very short. */
183 basetype = DECL_FIELD_CONTEXT (field);
184 instance_ptr = convert_pointer_to (basetype, instance_ptr);
186 instance = build_indirect_ref (instance_ptr, NULL_PTR);
187 return build_opfncall (CALL_EXPR, LOOKUP_NORMAL,
188 build_component_ref_1 (instance, field, 0),
191 if (TREE_CODE (ftype) == POINTER_TYPE)
193 if (TREE_CODE (TREE_TYPE (ftype)) == FUNCTION_TYPE
194 || TREE_CODE (TREE_TYPE (ftype)) == METHOD_TYPE)
196 /* This is a member which is a pointer to function. */
198 = build_component_ref_1 (build_indirect_ref (instance_ptr,
200 field, LOOKUP_COMPLAIN);
201 if (ref == error_mark_node)
202 return error_mark_node;
203 return build_function_call (ref, parms);
206 else if (TREE_CODE (ftype) == METHOD_TYPE)
208 error ("invalid call via pointer-to-member function");
209 return error_mark_node;
218 find_scoped_type (type, inner_name, inner_types)
219 tree type, inner_name, inner_types;
221 tree tags = CLASSTYPE_TAGS (type);
225 /* The TREE_PURPOSE of an enum tag (which becomes a member of the
226 enclosing class) is set to the name for the enum type. So, if
227 inner_name is `bar', and we strike `baz' for `enum bar { baz }',
228 then this test will be true. */
229 if (TREE_PURPOSE (tags) == inner_name)
231 if (inner_types == NULL_TREE)
232 return TYPE_MAIN_DECL (TREE_VALUE (tags));
233 return resolve_scope_to_name (TREE_VALUE (tags), inner_types);
235 tags = TREE_CHAIN (tags);
238 /* Look for a TYPE_DECL. */
239 for (tags = TYPE_FIELDS (type); tags; tags = TREE_CHAIN (tags))
240 if (TREE_CODE (tags) == TYPE_DECL && DECL_NAME (tags) == inner_name)
242 /* Code by raeburn. */
243 if (inner_types == NULL_TREE)
245 return resolve_scope_to_name (TREE_TYPE (tags), inner_types);
251 /* Resolve an expression NAME1::NAME2::...::NAMEn to
252 the name that names the above nested type. INNER_TYPES
253 is a chain of nested type names (held together by SCOPE_REFs);
254 OUTER_TYPE is the type we know to enclose INNER_TYPES.
255 Returns NULL_TREE if there is an error. */
258 resolve_scope_to_name (outer_type, inner_stuff)
259 tree outer_type, inner_stuff;
262 tree inner_name, inner_type;
264 if (outer_type == NULL_TREE && current_class_type != NULL_TREE)
266 /* We first try to look for a nesting in our current class context,
267 then try any enclosing classes. */
268 tree type = current_class_type;
270 while (type && (TREE_CODE (type) == RECORD_TYPE
271 || TREE_CODE (type) == UNION_TYPE))
273 tree rval = resolve_scope_to_name (type, inner_stuff);
275 if (rval != NULL_TREE)
277 type = DECL_CONTEXT (TYPE_MAIN_DECL (type));
281 if (TREE_CODE (inner_stuff) == SCOPE_REF)
283 inner_name = TREE_OPERAND (inner_stuff, 0);
284 inner_type = TREE_OPERAND (inner_stuff, 1);
288 inner_name = inner_stuff;
289 inner_type = NULL_TREE;
292 if (outer_type == NULL_TREE)
295 /* If we have something that's already a type by itself,
297 if (IDENTIFIER_HAS_TYPE_VALUE (inner_name))
300 return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name),
305 x = lookup_name (inner_name, 0);
307 if (x && TREE_CODE (x) == NAMESPACE_DECL)
309 x = lookup_namespace_name (x, inner_type);
315 if (! IS_AGGR_TYPE (outer_type))
318 /* Look for member classes or enums. */
319 tmp = find_scoped_type (outer_type, inner_name, inner_type);
321 /* If it's not a type in this class, then go down into the
322 base classes and search there. */
323 if (! tmp && TYPE_BINFO (outer_type))
325 tree binfos = TYPE_BINFO_BASETYPES (outer_type);
326 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
328 for (i = 0; i < n_baselinks; i++)
330 tree base_binfo = TREE_VEC_ELT (binfos, i);
331 tmp = resolve_scope_to_name (BINFO_TYPE (base_binfo), inner_stuff);
341 /* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'.
342 This is how virtual function calls are avoided. */
345 build_scoped_method_call (exp, basetype, name, parms)
346 tree exp, basetype, name, parms;
348 /* Because this syntactic form does not allow
349 a pointer to a base class to be `stolen',
350 we need not protect the derived->base conversion
353 @@ But we do have to check access privileges later. */
355 tree type = TREE_TYPE (exp);
357 if (type == error_mark_node
358 || basetype == error_mark_node)
359 return error_mark_node;
361 if (processing_template_decl)
363 if (TREE_CODE (name) == BIT_NOT_EXPR)
365 tree type = get_aggr_from_typedef (TREE_OPERAND (name, 0), 0);
367 name = build_min_nt (BIT_NOT_EXPR, type);
369 name = build_min_nt (SCOPE_REF, basetype, name);
370 return build_min_nt (METHOD_CALL_EXPR, name, exp, parms, NULL_TREE);
373 if (TREE_CODE (type) == REFERENCE_TYPE)
374 type = TREE_TYPE (type);
376 if (TREE_CODE (basetype) == TREE_VEC)
379 basetype = BINFO_TYPE (binfo);
384 /* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
385 that explicit ~int is caught in the parser; this deals with typedefs
386 and template parms. */
387 if (TREE_CODE (name) == BIT_NOT_EXPR && ! IS_AGGR_TYPE (basetype))
389 if (type != basetype)
390 cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
391 exp, basetype, type);
392 name = TREE_OPERAND (name, 0);
393 if (basetype != name && basetype != get_type_value (name))
394 cp_error ("qualified type `%T' does not match destructor name `~%T'",
396 return cp_convert (void_type_node, exp);
399 if (! is_aggr_type (basetype, 1))
400 return error_mark_node;
402 if (! IS_AGGR_TYPE (type))
404 cp_error ("base object `%E' of scoped method call is of non-aggregate type `%T'",
406 return error_mark_node;
411 binfo = get_binfo (basetype, type, 1);
412 if (binfo == error_mark_node)
413 return error_mark_node;
415 error_not_base_type (basetype, type);
420 if (TREE_CODE (exp) == INDIRECT_REF)
421 decl = build_indirect_ref
422 (convert_pointer_to_real
423 (binfo, build_unary_op (ADDR_EXPR, exp, 0)), NULL_PTR);
425 decl = build_scoped_ref (exp, basetype);
427 /* Call to a destructor. */
428 if (TREE_CODE (name) == BIT_NOT_EXPR)
430 /* Explicit call to destructor. */
431 name = TREE_OPERAND (name, 0);
432 if (! (name == TYPE_MAIN_VARIANT (TREE_TYPE (decl))
433 || name == constructor_name (TREE_TYPE (decl))
434 || TREE_TYPE (decl) == get_type_value (name)))
437 ("qualified type `%T' does not match destructor name `~%T'",
438 TREE_TYPE (decl), name);
439 return error_mark_node;
441 if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl)))
442 return cp_convert (void_type_node, exp);
444 return build_delete (TREE_TYPE (decl), decl, integer_two_node,
445 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR,
449 /* Call to a method. */
450 return build_method_call (decl, name, parms, binfo,
451 LOOKUP_NORMAL|LOOKUP_NONVIRTUAL);
453 return error_mark_node;
456 /* We want the address of a function or method. We avoid creating a
457 pointer-to-member function. */
460 build_addr_func (function)
463 tree type = TREE_TYPE (function);
465 /* We have to do these by hand to avoid real pointer to member
467 if (TREE_CODE (type) == METHOD_TYPE)
471 type = build_pointer_type (type);
473 if (mark_addressable (function) == 0)
474 return error_mark_node;
476 addr = build1 (ADDR_EXPR, type, function);
478 /* Address of a static or external variable or function counts
480 if (staticp (function))
481 TREE_CONSTANT (addr) = 1;
486 function = default_conversion (function);
491 /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
492 POINTER_TYPE to those. Note, pointer to member function types
493 (TYPE_PTRMEMFUNC_P) must be handled by our callers. */
496 build_call (function, result_type, parms)
497 tree function, result_type, parms;
499 int is_constructor = 0;
501 function = build_addr_func (function);
503 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
505 sorry ("unable to call pointer to member function here");
506 return error_mark_node;
509 if (TREE_CODE (function) == ADDR_EXPR
510 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
511 && DECL_CONSTRUCTOR_P (TREE_OPERAND (function, 0)))
514 function = build_nt (CALL_EXPR, function, parms, NULL_TREE);
515 TREE_HAS_CONSTRUCTOR (function) = is_constructor;
516 TREE_TYPE (function) = result_type;
517 TREE_SIDE_EFFECTS (function) = 1;
522 /* Build something of the form ptr->method (args)
523 or object.method (args). This can also build
524 calls to constructors, and find friends.
526 Member functions always take their class variable
529 INSTANCE is a class instance.
531 NAME is the name of the method desired, usually an IDENTIFIER_NODE.
533 PARMS help to figure out what that NAME really refers to.
535 BASETYPE_PATH, if non-NULL, contains a chain from the type of INSTANCE
536 down to the real instance type to use for access checking. We need this
537 information to get protected accesses correct. This parameter is used
538 by build_member_call.
540 FLAGS is the logical disjunction of zero or more LOOKUP_
541 flags. See cp-tree.h for more info.
543 If this is all OK, calls build_function_call with the resolved
546 This function must also handle being called to perform
547 initialization, promotion/coercion of arguments, and
548 instantiation of default parameters.
550 Note that NAME may refer to an instance variable name. If
551 `operator()()' is defined for the type of that field, then we return
555 build_method_call (instance, name, parms, basetype_path, flags)
556 tree instance, name, parms, basetype_path;
559 tree basetype, instance_ptr;
561 #ifdef GATHER_STATISTICS
562 n_build_method_call++;
565 if (instance == error_mark_node
566 || name == error_mark_node
567 || parms == error_mark_node
568 || (instance != NULL_TREE && TREE_TYPE (instance) == error_mark_node))
569 return error_mark_node;
571 if (processing_template_decl)
573 if (TREE_CODE (name) == BIT_NOT_EXPR)
575 tree type = get_aggr_from_typedef (TREE_OPERAND (name, 0), 1);
576 name = build_min_nt (BIT_NOT_EXPR, type);
579 return build_min_nt (METHOD_CALL_EXPR, name, instance, parms, NULL_TREE);
582 /* This is the logic that magically deletes the second argument to
583 operator delete, if it is not needed. */
584 if (name == ansi_opname[(int) DELETE_EXPR] && list_length (parms)==2)
586 tree save_last = TREE_CHAIN (parms);
588 /* get rid of unneeded argument */
589 TREE_CHAIN (parms) = NULL_TREE;
590 if (build_method_call (instance, name, parms, basetype_path,
591 (LOOKUP_SPECULATIVELY|flags) & ~LOOKUP_COMPLAIN))
593 /* If it finds a match, return it. */
594 return build_method_call (instance, name, parms, basetype_path, flags);
596 /* If it doesn't work, two argument delete must work */
597 TREE_CHAIN (parms) = save_last;
599 /* We already know whether it's needed or not for vec delete. */
600 else if (name == ansi_opname[(int) VEC_DELETE_EXPR]
601 && TYPE_LANG_SPECIFIC (TREE_TYPE (instance))
602 && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance)))
603 TREE_CHAIN (parms) = NULL_TREE;
605 if (TREE_CODE (name) == BIT_NOT_EXPR)
607 flags |= LOOKUP_DESTRUCTOR;
608 name = TREE_OPERAND (name, 0);
610 error ("destructors take no parameters");
611 basetype = TREE_TYPE (instance);
612 if (TREE_CODE (basetype) == REFERENCE_TYPE)
613 basetype = TREE_TYPE (basetype);
614 if (! (name == basetype
615 || (IS_AGGR_TYPE (basetype)
616 && name == constructor_name (basetype))
617 || basetype == get_type_value (name)))
619 cp_error ("destructor name `~%D' does not match type `%T' of expression",
621 return cp_convert (void_type_node, instance);
624 if (! TYPE_HAS_DESTRUCTOR (complete_type (basetype)))
625 return cp_convert (void_type_node, instance);
626 instance = default_conversion (instance);
627 instance_ptr = build_unary_op (ADDR_EXPR, instance, 0);
628 return build_delete (build_pointer_type (basetype),
629 instance_ptr, integer_two_node,
630 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
633 return build_new_method_call (instance, name, parms, basetype_path, flags);
636 /* New overloading code. */
645 struct z_candidate *next;
648 #define IDENTITY_RANK 0
654 #define ELLIPSIS_RANK 6
657 #define ICS_RANK(NODE) \
658 (ICS_BAD_FLAG (NODE) ? BAD_RANK \
659 : ICS_ELLIPSIS_FLAG (NODE) ? ELLIPSIS_RANK \
660 : ICS_USER_FLAG (NODE) ? USER_RANK \
661 : ICS_STD_RANK (NODE))
663 #define ICS_STD_RANK(NODE) TREE_COMPLEXITY (NODE)
665 #define ICS_USER_FLAG(NODE) TREE_LANG_FLAG_0 (NODE)
666 #define ICS_ELLIPSIS_FLAG(NODE) TREE_LANG_FLAG_1 (NODE)
667 #define ICS_THIS_FLAG(NODE) TREE_LANG_FLAG_2 (NODE)
668 #define ICS_BAD_FLAG(NODE) TREE_LANG_FLAG_3 (NODE)
670 #define USER_CONV_FN(NODE) TREE_OPERAND (NODE, 1)
677 || (integer_zerop (t) && TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE))
683 build_conv (code, type, from)
687 tree t = build1 (code, type, from);
688 int rank = ICS_STD_RANK (from);
700 if (rank < EXACT_RANK)
706 ICS_STD_RANK (t) = rank;
707 ICS_USER_FLAG (t) = ICS_USER_FLAG (from);
708 ICS_BAD_FLAG (t) = ICS_BAD_FLAG (from);
716 if (TREE_CODE (t) == REFERENCE_TYPE)
725 if (TREE_CODE (t) == ARRAY_TYPE)
727 return TYPE_MAIN_VARIANT (t);
730 /* Returns the standard conversion path (see [conv]) from type FROM to type
731 TO, if any. For proper handling of null pointer constants, you must
732 also pass the expression EXPR to convert from. */
735 standard_conversion (to, from, expr)
738 enum tree_code fcode, tcode;
742 if (TREE_CODE (to) == REFERENCE_TYPE)
744 if (TREE_CODE (from) == REFERENCE_TYPE)
747 from = TREE_TYPE (from);
749 to = strip_top_quals (to);
750 from = strip_top_quals (from);
752 fcode = TREE_CODE (from);
753 tcode = TREE_CODE (to);
755 conv = build1 (IDENTITY_CONV, from, expr);
757 if (fcode == FUNCTION_TYPE)
759 from = build_pointer_type (from);
760 fcode = TREE_CODE (from);
761 conv = build_conv (LVALUE_CONV, from, conv);
763 else if (fcode == ARRAY_TYPE)
765 from = build_pointer_type (TREE_TYPE (from));
766 fcode = TREE_CODE (from);
767 conv = build_conv (LVALUE_CONV, from, conv);
769 else if (fromref || (expr && real_lvalue_p (expr)))
770 conv = build_conv (RVALUE_CONV, from, conv);
775 if ((tcode == POINTER_TYPE || TYPE_PTRMEMFUNC_P (to))
776 && expr && null_ptr_cst_p (expr))
778 conv = build_conv (STD_CONV, to, conv);
780 else if (tcode == POINTER_TYPE && fcode == POINTER_TYPE)
782 enum tree_code ufcode = TREE_CODE (TREE_TYPE (from));
783 enum tree_code utcode = TREE_CODE (TREE_TYPE (to));
785 if (utcode == VOID_TYPE && ufcode != OFFSET_TYPE
786 && ufcode != FUNCTION_TYPE)
788 from = build_pointer_type
789 (cp_build_type_variant (void_type_node,
790 TYPE_READONLY (TREE_TYPE (from)),
791 TYPE_VOLATILE (TREE_TYPE (from))));
792 conv = build_conv (PTR_CONV, from, conv);
794 else if (ufcode == OFFSET_TYPE && utcode == OFFSET_TYPE)
796 tree fbase = TYPE_OFFSET_BASETYPE (TREE_TYPE (from));
797 tree tbase = TYPE_OFFSET_BASETYPE (TREE_TYPE (to));
799 if (DERIVED_FROM_P (fbase, tbase)
800 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (from))),
801 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (to))),
804 from = build_offset_type (tbase, TREE_TYPE (TREE_TYPE (from)));
805 from = build_pointer_type (from);
806 conv = build_conv (PMEM_CONV, from, conv);
809 else if (IS_AGGR_TYPE (TREE_TYPE (from))
810 && IS_AGGR_TYPE (TREE_TYPE (to)))
812 if (DERIVED_FROM_P (TREE_TYPE (to), TREE_TYPE (from)))
814 from = cp_build_type_variant (TREE_TYPE (to),
815 TYPE_READONLY (TREE_TYPE (from)),
816 TYPE_VOLATILE (TREE_TYPE (from)));
817 from = build_pointer_type (from);
818 conv = build_conv (PTR_CONV, from, conv);
822 if (comptypes (from, to, 1))
824 else if (comp_ptr_ttypes (TREE_TYPE (to), TREE_TYPE (from)))
825 conv = build_conv (QUAL_CONV, to, conv);
826 else if (ptr_reasonably_similar (TREE_TYPE (to), TREE_TYPE (from)))
828 conv = build_conv (PTR_CONV, to, conv);
829 ICS_BAD_FLAG (conv) = 1;
836 else if (TYPE_PTRMEMFUNC_P (to) && TYPE_PTRMEMFUNC_P (from))
838 tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
839 tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
840 tree fbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn)));
841 tree tbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn)));
843 if (! DERIVED_FROM_P (fbase, tbase)
844 || ! comptypes (TREE_TYPE (fromfn), TREE_TYPE (tofn), 1)
845 || ! compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn)),
846 TREE_CHAIN (TYPE_ARG_TYPES (tofn)), 1)
847 || TYPE_READONLY (fbase) != TYPE_READONLY (tbase)
848 || TYPE_VOLATILE (fbase) != TYPE_VOLATILE (tbase))
851 from = cp_build_type_variant (tbase, TYPE_READONLY (fbase),
852 TYPE_VOLATILE (fbase));
853 from = build_cplus_method_type (from, TREE_TYPE (fromfn),
854 TREE_CHAIN (TYPE_ARG_TYPES (fromfn)));
855 from = build_ptrmemfunc_type (build_pointer_type (from));
856 conv = build_conv (PMEM_CONV, from, conv);
858 else if (tcode == BOOLEAN_TYPE)
860 if (! (INTEGRAL_CODE_P (fcode) || fcode == REAL_TYPE
861 || fcode == POINTER_TYPE || TYPE_PTRMEMFUNC_P (from)))
864 conv = build_conv (STD_CONV, to, conv);
865 if (fcode == POINTER_TYPE
866 || (TYPE_PTRMEMFUNC_P (from) && ICS_STD_RANK (conv) < PBOOL_RANK))
867 ICS_STD_RANK (conv) = PBOOL_RANK;
869 /* We don't check for ENUMERAL_TYPE here because there are no standard
870 conversions to enum type. */
871 else if (tcode == INTEGER_TYPE || tcode == BOOLEAN_TYPE
872 || tcode == REAL_TYPE)
874 if (! (INTEGRAL_CODE_P (fcode) || fcode == REAL_TYPE))
876 conv = build_conv (STD_CONV, to, conv);
878 /* Give this a better rank if it's a promotion. */
879 if (to == type_promotes_to (from)
880 && ICS_STD_RANK (TREE_OPERAND (conv, 0)) <= PROMO_RANK)
881 ICS_STD_RANK (conv) = PROMO_RANK;
883 else if (IS_AGGR_TYPE (to) && IS_AGGR_TYPE (from)
884 && DERIVED_FROM_P (to, from))
886 if (TREE_CODE (conv) == RVALUE_CONV)
887 conv = TREE_OPERAND (conv, 0);
888 conv = build_conv (BASE_CONV, to, conv);
896 /* Returns the conversion path from type FROM to reference type TO for
897 purposes of reference binding. For lvalue binding, either pass a
898 reference type to FROM or an lvalue expression to EXPR.
900 Currently does not distinguish in the generated trees between binding to
901 an lvalue and a temporary. Should it? */
904 reference_binding (rto, rfrom, expr, flags)
905 tree rto, rfrom, expr;
910 tree to = TREE_TYPE (rto);
914 if (TREE_CODE (from) == REFERENCE_TYPE)
915 from = TREE_TYPE (from);
916 else if (! expr || ! real_lvalue_p (expr))
919 related = (comptypes (TYPE_MAIN_VARIANT (to),
920 TYPE_MAIN_VARIANT (from), 1)
921 || (IS_AGGR_TYPE (to) && IS_AGGR_TYPE (from)
922 && DERIVED_FROM_P (to, from)));
924 if (lvalue && related
925 && TYPE_READONLY (to) >= TYPE_READONLY (from)
926 && TYPE_VOLATILE (to) >= TYPE_VOLATILE (from))
928 conv = build1 (IDENTITY_CONV, from, expr);
930 if (comptypes (TYPE_MAIN_VARIANT (to),
931 TYPE_MAIN_VARIANT (from), 1))
932 conv = build_conv (REF_BIND, rto, conv);
935 conv = build_conv (REF_BIND, rto, conv);
936 ICS_STD_RANK (conv) = STD_RANK;
944 conv = standard_conversion (to, rfrom, expr);
947 conv = build_conv (REF_BIND, rto, conv);
949 /* Bind directly to a base subobject of a class rvalue. Do it
950 after building the conversion for proper handling of ICS_RANK. */
951 if (TREE_CODE (TREE_OPERAND (conv, 0)) == BASE_CONV)
952 TREE_OPERAND (conv, 0) = TREE_OPERAND (TREE_OPERAND (conv, 0), 0);
955 && ((! (TYPE_READONLY (to) && ! TYPE_VOLATILE (to)
956 && (flags & LOOKUP_NO_TEMP_BIND) == 0))
957 /* If T1 is reference-related to T2, cv1 must be the same
958 cv-qualification as, or greater cv-qualification than,
959 cv2; otherwise, the program is ill-formed. */
961 && (TYPE_READONLY (to) < TYPE_READONLY (from)
962 || TYPE_VOLATILE (to) < TYPE_VOLATILE (from)))))
963 ICS_BAD_FLAG (conv) = 1;
969 /* Returns the implicit conversion sequence (see [over.ics]) from type FROM
970 to type TO. The optional expression EXPR may affect the conversion.
971 FLAGS are the usual overloading flags. Only LOOKUP_NO_CONVERSION is
975 implicit_conversion (to, from, expr, flags)
980 struct z_candidate *cand;
982 if (expr && type_unknown_p (expr))
984 expr = instantiate_type (to, expr, 0);
985 if (expr == error_mark_node)
987 from = TREE_TYPE (expr);
990 if (TREE_CODE (to) == REFERENCE_TYPE)
991 conv = reference_binding (to, from, expr, flags);
993 conv = standard_conversion (to, from, expr);
997 else if (expr != NULL_TREE
998 && (IS_AGGR_TYPE (non_reference (from))
999 || IS_AGGR_TYPE (non_reference (to)))
1000 && (flags & LOOKUP_NO_CONVERSION) == 0)
1002 cand = build_user_type_conversion_1
1003 (to, expr, LOOKUP_ONLYCONVERTING);
1005 conv = cand->second_conv;
1006 if ((! conv || ICS_BAD_FLAG (conv))
1007 && TREE_CODE (to) == REFERENCE_TYPE
1008 && (flags & LOOKUP_NO_TEMP_BIND) == 0)
1010 cand = build_user_type_conversion_1
1011 (TYPE_MAIN_VARIANT (TREE_TYPE (to)), expr, LOOKUP_ONLYCONVERTING);
1014 if (! TYPE_READONLY (TREE_TYPE (to))
1015 || TYPE_VOLATILE (TREE_TYPE (to)))
1016 ICS_BAD_FLAG (cand->second_conv) = 1;
1017 if (!conv || (ICS_BAD_FLAG (conv)
1018 > ICS_BAD_FLAG (cand->second_conv)))
1019 conv = build_conv (REF_BIND, to, cand->second_conv);
1027 /* Create an overload candidate for the function or method FN called with
1028 the argument list ARGLIST and add it to CANDIDATES. FLAGS is passed on
1029 to implicit_conversion. */
1031 static struct z_candidate *
1032 add_function_candidate (candidates, fn, arglist, flags)
1033 struct z_candidate *candidates;
1037 tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
1040 tree parmnode = parmlist;
1041 tree argnode = arglist;
1043 struct z_candidate *cand;
1045 /* The `this' and `in_chrg' arguments to constructors are not considered
1046 in overload resolution. */
1047 if (DECL_CONSTRUCTOR_P (fn))
1049 parmnode = TREE_CHAIN (parmnode);
1050 argnode = TREE_CHAIN (argnode);
1051 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn)))
1053 parmnode = TREE_CHAIN (parmnode);
1054 argnode = TREE_CHAIN (argnode);
1058 len = list_length (argnode);
1059 convs = make_scratch_vec (len);
1061 for (i = 0; i < len; ++i)
1063 tree arg = TREE_VALUE (argnode);
1064 tree argtype = TREE_TYPE (arg);
1067 argtype = cp_build_type_variant
1068 (argtype, TREE_READONLY (arg), TREE_THIS_VOLATILE (arg));
1070 if (parmnode == void_list_node)
1073 t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg, flags);
1076 t = build1 (IDENTITY_CONV, argtype, arg);
1077 ICS_ELLIPSIS_FLAG (t) = 1;
1080 if (i == 0 && t && TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE
1081 && ! DECL_CONSTRUCTOR_P (fn))
1082 ICS_THIS_FLAG (t) = 1;
1084 TREE_VEC_ELT (convs, i) = t;
1088 if (ICS_BAD_FLAG (t))
1092 parmnode = TREE_CHAIN (parmnode);
1093 argnode = TREE_CHAIN (argnode);
1099 /* Make sure there are default args for the rest of the parms. */
1100 for (; parmnode && parmnode != void_list_node;
1101 parmnode = TREE_CHAIN (parmnode))
1102 if (! TREE_PURPOSE (parmnode))
1108 cand = (struct z_candidate *) scratchalloc (sizeof (struct z_candidate));
1111 cand->convs = convs;
1112 cand->second_conv = NULL_TREE;
1113 cand->viable = viable;
1114 cand->basetype_path = NULL_TREE;
1115 cand->template = NULL_TREE;
1116 cand->next = candidates;
1121 /* Create an overload candidate for the conversion function FN which will
1122 be invoked for expression OBJ, producing a pointer-to-function which
1123 will in turn be called with the argument list ARGLIST, and add it to
1124 CANDIDATES. FLAGS is passed on to implicit_conversion. */
1126 static struct z_candidate *
1127 add_conv_candidate (candidates, fn, obj, arglist)
1128 struct z_candidate *candidates;
1129 tree fn, obj, arglist;
1131 tree totype = TREE_TYPE (TREE_TYPE (fn));
1132 tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (totype));
1133 int i, len = list_length (arglist) + 1;
1134 tree convs = make_scratch_vec (len);
1135 tree parmnode = parmlist;
1136 tree argnode = arglist;
1138 struct z_candidate *cand;
1139 int flags = LOOKUP_NORMAL;
1141 for (i = 0; i < len; ++i)
1143 tree arg = i == 0 ? obj : TREE_VALUE (argnode);
1144 tree argtype = lvalue_type (arg);
1148 t = implicit_conversion (totype, argtype, arg, flags);
1149 else if (parmnode == void_list_node)
1152 t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg, flags);
1155 t = build1 (IDENTITY_CONV, argtype, arg);
1156 ICS_ELLIPSIS_FLAG (t) = 1;
1159 TREE_VEC_ELT (convs, i) = t;
1163 if (ICS_BAD_FLAG (t))
1170 parmnode = TREE_CHAIN (parmnode);
1171 argnode = TREE_CHAIN (argnode);
1177 for (; parmnode && parmnode != void_list_node;
1178 parmnode = TREE_CHAIN (parmnode))
1179 if (! TREE_PURPOSE (parmnode))
1185 cand = (struct z_candidate *) scratchalloc (sizeof (struct z_candidate));
1188 cand->convs = convs;
1189 cand->second_conv = NULL_TREE;
1190 cand->viable = viable;
1191 cand->basetype_path = NULL_TREE;
1192 cand->template = NULL_TREE;
1193 cand->next = candidates;
1198 static struct z_candidate *
1199 build_builtin_candidate (candidates, fnname, type1, type2,
1200 args, argtypes, flags)
1201 struct z_candidate *candidates;
1202 tree fnname, type1, type2, *args, *argtypes;
1208 struct z_candidate *cand;
1214 convs = make_scratch_vec (args[2] ? 3 : (args[1] ? 2 : 1));
1216 for (i = 0; i < 2; ++i)
1221 t = implicit_conversion (types[i], argtypes[i], args[i], flags);
1225 /* We need something for printing the candidate. */
1226 t = build1 (IDENTITY_CONV, types[i], NULL_TREE);
1228 else if (ICS_BAD_FLAG (t))
1230 TREE_VEC_ELT (convs, i) = t;
1233 /* For COND_EXPR we rearranged the arguments; undo that now. */
1236 TREE_VEC_ELT (convs, 2) = TREE_VEC_ELT (convs, 1);
1237 TREE_VEC_ELT (convs, 1) = TREE_VEC_ELT (convs, 0);
1238 t = implicit_conversion (boolean_type_node, argtypes[2], args[2], flags);
1240 TREE_VEC_ELT (convs, 0) = t;
1245 cand = (struct z_candidate *) scratchalloc (sizeof (struct z_candidate));
1248 cand->convs = convs;
1249 cand->second_conv = NULL_TREE;
1250 cand->viable = viable;
1251 cand->basetype_path = NULL_TREE;
1252 cand->template = NULL_TREE;
1253 cand->next = candidates;
1262 return TYPE_SIZE (complete_type (t)) != NULL_TREE;
1265 /* Create any builtin operator overload candidates for the operator in
1266 question given the converted operand types TYPE1 and TYPE2. The other
1267 args are passed through from add_builtin_candidates to
1268 build_builtin_candidate. */
1270 static struct z_candidate *
1271 add_builtin_candidate (candidates, code, code2, fnname, type1, type2,
1272 args, argtypes, flags)
1273 struct z_candidate *candidates;
1274 enum tree_code code, code2;
1275 tree fnname, type1, type2, *args, *argtypes;
1280 case POSTINCREMENT_EXPR:
1281 case POSTDECREMENT_EXPR:
1282 args[1] = integer_zero_node;
1283 type2 = integer_type_node;
1292 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
1293 and VQ is either volatile or empty, there exist candidate operator
1294 functions of the form
1295 VQ T& operator++(VQ T&);
1296 T operator++(VQ T&, int);
1297 5 For every pair T, VQ), where T is an enumeration type or an arithmetic
1298 type other than bool, and VQ is either volatile or empty, there exist
1299 candidate operator functions of the form
1300 VQ T& operator--(VQ T&);
1301 T operator--(VQ T&, int);
1302 6 For every pair T, VQ), where T is a cv-qualified or cv-unqualified
1303 complete object type, and VQ is either volatile or empty, there exist
1304 candidate operator functions of the form
1305 T*VQ& operator++(T*VQ&);
1306 T*VQ& operator--(T*VQ&);
1307 T* operator++(T*VQ&, int);
1308 T* operator--(T*VQ&, int); */
1310 case POSTDECREMENT_EXPR:
1311 case PREDECREMENT_EXPR:
1312 if (TREE_CODE (type1) == BOOLEAN_TYPE)
1314 case POSTINCREMENT_EXPR:
1315 case PREINCREMENT_EXPR:
1316 if ((ARITHMETIC_TYPE_P (type1) && TREE_CODE (type1) != ENUMERAL_TYPE)
1317 || TYPE_PTROB_P (type1))
1319 type1 = build_reference_type (type1);
1324 /* 7 For every cv-qualified or cv-unqualified complete object type T, there
1325 exist candidate operator functions of the form
1329 8 For every function type T, there exist candidate operator functions of
1331 T& operator*(T*); */
1334 if (TREE_CODE (type1) == POINTER_TYPE
1335 && (TYPE_PTROB_P (type1)
1336 || TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE))
1340 /* 9 For every type T, there exist candidate operator functions of the form
1343 10For every promoted arithmetic type T, there exist candidate operator
1344 functions of the form
1348 case CONVERT_EXPR: /* unary + */
1349 if (TREE_CODE (type1) == POINTER_TYPE
1350 && TREE_CODE (TREE_TYPE (type1)) != OFFSET_TYPE)
1353 if (ARITHMETIC_TYPE_P (type1))
1357 /* 11For every promoted integral type T, there exist candidate operator
1358 functions of the form
1362 if (INTEGRAL_TYPE_P (type1))
1366 /* 12For every quintuple C1, C2, T, CV1, CV2), where C2 is a class type, C1
1367 is the same type as C2 or is a derived class of C2, T is a complete
1368 object type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
1369 there exist candidate operator functions of the form
1370 CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
1371 where CV12 is the union of CV1 and CV2. */
1374 if (TREE_CODE (type1) == POINTER_TYPE
1375 && (TYPE_PTRMEMFUNC_P (type2) || TYPE_PTRMEM_P (type2)))
1377 tree c1 = TREE_TYPE (type1);
1378 tree c2 = (TYPE_PTRMEMFUNC_P (type2)
1379 ? TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type2)))
1380 : TYPE_OFFSET_BASETYPE (TREE_TYPE (type2)));
1382 if (IS_AGGR_TYPE (c1) && DERIVED_FROM_P (c2, c1)
1383 && (TYPE_PTRMEMFUNC_P (type2)
1384 || is_complete (TREE_TYPE (TREE_TYPE (type2)))))
1389 /* 13For every pair of promoted arithmetic types L and R, there exist can-
1390 didate operator functions of the form
1395 bool operator<(L, R);
1396 bool operator>(L, R);
1397 bool operator<=(L, R);
1398 bool operator>=(L, R);
1399 bool operator==(L, R);
1400 bool operator!=(L, R);
1401 where LR is the result of the usual arithmetic conversions between
1404 14For every pair of types T and I, where T is a cv-qualified or cv-
1405 unqualified complete object type and I is a promoted integral type,
1406 there exist candidate operator functions of the form
1407 T* operator+(T*, I);
1408 T& operator[](T*, I);
1409 T* operator-(T*, I);
1410 T* operator+(I, T*);
1411 T& operator[](I, T*);
1413 15For every T, where T is a pointer to complete object type, there exist
1414 candidate operator functions of the form112)
1415 ptrdiff_t operator-(T, T);
1417 16For every pointer type T, there exist candidate operator functions of
1419 bool operator<(T, T);
1420 bool operator>(T, T);
1421 bool operator<=(T, T);
1422 bool operator>=(T, T);
1423 bool operator==(T, T);
1424 bool operator!=(T, T);
1426 17For every pointer to member type T, there exist candidate operator
1427 functions of the form
1428 bool operator==(T, T);
1429 bool operator!=(T, T); */
1432 if (TYPE_PTROB_P (type1) && TYPE_PTROB_P (type2))
1434 if (TYPE_PTROB_P (type1) && INTEGRAL_TYPE_P (type2))
1436 type2 = ptrdiff_type_node;
1440 case TRUNC_DIV_EXPR:
1441 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
1447 if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
1448 || (TYPE_PTRMEM_P (type1) && TYPE_PTRMEM_P (type2)))
1450 if ((TYPE_PTRMEMFUNC_P (type1) || TYPE_PTRMEM_P (type1))
1451 && null_ptr_cst_p (args[1]))
1456 if ((TYPE_PTRMEMFUNC_P (type2) || TYPE_PTRMEM_P (type2))
1457 && null_ptr_cst_p (args[0]))
1468 if ((ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
1469 || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2)))
1471 if (TYPE_PTR_P (type1) && null_ptr_cst_p (args[1]))
1476 if (null_ptr_cst_p (args[0]) && TYPE_PTR_P (type2))
1484 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
1487 if (INTEGRAL_TYPE_P (type1) && TYPE_PTROB_P (type2))
1489 type1 = ptrdiff_type_node;
1492 if (TYPE_PTROB_P (type1) && INTEGRAL_TYPE_P (type2))
1494 type2 = ptrdiff_type_node;
1499 /* 18For every pair of promoted integral types L and R, there exist candi-
1500 date operator functions of the form
1507 where LR is the result of the usual arithmetic conversions between
1510 case TRUNC_MOD_EXPR:
1516 if (INTEGRAL_TYPE_P (type1) && INTEGRAL_TYPE_P (type2))
1520 /* 19For every triple L, VQ, R), where L is an arithmetic or enumeration
1521 type, VQ is either volatile or empty, and R is a promoted arithmetic
1522 type, there exist candidate operator functions of the form
1523 VQ L& operator=(VQ L&, R);
1524 VQ L& operator*=(VQ L&, R);
1525 VQ L& operator/=(VQ L&, R);
1526 VQ L& operator+=(VQ L&, R);
1527 VQ L& operator-=(VQ L&, R);
1529 20For every pair T, VQ), where T is any type and VQ is either volatile
1530 or empty, there exist candidate operator functions of the form
1531 T*VQ& operator=(T*VQ&, T*);
1533 21For every pair T, VQ), where T is a pointer to member type and VQ is
1534 either volatile or empty, there exist candidate operator functions of
1536 VQ T& operator=(VQ T&, T);
1538 22For every triple T, VQ, I), where T is a cv-qualified or cv-
1539 unqualified complete object type, VQ is either volatile or empty, and
1540 I is a promoted integral type, there exist candidate operator func-
1542 T*VQ& operator+=(T*VQ&, I);
1543 T*VQ& operator-=(T*VQ&, I);
1545 23For every triple L, VQ, R), where L is an integral or enumeration
1546 type, VQ is either volatile or empty, and R is a promoted integral
1547 type, there exist candidate operator functions of the form
1549 VQ L& operator%=(VQ L&, R);
1550 VQ L& operator<<=(VQ L&, R);
1551 VQ L& operator>>=(VQ L&, R);
1552 VQ L& operator&=(VQ L&, R);
1553 VQ L& operator^=(VQ L&, R);
1554 VQ L& operator|=(VQ L&, R); */
1561 if (TYPE_PTROB_P (type1) && INTEGRAL_TYPE_P (type2))
1563 type2 = ptrdiff_type_node;
1567 case TRUNC_DIV_EXPR:
1568 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
1572 case TRUNC_MOD_EXPR:
1578 if (INTEGRAL_TYPE_P (type1) && INTEGRAL_TYPE_P (type2))
1583 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
1585 if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
1586 || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
1587 || (TYPE_PTRMEM_P (type1) && TYPE_PTRMEM_P (type2))
1588 || ((TYPE_PTRMEMFUNC_P (type1)
1589 || TREE_CODE (type1) == POINTER_TYPE)
1590 && null_ptr_cst_p (args[1])))
1598 my_friendly_abort (367);
1600 type1 = build_reference_type (type1);
1604 /* Kludge around broken overloading rules whereby
1605 bool ? const char& : enum is ambiguous
1606 (between int and const char&). */
1607 flags |= LOOKUP_NO_TEMP_BIND;
1609 /* Extension: Support ?: of enumeral type. Hopefully this will not
1610 be an extension for long. */
1611 if (TREE_CODE (type1) == ENUMERAL_TYPE && type1 == type2)
1613 else if (TREE_CODE (type1) == ENUMERAL_TYPE
1614 || TREE_CODE (type2) == ENUMERAL_TYPE)
1616 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
1618 if (TREE_CODE (type1) == TREE_CODE (type2)
1619 && (TREE_CODE (type1) == REFERENCE_TYPE
1620 || TREE_CODE (type1) == POINTER_TYPE
1621 || TYPE_PTRMEMFUNC_P (type1)
1622 || IS_AGGR_TYPE (type1)))
1624 if (TREE_CODE (type1) == REFERENCE_TYPE
1625 || TREE_CODE (type2) == REFERENCE_TYPE)
1627 if (((TYPE_PTRMEMFUNC_P (type1) || TREE_CODE (type1) == POINTER_TYPE)
1628 && null_ptr_cst_p (args[1]))
1629 || IS_AGGR_TYPE (type1))
1634 if (((TYPE_PTRMEMFUNC_P (type2) || TREE_CODE (type2) == POINTER_TYPE)
1635 && null_ptr_cst_p (args[0]))
1636 || IS_AGGR_TYPE (type2))
1644 my_friendly_abort (367);
1647 /* If we're dealing with two pointer types, we need candidates
1648 for both of them. */
1649 if (type2 && type1 != type2
1650 && TREE_CODE (type1) == TREE_CODE (type2)
1651 && (TREE_CODE (type1) == REFERENCE_TYPE
1652 || (TREE_CODE (type1) == POINTER_TYPE
1653 && TYPE_PTRMEM_P (type1) == TYPE_PTRMEM_P (type2))
1654 || TYPE_PTRMEMFUNC_P (type1)
1655 || IS_AGGR_TYPE (type1)))
1657 candidates = build_builtin_candidate
1658 (candidates, fnname, type1, type1, args, argtypes, flags);
1659 return build_builtin_candidate
1660 (candidates, fnname, type2, type2, args, argtypes, flags);
1663 return build_builtin_candidate
1664 (candidates, fnname, type1, type2, args, argtypes, flags);
1668 type_decays_to (type)
1671 if (TREE_CODE (type) == ARRAY_TYPE)
1672 return build_pointer_type (TREE_TYPE (type));
1673 if (TREE_CODE (type) == FUNCTION_TYPE)
1674 return build_pointer_type (type);
1678 /* There are three conditions of builtin candidates:
1680 1) bool-taking candidates. These are the same regardless of the input.
1681 2) pointer-pair taking candidates. These are generated for each type
1682 one of the input types converts to.
1683 3) arithmetic candidates. According to the WP, we should generate
1684 all of these, but I'm trying not to... */
1686 static struct z_candidate *
1687 add_builtin_candidates (candidates, code, code2, fnname, args, flags)
1688 struct z_candidate *candidates;
1689 enum tree_code code, code2;
1694 tree type, argtypes[3], types[2];
1696 for (i = 0; i < 3; ++i)
1699 argtypes[i] = lvalue_type (args[i]);
1701 argtypes[i] = NULL_TREE;
1706 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
1707 and VQ is either volatile or empty, there exist candidate operator
1708 functions of the form
1709 VQ T& operator++(VQ T&); */
1711 case POSTINCREMENT_EXPR:
1712 case PREINCREMENT_EXPR:
1713 case POSTDECREMENT_EXPR:
1714 case PREDECREMENT_EXPR:
1719 /* 24There also exist candidate operator functions of the form
1720 bool operator!(bool);
1721 bool operator&&(bool, bool);
1722 bool operator||(bool, bool); */
1724 case TRUTH_NOT_EXPR:
1725 return build_builtin_candidate
1726 (candidates, fnname, boolean_type_node,
1727 NULL_TREE, args, argtypes, flags);
1729 case TRUTH_ORIF_EXPR:
1730 case TRUTH_ANDIF_EXPR:
1731 return build_builtin_candidate
1732 (candidates, fnname, boolean_type_node,
1733 boolean_type_node, args, argtypes, flags);
1744 types[0] = types[1] = NULL_TREE;
1746 for (i = 0; i < 2; ++i)
1750 else if (IS_AGGR_TYPE (argtypes[i]))
1752 tree convs = lookup_conversions (argtypes[i]);
1754 if (code == COND_EXPR)
1756 if (real_lvalue_p (args[i]))
1757 types[i] = scratch_tree_cons
1758 (NULL_TREE, build_reference_type (argtypes[i]), types[i]);
1760 types[i] = scratch_tree_cons
1761 (NULL_TREE, TYPE_MAIN_VARIANT (argtypes[i]), types[i]);
1764 else if (! convs || (i == 0 && code == MODIFY_EXPR
1765 && code2 == NOP_EXPR))
1768 for (; convs; convs = TREE_CHAIN (convs))
1770 type = TREE_TYPE (TREE_TYPE (TREE_VALUE (convs)));
1773 && (TREE_CODE (type) != REFERENCE_TYPE
1774 || TYPE_READONLY (TREE_TYPE (type))))
1777 if (code == COND_EXPR && TREE_CODE (type) == REFERENCE_TYPE)
1778 types[i] = scratch_tree_cons (NULL_TREE, type, types[i]);
1780 type = non_reference (type);
1781 if (i != 0 || ! ref1)
1783 type = TYPE_MAIN_VARIANT (type_decays_to (type));
1784 if (code == COND_EXPR && TREE_CODE (type) == ENUMERAL_TYPE)
1785 types[i] = scratch_tree_cons (NULL_TREE, type, types[i]);
1786 if (INTEGRAL_TYPE_P (type))
1787 type = type_promotes_to (type);
1790 if (! value_member (type, types[i]))
1791 types[i] = scratch_tree_cons (NULL_TREE, type, types[i]);
1796 if (code == COND_EXPR && real_lvalue_p (args[i]))
1797 types[i] = scratch_tree_cons
1798 (NULL_TREE, build_reference_type (argtypes[i]), types[i]);
1799 type = non_reference (argtypes[i]);
1800 if (i != 0 || ! ref1)
1802 type = TYPE_MAIN_VARIANT (type_decays_to (type));
1803 if (code == COND_EXPR && TREE_CODE (type) == ENUMERAL_TYPE)
1804 types[i] = scratch_tree_cons (NULL_TREE, type, types[i]);
1805 if (INTEGRAL_TYPE_P (type))
1806 type = type_promotes_to (type);
1808 types[i] = scratch_tree_cons (NULL_TREE, type, types[i]);
1812 for (; types[0]; types[0] = TREE_CHAIN (types[0]))
1815 for (type = types[1]; type; type = TREE_CHAIN (type))
1816 candidates = add_builtin_candidate
1817 (candidates, code, code2, fnname, TREE_VALUE (types[0]),
1818 TREE_VALUE (type), args, argtypes, flags);
1820 candidates = add_builtin_candidate
1821 (candidates, code, code2, fnname, TREE_VALUE (types[0]),
1822 NULL_TREE, args, argtypes, flags);
1829 /* If TMPL can be successfully instantiated as indicated by
1830 EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
1832 TMPL is the template. EXPLICIT_TARGS are any explicit template
1833 arguments. ARGLIST is the arguments provided at the call-site.
1834 The RETURN_TYPE is the desired type for conversion operators. If
1835 OBJ is NULL_TREE, FLAGS are as for add_function_candidate. If an
1836 OBJ is supplied, FLAGS are ignored, and OBJ is as for
1837 add_conv_candidate. */
1839 static struct z_candidate*
1840 add_template_candidate_real (candidates, tmpl, explicit_targs,
1841 arglist, return_type, flags,
1843 struct z_candidate *candidates;
1844 tree tmpl, explicit_targs, arglist, return_type;
1848 int ntparms = DECL_NTPARMS (tmpl);
1849 tree targs = make_scratch_vec (ntparms);
1850 struct z_candidate *cand;
1854 i = fn_type_unification (tmpl, explicit_targs, targs, arglist,
1855 return_type, 0, NULL_TREE);
1860 fn = instantiate_template (tmpl, targs);
1861 if (fn == error_mark_node)
1864 if (obj != NULL_TREE)
1865 /* Aha, this is a conversion function. */
1866 cand = add_conv_candidate (candidates, fn, obj, arglist);
1868 cand = add_function_candidate (candidates, fn, arglist, flags);
1869 if (DECL_TI_TEMPLATE (fn) != tmpl)
1870 /* This situation can occur if a member template of a template
1871 class is specialized. Then, instantiate_template might return
1872 an instantiation of the specialization, in which case the
1873 DECL_TI_TEMPLATE field will point at the original
1874 specialization. For example:
1876 template <class T> struct S { template <class U> void f(U);
1877 template <> void f(int) {}; };
1881 Here, TMPL will be template <class U> S<double>::f(U).
1882 And, instantiate template will give us the specialization
1883 template <> S<double>::f(int). But, the DECL_TI_TEMPLATE field
1884 for this will point at template <class T> template <> S<T>::f(int),
1885 so that we can find the definition. For the purposes of
1886 overload resolution, however, we want the original TMPL. */
1887 cand->template = tree_cons (tmpl, targs, NULL_TREE);
1889 cand->template = DECL_TEMPLATE_INFO (fn);
1895 static struct z_candidate *
1896 add_template_candidate (candidates, tmpl, explicit_targs,
1897 arglist, return_type, flags)
1898 struct z_candidate *candidates;
1899 tree tmpl, explicit_targs, arglist, return_type;
1903 add_template_candidate_real (candidates, tmpl, explicit_targs,
1904 arglist, return_type, flags, NULL_TREE);
1908 static struct z_candidate *
1909 add_template_conv_candidate (candidates, tmpl, obj, arglist, return_type)
1910 struct z_candidate *candidates;
1911 tree tmpl, obj, arglist, return_type;
1914 add_template_candidate_real (candidates, tmpl, NULL_TREE, arglist,
1915 return_type, 0, obj);
1921 struct z_candidate *cands;
1923 for (; cands; cands = cands->next)
1924 if (pedantic ? cands->viable == 1 : cands->viable)
1929 static struct z_candidate *
1930 splice_viable (cands)
1931 struct z_candidate *cands;
1933 struct z_candidate **p = &cands;
1937 if (pedantic ? (*p)->viable == 1 : (*p)->viable)
1950 /* Fix this to work on non-lvalues. */
1951 if (IS_SIGNATURE_POINTER (TREE_TYPE (obj))
1952 || IS_SIGNATURE_REFERENCE (TREE_TYPE (obj)))
1955 return build_unary_op (ADDR_EXPR, obj, 0);
1959 print_z_candidates (candidates)
1960 struct z_candidate *candidates;
1962 char *str = "candidates are:";
1963 for (; candidates; candidates = candidates->next)
1965 if (TREE_CODE (candidates->fn) == IDENTIFIER_NODE)
1967 if (candidates->fn == ansi_opname [COND_EXPR])
1968 cp_error ("%s %D(%T, %T, %T) <builtin>", str, candidates->fn,
1969 TREE_TYPE (TREE_VEC_ELT (candidates->convs, 0)),
1970 TREE_TYPE (TREE_VEC_ELT (candidates->convs, 1)),
1971 TREE_TYPE (TREE_VEC_ELT (candidates->convs, 2)));
1972 else if (TREE_VEC_LENGTH (candidates->convs) == 2)
1973 cp_error ("%s %D(%T, %T) <builtin>", str, candidates->fn,
1974 TREE_TYPE (TREE_VEC_ELT (candidates->convs, 0)),
1975 TREE_TYPE (TREE_VEC_ELT (candidates->convs, 1)));
1977 cp_error ("%s %D(%T) <builtin>", str, candidates->fn,
1978 TREE_TYPE (TREE_VEC_ELT (candidates->convs, 0)));
1981 cp_error_at ("%s %+D%s", str, candidates->fn,
1982 candidates->viable == -1 ? " <near match>" : "");
1987 /* Returns the best overload candidate to perform the requested
1988 conversion. This function is used for three the overloading situations
1989 described in [over.match.copy], [over.match.conv], and [over.match.ref].
1990 If TOTYPE is a REFERENCE_TYPE, we're trying to find an lvalue binding as
1991 per [dcl.init.ref], so we ignore temporary bindings. */
1993 static struct z_candidate *
1994 build_user_type_conversion_1 (totype, expr, flags)
1998 struct z_candidate *candidates, *cand;
1999 tree fromtype = TREE_TYPE (expr);
2000 tree ctors = NULL_TREE, convs = NULL_TREE, *p;
2001 tree args = NULL_TREE;
2002 tree templates = NULL_TREE;
2004 if (IS_AGGR_TYPE (totype))
2005 ctors = lookup_fnfields (TYPE_BINFO (totype), ctor_identifier, 0);
2006 if (IS_AGGR_TYPE (fromtype)
2007 && (! IS_AGGR_TYPE (totype) || ! DERIVED_FROM_P (totype, fromtype)))
2008 convs = lookup_conversions (fromtype);
2011 flags |= LOOKUP_NO_CONVERSION;
2015 tree t = build_int_2 (0, 0);
2016 TREE_TYPE (t) = build_pointer_type (totype);
2017 args = build_scratch_list (NULL_TREE, expr);
2018 if (TYPE_USES_VIRTUAL_BASECLASSES (totype))
2019 args = scratch_tree_cons (NULL_TREE, integer_one_node, args);
2020 args = scratch_tree_cons (NULL_TREE, t, args);
2022 ctors = TREE_VALUE (ctors);
2024 for (; ctors; ctors = DECL_CHAIN (ctors))
2026 if (DECL_NONCONVERTING_P (ctors))
2029 if (TREE_CODE (ctors) == TEMPLATE_DECL)
2031 templates = scratch_tree_cons (NULL_TREE, ctors, templates);
2033 add_template_candidate (candidates, ctors,
2034 NULL_TREE, args, NULL_TREE, flags);
2037 candidates = add_function_candidate (candidates, ctors,
2042 candidates->second_conv = build1 (IDENTITY_CONV, totype, NULL_TREE);
2043 candidates->basetype_path = TYPE_BINFO (totype);
2048 args = build_scratch_list (NULL_TREE, build_this (expr));
2050 for (; convs; convs = TREE_CHAIN (convs))
2052 tree fn = TREE_VALUE (convs);
2053 int convflags = LOOKUP_NO_CONVERSION;
2056 /* If we are called to convert to a reference type, we are trying to
2057 find an lvalue binding, so don't even consider temporaries. If
2058 we don't find an lvalue binding, the caller will try again to
2059 look for a temporary binding. */
2060 if (TREE_CODE (totype) == REFERENCE_TYPE)
2061 convflags |= LOOKUP_NO_TEMP_BIND;
2063 if (TREE_CODE (fn) != TEMPLATE_DECL)
2064 ics = implicit_conversion
2065 (totype, TREE_TYPE (TREE_TYPE (fn)), 0, convflags);
2067 /* Here, the template conversion operator result must
2068 precisely match the TOTYPE. (FIXME: Actually, we're
2069 supposed to do some simple conversions here; see
2070 [temp.deduct.conv].). If the result of the conversion
2071 operator is not actually TOTYPE, then
2072 add_template_candidate will fail below. */
2073 ics = implicit_conversion (totype, totype, 0, convflags);
2075 if (TREE_CODE (totype) == REFERENCE_TYPE && ics && ICS_BAD_FLAG (ics))
2076 /* ignore the near match. */;
2078 for (; fn; fn = DECL_CHAIN (fn))
2080 if (TREE_CODE (fn) == TEMPLATE_DECL)
2082 templates = scratch_tree_cons (NULL_TREE, fn, templates);
2084 add_template_candidate (candidates, fn, NULL_TREE,
2085 args, totype, flags);
2088 candidates = add_function_candidate (candidates, fn,
2093 candidates->second_conv = ics;
2094 candidates->basetype_path = TREE_PURPOSE (convs);
2095 if (candidates->viable == 1 && ICS_BAD_FLAG (ics))
2096 candidates->viable = -1;
2101 if (! any_viable (candidates))
2104 if (flags & LOOKUP_COMPLAIN)
2106 if (candidates && ! candidates->next)
2107 /* say why this one won't work or try to be loose */;
2109 cp_error ("no viable candidates");
2116 candidates = splice_viable (candidates);
2117 cand = tourney (candidates);
2121 if (flags & LOOKUP_COMPLAIN)
2123 cp_error ("conversion from `%T' to `%T' is ambiguous",
2125 print_z_candidates (candidates);
2128 cand = candidates; /* any one will do */
2129 cand->second_conv = build1 (AMBIG_CONV, totype, expr);
2130 ICS_USER_FLAG (cand->second_conv) = 1;
2131 ICS_BAD_FLAG (cand->second_conv) = 1;
2136 for (p = &(cand->second_conv); TREE_CODE (*p) != IDENTITY_CONV; )
2137 p = &(TREE_OPERAND (*p, 0));
2139 /* Pedantically, normal function declarations are never considered
2140 to refer to template instantiations, so we only do this with
2142 if (flag_guiding_decls && templates && ! cand->template
2143 && !DECL_INITIAL (cand->fn)
2144 && TREE_CODE (TREE_TYPE (cand->fn)) != METHOD_TYPE)
2145 add_maybe_template (cand->fn, templates);
2149 (DECL_CONSTRUCTOR_P (cand->fn)
2150 ? totype : non_reference (TREE_TYPE (TREE_TYPE (cand->fn)))),
2151 expr, cand->fn, cand->convs, cand->basetype_path);
2152 ICS_USER_FLAG (cand->second_conv) = 1;
2153 if (cand->viable == -1)
2154 ICS_BAD_FLAG (cand->second_conv) = 1;
2160 build_user_type_conversion (totype, expr, flags)
2164 struct z_candidate *cand
2165 = build_user_type_conversion_1 (totype, expr, flags);
2169 if (TREE_CODE (cand->second_conv) == AMBIG_CONV)
2170 return error_mark_node;
2171 return convert_from_reference (convert_like (cand->second_conv, expr));
2176 /* Do any initial processing on the arguments to a function call. */
2183 for (t = args; t; t = TREE_CHAIN (t))
2185 if (TREE_VALUE (t) == error_mark_node)
2186 return error_mark_node;
2187 else if (TREE_CODE (TREE_TYPE (TREE_VALUE (t))) == VOID_TYPE)
2189 error ("invalid use of void expression");
2190 return error_mark_node;
2192 else if (TREE_CODE (TREE_VALUE (t)) == OFFSET_REF)
2193 TREE_VALUE (t) = resolve_offset_ref (TREE_VALUE (t));
2199 build_new_function_call (fn, args)
2202 struct z_candidate *candidates = 0, *cand;
2203 tree explicit_targs = NULL_TREE;
2204 int template_only = 0;
2206 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
2208 explicit_targs = TREE_OPERAND (fn, 1);
2209 fn = TREE_OPERAND (fn, 0);
2213 if (really_overloaded_fn (fn))
2216 tree templates = NULL_TREE;
2218 args = resolve_args (args);
2220 if (args == error_mark_node)
2221 return error_mark_node;
2223 for (t = TREE_VALUE (fn); t; t = DECL_CHAIN (t))
2225 if (TREE_CODE (t) == TEMPLATE_DECL)
2227 templates = scratch_tree_cons (NULL_TREE, t, templates);
2228 candidates = add_template_candidate
2229 (candidates, t, explicit_targs, args, NULL_TREE,
2232 else if (! template_only)
2233 candidates = add_function_candidate
2234 (candidates, t, args, LOOKUP_NORMAL);
2237 if (! any_viable (candidates))
2239 if (candidates && ! candidates->next)
2240 return build_function_call (candidates->fn, args);
2241 cp_error ("no matching function for call to `%D (%A)'",
2242 TREE_PURPOSE (fn), args);
2244 print_z_candidates (candidates);
2245 return error_mark_node;
2247 candidates = splice_viable (candidates);
2248 cand = tourney (candidates);
2252 cp_error ("call of overloaded `%D (%A)' is ambiguous",
2253 TREE_PURPOSE (fn), args);
2254 print_z_candidates (candidates);
2255 return error_mark_node;
2258 /* Pedantically, normal function declarations are never considered
2259 to refer to template instantiations, so we only do this with
2261 if (flag_guiding_decls && templates && ! cand->template
2262 && ! DECL_INITIAL (cand->fn))
2263 add_maybe_template (cand->fn, templates);
2265 return build_over_call (cand->fn, cand->convs, args, LOOKUP_NORMAL);
2268 return build_function_call (fn, args);
2272 build_object_call (obj, args)
2275 struct z_candidate *candidates = 0, *cand;
2276 tree fns, convs, mem_args = NULL_TREE;
2277 tree type = TREE_TYPE (obj);
2278 tree templates = NULL_TREE;
2280 fns = lookup_fnfields (TYPE_BINFO (type), ansi_opname [CALL_EXPR], 0);
2282 args = resolve_args (args);
2284 if (args == error_mark_node)
2285 return error_mark_node;
2289 tree fn = TREE_VALUE (fns);
2290 mem_args = scratch_tree_cons (NULL_TREE, build_this (obj), args);
2292 for (; fn; fn = DECL_CHAIN (fn))
2294 if (TREE_CODE (fn) == TEMPLATE_DECL)
2296 templates = scratch_tree_cons (NULL_TREE, fn, templates);
2298 = add_template_candidate (candidates, fn, NULL_TREE,
2299 mem_args, NULL_TREE,
2303 candidates = add_function_candidate
2304 (candidates, fn, mem_args, LOOKUP_NORMAL);
2307 candidates->basetype_path = TREE_PURPOSE (fns);
2311 convs = lookup_conversions (type);
2313 for (; convs; convs = TREE_CHAIN (convs))
2315 tree fn = TREE_VALUE (convs);
2316 tree totype = TREE_TYPE (TREE_TYPE (fn));
2318 if (TREE_CODE (totype) == POINTER_TYPE
2319 && TREE_CODE (TREE_TYPE (totype)) == FUNCTION_TYPE)
2320 for (; fn; fn = DECL_CHAIN (fn))
2322 if (TREE_CODE (fn) == TEMPLATE_DECL)
2324 templates = scratch_tree_cons (NULL_TREE, fn, templates);
2325 candidates = add_template_conv_candidate (candidates,
2332 candidates = add_conv_candidate (candidates, fn, obj, args);
2335 candidates->basetype_path = TREE_PURPOSE (convs);
2339 if (! any_viable (candidates))
2341 cp_error ("no match for call to `(%T) (%A)'", TREE_TYPE (obj), args);
2342 print_z_candidates (candidates);
2343 return error_mark_node;
2346 candidates = splice_viable (candidates);
2347 cand = tourney (candidates);
2351 cp_error ("call of `(%T) (%A)' is ambiguous", TREE_TYPE (obj), args);
2352 print_z_candidates (candidates);
2353 return error_mark_node;
2356 if (DECL_NAME (cand->fn) == ansi_opname [CALL_EXPR])
2357 return build_over_call (cand->fn, cand->convs, mem_args, LOOKUP_NORMAL);
2359 obj = convert_like (TREE_VEC_ELT (cand->convs, 0), obj);
2362 return build_function_call (obj, args);
2366 op_error (code, code2, arg1, arg2, arg3, problem)
2367 enum tree_code code, code2;
2368 tree arg1, arg2, arg3;
2372 = (code == MODIFY_EXPR ? assignop_tab [code2] : opname_tab [code]);
2377 cp_error ("%s for `%T ? %T : %T'", problem,
2378 error_type (arg1), error_type (arg2), error_type (arg3));
2380 case POSTINCREMENT_EXPR:
2381 case POSTDECREMENT_EXPR:
2382 cp_error ("%s for `%T%s'", problem, error_type (arg1), opname);
2385 cp_error ("%s for `%T[%T]'", problem,
2386 error_type (arg1), error_type (arg2));
2390 cp_error ("%s for `%T %s %T'", problem,
2391 error_type (arg1), opname, error_type (arg2));
2393 cp_error ("%s for `%s%T'", problem, opname, error_type (arg1));
2398 build_new_op (code, flags, arg1, arg2, arg3)
2399 enum tree_code code;
2401 tree arg1, arg2, arg3;
2403 struct z_candidate *candidates = 0, *cand;
2404 tree fns, mem_arglist = NULL_TREE, arglist, fnname;
2405 enum tree_code code2 = NOP_EXPR;
2406 tree templates = NULL_TREE;
2409 if (arg1 == error_mark_node
2410 || arg2 == error_mark_node
2411 || arg3 == error_mark_node)
2412 return error_mark_node;
2414 /* This can happen if a template takes all non-type parameters, e.g.
2415 undeclared_template<1, 5, 72>a; */
2416 if (code == LT_EXPR && TREE_CODE (arg1) == TEMPLATE_DECL)
2418 cp_error ("`%D' must be declared before use", arg1);
2419 return error_mark_node;
2422 if (code == MODIFY_EXPR)
2424 code2 = TREE_CODE (arg3);
2426 fnname = ansi_assopname[code2];
2429 fnname = ansi_opname[code];
2438 arglist = scratch_tree_cons (NULL_TREE, arg2, arg3);
2439 if (flags & LOOKUP_GLOBAL)
2440 return build_new_function_call
2441 (lookup_name_nonclass (fnname), arglist);
2444 rval = build_method_call
2445 (build_indirect_ref (build1 (NOP_EXPR, arg1, error_mark_node),
2447 fnname, arglist, NULL_TREE, flags);
2448 if (rval == error_mark_node)
2449 /* User might declare fancy operator new, but invoke it
2450 like standard one. */
2453 TREE_TYPE (rval) = arg1;
2457 case VEC_DELETE_EXPR:
2462 if (flags & LOOKUP_GLOBAL)
2463 return build_new_function_call
2464 (lookup_name_nonclass (fnname),
2465 build_scratch_list (NULL_TREE, arg1));
2467 arglist = scratch_tree_cons (NULL_TREE, arg1, build_scratch_list (NULL_TREE, arg2));
2469 arg1 = TREE_TYPE (arg1);
2471 /* This handles the case where we're trying to delete
2476 if (TREE_CODE (TREE_TYPE (arg1)) == ARRAY_TYPE)
2478 /* Strip off the pointer and the array. */
2479 arg1 = TREE_TYPE (TREE_TYPE (arg1));
2481 while (TREE_CODE (arg1) == ARRAY_TYPE)
2482 arg1 = (TREE_TYPE (arg1));
2484 arg1 = build_pointer_type (arg1);
2488 rval = build_method_call
2489 (build_indirect_ref (build1 (NOP_EXPR, arg1,
2492 fnname, arglist, NULL_TREE, flags);
2494 /* This can happen when operator delete is protected. */
2495 my_friendly_assert (rval != error_mark_node, 250);
2496 TREE_TYPE (rval) = void_type_node;
2502 return build_object_call (arg1, arg2);
2508 /* The comma operator can have void args. */
2509 if (TREE_CODE (arg1) == OFFSET_REF)
2510 arg1 = resolve_offset_ref (arg1);
2511 if (arg2 && TREE_CODE (arg2) == OFFSET_REF)
2512 arg2 = resolve_offset_ref (arg2);
2513 if (arg3 && TREE_CODE (arg3) == OFFSET_REF)
2514 arg3 = resolve_offset_ref (arg3);
2516 if (code == COND_EXPR)
2518 if (arg2 == NULL_TREE
2519 || TREE_CODE (TREE_TYPE (arg2)) == VOID_TYPE
2520 || TREE_CODE (TREE_TYPE (arg3)) == VOID_TYPE
2521 || (! IS_OVERLOAD_TYPE (TREE_TYPE (arg2))
2522 && ! IS_OVERLOAD_TYPE (TREE_TYPE (arg3))))
2525 else if (! IS_OVERLOAD_TYPE (TREE_TYPE (arg1))
2526 && (! arg2 || ! IS_OVERLOAD_TYPE (TREE_TYPE (arg2))))
2529 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
2530 arg2 = integer_zero_node;
2533 arglist = scratch_tree_cons (NULL_TREE, arg1, scratch_tree_cons
2534 (NULL_TREE, arg2, build_scratch_list (NULL_TREE, arg3)));
2536 arglist = scratch_tree_cons (NULL_TREE, arg1, build_scratch_list (NULL_TREE, arg2));
2538 arglist = build_scratch_list (NULL_TREE, arg1);
2540 fns = lookup_name_nonclass (fnname);
2541 /* + Koenig lookup */
2543 if (fns && TREE_CODE (fns) == TREE_LIST)
2544 fns = TREE_VALUE (fns);
2545 for (; fns; fns = DECL_CHAIN (fns))
2547 if (TREE_CODE (fns) == TEMPLATE_DECL)
2549 templates = scratch_tree_cons (NULL_TREE, fns, templates);
2551 = add_template_candidate (candidates, fns, NULL_TREE,
2552 arglist, TREE_TYPE (fnname),
2556 candidates = add_function_candidate (candidates, fns, arglist, flags);
2559 if (IS_AGGR_TYPE (TREE_TYPE (arg1)))
2560 fns = lookup_fnfields (TYPE_BINFO (TREE_TYPE (arg1)), fnname, 0);
2566 tree fn = TREE_VALUE (fns);
2567 mem_arglist = scratch_tree_cons (NULL_TREE, build_this (arg1), TREE_CHAIN (arglist));
2568 for (; fn; fn = DECL_CHAIN (fn))
2572 if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
2573 this_arglist = mem_arglist;
2575 this_arglist = arglist;
2577 if (TREE_CODE (fn) == TEMPLATE_DECL)
2579 /* A member template. */
2580 templates = scratch_tree_cons (NULL_TREE, fn, templates);
2582 = add_template_candidate (candidates, fn, NULL_TREE,
2583 this_arglist, TREE_TYPE (fnname),
2587 candidates = add_function_candidate
2588 (candidates, fn, this_arglist, flags);
2591 candidates->basetype_path = TREE_PURPOSE (fns);
2598 /* Rearrange the arguments for ?: so that add_builtin_candidate only has
2599 to know about two args; a builtin candidate will always have a first
2600 parameter of type bool. We'll handle that in
2601 build_builtin_candidate. */
2602 if (code == COND_EXPR)
2612 args[2] = NULL_TREE;
2615 candidates = add_builtin_candidates
2616 (candidates, code, code2, fnname, args, flags);
2619 if (! any_viable (candidates))
2623 case POSTINCREMENT_EXPR:
2624 case POSTDECREMENT_EXPR:
2625 /* Look for an `operator++ (int)'. If they didn't have
2626 one, then we fall back to the old way of doing things. */
2627 if (flags & LOOKUP_COMPLAIN)
2628 cp_pedwarn ("no `%D (int)' declared for postfix `%s', trying prefix operator instead",
2629 fnname, opname_tab [code]);
2630 if (code == POSTINCREMENT_EXPR)
2631 code = PREINCREMENT_EXPR;
2633 code = PREDECREMENT_EXPR;
2634 return build_new_op (code, flags, arg1, NULL_TREE, NULL_TREE);
2636 /* The caller will deal with these. */
2645 if (flags & LOOKUP_COMPLAIN)
2647 op_error (code, code2, arg1, arg2, arg3, "no match");
2648 print_z_candidates (candidates);
2650 return error_mark_node;
2652 candidates = splice_viable (candidates);
2653 cand = tourney (candidates);
2657 if (flags & LOOKUP_COMPLAIN)
2659 op_error (code, code2, arg1, arg2, arg3, "ambiguous overload");
2660 print_z_candidates (candidates);
2662 return error_mark_node;
2665 if (TREE_CODE (cand->fn) == FUNCTION_DECL)
2667 extern int warn_synth;
2669 && fnname == ansi_opname[MODIFY_EXPR]
2670 && DECL_ARTIFICIAL (cand->fn)
2672 && ! candidates->next->next)
2674 cp_warning ("using synthesized `%#D' for copy assignment",
2676 cp_warning_at (" where cfront would use `%#D'",
2678 ? candidates->next->fn
2682 if (DECL_FUNCTION_MEMBER_P (cand->fn))
2683 enforce_access (cand->basetype_path, cand->fn);
2685 /* Pedantically, normal function declarations are never considered
2686 to refer to template instantiations, so we only do this with
2688 if (flag_guiding_decls && templates && ! cand->template
2689 && ! DECL_INITIAL (cand->fn)
2690 && TREE_CODE (TREE_TYPE (cand->fn)) != METHOD_TYPE)
2691 add_maybe_template (cand->fn, templates);
2693 return build_over_call
2694 (cand->fn, cand->convs,
2695 TREE_CODE (TREE_TYPE (cand->fn)) == METHOD_TYPE
2696 ? mem_arglist : arglist,
2700 /* Check for comparison of different enum types. */
2709 if (flag_int_enum_equivalence == 0
2710 && TREE_CODE (TREE_TYPE (arg1)) == ENUMERAL_TYPE
2711 && TREE_CODE (TREE_TYPE (arg2)) == ENUMERAL_TYPE
2712 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg1))
2713 != TYPE_MAIN_VARIANT (TREE_TYPE (arg2))))
2715 cp_warning ("comparison between `%#T' and `%#T'",
2716 TREE_TYPE (arg1), TREE_TYPE (arg2));
2723 /* We need to strip any leading REF_BIND so that bitfields don't cause
2724 errors. This should not remove any important conversions, because
2725 builtins don't apply to class objects directly. */
2726 conv = TREE_VEC_ELT (cand->convs, 0);
2727 if (TREE_CODE (conv) == REF_BIND)
2728 conv = TREE_OPERAND (conv, 0);
2729 arg1 = convert_like (conv, arg1);
2731 arg2 = convert_like (TREE_VEC_ELT (cand->convs, 1), arg2);
2733 arg3 = convert_like (TREE_VEC_ELT (cand->convs, 2), arg3);
2739 return build_modify_expr (arg1, code2, arg2);
2742 return build_indirect_ref (arg1, "unary *");
2747 case TRUNC_DIV_EXPR:
2758 case TRUNC_MOD_EXPR:
2762 case TRUTH_ANDIF_EXPR:
2763 case TRUTH_ORIF_EXPR:
2764 return build_binary_op_nodefault (code, arg1, arg2, code);
2769 case TRUTH_NOT_EXPR:
2770 case PREINCREMENT_EXPR:
2771 case POSTINCREMENT_EXPR:
2772 case PREDECREMENT_EXPR:
2773 case POSTDECREMENT_EXPR:
2776 return build_unary_op (code, arg1, candidates != 0);
2779 return build_array_ref (arg1, arg2);
2782 return build_conditional_expr (arg1, arg2, arg3);
2785 return build_m_component_ref
2786 (build_indirect_ref (arg1, NULL_PTR), arg2);
2788 /* The caller will deal with these. */
2795 my_friendly_abort (367);
2800 /* Build up a call to operator new. This has to be handled differently
2801 from other operators in the way lookup is handled; first members are
2802 considered, then globals. CODE is either NEW_EXPR or VEC_NEW_EXPR.
2803 TYPE is the type to be created. ARGS are any new-placement args.
2804 FLAGS are the usual overloading flags. */
2807 build_op_new_call (code, type, args, flags)
2808 enum tree_code code;
2812 tree fnname = ansi_opname[code];
2814 if (IS_AGGR_TYPE (type) && ! (flags & LOOKUP_GLOBAL)
2815 && (TYPE_GETS_NEW (type) & (1 << (code == VEC_NEW_EXPR))))
2817 tree dummy = build1 (NOP_EXPR, build_pointer_type (type),
2819 dummy = build_indirect_ref (dummy, "new");
2820 return build_method_call (dummy, fnname, args, NULL_TREE, flags);
2823 return build_new_function_call (lookup_name_nonclass (fnname), args);
2826 /* Build a call to operator delete. This has to be handled very specially,
2827 because the restrictions on what signatures match are different from all
2828 other call instances. For a normal delete, only a delete taking (void *)
2829 or (void *, size_t) is accepted. For a placement delete, only an exact
2830 match with the placement new is accepted.
2832 CODE is either DELETE_EXPR or VEC_DELETE_EXPR.
2833 ADDR is the pointer to be deleted. For placement delete, it is also
2834 used to determine what the corresponding new looked like.
2835 SIZE is the size of the memory block to be deleted.
2836 FLAGS are the usual overloading flags. */
2839 build_op_delete_call (code, addr, size, flags)
2840 enum tree_code code;
2844 tree fn, fns, fnname, fntype, argtypes, args, type;
2847 if (addr == error_mark_node)
2848 return error_mark_node;
2850 type = TREE_TYPE (TREE_TYPE (addr));
2851 fnname = ansi_opname[code];
2853 if (IS_AGGR_TYPE (type) && ! (flags & LOOKUP_GLOBAL))
2854 fns = lookup_fnfields (TYPE_BINFO (type), fnname, 0);
2860 /* Build this up like build_offset_ref does. */
2861 fns = build_tree_list (error_mark_node, fns);
2862 TREE_TYPE (fns) = build_offset_type (type, unknown_type_node);
2865 fns = lookup_name_nonclass (fnname);
2867 /* We can recognize a placement delete because of LOOKUP_SPECULATIVELY;
2868 if we are doing placement delete we do nothing if we don't find a
2869 matching op delete. */
2870 placement = !!(flags & LOOKUP_SPECULATIVELY);
2873 /* If placement, we are coming from build_new, and we know that addr
2874 is the allocation expression, so extract the info we need from it.
2875 Obviously, if the build_new process changes this may have to
2879 tree t = TREE_OPERAND (addr, 1);
2880 /* The CALL_EXPR. */
2881 t = TREE_OPERAND (t, 0);
2883 argtypes = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
2884 /* The second parm type. */
2885 argtypes = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (argtypes)));
2886 /* The second argument. */
2887 args = TREE_CHAIN (TREE_OPERAND (t, 1));
2889 /* Pull the dummy var out of the TARGET_EXPR for use in our call. */
2890 addr = TREE_OPERAND (addr, 0);
2894 /* First try it without the size argument. */
2895 argtypes = void_list_node;
2899 argtypes = tree_cons (NULL_TREE, ptr_type_node, argtypes);
2900 fntype = build_function_type (void_type_node, argtypes);
2902 /* Strip const and volatile from addr. */
2903 if (type != TYPE_MAIN_VARIANT (type))
2904 addr = cp_convert (build_pointer_type (TYPE_MAIN_VARIANT (type)), addr);
2906 /* instantiate_type will always return a plain function; pretend it's
2908 if (TREE_CODE (fns) == FUNCTION_DECL)
2909 fns = scratch_tree_cons (NULL_TREE, fns, NULL_TREE);
2911 fn = instantiate_type (fntype, fns, 0);
2913 if (fn != error_mark_node)
2915 if (TREE_CODE (TREE_VALUE (fns)) == TREE_LIST)
2916 /* Member functions. */
2917 enforce_access (TREE_PURPOSE (TREE_VALUE (fns)), fn);
2918 return build_function_call (fn, expr_tree_cons (NULL_TREE, addr, args));
2924 /* Normal delete; now try to find a match including the size argument. */
2925 argtypes = tree_cons (NULL_TREE, ptr_type_node,
2926 tree_cons (NULL_TREE, sizetype, void_list_node));
2927 fntype = build_function_type (void_type_node, argtypes);
2929 fn = instantiate_type (fntype, fns, 0);
2931 if (fn != error_mark_node)
2932 return build_function_call
2933 (fn, expr_tree_cons (NULL_TREE, addr,
2934 build_expr_list (NULL_TREE, size)));
2936 cp_error ("no suitable operator delete for `%T'", type);
2937 return error_mark_node;
2940 /* If the current scope isn't allowed to access FUNCTION along
2941 BASETYPE_PATH, give an error. */
2944 enforce_access (basetype_path, function)
2945 tree basetype_path, function;
2947 tree access = compute_access (basetype_path, function);
2949 if (access == access_private_node)
2951 cp_error_at ("`%+#D' is %s", function,
2952 TREE_PRIVATE (function) ? "private"
2953 : "from private base class");
2954 error ("within this context");
2956 else if (access == access_protected_node)
2958 cp_error_at ("`%+#D' %s", function,
2959 TREE_PROTECTED (function) ? "is protected"
2960 : "has protected accessibility");
2961 error ("within this context");
2965 /* Perform the conversions in CONVS on the expression EXPR. */
2968 convert_like (convs, expr)
2971 if (ICS_BAD_FLAG (convs)
2972 && TREE_CODE (convs) != USER_CONV
2973 && TREE_CODE (convs) != AMBIG_CONV)
2976 for (; t; t = TREE_OPERAND (t, 0))
2978 if (TREE_CODE (t) == USER_CONV)
2980 expr = convert_like (t, expr);
2983 else if (TREE_CODE (t) == AMBIG_CONV)
2984 return convert_like (t, expr);
2985 else if (TREE_CODE (t) == IDENTITY_CONV)
2988 return convert_for_initialization
2989 (NULL_TREE, TREE_TYPE (convs), expr, LOOKUP_NORMAL,
2990 "conversion", NULL_TREE, 0);
2993 switch (TREE_CODE (convs))
2997 tree fn = TREE_OPERAND (convs, 1);
2999 enforce_access (TREE_OPERAND (convs, 3), fn);
3001 if (DECL_CONSTRUCTOR_P (fn))
3003 tree t = build_int_2 (0, 0);
3004 TREE_TYPE (t) = build_pointer_type (DECL_CONTEXT (fn));
3006 args = build_scratch_list (NULL_TREE, expr);
3007 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn)))
3008 args = scratch_tree_cons (NULL_TREE, integer_one_node, args);
3009 args = scratch_tree_cons (NULL_TREE, t, args);
3012 args = build_this (expr);
3013 expr = build_over_call
3014 (TREE_OPERAND (convs, 1), TREE_OPERAND (convs, 2),
3015 args, LOOKUP_NORMAL);
3017 /* If this is a constructor or a function returning an aggr type,
3018 we need to build up a TARGET_EXPR. */
3019 if (DECL_CONSTRUCTOR_P (fn))
3020 expr = build_cplus_new (TREE_TYPE (convs), expr);
3025 if (type_unknown_p (expr))
3026 expr = instantiate_type (TREE_TYPE (convs), expr, 1);
3027 if (TREE_READONLY_DECL_P (expr))
3028 expr = decl_constant_value (expr);
3031 /* Call build_user_type_conversion again for the error. */
3032 return build_user_type_conversion
3033 (TREE_TYPE (convs), TREE_OPERAND (convs, 0), LOOKUP_NORMAL);
3039 expr = convert_like (TREE_OPERAND (convs, 0), expr);
3040 if (expr == error_mark_node)
3041 return error_mark_node;
3043 switch (TREE_CODE (convs))
3046 if (! IS_AGGR_TYPE (TREE_TYPE (convs)))
3048 /* else fall through */
3050 return build_user_type_conversion
3051 (TREE_TYPE (convs), expr, LOOKUP_NORMAL);
3053 return convert_to_reference
3054 (TREE_TYPE (convs), expr,
3055 CONV_IMPLICIT, LOOKUP_NORMAL|LOOKUP_NO_CONVERSION,
3058 return decay_conversion (expr);
3063 return ocp_convert (TREE_TYPE (convs), expr, CONV_IMPLICIT,
3064 LOOKUP_NORMAL|LOOKUP_NO_CONVERSION);
3068 convert_default_arg (type, arg)
3071 arg = break_out_target_exprs (arg);
3073 if (TREE_CODE (arg) == CONSTRUCTOR)
3075 arg = digest_init (type, arg, 0);
3076 arg = convert_for_initialization (0, type, arg, LOOKUP_NORMAL,
3077 "default argument", 0, 0);
3081 /* This could get clobbered by the following call. */
3082 if (TREE_HAS_CONSTRUCTOR (arg))
3083 arg = copy_node (arg);
3085 arg = convert_for_initialization (0, type, arg, LOOKUP_NORMAL,
3086 "default argument", 0, 0);
3087 #ifdef PROMOTE_PROTOTYPES
3088 if ((TREE_CODE (type) == INTEGER_TYPE
3089 || TREE_CODE (type) == ENUMERAL_TYPE)
3090 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
3091 arg = default_conversion (arg);
3099 build_over_call (fn, convs, args, flags)
3100 tree fn, convs, args;
3103 tree converted_args = NULL_TREE;
3104 tree parm = TYPE_ARG_TYPES (TREE_TYPE (fn));
3105 tree conv, arg, val;
3109 if (args && TREE_CODE (args) != TREE_LIST)
3110 args = build_scratch_list (NULL_TREE, args);
3113 /* The implicit parameters to a constructor are not considered by overload
3114 resolution, and must be of the proper type. */
3115 if (DECL_CONSTRUCTOR_P (fn))
3117 converted_args = expr_tree_cons (NULL_TREE, TREE_VALUE (arg), converted_args);
3118 arg = TREE_CHAIN (arg);
3119 parm = TREE_CHAIN (parm);
3120 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn)))
3122 converted_args = expr_tree_cons
3123 (NULL_TREE, TREE_VALUE (arg), converted_args);
3124 arg = TREE_CHAIN (arg);
3125 parm = TREE_CHAIN (parm);
3128 /* Bypass access control for 'this' parameter. */
3129 else if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
3131 tree parmtype = TREE_VALUE (parm);
3132 tree argtype = TREE_TYPE (TREE_VALUE (arg));
3133 if (ICS_BAD_FLAG (TREE_VEC_ELT (convs, i)))
3135 int dv = (TYPE_VOLATILE (TREE_TYPE (parmtype))
3136 < TYPE_VOLATILE (TREE_TYPE (argtype)));
3137 int dc = (TYPE_READONLY (TREE_TYPE (parmtype))
3138 < TYPE_READONLY (TREE_TYPE (argtype)));
3139 char *p = (dv && dc ? "const and volatile"
3140 : dc ? "const" : dv ? "volatile" : "");
3142 cp_pedwarn ("passing `%T' as `this' argument of `%#D' discards %s",
3143 TREE_TYPE (argtype), fn, p);
3145 converted_args = expr_tree_cons
3146 (NULL_TREE, convert_force (TREE_VALUE (parm), TREE_VALUE (arg), CONV_C_CAST),
3148 parm = TREE_CHAIN (parm);
3149 arg = TREE_CHAIN (arg);
3155 parm = TREE_CHAIN (parm), arg = TREE_CHAIN (arg), ++i)
3157 tree type = TREE_VALUE (parm);
3159 conv = TREE_VEC_ELT (convs, i);
3160 if (ICS_BAD_FLAG (conv))
3163 val = TREE_VALUE (arg);
3165 for (; t; t = TREE_OPERAND (t, 0))
3167 if (TREE_CODE (t) == USER_CONV
3168 || TREE_CODE (t) == AMBIG_CONV)
3170 val = convert_like (t, val);
3173 else if (TREE_CODE (t) == IDENTITY_CONV)
3176 val = convert_for_initialization
3177 (NULL_TREE, type, val, LOOKUP_NORMAL,
3178 "argument passing", fn, i - is_method);
3181 val = convert_like (conv, TREE_VALUE (arg));
3183 #ifdef PROMOTE_PROTOTYPES
3184 if ((TREE_CODE (type) == INTEGER_TYPE
3185 || TREE_CODE (type) == ENUMERAL_TYPE)
3186 && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
3187 val = default_conversion (val);
3189 converted_args = expr_tree_cons (NULL_TREE, val, converted_args);
3192 /* Default arguments */
3193 for (; parm && parm != void_list_node; parm = TREE_CHAIN (parm))
3195 tree arg = TREE_PURPOSE (parm);
3197 if (DECL_TEMPLATE_INFO (fn))
3198 /* This came from a template. Instantiate the default arg here,
3200 arg = tsubst_expr (arg, DECL_TI_ARGS (fn), NULL_TREE);
3201 converted_args = expr_tree_cons
3202 (NULL_TREE, convert_default_arg (TREE_VALUE (parm), arg),
3207 for (; arg; arg = TREE_CHAIN (arg))
3209 val = TREE_VALUE (arg);
3211 if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
3212 && (TYPE_PRECISION (TREE_TYPE (val))
3213 < TYPE_PRECISION (double_type_node)))
3214 /* Convert `float' to `double'. */
3215 val = cp_convert (double_type_node, val);
3216 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val))
3217 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val)))
3218 cp_warning ("cannot pass objects of type `%T' through `...'",
3221 /* Convert `short' and `char' to full-size `int'. */
3222 val = default_conversion (val);
3224 converted_args = expr_tree_cons (NULL_TREE, val, converted_args);
3227 converted_args = nreverse (converted_args);
3229 /* Avoid actually calling copy constructors and copy assignment operators,
3231 if (DECL_CONSTRUCTOR_P (fn)
3232 && TREE_VEC_LENGTH (convs) == 1
3233 && copy_args_p (fn))
3236 arg = TREE_CHAIN (converted_args);
3237 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn)))
3238 arg = TREE_CHAIN (arg);
3239 arg = TREE_VALUE (arg);
3241 /* Pull out the real argument, disregarding const-correctness. */
3243 while (TREE_CODE (targ) == NOP_EXPR
3244 || TREE_CODE (targ) == NON_LVALUE_EXPR
3245 || TREE_CODE (targ) == CONVERT_EXPR)
3246 targ = TREE_OPERAND (targ, 0);
3247 if (TREE_CODE (targ) == ADDR_EXPR)
3249 targ = TREE_OPERAND (targ, 0);
3250 if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg))),
3251 TYPE_MAIN_VARIANT (TREE_TYPE (targ)), 1))
3260 arg = build_indirect_ref (arg, 0);
3262 /* [class.copy]: the copy constructor is implicitly defined even if
3263 the implementation elided its use. */
3264 if (TYPE_HAS_COMPLEX_INIT_REF (DECL_CONTEXT (fn)))
3267 /* If we're creating a temp and we already have one, don't create a
3268 new one. If we're not creating a temp but we get one, use
3269 INIT_EXPR to collapse the temp into our target. Otherwise, if the
3270 ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
3271 temp or an INIT_EXPR otherwise. */
3272 if (integer_zerop (TREE_VALUE (args)))
3274 if (! real_lvalue_p (arg))
3276 else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
3278 val = build (VAR_DECL, DECL_CONTEXT (fn));
3279 layout_decl (val, 0);
3280 val = build (TARGET_EXPR, DECL_CONTEXT (fn), val, arg, 0, 0);
3281 TREE_SIDE_EFFECTS (val) = 1;
3285 else if (! real_lvalue_p (arg)
3286 || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
3288 tree to = stabilize_reference
3289 (build_indirect_ref (TREE_VALUE (args), 0));
3290 val = build (INIT_EXPR, DECL_CONTEXT (fn), to, arg);
3291 TREE_SIDE_EFFECTS (val) = 1;
3292 return build_unary_op (ADDR_EXPR, val, 0);
3295 else if (DECL_NAME (fn) == ansi_opname[MODIFY_EXPR]
3297 && TYPE_HAS_TRIVIAL_ASSIGN_REF (DECL_CONTEXT (fn)))
3299 tree to = stabilize_reference
3300 (build_indirect_ref (TREE_VALUE (converted_args), 0));
3301 arg = build_indirect_ref (TREE_VALUE (TREE_CHAIN (converted_args)), 0);
3302 val = build (MODIFY_EXPR, TREE_TYPE (to), to, arg);
3303 TREE_SIDE_EFFECTS (val) = 1;
3309 if (DECL_CONTEXT (fn) && IS_SIGNATURE (DECL_CONTEXT (fn)))
3310 return build_signature_method_call (fn, converted_args);
3311 else if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
3313 tree t, *p = &TREE_VALUE (converted_args);
3314 tree binfo = get_binfo
3315 (DECL_CONTEXT (fn), TREE_TYPE (TREE_TYPE (*p)), 0);
3316 *p = convert_pointer_to_real (binfo, *p);
3317 if (TREE_SIDE_EFFECTS (*p))
3318 *p = save_expr (*p);
3319 t = build_pointer_type (TREE_TYPE (fn));
3320 fn = build_vfn_ref (p, build_indirect_ref (*p, 0), DECL_VINDEX (fn));
3323 else if (DECL_INLINE (fn))
3324 fn = inline_conversion (fn);
3326 fn = build_addr_func (fn);
3328 /* Recognize certain built-in functions so we can make tree-codes
3329 other than CALL_EXPR. We do this when it enables fold-const.c
3330 to do something useful. */
3332 if (TREE_CODE (fn) == ADDR_EXPR
3333 && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
3334 && DECL_BUILT_IN (TREE_OPERAND (fn, 0)))
3335 switch (DECL_FUNCTION_CODE (TREE_OPERAND (fn, 0)))
3340 if (converted_args == 0)
3341 return integer_zero_node;
3342 return build_unary_op (ABS_EXPR, TREE_VALUE (converted_args), 0);
3347 fn = build_call (fn, TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))), converted_args);
3348 if (TREE_TYPE (fn) == void_type_node)
3350 fn = require_complete_type (fn);
3351 if (IS_AGGR_TYPE (TREE_TYPE (fn)))
3352 fn = build_cplus_new (TREE_TYPE (fn), fn);
3353 return convert_from_reference (fn);
3357 build_new_method_call (instance, name, args, basetype_path, flags)
3358 tree instance, name, args, basetype_path;
3361 struct z_candidate *candidates = 0, *cand;
3362 tree explicit_targs = NULL_TREE;
3363 tree basetype, mem_args = NULL_TREE, fns, instance_ptr;
3365 tree user_args = args;
3366 tree templates = NULL_TREE;
3367 int template_only = 0;
3369 if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
3371 explicit_targs = TREE_OPERAND (name, 1);
3372 name = TREE_OPERAND (name, 0);
3373 if (TREE_CODE (name) == TEMPLATE_DECL)
3374 name = DECL_NAME (name);
3378 /* If there is an extra argument for controlling virtual bases,
3379 remove it for error reporting. */
3380 if (flags & LOOKUP_HAS_IN_CHARGE)
3381 user_args = TREE_CHAIN (args);
3383 args = resolve_args (args);
3385 if (args == error_mark_node)
3386 return error_mark_node;
3388 if (instance == NULL_TREE)
3389 basetype = BINFO_TYPE (basetype_path);
3392 if (TREE_CODE (instance) == OFFSET_REF)
3393 instance = resolve_offset_ref (instance);
3394 if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
3395 instance = convert_from_reference (instance);
3396 basetype = TREE_TYPE (instance);
3398 /* XXX this should be handled before we get here. */
3399 if (! IS_AGGR_TYPE (basetype)
3400 && ! (TYPE_LANG_SPECIFIC (basetype)
3401 && (IS_SIGNATURE_POINTER (basetype)
3402 || IS_SIGNATURE_REFERENCE (basetype))))
3404 if ((flags & LOOKUP_COMPLAIN) && basetype != error_mark_node)
3405 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
3406 name, instance, basetype);
3408 return error_mark_node;
3411 /* If `instance' is a signature pointer/reference and `name' is
3412 not a constructor, we are calling a signature member function.
3413 In that case set the `basetype' to the signature type. */
3414 if ((IS_SIGNATURE_POINTER (basetype)
3415 || IS_SIGNATURE_REFERENCE (basetype))
3416 && TYPE_IDENTIFIER (basetype) != name)
3417 basetype = SIGNATURE_TYPE (basetype);
3420 if (basetype_path == NULL_TREE)
3421 basetype_path = TYPE_BINFO (basetype);
3425 instance_ptr = build_this (instance);
3427 if (! template_only)
3429 /* XXX this should be handled before we get here. */
3430 fns = build_field_call (basetype_path, instance_ptr, name, args);
3437 instance_ptr = build_int_2 (0, 0);
3438 TREE_TYPE (instance_ptr) = build_pointer_type (basetype);
3442 = (name == ctor_identifier ? constructor_name (basetype) : name);
3444 fns = lookup_fnfields (basetype_path, name, 1);
3446 if (fns == error_mark_node)
3447 return error_mark_node;
3450 tree t = TREE_VALUE (fns);
3451 if (name == ctor_identifier && TYPE_USES_VIRTUAL_BASECLASSES (basetype)
3452 && ! (flags & LOOKUP_HAS_IN_CHARGE))
3454 flags |= LOOKUP_HAS_IN_CHARGE;
3455 args = scratch_tree_cons (NULL_TREE, integer_one_node, args);
3457 mem_args = scratch_tree_cons (NULL_TREE, instance_ptr, args);
3458 for (; t; t = DECL_CHAIN (t))
3462 /* We can end up here for copy-init of same or base class. */
3463 if (name == ctor_identifier
3464 && (flags & LOOKUP_ONLYCONVERTING)
3465 && DECL_NONCONVERTING_P (t))
3467 if (TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE)
3468 this_arglist = mem_args;
3470 this_arglist = args;
3472 if (TREE_CODE (t) == TEMPLATE_DECL)
3474 /* A member template. */
3475 templates = scratch_tree_cons (NULL_TREE, t, templates);
3477 add_template_candidate (candidates, t, explicit_targs,
3479 TREE_TYPE (name), flags);
3481 else if (! template_only)
3482 candidates = add_function_candidate (candidates, t,
3483 this_arglist, flags);
3486 candidates->basetype_path = TREE_PURPOSE (fns);
3490 if (! any_viable (candidates))
3492 /* XXX will LOOKUP_SPECULATIVELY be needed when this is done? */
3493 if (flags & LOOKUP_SPECULATIVELY)
3495 cp_error ("no matching function for call to `%T::%D (%A)%V'", basetype,
3496 pretty_name, user_args, TREE_TYPE (TREE_TYPE (instance_ptr)));
3497 print_z_candidates (candidates);
3498 return error_mark_node;
3500 candidates = splice_viable (candidates);
3501 cand = tourney (candidates);
3505 cp_error ("call of overloaded `%D(%A)' is ambiguous", pretty_name,
3507 print_z_candidates (candidates);
3508 return error_mark_node;
3511 enforce_access (cand->basetype_path, cand->fn);
3512 if (DECL_ABSTRACT_VIRTUAL_P (cand->fn)
3513 && instance == current_class_ref
3514 && DECL_CONSTRUCTOR_P (current_function_decl)
3515 && ! (flags & LOOKUP_NONVIRTUAL)
3516 && value_member (cand->fn, get_abstract_virtuals (basetype)))
3517 cp_error ("abstract virtual `%#D' called from constructor", cand->fn);
3518 if (TREE_CODE (TREE_TYPE (cand->fn)) == METHOD_TYPE
3519 && TREE_CODE (instance_ptr) == NOP_EXPR
3520 && TREE_OPERAND (instance_ptr, 0) == error_mark_node)
3521 cp_error ("cannot call member function `%D' without object", cand->fn);
3523 if (DECL_VINDEX (cand->fn) && ! (flags & LOOKUP_NONVIRTUAL)
3524 && ((instance == current_class_ref && (dtor_label || ctor_label))
3525 || resolves_to_fixed_type_p (instance, 0)))
3526 flags |= LOOKUP_NONVIRTUAL;
3528 /* Pedantically, normal function declarations are never considered
3529 to refer to template instantiations, so we only do this with
3531 if (flag_guiding_decls && templates && ! cand->template
3532 && ! DECL_INITIAL (cand->fn))
3533 add_maybe_template (cand->fn, templates);
3535 return build_over_call
3536 (cand->fn, cand->convs,
3537 TREE_CODE (TREE_TYPE (cand->fn)) == METHOD_TYPE ? mem_args : args,
3541 /* Compare two implicit conversion sequences that differ only in their
3542 qualification conversion. Subroutine of compare_ics. */
3545 compare_qual (ics1, ics2)
3548 tree to1 = TREE_TYPE (ics1);
3549 tree to2 = TREE_TYPE (ics2);
3551 if (TYPE_PTRMEMFUNC_P (to1))
3552 to1 = TYPE_PTRMEMFUNC_FN_TYPE (to1);
3553 if (TYPE_PTRMEMFUNC_P (to2))
3554 to2 = TYPE_PTRMEMFUNC_FN_TYPE (to2);
3556 to1 = TREE_TYPE (to1);
3557 to2 = TREE_TYPE (to2);
3559 if (TREE_CODE (to1) == OFFSET_TYPE)
3561 to1 = TREE_TYPE (to1);
3562 to2 = TREE_TYPE (to2);
3565 if (TYPE_READONLY (to1) >= TYPE_READONLY (to2)
3566 && TYPE_VOLATILE (to1) > TYPE_VOLATILE (to2))
3568 else if (TYPE_READONLY (to1) > TYPE_READONLY (to2)
3569 && TYPE_VOLATILE (to1) == TYPE_VOLATILE (to2))
3571 else if (TYPE_READONLY (to1) <= TYPE_READONLY (to2)
3572 && TYPE_VOLATILE (to1) < TYPE_VOLATILE (to2))
3574 else if (TYPE_READONLY (to1) < TYPE_READONLY (to2)
3575 && TYPE_VOLATILE (to1) == TYPE_VOLATILE (to2))
3580 /* Determine whether standard conversion sequence ICS1 is a proper
3581 subsequence of ICS2. We assume that a conversion of the same code
3582 between the same types indicates a subsequence. */
3585 is_subseq (ics1, ics2)
3588 /* Do not consider lvalue transformations here. */
3589 if (TREE_CODE (ics2) == RVALUE_CONV
3590 || TREE_CODE (ics2) == LVALUE_CONV)
3593 for (;; ics2 = TREE_OPERAND (ics2, 0))
3595 if (TREE_CODE (ics2) == TREE_CODE (ics1)
3596 && comptypes (TREE_TYPE (ics2), TREE_TYPE (ics1), 1)
3597 && comptypes (TREE_TYPE (TREE_OPERAND (ics2, 0)),
3598 TREE_TYPE (TREE_OPERAND (ics1, 0)), 1))
3601 if (TREE_CODE (ics2) == USER_CONV
3602 || TREE_CODE (ics2) == AMBIG_CONV
3603 || TREE_CODE (ics2) == IDENTITY_CONV)
3608 /* Compare two implicit conversion sequences according to the rules set out in
3609 [over.ics.rank]. Return values:
3611 1: ics1 is better than ics2
3612 -1: ics2 is better than ics1
3613 0: ics1 and ics2 are indistinguishable */
3616 compare_ics (ics1, ics2)
3621 if (TREE_CODE (ics1) == QUAL_CONV)
3622 main1 = TREE_OPERAND (ics1, 0);
3626 if (TREE_CODE (ics2) == QUAL_CONV)
3627 main2 = TREE_OPERAND (ics2, 0);
3631 /* Conversions for `this' are PTR_CONVs, but we compare them as though
3632 they were REF_BINDs. */
3633 if (ICS_THIS_FLAG (ics1))
3636 if (TREE_CODE (t) == PTR_CONV)
3637 t = TREE_OPERAND (t, 0);
3638 t = build1 (IDENTITY_CONV, TREE_TYPE (TREE_TYPE (t)), NULL_TREE);
3639 t = build_conv (REF_BIND, TREE_TYPE (ics1), t);
3640 ICS_STD_RANK (t) = ICS_STD_RANK (main1);
3643 if (ICS_THIS_FLAG (ics2))
3646 if (TREE_CODE (t) == PTR_CONV)
3647 t = TREE_OPERAND (t, 0);
3648 t = build1 (IDENTITY_CONV, TREE_TYPE (TREE_TYPE (t)), NULL_TREE);
3649 t = build_conv (REF_BIND, TREE_TYPE (ics2), t);
3650 ICS_STD_RANK (t) = ICS_STD_RANK (main2);
3654 if (ICS_RANK (ics1) > ICS_RANK (ics2))
3656 else if (ICS_RANK (ics1) < ICS_RANK (ics2))
3659 if (ICS_RANK (ics1) == BAD_RANK)
3661 if (ICS_USER_FLAG (ics1) > ICS_USER_FLAG (ics2)
3662 || ICS_STD_RANK (ics1) > ICS_STD_RANK (ics2))
3664 else if (ICS_USER_FLAG (ics1) < ICS_USER_FLAG (ics2)
3665 || ICS_STD_RANK (ics1) < ICS_STD_RANK (ics2))
3668 /* else fall through */
3671 /* User-defined conversion sequence U1 is a better conversion sequence
3672 than another user-defined conversion sequence U2 if they contain the
3673 same user-defined conversion operator or constructor and if the sec-
3674 ond standard conversion sequence of U1 is better than the second
3675 standard conversion sequence of U2. */
3677 if (ICS_USER_FLAG (ics1))
3681 for (t1 = ics1; TREE_CODE (t1) != USER_CONV; t1 = TREE_OPERAND (t1, 0))
3682 if (TREE_CODE (t1) == AMBIG_CONV)
3684 for (t2 = ics2; TREE_CODE (t2) != USER_CONV; t2 = TREE_OPERAND (t2, 0))
3685 if (TREE_CODE (t2) == AMBIG_CONV)
3688 if (USER_CONV_FN (t1) != USER_CONV_FN (t2))
3690 else if (ICS_STD_RANK (ics1) > ICS_STD_RANK (ics2))
3692 else if (ICS_STD_RANK (ics1) < ICS_STD_RANK (ics2))
3695 /* else fall through */
3698 #if 0 /* Handled by ranking */
3699 /* A conversion that is not a conversion of a pointer, or pointer to
3700 member, to bool is better than another conversion that is such a
3704 if (TREE_CODE (main1) != TREE_CODE (main2))
3706 /* ...if S1 is a proper subsequence of S2 */
3707 if (is_subseq (main1, main2))
3709 if (is_subseq (main2, main1))
3714 if (TREE_CODE (main1) == PTR_CONV || TREE_CODE (main1) == PMEM_CONV
3715 || TREE_CODE (main1) == REF_BIND || TREE_CODE (main1) == BASE_CONV)
3717 tree to1 = TREE_TYPE (main1);
3718 tree from1 = TREE_TYPE (TREE_OPERAND (main1, 0));
3719 tree to2 = TREE_TYPE (main2);
3720 tree from2 = TREE_TYPE (TREE_OPERAND (main2, 0));
3723 /* Standard conversion sequence S1 is a better conversion sequence than
3724 standard conversion sequence S2 if...
3726 S1 and S2 differ only in their qualification conversion and they
3727 yield types identical except for cv-qualifiers and S2 adds all the
3728 qualifiers that S1 adds (and in the same places) and S2 adds yet
3729 more cv-qualifiers than S1, or the similar case with reference
3731 if (TREE_CODE (main1) == REF_BIND)
3733 if (TYPE_MAIN_VARIANT (TREE_TYPE (to1))
3734 == TYPE_MAIN_VARIANT (TREE_TYPE (to2)))
3735 return compare_qual (ics1, ics2);
3737 else if (TREE_CODE (main1) != BASE_CONV && from1 == from2 && to1 == to2)
3738 return compare_qual (ics1, ics2);
3740 if (TYPE_PTRMEMFUNC_P (to1))
3742 to1 = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to1)));
3743 from1 = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from1)));
3745 else if (TREE_CODE (main1) != BASE_CONV)
3747 to1 = TREE_TYPE (to1);
3748 if (TREE_CODE (main1) != REF_BIND)
3749 from1 = TREE_TYPE (from1);
3751 if (TREE_CODE (to1) == OFFSET_TYPE)
3753 to1 = TYPE_OFFSET_BASETYPE (to1);
3754 from1 = TYPE_OFFSET_BASETYPE (from1);
3758 if (TYPE_PTRMEMFUNC_P (to2))
3760 to2 = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to2)));
3761 from2 = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from2)));
3763 else if (TREE_CODE (main1) != BASE_CONV)
3765 to2 = TREE_TYPE (to2);
3766 if (TREE_CODE (main1) != REF_BIND)
3767 from2 = TREE_TYPE (from2);
3769 if (TREE_CODE (to2) == OFFSET_TYPE)
3771 to2 = TYPE_OFFSET_BASETYPE (to2);
3772 from2 = TYPE_OFFSET_BASETYPE (from2);
3776 if (! (IS_AGGR_TYPE (from1) && IS_AGGR_TYPE (from2)))
3779 /* The sense of pmem conversions is reversed from that of the other
3781 if (TREE_CODE (main1) == PMEM_CONV)
3783 tree t = from1; from1 = from2; from2 = t;
3784 t = to1; to1 = to2; to2 = t;
3787 distf = get_base_distance (from1, from2, 0, 0);
3790 distf = -get_base_distance (from2, from1, 0, 0);
3795 /* If class B is derived directly or indirectly from class A,
3796 conver- sion of B* to A* is better than conversion of B* to
3797 void*, and conversion of A* to void* is better than
3798 conversion of B* to void*. */
3800 if (TREE_CODE (to1) == VOID_TYPE && TREE_CODE (to2) == VOID_TYPE)
3807 else if (TREE_CODE (to2) == VOID_TYPE && IS_AGGR_TYPE (to1)
3808 && get_base_distance (to1, from1, 0, 0) != -1)
3810 else if (TREE_CODE (to1) == VOID_TYPE && IS_AGGR_TYPE (to2)
3811 && get_base_distance (to2, from2, 0, 0) != -1)
3814 if (! (IS_AGGR_TYPE (to1) && IS_AGGR_TYPE (to2)))
3817 /* If class B is derived directly or indirectly from class A and class
3818 C is derived directly or indirectly from B */
3820 distt = get_base_distance (to1, to2, 0, 0);
3823 distt = -get_base_distance (to2, to1, 0, 0);
3828 /* --conversion of C* to B* is better than conversion of C* to A*, */
3836 /* --conversion of B* to A* is better than conversion of C* to A*, */
3837 else if (distt == 0)
3845 else if (TREE_CODE (TREE_TYPE (main1)) == POINTER_TYPE
3846 || TYPE_PTRMEMFUNC_P (TREE_TYPE (main1)))
3848 if (TREE_TYPE (main1) == TREE_TYPE (main2))
3849 return compare_qual (ics1, ics2);
3851 #if 0 /* This is now handled by making identity better than anything else. */
3852 /* existing practice, not WP-endorsed: const char * -> const char *
3853 is better than char * -> const char *. (jason 6/29/96) */
3854 if (TREE_TYPE (ics1) == TREE_TYPE (ics2))
3855 return -compare_qual (main1, main2);
3862 /* The source type for this standard conversion sequence. */
3868 for (;; t = TREE_OPERAND (t, 0))
3870 if (TREE_CODE (t) == USER_CONV
3871 || TREE_CODE (t) == AMBIG_CONV
3872 || TREE_CODE (t) == IDENTITY_CONV)
3873 return TREE_TYPE (t);
3875 my_friendly_abort (1823);
3878 /* Compare two candidates for overloading as described in
3879 [over.match.best]. Return values:
3881 1: cand1 is better than cand2
3882 -1: cand2 is better than cand1
3883 0: cand1 and cand2 are indistinguishable */
3886 joust (cand1, cand2)
3887 struct z_candidate *cand1, *cand2;
3890 int i, off1 = 0, off2 = 0, len;
3892 /* Candidates that involve bad conversions are always worse than those
3894 if (cand1->viable > cand2->viable)
3896 if (cand1->viable < cand2->viable)
3899 /* a viable function F1
3900 is defined to be a better function than another viable function F2 if
3901 for all arguments i, ICSi(F1) is not a worse conversion sequence than
3902 ICSi(F2), and then */
3904 /* for some argument j, ICSj(F1) is a better conversion sequence than
3907 /* For comparing static and non-static member functions, we ignore the
3908 implicit object parameter of the non-static function. The WP says to
3909 pretend that the static function has an object parm, but that won't
3910 work with operator overloading. */
3911 len = TREE_VEC_LENGTH (cand1->convs);
3912 if (len != TREE_VEC_LENGTH (cand2->convs))
3914 if (DECL_STATIC_FUNCTION_P (cand1->fn)
3915 && ! DECL_STATIC_FUNCTION_P (cand2->fn))
3917 else if (! DECL_STATIC_FUNCTION_P (cand1->fn)
3918 && DECL_STATIC_FUNCTION_P (cand2->fn))
3924 my_friendly_abort (42);
3927 for (i = 0; i < len; ++i)
3929 tree t1 = TREE_VEC_ELT (cand1->convs, i+off1);
3930 tree t2 = TREE_VEC_ELT (cand2->convs, i+off2);
3931 int comp = compare_ics (t1, t2);
3935 #if 0 /* move this warning to tourney. */
3937 && ICS_RANK (t1) + ICS_RANK (t2) == STD_RANK + PROMO_RANK
3938 && TREE_CODE (t1) == STD_CONV
3939 && TREE_CODE (t2) == STD_CONV
3940 && TREE_CODE (TREE_TYPE (t1)) == INTEGER_TYPE
3941 && TREE_CODE (TREE_TYPE (t2)) == INTEGER_TYPE
3942 && (TYPE_PRECISION (TREE_TYPE (t1))
3943 == TYPE_PRECISION (TREE_TYPE (t2)))
3944 && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (t1, 0)))
3945 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (t1, 0)))
3948 tree type = TREE_TYPE (TREE_OPERAND (t1, 0));
3951 type1 = TREE_TYPE (t1), type2 = TREE_TYPE (t2);
3953 type1 = TREE_TYPE (t2), type2 = TREE_TYPE (t1);
3955 cp_warning ("passing `%T' chooses `%T' over `%T'",
3956 type, type1, type2);
3957 cp_warning (" in call to `%D'", DECL_NAME (cand1->fn));
3961 if (winner && comp != winner)
3970 #if 0 /* move this warning to tourney. */
3971 /* warn about confusing overload resolution */
3972 if (winner && cand1->second_conv
3973 && ! DECL_CONSTRUCTOR_P (cand1->fn)
3974 && ! DECL_CONSTRUCTOR_P (cand2->fn))
3976 int comp = compare_ics (cand1->second_conv, cand2->second_conv);
3977 if (comp && comp != winner)
3979 struct z_candidate *w, *l;
3981 w = cand1, l = cand2;
3983 w = cand2, l = cand1;
3984 cp_warning ("choosing `%D' over `%D'", w->fn, l->fn);
3985 cp_warning (" for conversion from `%T' to `%T'",
3986 TREE_TYPE (source_type (TREE_VEC_ELT (w->convs, 0))),
3987 TREE_TYPE (w->second_conv));
3988 cp_warning (" because conversion sequence for `this' argument is better");
3997 F1 is a non-template function and F2 is a template function */
3999 if (! cand1->template && cand2->template)
4001 else if (cand1->template && ! cand2->template)
4003 else if (cand1->template && cand2->template)
4004 winner = more_specialized
4005 (TI_TEMPLATE (cand1->template), TI_TEMPLATE (cand2->template),
4009 the context is an initialization by user-defined conversion (see
4010 _dcl.init_ and _over.match.user_) and the standard conversion
4011 sequence from the return type of F1 to the destination type (i.e.,
4012 the type of the entity being initialized) is a better conversion
4013 sequence than the standard conversion sequence from the return type
4014 of F2 to the destination type. */
4016 if (! winner && cand1->second_conv)
4017 winner = compare_ics (cand1->second_conv, cand2->second_conv);
4019 /* If the built-in candidates are the same, arbitrarily pick one. */
4020 if (! winner && cand1->fn == cand2->fn
4021 && TREE_CODE (cand1->fn) == IDENTIFIER_NODE)
4023 for (i = 0; i < len; ++i)
4024 if (! comptypes (TREE_TYPE (TREE_VEC_ELT (cand1->convs, i)),
4025 TREE_TYPE (TREE_VEC_ELT (cand2->convs, i)), 1))
4027 if (i == TREE_VEC_LENGTH (cand1->convs))
4030 /* Kludge around broken overloading rules whereby
4031 Integer a, b; test ? a : b; is ambiguous, since there's a builtin
4032 that takes references and another that takes values. */
4033 if (cand1->fn == ansi_opname[COND_EXPR])
4035 tree c1 = TREE_VEC_ELT (cand1->convs, 1);
4036 tree c2 = TREE_VEC_ELT (cand2->convs, 1);
4037 tree t1 = strip_top_quals (non_reference (TREE_TYPE (c1)));
4038 tree t2 = strip_top_quals (non_reference (TREE_TYPE (c2)));
4040 if (comptypes (t1, t2, 1))
4042 if (TREE_CODE (c1) == REF_BIND && TREE_CODE (c2) != REF_BIND)
4044 if (TREE_CODE (c1) != REF_BIND && TREE_CODE (c2) == REF_BIND)
4052 /* Extension: If the worst conversion for one candidate is worse than the
4053 worst conversion for the other, take the first. */
4054 if (! winner && ! pedantic)
4056 int rank1 = IDENTITY_RANK, rank2 = IDENTITY_RANK;
4058 for (i = 0; i < len; ++i)
4060 if (ICS_RANK (TREE_VEC_ELT (cand1->convs, i+off1)) > rank1)
4061 rank1 = ICS_RANK (TREE_VEC_ELT (cand1->convs, i+off1));
4062 if (ICS_RANK (TREE_VEC_ELT (cand2->convs, i+off2)) > rank2)
4063 rank2 = ICS_RANK (TREE_VEC_ELT (cand2->convs, i+off2));
4075 /* Given a list of candidates for overloading, find the best one, if any.
4076 This algorithm has a worst case of O(2n) (winner is last), and a best
4077 case of O(n/2) (totally ambiguous); much better than a sorting
4080 static struct z_candidate *
4081 tourney (candidates)
4082 struct z_candidate *candidates;
4084 struct z_candidate *champ = candidates, *challenger;
4087 /* Walk through the list once, comparing each current champ to the next
4088 candidate, knocking out a candidate or two with each comparison. */
4090 for (challenger = champ->next; challenger; )
4092 fate = joust (champ, challenger);
4094 challenger = challenger->next;
4099 champ = challenger->next;
4106 challenger = champ->next;
4110 /* Make sure the champ is better than all the candidates it hasn't yet
4111 been compared to. This may do one more comparison than necessary. Oh
4114 for (challenger = candidates; challenger != champ;
4115 challenger = challenger->next)
4117 fate = joust (champ, challenger);
4126 can_convert (to, from)
4129 tree t = implicit_conversion (to, from, NULL_TREE, LOOKUP_NORMAL);
4130 return (t && ! ICS_BAD_FLAG (t));
4134 can_convert_arg (to, from, arg)
4137 tree t = implicit_conversion (to, from, arg, LOOKUP_NORMAL);
4138 return (t && ! ICS_BAD_FLAG (t));