1 /* Functions related to invoking methods and overloaded functions.
2 Copyright (C) 1987, 92-97, 1998 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com) and
4 modified by Brendan Kehoe (brendan@cygnus.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 /* High-level class interface. */
35 #define obstack_chunk_alloc xmalloc
36 #define obstack_chunk_free free
38 extern int inhibit_warnings
;
39 extern tree ctor_label
, dtor_label
;
41 static tree build_new_method_call
PROTO((tree
, tree
, tree
, tree
, int));
43 static tree build_field_call
PROTO((tree
, tree
, tree
, tree
));
44 static tree find_scoped_type
PROTO((tree
, tree
, tree
));
45 static struct z_candidate
* tourney
PROTO((struct z_candidate
*));
46 static int joust
PROTO((struct z_candidate
*, struct z_candidate
*, int));
47 static int compare_qual
PROTO((tree
, tree
));
48 static int compare_ics
PROTO((tree
, tree
));
49 static tree build_over_call
PROTO((struct z_candidate
*, tree
, int));
50 static tree convert_default_arg
PROTO((tree
, tree
));
51 static tree convert_like
PROTO((tree
, tree
));
52 static void op_error
PROTO((enum tree_code
, enum tree_code
, tree
, tree
,
54 static tree build_object_call
PROTO((tree
, tree
));
55 static tree resolve_args
PROTO((tree
));
56 static struct z_candidate
* build_user_type_conversion_1
57 PROTO ((tree
, tree
, int));
58 static void print_z_candidates
PROTO((struct z_candidate
*));
59 static tree build_this
PROTO((tree
));
60 static struct z_candidate
* splice_viable
PROTO((struct z_candidate
*));
61 static int any_viable
PROTO((struct z_candidate
*));
62 static struct z_candidate
* add_template_candidate
63 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
, int));
64 static struct z_candidate
* add_template_candidate_real
65 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
, int, tree
));
66 static struct z_candidate
* add_template_conv_candidate
67 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
));
68 static struct z_candidate
* add_builtin_candidates
69 PROTO((struct z_candidate
*, enum tree_code
, enum tree_code
,
71 static struct z_candidate
* add_builtin_candidate
72 PROTO((struct z_candidate
*, enum tree_code
, enum tree_code
,
73 tree
, tree
, tree
, tree
*, tree
*, int));
74 static int is_complete
PROTO((tree
));
75 static struct z_candidate
* build_builtin_candidate
76 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
*, tree
*,
78 static struct z_candidate
* add_conv_candidate
79 PROTO((struct z_candidate
*, tree
, tree
, tree
));
80 static struct z_candidate
* add_function_candidate
81 PROTO((struct z_candidate
*, tree
, tree
, int));
82 static tree implicit_conversion
PROTO((tree
, tree
, tree
, int));
83 static tree standard_conversion
PROTO((tree
, tree
, tree
));
84 static tree reference_binding
PROTO((tree
, tree
, tree
, int));
85 static tree strip_top_quals
PROTO((tree
));
86 static tree non_reference
PROTO((tree
));
87 static tree build_conv
PROTO((enum tree_code
, tree
, tree
));
88 static int is_subseq
PROTO((tree
, tree
));
91 build_vfield_ref (datum
, type
)
95 int old_assume_nonnull_objects
= flag_assume_nonnull_objects
;
97 if (datum
== error_mark_node
)
98 return error_mark_node
;
100 /* Vtable references are always made from non-null objects. */
101 flag_assume_nonnull_objects
= 1;
102 if (TREE_CODE (TREE_TYPE (datum
)) == REFERENCE_TYPE
)
103 datum
= convert_from_reference (datum
);
105 if (! TYPE_USES_COMPLEX_INHERITANCE (type
))
106 rval
= build (COMPONENT_REF
, TREE_TYPE (CLASSTYPE_VFIELD (type
)),
107 datum
, CLASSTYPE_VFIELD (type
));
109 rval
= build_component_ref (datum
, DECL_NAME (CLASSTYPE_VFIELD (type
)), NULL_TREE
, 0);
110 flag_assume_nonnull_objects
= old_assume_nonnull_objects
;
115 /* Build a call to a member of an object. I.e., one that overloads
116 operator ()(), or is a pointer-to-function or pointer-to-method. */
119 build_field_call (basetype_path
, instance_ptr
, name
, parms
)
120 tree basetype_path
, instance_ptr
, name
, parms
;
122 tree field
, instance
;
124 if (name
== ctor_identifier
|| name
== dtor_identifier
)
127 if (instance_ptr
== current_class_ptr
)
129 /* Check to see if we really have a reference to an instance variable
130 with `operator()()' overloaded. */
131 field
= IDENTIFIER_CLASS_VALUE (name
);
133 if (field
== NULL_TREE
)
135 cp_error ("`this' has no member named `%D'", name
);
136 return error_mark_node
;
139 if (TREE_CODE (field
) == FIELD_DECL
)
141 /* If it's a field, try overloading operator (),
142 or calling if the field is a pointer-to-function. */
143 instance
= build_component_ref_1 (current_class_ref
, field
, 0);
144 if (instance
== error_mark_node
)
145 return error_mark_node
;
147 if (TYPE_LANG_SPECIFIC (TREE_TYPE (instance
)))
148 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, instance
, parms
, NULL_TREE
);
150 if (TREE_CODE (TREE_TYPE (instance
)) == POINTER_TYPE
)
152 if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == FUNCTION_TYPE
)
153 return build_function_call (instance
, parms
);
154 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == METHOD_TYPE
)
155 return build_function_call (instance
, expr_tree_cons (NULL_TREE
, current_class_ptr
, parms
));
161 /* Check to see if this is not really a reference to an instance variable
162 with `operator()()' overloaded. */
163 field
= lookup_field (basetype_path
, name
, 1, 0);
165 /* This can happen if the reference was ambiguous or for access
167 if (field
== error_mark_node
)
168 return error_mark_node
;
170 if (field
&& TREE_CODE (field
) == FIELD_DECL
)
173 tree ftype
= TREE_TYPE (field
);
175 if (TREE_CODE (ftype
) == REFERENCE_TYPE
)
176 ftype
= TREE_TYPE (ftype
);
178 if (TYPE_LANG_SPECIFIC (ftype
))
180 /* Make the next search for this field very short. */
181 basetype
= DECL_FIELD_CONTEXT (field
);
182 instance_ptr
= convert_pointer_to (basetype
, instance_ptr
);
184 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
185 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
,
186 build_component_ref_1 (instance
, field
, 0),
189 if (TREE_CODE (ftype
) == POINTER_TYPE
)
191 if (TREE_CODE (TREE_TYPE (ftype
)) == FUNCTION_TYPE
192 || TREE_CODE (TREE_TYPE (ftype
)) == METHOD_TYPE
)
194 /* This is a member which is a pointer to function. */
196 = build_component_ref_1 (build_indirect_ref (instance_ptr
,
198 field
, LOOKUP_COMPLAIN
);
199 if (ref
== error_mark_node
)
200 return error_mark_node
;
201 return build_function_call (ref
, parms
);
204 else if (TREE_CODE (ftype
) == METHOD_TYPE
)
206 error ("invalid call via pointer-to-member function");
207 return error_mark_node
;
216 find_scoped_type (type
, inner_name
, inner_types
)
217 tree type
, inner_name
, inner_types
;
219 tree tags
= CLASSTYPE_TAGS (type
);
223 /* The TREE_PURPOSE of an enum tag (which becomes a member of the
224 enclosing class) is set to the name for the enum type. So, if
225 inner_name is `bar', and we strike `baz' for `enum bar { baz }',
226 then this test will be true. */
227 if (TREE_PURPOSE (tags
) == inner_name
)
229 if (inner_types
== NULL_TREE
)
230 return TYPE_MAIN_DECL (TREE_VALUE (tags
));
231 return resolve_scope_to_name (TREE_VALUE (tags
), inner_types
);
233 tags
= TREE_CHAIN (tags
);
236 /* Look for a TYPE_DECL. */
237 for (tags
= TYPE_FIELDS (type
); tags
; tags
= TREE_CHAIN (tags
))
238 if (TREE_CODE (tags
) == TYPE_DECL
&& DECL_NAME (tags
) == inner_name
)
240 /* Code by raeburn. */
241 if (inner_types
== NULL_TREE
)
243 return resolve_scope_to_name (TREE_TYPE (tags
), inner_types
);
249 /* Resolve an expression NAME1::NAME2::...::NAMEn to
250 the name that names the above nested type. INNER_TYPES
251 is a chain of nested type names (held together by SCOPE_REFs);
252 OUTER_TYPE is the type we know to enclose INNER_TYPES.
253 Returns NULL_TREE if there is an error. */
256 resolve_scope_to_name (outer_type
, inner_stuff
)
257 tree outer_type
, inner_stuff
;
260 tree inner_name
, inner_type
;
262 if (outer_type
== NULL_TREE
&& current_class_type
!= NULL_TREE
)
264 /* We first try to look for a nesting in our current class context,
265 then try any enclosing classes. */
266 tree type
= current_class_type
;
268 while (type
&& (TREE_CODE (type
) == RECORD_TYPE
269 || TREE_CODE (type
) == UNION_TYPE
))
271 tree rval
= resolve_scope_to_name (type
, inner_stuff
);
273 if (rval
!= NULL_TREE
)
275 type
= DECL_CONTEXT (TYPE_MAIN_DECL (type
));
279 if (TREE_CODE (inner_stuff
) == SCOPE_REF
)
281 inner_name
= TREE_OPERAND (inner_stuff
, 0);
282 inner_type
= TREE_OPERAND (inner_stuff
, 1);
286 inner_name
= inner_stuff
;
287 inner_type
= NULL_TREE
;
290 if (outer_type
== NULL_TREE
)
293 /* If we have something that's already a type by itself,
295 if (IDENTIFIER_HAS_TYPE_VALUE (inner_name
))
298 return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name
),
303 x
= lookup_name (inner_name
, 0);
305 if (x
&& TREE_CODE (x
) == NAMESPACE_DECL
)
307 x
= lookup_namespace_name (x
, inner_type
);
313 if (! IS_AGGR_TYPE (outer_type
))
316 /* Look for member classes or enums. */
317 tmp
= find_scoped_type (outer_type
, inner_name
, inner_type
);
319 /* If it's not a type in this class, then go down into the
320 base classes and search there. */
321 if (! tmp
&& TYPE_BINFO (outer_type
))
323 tree binfos
= TYPE_BINFO_BASETYPES (outer_type
);
324 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
326 for (i
= 0; i
< n_baselinks
; i
++)
328 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
329 tmp
= resolve_scope_to_name (BINFO_TYPE (base_binfo
), inner_stuff
);
339 /* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'.
340 This is how virtual function calls are avoided. */
343 build_scoped_method_call (exp
, basetype
, name
, parms
)
344 tree exp
, basetype
, name
, parms
;
346 /* Because this syntactic form does not allow
347 a pointer to a base class to be `stolen',
348 we need not protect the derived->base conversion
351 @@ But we do have to check access privileges later. */
353 tree type
= TREE_TYPE (exp
);
355 if (type
== error_mark_node
356 || basetype
== error_mark_node
)
357 return error_mark_node
;
359 if (processing_template_decl
)
361 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
363 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 0);
365 name
= build_min_nt (BIT_NOT_EXPR
, type
);
367 name
= build_min_nt (SCOPE_REF
, basetype
, name
);
368 return build_min_nt (METHOD_CALL_EXPR
, name
, exp
, parms
, NULL_TREE
);
371 if (TREE_CODE (type
) == REFERENCE_TYPE
)
372 type
= TREE_TYPE (type
);
374 if (TREE_CODE (basetype
) == TREE_VEC
)
377 basetype
= BINFO_TYPE (binfo
);
382 /* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
383 that explicit ~int is caught in the parser; this deals with typedefs
384 and template parms. */
385 if (TREE_CODE (name
) == BIT_NOT_EXPR
&& ! IS_AGGR_TYPE (basetype
))
387 if (TYPE_MAIN_VARIANT (type
) != TYPE_MAIN_VARIANT (basetype
))
388 cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
389 exp
, basetype
, type
);
390 name
= TREE_OPERAND (name
, 0);
391 if (TYPE_MAIN_VARIANT (basetype
) != name
392 && basetype
!= get_type_value (name
))
393 cp_error ("qualified type `%T' does not match destructor name `~%T'",
395 return cp_convert (void_type_node
, exp
);
398 if (! is_aggr_type (basetype
, 1))
399 return error_mark_node
;
401 if (! IS_AGGR_TYPE (type
))
403 cp_error ("base object `%E' of scoped method call is of non-aggregate type `%T'",
405 return error_mark_node
;
410 binfo
= get_binfo (basetype
, type
, 1);
411 if (binfo
== error_mark_node
)
412 return error_mark_node
;
414 error_not_base_type (basetype
, type
);
419 if (TREE_CODE (exp
) == INDIRECT_REF
)
420 decl
= build_indirect_ref
421 (convert_pointer_to_real
422 (binfo
, build_unary_op (ADDR_EXPR
, exp
, 0)), NULL_PTR
);
424 decl
= build_scoped_ref (exp
, basetype
);
426 /* Call to a destructor. */
427 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
429 /* Explicit call to destructor. */
430 name
= TREE_OPERAND (name
, 0);
431 if (! (name
== TYPE_MAIN_VARIANT (TREE_TYPE (decl
))
432 || name
== constructor_name (TREE_TYPE (decl
))
433 || TREE_TYPE (decl
) == get_type_value (name
)))
436 ("qualified type `%T' does not match destructor name `~%T'",
437 TREE_TYPE (decl
), name
);
438 return error_mark_node
;
440 if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl
)))
441 return cp_convert (void_type_node
, exp
);
443 return build_delete (TREE_TYPE (decl
), decl
, integer_two_node
,
444 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
,
448 /* Call to a method. */
449 return build_method_call (decl
, name
, parms
, binfo
,
450 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
);
452 return error_mark_node
;
455 /* We want the address of a function or method. We avoid creating a
456 pointer-to-member function. */
459 build_addr_func (function
)
462 tree type
= TREE_TYPE (function
);
464 /* We have to do these by hand to avoid real pointer to member
466 if (TREE_CODE (type
) == METHOD_TYPE
)
470 type
= build_pointer_type (type
);
472 if (mark_addressable (function
) == 0)
473 return error_mark_node
;
475 addr
= build1 (ADDR_EXPR
, type
, function
);
477 /* Address of a static or external variable or function counts
479 if (staticp (function
))
480 TREE_CONSTANT (addr
) = 1;
485 function
= default_conversion (function
);
490 /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
491 POINTER_TYPE to those. Note, pointer to member function types
492 (TYPE_PTRMEMFUNC_P) must be handled by our callers. */
495 build_call (function
, result_type
, parms
)
496 tree function
, result_type
, parms
;
498 int is_constructor
= 0;
502 function
= build_addr_func (function
);
504 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
506 sorry ("unable to call pointer to member function here");
507 return error_mark_node
;
510 if (TREE_CODE (function
) == ADDR_EXPR
511 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
)
512 decl
= TREE_OPERAND (function
, 0);
516 if (decl
&& DECL_CONSTRUCTOR_P (decl
))
519 /* Don't pass empty class objects by value. This is useful
520 for tags in STL, which are used to control overload resolution.
521 We don't need to handle other cases of copying empty classes. */
522 if (! decl
|| ! DECL_BUILT_IN (decl
))
523 for (tmp
= parms
; tmp
; tmp
= TREE_CHAIN (tmp
))
524 if (is_empty_class (TREE_TYPE (TREE_VALUE (tmp
)))
525 && ! TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (tmp
))))
527 tree t
= make_node (RTL_EXPR
);
528 TREE_TYPE (t
) = TREE_TYPE (TREE_VALUE (tmp
));
529 RTL_EXPR_RTL (t
) = const0_rtx
;
530 RTL_EXPR_SEQUENCE (t
) = NULL_RTX
;
531 TREE_VALUE (tmp
) = build (COMPOUND_EXPR
, TREE_TYPE (t
),
532 TREE_VALUE (tmp
), t
);
535 function
= build_nt (CALL_EXPR
, function
, parms
, NULL_TREE
);
536 TREE_HAS_CONSTRUCTOR (function
) = is_constructor
;
537 TREE_TYPE (function
) = result_type
;
538 TREE_SIDE_EFFECTS (function
) = 1;
543 /* Build something of the form ptr->method (args)
544 or object.method (args). This can also build
545 calls to constructors, and find friends.
547 Member functions always take their class variable
550 INSTANCE is a class instance.
552 NAME is the name of the method desired, usually an IDENTIFIER_NODE.
554 PARMS help to figure out what that NAME really refers to.
556 BASETYPE_PATH, if non-NULL, contains a chain from the type of INSTANCE
557 down to the real instance type to use for access checking. We need this
558 information to get protected accesses correct. This parameter is used
559 by build_member_call.
561 FLAGS is the logical disjunction of zero or more LOOKUP_
562 flags. See cp-tree.h for more info.
564 If this is all OK, calls build_function_call with the resolved
567 This function must also handle being called to perform
568 initialization, promotion/coercion of arguments, and
569 instantiation of default parameters.
571 Note that NAME may refer to an instance variable name. If
572 `operator()()' is defined for the type of that field, then we return
576 build_method_call (instance
, name
, parms
, basetype_path
, flags
)
577 tree instance
, name
, parms
, basetype_path
;
580 tree basetype
, instance_ptr
;
582 #ifdef GATHER_STATISTICS
583 n_build_method_call
++;
586 if (instance
== error_mark_node
587 || name
== error_mark_node
588 || parms
== error_mark_node
589 || (instance
!= NULL_TREE
&& TREE_TYPE (instance
) == error_mark_node
))
590 return error_mark_node
;
592 if (processing_template_decl
)
594 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
596 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 0);
598 name
= build_min_nt (BIT_NOT_EXPR
, type
);
601 return build_min_nt (METHOD_CALL_EXPR
, name
, instance
, parms
, NULL_TREE
);
604 /* This is the logic that magically deletes the second argument to
605 operator delete, if it is not needed. */
606 if (name
== ansi_opname
[(int) DELETE_EXPR
] && list_length (parms
)==2)
608 tree save_last
= TREE_CHAIN (parms
);
610 /* get rid of unneeded argument */
611 TREE_CHAIN (parms
) = NULL_TREE
;
612 if (build_method_call (instance
, name
, parms
, basetype_path
,
613 (LOOKUP_SPECULATIVELY
|flags
) & ~LOOKUP_COMPLAIN
))
615 /* If it finds a match, return it. */
616 return build_method_call (instance
, name
, parms
, basetype_path
, flags
);
618 /* If it doesn't work, two argument delete must work */
619 TREE_CHAIN (parms
) = save_last
;
621 /* We already know whether it's needed or not for vec delete. */
622 else if (name
== ansi_opname
[(int) VEC_DELETE_EXPR
]
623 && TYPE_LANG_SPECIFIC (TREE_TYPE (instance
))
624 && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance
)))
625 TREE_CHAIN (parms
) = NULL_TREE
;
627 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
629 flags
|= LOOKUP_DESTRUCTOR
;
630 name
= TREE_OPERAND (name
, 0);
632 error ("destructors take no parameters");
633 basetype
= TREE_TYPE (instance
);
634 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
635 basetype
= TREE_TYPE (basetype
);
636 if (! (name
== TYPE_MAIN_VARIANT (basetype
)
637 || (IS_AGGR_TYPE (basetype
)
638 && name
== constructor_name (basetype
))
639 || basetype
== get_type_value (name
)))
641 cp_error ("destructor name `~%D' does not match type `%T' of expression",
643 return cp_convert (void_type_node
, instance
);
646 if (! TYPE_HAS_DESTRUCTOR (complete_type (basetype
)))
647 return cp_convert (void_type_node
, instance
);
648 instance
= default_conversion (instance
);
649 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
650 return build_delete (build_pointer_type (basetype
),
651 instance_ptr
, integer_two_node
,
652 LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
, 0);
655 return build_new_method_call (instance
, name
, parms
, basetype_path
, flags
);
658 /* New overloading code. */
668 struct z_candidate
*next
;
671 #define IDENTITY_RANK 0
677 #define ELLIPSIS_RANK 6
680 #define ICS_RANK(NODE) \
681 (ICS_BAD_FLAG (NODE) ? BAD_RANK \
682 : ICS_ELLIPSIS_FLAG (NODE) ? ELLIPSIS_RANK \
683 : ICS_USER_FLAG (NODE) ? USER_RANK \
684 : ICS_STD_RANK (NODE))
686 #define ICS_STD_RANK(NODE) TREE_COMPLEXITY (NODE)
688 #define ICS_USER_FLAG(NODE) TREE_LANG_FLAG_0 (NODE)
689 #define ICS_ELLIPSIS_FLAG(NODE) TREE_LANG_FLAG_1 (NODE)
690 #define ICS_THIS_FLAG(NODE) TREE_LANG_FLAG_2 (NODE)
691 #define ICS_BAD_FLAG(NODE) TREE_LANG_FLAG_3 (NODE)
693 #define USER_CONV_CAND(NODE) \
694 ((struct z_candidate *)WRAPPER_PTR (TREE_OPERAND (NODE, 1)))
695 #define USER_CONV_FN(NODE) (USER_CONV_CAND (NODE)->fn)
702 || (integer_zerop (t
) && TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
))
708 build_conv (code
, type
, from
)
712 tree t
= build1 (code
, type
, from
);
713 int rank
= ICS_STD_RANK (from
);
725 if (rank
< EXACT_RANK
)
731 ICS_STD_RANK (t
) = rank
;
732 ICS_USER_FLAG (t
) = ICS_USER_FLAG (from
);
733 ICS_BAD_FLAG (t
) = ICS_BAD_FLAG (from
);
741 if (TREE_CODE (t
) == REFERENCE_TYPE
)
750 if (TREE_CODE (t
) == ARRAY_TYPE
)
752 return TYPE_MAIN_VARIANT (t
);
755 /* Returns the standard conversion path (see [conv]) from type FROM to type
756 TO, if any. For proper handling of null pointer constants, you must
757 also pass the expression EXPR to convert from. */
760 standard_conversion (to
, from
, expr
)
763 enum tree_code fcode
, tcode
;
767 if (TREE_CODE (to
) == REFERENCE_TYPE
)
769 if (TREE_CODE (from
) == REFERENCE_TYPE
)
772 from
= TREE_TYPE (from
);
774 to
= strip_top_quals (to
);
775 from
= strip_top_quals (from
);
777 fcode
= TREE_CODE (from
);
778 tcode
= TREE_CODE (to
);
780 conv
= build1 (IDENTITY_CONV
, from
, expr
);
782 if (fcode
== FUNCTION_TYPE
)
784 from
= build_pointer_type (from
);
785 fcode
= TREE_CODE (from
);
786 conv
= build_conv (LVALUE_CONV
, from
, conv
);
788 else if (fcode
== ARRAY_TYPE
)
790 from
= build_pointer_type (TREE_TYPE (from
));
791 fcode
= TREE_CODE (from
);
792 conv
= build_conv (LVALUE_CONV
, from
, conv
);
794 else if (fromref
|| (expr
&& real_lvalue_p (expr
)))
795 conv
= build_conv (RVALUE_CONV
, from
, conv
);
800 if ((tcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (to
))
801 && expr
&& null_ptr_cst_p (expr
))
803 conv
= build_conv (STD_CONV
, to
, conv
);
805 else if (tcode
== POINTER_TYPE
&& fcode
== POINTER_TYPE
)
807 enum tree_code ufcode
= TREE_CODE (TREE_TYPE (from
));
808 enum tree_code utcode
= TREE_CODE (TREE_TYPE (to
));
810 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (from
)),
811 TYPE_MAIN_VARIANT (TREE_TYPE (to
)), 1))
813 else if (utcode
== VOID_TYPE
&& ufcode
!= OFFSET_TYPE
814 && ufcode
!= FUNCTION_TYPE
)
816 from
= build_pointer_type
817 (cp_build_type_variant (void_type_node
,
818 TYPE_READONLY (TREE_TYPE (from
)),
819 TYPE_VOLATILE (TREE_TYPE (from
))));
820 conv
= build_conv (PTR_CONV
, from
, conv
);
822 else if (ufcode
== OFFSET_TYPE
&& utcode
== OFFSET_TYPE
)
824 tree fbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from
));
825 tree tbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to
));
827 if (DERIVED_FROM_P (fbase
, tbase
)
828 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (from
))),
829 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (to
))),
832 from
= build_offset_type (tbase
, TREE_TYPE (TREE_TYPE (from
)));
833 from
= build_pointer_type (from
);
834 conv
= build_conv (PMEM_CONV
, from
, conv
);
837 else if (IS_AGGR_TYPE (TREE_TYPE (from
))
838 && IS_AGGR_TYPE (TREE_TYPE (to
)))
840 if (DERIVED_FROM_P (TREE_TYPE (to
), TREE_TYPE (from
)))
842 from
= cp_build_type_variant (TREE_TYPE (to
),
843 TYPE_READONLY (TREE_TYPE (from
)),
844 TYPE_VOLATILE (TREE_TYPE (from
)));
845 from
= build_pointer_type (from
);
846 conv
= build_conv (PTR_CONV
, from
, conv
);
850 if (comptypes (from
, to
, 1))
852 else if (comp_ptr_ttypes (TREE_TYPE (to
), TREE_TYPE (from
)))
853 conv
= build_conv (QUAL_CONV
, to
, conv
);
854 else if (ptr_reasonably_similar (TREE_TYPE (to
), TREE_TYPE (from
)))
856 conv
= build_conv (PTR_CONV
, to
, conv
);
857 ICS_BAD_FLAG (conv
) = 1;
864 else if (TYPE_PTRMEMFUNC_P (to
) && TYPE_PTRMEMFUNC_P (from
))
866 tree fromfn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from
));
867 tree tofn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to
));
868 tree fbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn
)));
869 tree tbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn
)));
871 if (! DERIVED_FROM_P (fbase
, tbase
)
872 || ! comptypes (TREE_TYPE (fromfn
), TREE_TYPE (tofn
), 1)
873 || ! compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)),
874 TREE_CHAIN (TYPE_ARG_TYPES (tofn
)), 1)
875 || TYPE_READONLY (fbase
) != TYPE_READONLY (tbase
)
876 || TYPE_VOLATILE (fbase
) != TYPE_VOLATILE (tbase
))
879 from
= cp_build_type_variant (tbase
, TYPE_READONLY (fbase
),
880 TYPE_VOLATILE (fbase
));
881 from
= build_cplus_method_type (from
, TREE_TYPE (fromfn
),
882 TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)));
883 from
= build_ptrmemfunc_type (build_pointer_type (from
));
884 conv
= build_conv (PMEM_CONV
, from
, conv
);
886 else if (tcode
== BOOLEAN_TYPE
)
888 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
889 || fcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (from
)))
892 conv
= build_conv (STD_CONV
, to
, conv
);
893 if (fcode
== POINTER_TYPE
894 || (TYPE_PTRMEMFUNC_P (from
) && ICS_STD_RANK (conv
) < PBOOL_RANK
))
895 ICS_STD_RANK (conv
) = PBOOL_RANK
;
897 /* We don't check for ENUMERAL_TYPE here because there are no standard
898 conversions to enum type. */
899 else if (tcode
== INTEGER_TYPE
|| tcode
== BOOLEAN_TYPE
900 || tcode
== REAL_TYPE
)
902 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
))
904 conv
= build_conv (STD_CONV
, to
, conv
);
906 /* Give this a better rank if it's a promotion. */
907 if (to
== type_promotes_to (from
)
908 && ICS_STD_RANK (TREE_OPERAND (conv
, 0)) <= PROMO_RANK
)
909 ICS_STD_RANK (conv
) = PROMO_RANK
;
911 else if (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
912 && DERIVED_FROM_P (to
, from
))
914 if (TREE_CODE (conv
) == RVALUE_CONV
)
915 conv
= TREE_OPERAND (conv
, 0);
916 conv
= build_conv (BASE_CONV
, to
, conv
);
924 /* Returns the conversion path from type FROM to reference type TO for
925 purposes of reference binding. For lvalue binding, either pass a
926 reference type to FROM or an lvalue expression to EXPR.
928 Currently does not distinguish in the generated trees between binding to
929 an lvalue and a temporary. Should it? */
932 reference_binding (rto
, rfrom
, expr
, flags
)
933 tree rto
, rfrom
, expr
;
938 tree to
= TREE_TYPE (rto
);
942 if (TREE_CODE (from
) == REFERENCE_TYPE
)
943 from
= TREE_TYPE (from
);
944 else if (! expr
|| ! real_lvalue_p (expr
))
947 related
= (comptypes (TYPE_MAIN_VARIANT (to
),
948 TYPE_MAIN_VARIANT (from
), 1)
949 || (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
950 && DERIVED_FROM_P (to
, from
)));
952 if (lvalue
&& related
953 && TYPE_READONLY (to
) >= TYPE_READONLY (from
)
954 && TYPE_VOLATILE (to
) >= TYPE_VOLATILE (from
))
956 conv
= build1 (IDENTITY_CONV
, from
, expr
);
958 if (comptypes (TYPE_MAIN_VARIANT (to
),
959 TYPE_MAIN_VARIANT (from
), 1))
960 conv
= build_conv (REF_BIND
, rto
, conv
);
963 conv
= build_conv (REF_BIND
, rto
, conv
);
964 ICS_STD_RANK (conv
) = STD_RANK
;
972 conv
= standard_conversion (to
, rfrom
, expr
);
975 conv
= build_conv (REF_BIND
, rto
, conv
);
977 /* Bind directly to a base subobject of a class rvalue. Do it
978 after building the conversion for proper handling of ICS_RANK. */
979 if (TREE_CODE (TREE_OPERAND (conv
, 0)) == BASE_CONV
)
980 TREE_OPERAND (conv
, 0) = TREE_OPERAND (TREE_OPERAND (conv
, 0), 0);
983 && ((! (TYPE_READONLY (to
) && ! TYPE_VOLATILE (to
)
984 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0))
985 /* If T1 is reference-related to T2, cv1 must be the same
986 cv-qualification as, or greater cv-qualification than,
987 cv2; otherwise, the program is ill-formed. */
989 && (TYPE_READONLY (to
) < TYPE_READONLY (from
)
990 || TYPE_VOLATILE (to
) < TYPE_VOLATILE (from
)))))
991 ICS_BAD_FLAG (conv
) = 1;
997 /* Returns the implicit conversion sequence (see [over.ics]) from type FROM
998 to type TO. The optional expression EXPR may affect the conversion.
999 FLAGS are the usual overloading flags. Only LOOKUP_NO_CONVERSION is
1003 implicit_conversion (to
, from
, expr
, flags
)
1004 tree to
, from
, expr
;
1008 struct z_candidate
*cand
;
1010 if (expr
&& type_unknown_p (expr
))
1012 expr
= instantiate_type (to
, expr
, 0);
1013 if (expr
== error_mark_node
)
1015 from
= TREE_TYPE (expr
);
1018 if (TREE_CODE (to
) == REFERENCE_TYPE
)
1019 conv
= reference_binding (to
, from
, expr
, flags
);
1021 conv
= standard_conversion (to
, from
, expr
);
1025 else if (expr
!= NULL_TREE
1026 && (IS_AGGR_TYPE (non_reference (from
))
1027 || IS_AGGR_TYPE (non_reference (to
)))
1028 && (flags
& LOOKUP_NO_CONVERSION
) == 0)
1030 cand
= build_user_type_conversion_1
1031 (to
, expr
, LOOKUP_ONLYCONVERTING
);
1033 conv
= cand
->second_conv
;
1034 if ((! conv
|| ICS_BAD_FLAG (conv
))
1035 && TREE_CODE (to
) == REFERENCE_TYPE
1036 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0)
1038 cand
= build_user_type_conversion_1
1039 (TYPE_MAIN_VARIANT (TREE_TYPE (to
)), expr
, LOOKUP_ONLYCONVERTING
);
1042 if (! TYPE_READONLY (TREE_TYPE (to
))
1043 || TYPE_VOLATILE (TREE_TYPE (to
)))
1044 ICS_BAD_FLAG (cand
->second_conv
) = 1;
1045 if (!conv
|| (ICS_BAD_FLAG (conv
)
1046 > ICS_BAD_FLAG (cand
->second_conv
)))
1047 conv
= build_conv (REF_BIND
, to
, cand
->second_conv
);
1055 /* Add a new entry to the list of candidates. Used by the add_*_candidate
1058 static struct z_candidate
*
1059 add_candidate (candidates
, fn
, convs
, viable
)
1060 struct z_candidate
*candidates
;
1064 struct z_candidate
*cand
1065 = (struct z_candidate
*) scratchalloc (sizeof (struct z_candidate
));
1068 cand
->convs
= convs
;
1069 cand
->second_conv
= NULL_TREE
;
1070 cand
->viable
= viable
;
1071 cand
->basetype_path
= NULL_TREE
;
1072 cand
->template = NULL_TREE
;
1073 cand
->warnings
= NULL_TREE
;
1074 cand
->next
= candidates
;
1079 /* Create an overload candidate for the function or method FN called with
1080 the argument list ARGLIST and add it to CANDIDATES. FLAGS is passed on
1081 to implicit_conversion. */
1083 static struct z_candidate
*
1084 add_function_candidate (candidates
, fn
, arglist
, flags
)
1085 struct z_candidate
*candidates
;
1089 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1092 tree parmnode
= parmlist
;
1093 tree argnode
= arglist
;
1095 struct z_candidate
*cand
;
1097 /* The `this' and `in_chrg' arguments to constructors are not considered
1098 in overload resolution. */
1099 if (DECL_CONSTRUCTOR_P (fn
))
1101 parmnode
= TREE_CHAIN (parmnode
);
1102 argnode
= TREE_CHAIN (argnode
);
1103 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
1105 parmnode
= TREE_CHAIN (parmnode
);
1106 argnode
= TREE_CHAIN (argnode
);
1110 len
= list_length (argnode
);
1111 convs
= make_scratch_vec (len
);
1113 for (i
= 0; i
< len
; ++i
)
1115 tree arg
= TREE_VALUE (argnode
);
1116 tree argtype
= TREE_TYPE (arg
);
1119 argtype
= cp_build_type_variant
1120 (argtype
, TREE_READONLY (arg
), TREE_THIS_VOLATILE (arg
));
1122 if (parmnode
== void_list_node
)
1125 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
1128 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
1129 ICS_ELLIPSIS_FLAG (t
) = 1;
1132 if (i
== 0 && t
&& TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
1133 && ! DECL_CONSTRUCTOR_P (fn
))
1134 ICS_THIS_FLAG (t
) = 1;
1136 TREE_VEC_ELT (convs
, i
) = t
;
1140 if (ICS_BAD_FLAG (t
))
1144 parmnode
= TREE_CHAIN (parmnode
);
1145 argnode
= TREE_CHAIN (argnode
);
1151 /* Make sure there are default args for the rest of the parms. */
1152 for (; parmnode
&& parmnode
!= void_list_node
;
1153 parmnode
= TREE_CHAIN (parmnode
))
1154 if (! TREE_PURPOSE (parmnode
))
1160 return add_candidate (candidates
, fn
, convs
, viable
);
1163 /* Create an overload candidate for the conversion function FN which will
1164 be invoked for expression OBJ, producing a pointer-to-function which
1165 will in turn be called with the argument list ARGLIST, and add it to
1166 CANDIDATES. FLAGS is passed on to implicit_conversion. */
1168 static struct z_candidate
*
1169 add_conv_candidate (candidates
, fn
, obj
, arglist
)
1170 struct z_candidate
*candidates
;
1171 tree fn
, obj
, arglist
;
1173 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
1174 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (totype
));
1175 int i
, len
= list_length (arglist
) + 1;
1176 tree convs
= make_scratch_vec (len
);
1177 tree parmnode
= parmlist
;
1178 tree argnode
= arglist
;
1180 struct z_candidate
*cand
;
1181 int flags
= LOOKUP_NORMAL
;
1183 for (i
= 0; i
< len
; ++i
)
1185 tree arg
= i
== 0 ? obj
: TREE_VALUE (argnode
);
1186 tree argtype
= lvalue_type (arg
);
1190 t
= implicit_conversion (totype
, argtype
, arg
, flags
);
1191 else if (parmnode
== void_list_node
)
1194 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
1197 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
1198 ICS_ELLIPSIS_FLAG (t
) = 1;
1201 TREE_VEC_ELT (convs
, i
) = t
;
1205 if (ICS_BAD_FLAG (t
))
1212 parmnode
= TREE_CHAIN (parmnode
);
1213 argnode
= TREE_CHAIN (argnode
);
1219 for (; parmnode
&& parmnode
!= void_list_node
;
1220 parmnode
= TREE_CHAIN (parmnode
))
1221 if (! TREE_PURPOSE (parmnode
))
1227 return add_candidate (candidates
, fn
, convs
, viable
);
1230 static struct z_candidate
*
1231 build_builtin_candidate (candidates
, fnname
, type1
, type2
,
1232 args
, argtypes
, flags
)
1233 struct z_candidate
*candidates
;
1234 tree fnname
, type1
, type2
, *args
, *argtypes
;
1240 struct z_candidate
*cand
;
1246 convs
= make_scratch_vec (args
[2] ? 3 : (args
[1] ? 2 : 1));
1248 for (i
= 0; i
< 2; ++i
)
1253 t
= implicit_conversion (types
[i
], argtypes
[i
], args
[i
], flags
);
1257 /* We need something for printing the candidate. */
1258 t
= build1 (IDENTITY_CONV
, types
[i
], NULL_TREE
);
1260 else if (ICS_BAD_FLAG (t
))
1262 TREE_VEC_ELT (convs
, i
) = t
;
1265 /* For COND_EXPR we rearranged the arguments; undo that now. */
1268 TREE_VEC_ELT (convs
, 2) = TREE_VEC_ELT (convs
, 1);
1269 TREE_VEC_ELT (convs
, 1) = TREE_VEC_ELT (convs
, 0);
1270 t
= implicit_conversion (boolean_type_node
, argtypes
[2], args
[2], flags
);
1272 TREE_VEC_ELT (convs
, 0) = t
;
1277 return add_candidate (candidates
, fnname
, convs
, viable
);
1284 return TYPE_SIZE (complete_type (t
)) != NULL_TREE
;
1287 /* Create any builtin operator overload candidates for the operator in
1288 question given the converted operand types TYPE1 and TYPE2. The other
1289 args are passed through from add_builtin_candidates to
1290 build_builtin_candidate. */
1292 static struct z_candidate
*
1293 add_builtin_candidate (candidates
, code
, code2
, fnname
, type1
, type2
,
1294 args
, argtypes
, flags
)
1295 struct z_candidate
*candidates
;
1296 enum tree_code code
, code2
;
1297 tree fnname
, type1
, type2
, *args
, *argtypes
;
1302 case POSTINCREMENT_EXPR
:
1303 case POSTDECREMENT_EXPR
:
1304 args
[1] = integer_zero_node
;
1305 type2
= integer_type_node
;
1314 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
1315 and VQ is either volatile or empty, there exist candidate operator
1316 functions of the form
1317 VQ T& operator++(VQ T&);
1318 T operator++(VQ T&, int);
1319 5 For every pair T, VQ), where T is an enumeration type or an arithmetic
1320 type other than bool, and VQ is either volatile or empty, there exist
1321 candidate operator functions of the form
1322 VQ T& operator--(VQ T&);
1323 T operator--(VQ T&, int);
1324 6 For every pair T, VQ), where T is a cv-qualified or cv-unqualified
1325 complete object type, and VQ is either volatile or empty, there exist
1326 candidate operator functions of the form
1327 T*VQ& operator++(T*VQ&);
1328 T*VQ& operator--(T*VQ&);
1329 T* operator++(T*VQ&, int);
1330 T* operator--(T*VQ&, int); */
1332 case POSTDECREMENT_EXPR
:
1333 case PREDECREMENT_EXPR
:
1334 if (TREE_CODE (type1
) == BOOLEAN_TYPE
)
1336 case POSTINCREMENT_EXPR
:
1337 case PREINCREMENT_EXPR
:
1338 if ((ARITHMETIC_TYPE_P (type1
) && TREE_CODE (type1
) != ENUMERAL_TYPE
)
1339 || TYPE_PTROB_P (type1
))
1341 type1
= build_reference_type (type1
);
1346 /* 7 For every cv-qualified or cv-unqualified complete object type T, there
1347 exist candidate operator functions of the form
1351 8 For every function type T, there exist candidate operator functions of
1353 T& operator*(T*); */
1356 if (TREE_CODE (type1
) == POINTER_TYPE
1357 && (TYPE_PTROB_P (type1
)
1358 || TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
))
1362 /* 9 For every type T, there exist candidate operator functions of the form
1365 10For every promoted arithmetic type T, there exist candidate operator
1366 functions of the form
1370 case CONVERT_EXPR
: /* unary + */
1371 if (TREE_CODE (type1
) == POINTER_TYPE
1372 && TREE_CODE (TREE_TYPE (type1
)) != OFFSET_TYPE
)
1375 if (ARITHMETIC_TYPE_P (type1
))
1379 /* 11For every promoted integral type T, there exist candidate operator
1380 functions of the form
1384 if (INTEGRAL_TYPE_P (type1
))
1388 /* 12For every quintuple C1, C2, T, CV1, CV2), where C2 is a class type, C1
1389 is the same type as C2 or is a derived class of C2, T is a complete
1390 object type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
1391 there exist candidate operator functions of the form
1392 CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
1393 where CV12 is the union of CV1 and CV2. */
1396 if (TREE_CODE (type1
) == POINTER_TYPE
1397 && (TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
)))
1399 tree c1
= TREE_TYPE (type1
);
1400 tree c2
= (TYPE_PTRMEMFUNC_P (type2
)
1401 ? TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type2
)))
1402 : TYPE_OFFSET_BASETYPE (TREE_TYPE (type2
)));
1404 if (IS_AGGR_TYPE (c1
) && DERIVED_FROM_P (c2
, c1
)
1405 && (TYPE_PTRMEMFUNC_P (type2
)
1406 || is_complete (TREE_TYPE (TREE_TYPE (type2
)))))
1411 /* 13For every pair of promoted arithmetic types L and R, there exist can-
1412 didate operator functions of the form
1417 bool operator<(L, R);
1418 bool operator>(L, R);
1419 bool operator<=(L, R);
1420 bool operator>=(L, R);
1421 bool operator==(L, R);
1422 bool operator!=(L, R);
1423 where LR is the result of the usual arithmetic conversions between
1426 14For every pair of types T and I, where T is a cv-qualified or cv-
1427 unqualified complete object type and I is a promoted integral type,
1428 there exist candidate operator functions of the form
1429 T* operator+(T*, I);
1430 T& operator[](T*, I);
1431 T* operator-(T*, I);
1432 T* operator+(I, T*);
1433 T& operator[](I, T*);
1435 15For every T, where T is a pointer to complete object type, there exist
1436 candidate operator functions of the form112)
1437 ptrdiff_t operator-(T, T);
1439 16For every pointer type T, there exist candidate operator functions of
1441 bool operator<(T, T);
1442 bool operator>(T, T);
1443 bool operator<=(T, T);
1444 bool operator>=(T, T);
1445 bool operator==(T, T);
1446 bool operator!=(T, T);
1448 17For every pointer to member type T, there exist candidate operator
1449 functions of the form
1450 bool operator==(T, T);
1451 bool operator!=(T, T); */
1454 if (TYPE_PTROB_P (type1
) && TYPE_PTROB_P (type2
))
1456 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
1458 type2
= ptrdiff_type_node
;
1462 case TRUNC_DIV_EXPR
:
1463 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1469 if ((TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
))
1470 || (TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
)))
1472 if ((TYPE_PTRMEMFUNC_P (type1
) || TYPE_PTRMEM_P (type1
))
1473 && null_ptr_cst_p (args
[1]))
1478 if ((TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
))
1479 && null_ptr_cst_p (args
[0]))
1490 if ((ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1491 || (TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
)))
1493 if (TYPE_PTR_P (type1
) && null_ptr_cst_p (args
[1]))
1498 if (null_ptr_cst_p (args
[0]) && TYPE_PTR_P (type2
))
1506 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1509 if (INTEGRAL_TYPE_P (type1
) && TYPE_PTROB_P (type2
))
1511 type1
= ptrdiff_type_node
;
1514 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
1516 type2
= ptrdiff_type_node
;
1521 /* 18For every pair of promoted integral types L and R, there exist candi-
1522 date operator functions of the form
1529 where LR is the result of the usual arithmetic conversions between
1532 case TRUNC_MOD_EXPR
:
1538 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
1542 /* 19For every triple L, VQ, R), where L is an arithmetic or enumeration
1543 type, VQ is either volatile or empty, and R is a promoted arithmetic
1544 type, there exist candidate operator functions of the form
1545 VQ L& operator=(VQ L&, R);
1546 VQ L& operator*=(VQ L&, R);
1547 VQ L& operator/=(VQ L&, R);
1548 VQ L& operator+=(VQ L&, R);
1549 VQ L& operator-=(VQ L&, R);
1551 20For every pair T, VQ), where T is any type and VQ is either volatile
1552 or empty, there exist candidate operator functions of the form
1553 T*VQ& operator=(T*VQ&, T*);
1555 21For every pair T, VQ), where T is a pointer to member type and VQ is
1556 either volatile or empty, there exist candidate operator functions of
1558 VQ T& operator=(VQ T&, T);
1560 22For every triple T, VQ, I), where T is a cv-qualified or cv-
1561 unqualified complete object type, VQ is either volatile or empty, and
1562 I is a promoted integral type, there exist candidate operator func-
1564 T*VQ& operator+=(T*VQ&, I);
1565 T*VQ& operator-=(T*VQ&, I);
1567 23For every triple L, VQ, R), where L is an integral or enumeration
1568 type, VQ is either volatile or empty, and R is a promoted integral
1569 type, there exist candidate operator functions of the form
1571 VQ L& operator%=(VQ L&, R);
1572 VQ L& operator<<=(VQ L&, R);
1573 VQ L& operator>>=(VQ L&, R);
1574 VQ L& operator&=(VQ L&, R);
1575 VQ L& operator^=(VQ L&, R);
1576 VQ L& operator|=(VQ L&, R); */
1583 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
1585 type2
= ptrdiff_type_node
;
1589 case TRUNC_DIV_EXPR
:
1590 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1594 case TRUNC_MOD_EXPR
:
1600 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
1605 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1607 if ((TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
))
1608 || (TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
1609 || (TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
))
1610 || ((TYPE_PTRMEMFUNC_P (type1
)
1611 || TREE_CODE (type1
) == POINTER_TYPE
)
1612 && null_ptr_cst_p (args
[1])))
1620 my_friendly_abort (367);
1622 type1
= build_reference_type (type1
);
1626 /* Kludge around broken overloading rules whereby
1627 bool ? const char& : enum is ambiguous
1628 (between int and const char&). */
1629 flags
|= LOOKUP_NO_TEMP_BIND
;
1631 /* Extension: Support ?: of enumeral type. Hopefully this will not
1632 be an extension for long. */
1633 if (TREE_CODE (type1
) == ENUMERAL_TYPE
&& type1
== type2
)
1635 else if (TREE_CODE (type1
) == ENUMERAL_TYPE
1636 || TREE_CODE (type2
) == ENUMERAL_TYPE
)
1638 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
1640 if (TREE_CODE (type1
) == TREE_CODE (type2
)
1641 && (TREE_CODE (type1
) == REFERENCE_TYPE
1642 || TREE_CODE (type1
) == POINTER_TYPE
1643 || TYPE_PTRMEMFUNC_P (type1
)
1644 || IS_AGGR_TYPE (type1
)))
1646 if (TREE_CODE (type1
) == REFERENCE_TYPE
1647 || TREE_CODE (type2
) == REFERENCE_TYPE
)
1649 if (((TYPE_PTRMEMFUNC_P (type1
) || TREE_CODE (type1
) == POINTER_TYPE
)
1650 && null_ptr_cst_p (args
[1]))
1651 || IS_AGGR_TYPE (type1
))
1656 if (((TYPE_PTRMEMFUNC_P (type2
) || TREE_CODE (type2
) == POINTER_TYPE
)
1657 && null_ptr_cst_p (args
[0]))
1658 || IS_AGGR_TYPE (type2
))
1666 my_friendly_abort (367);
1669 /* If we're dealing with two pointer types, we need candidates
1670 for both of them. */
1671 if (type2
&& type1
!= type2
1672 && TREE_CODE (type1
) == TREE_CODE (type2
)
1673 && (TREE_CODE (type1
) == REFERENCE_TYPE
1674 || (TREE_CODE (type1
) == POINTER_TYPE
1675 && TYPE_PTRMEM_P (type1
) == TYPE_PTRMEM_P (type2
))
1676 || TYPE_PTRMEMFUNC_P (type1
)
1677 || IS_AGGR_TYPE (type1
)))
1679 candidates
= build_builtin_candidate
1680 (candidates
, fnname
, type1
, type1
, args
, argtypes
, flags
);
1681 return build_builtin_candidate
1682 (candidates
, fnname
, type2
, type2
, args
, argtypes
, flags
);
1685 return build_builtin_candidate
1686 (candidates
, fnname
, type1
, type2
, args
, argtypes
, flags
);
1690 type_decays_to (type
)
1693 if (TREE_CODE (type
) == ARRAY_TYPE
)
1694 return build_pointer_type (TREE_TYPE (type
));
1695 if (TREE_CODE (type
) == FUNCTION_TYPE
)
1696 return build_pointer_type (type
);
1700 /* There are three conditions of builtin candidates:
1702 1) bool-taking candidates. These are the same regardless of the input.
1703 2) pointer-pair taking candidates. These are generated for each type
1704 one of the input types converts to.
1705 3) arithmetic candidates. According to the WP, we should generate
1706 all of these, but I'm trying not to... */
1708 static struct z_candidate
*
1709 add_builtin_candidates (candidates
, code
, code2
, fnname
, args
, flags
)
1710 struct z_candidate
*candidates
;
1711 enum tree_code code
, code2
;
1716 tree type
, argtypes
[3], types
[2];
1718 for (i
= 0; i
< 3; ++i
)
1721 argtypes
[i
] = lvalue_type (args
[i
]);
1723 argtypes
[i
] = NULL_TREE
;
1728 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
1729 and VQ is either volatile or empty, there exist candidate operator
1730 functions of the form
1731 VQ T& operator++(VQ T&); */
1733 case POSTINCREMENT_EXPR
:
1734 case PREINCREMENT_EXPR
:
1735 case POSTDECREMENT_EXPR
:
1736 case PREDECREMENT_EXPR
:
1741 /* 24There also exist candidate operator functions of the form
1742 bool operator!(bool);
1743 bool operator&&(bool, bool);
1744 bool operator||(bool, bool); */
1746 case TRUTH_NOT_EXPR
:
1747 return build_builtin_candidate
1748 (candidates
, fnname
, boolean_type_node
,
1749 NULL_TREE
, args
, argtypes
, flags
);
1751 case TRUTH_ORIF_EXPR
:
1752 case TRUTH_ANDIF_EXPR
:
1753 return build_builtin_candidate
1754 (candidates
, fnname
, boolean_type_node
,
1755 boolean_type_node
, args
, argtypes
, flags
);
1766 types
[0] = types
[1] = NULL_TREE
;
1768 for (i
= 0; i
< 2; ++i
)
1772 else if (IS_AGGR_TYPE (argtypes
[i
]))
1774 tree convs
= lookup_conversions (argtypes
[i
]);
1776 if (code
== COND_EXPR
)
1778 if (real_lvalue_p (args
[i
]))
1779 types
[i
] = scratch_tree_cons
1780 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
1782 types
[i
] = scratch_tree_cons
1783 (NULL_TREE
, TYPE_MAIN_VARIANT (argtypes
[i
]), types
[i
]);
1786 else if (! convs
|| (i
== 0 && code
== MODIFY_EXPR
1787 && code2
== NOP_EXPR
))
1790 for (; convs
; convs
= TREE_CHAIN (convs
))
1792 type
= TREE_TYPE (TREE_TYPE (TREE_VALUE (convs
)));
1795 && (TREE_CODE (type
) != REFERENCE_TYPE
1796 || TYPE_READONLY (TREE_TYPE (type
))))
1799 if (code
== COND_EXPR
&& TREE_CODE (type
) == REFERENCE_TYPE
)
1800 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1802 type
= non_reference (type
);
1803 if (i
!= 0 || ! ref1
)
1805 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
1806 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
1807 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1808 if (INTEGRAL_TYPE_P (type
))
1809 type
= type_promotes_to (type
);
1812 if (! value_member (type
, types
[i
]))
1813 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1818 if (code
== COND_EXPR
&& real_lvalue_p (args
[i
]))
1819 types
[i
] = scratch_tree_cons
1820 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
1821 type
= non_reference (argtypes
[i
]);
1822 if (i
!= 0 || ! ref1
)
1824 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
1825 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
1826 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1827 if (INTEGRAL_TYPE_P (type
))
1828 type
= type_promotes_to (type
);
1830 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
1834 for (; types
[0]; types
[0] = TREE_CHAIN (types
[0]))
1837 for (type
= types
[1]; type
; type
= TREE_CHAIN (type
))
1838 candidates
= add_builtin_candidate
1839 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
1840 TREE_VALUE (type
), args
, argtypes
, flags
);
1842 candidates
= add_builtin_candidate
1843 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
1844 NULL_TREE
, args
, argtypes
, flags
);
1851 /* If TMPL can be successfully instantiated as indicated by
1852 EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
1854 TMPL is the template. EXPLICIT_TARGS are any explicit template
1855 arguments. ARGLIST is the arguments provided at the call-site.
1856 The RETURN_TYPE is the desired type for conversion operators. If
1857 OBJ is NULL_TREE, FLAGS are as for add_function_candidate. If an
1858 OBJ is supplied, FLAGS are ignored, and OBJ is as for
1859 add_conv_candidate. */
1861 static struct z_candidate
*
1862 add_template_candidate_real (candidates
, tmpl
, explicit_targs
,
1863 arglist
, return_type
, flags
,
1865 struct z_candidate
*candidates
;
1866 tree tmpl
, explicit_targs
, arglist
, return_type
;
1870 int ntparms
= DECL_NTPARMS (tmpl
);
1871 tree targs
= make_scratch_vec (ntparms
);
1872 struct z_candidate
*cand
;
1876 i
= fn_type_unification (tmpl
, explicit_targs
, targs
, arglist
,
1877 return_type
, 0, NULL_TREE
);
1882 fn
= instantiate_template (tmpl
, targs
);
1883 if (fn
== error_mark_node
)
1886 if (obj
!= NULL_TREE
)
1887 /* Aha, this is a conversion function. */
1888 cand
= add_conv_candidate (candidates
, fn
, obj
, arglist
);
1890 cand
= add_function_candidate (candidates
, fn
, arglist
, flags
);
1891 if (DECL_TI_TEMPLATE (fn
) != tmpl
)
1892 /* This situation can occur if a member template of a template
1893 class is specialized. Then, instantiate_template might return
1894 an instantiation of the specialization, in which case the
1895 DECL_TI_TEMPLATE field will point at the original
1896 specialization. For example:
1898 template <class T> struct S { template <class U> void f(U);
1899 template <> void f(int) {}; };
1903 Here, TMPL will be template <class U> S<double>::f(U).
1904 And, instantiate template will give us the specialization
1905 template <> S<double>::f(int). But, the DECL_TI_TEMPLATE field
1906 for this will point at template <class T> template <> S<T>::f(int),
1907 so that we can find the definition. For the purposes of
1908 overload resolution, however, we want the original TMPL. */
1909 cand
->template = tree_cons (tmpl
, targs
, NULL_TREE
);
1911 cand
->template = DECL_TEMPLATE_INFO (fn
);
1917 static struct z_candidate
*
1918 add_template_candidate (candidates
, tmpl
, explicit_targs
,
1919 arglist
, return_type
, flags
)
1920 struct z_candidate
*candidates
;
1921 tree tmpl
, explicit_targs
, arglist
, return_type
;
1925 add_template_candidate_real (candidates
, tmpl
, explicit_targs
,
1926 arglist
, return_type
, flags
, NULL_TREE
);
1930 static struct z_candidate
*
1931 add_template_conv_candidate (candidates
, tmpl
, obj
, arglist
, return_type
)
1932 struct z_candidate
*candidates
;
1933 tree tmpl
, obj
, arglist
, return_type
;
1936 add_template_candidate_real (candidates
, tmpl
, NULL_TREE
, arglist
,
1937 return_type
, 0, obj
);
1943 struct z_candidate
*cands
;
1945 for (; cands
; cands
= cands
->next
)
1946 if (pedantic
? cands
->viable
== 1 : cands
->viable
)
1951 static struct z_candidate
*
1952 splice_viable (cands
)
1953 struct z_candidate
*cands
;
1955 struct z_candidate
**p
= &cands
;
1959 if (pedantic
? (*p
)->viable
== 1 : (*p
)->viable
)
1972 /* Fix this to work on non-lvalues. */
1973 if (IS_SIGNATURE_POINTER (TREE_TYPE (obj
))
1974 || IS_SIGNATURE_REFERENCE (TREE_TYPE (obj
)))
1977 return build_unary_op (ADDR_EXPR
, obj
, 0);
1981 print_z_candidates (candidates
)
1982 struct z_candidate
*candidates
;
1984 char *str
= "candidates are:";
1985 for (; candidates
; candidates
= candidates
->next
)
1987 if (TREE_CODE (candidates
->fn
) == IDENTIFIER_NODE
)
1989 if (candidates
->fn
== ansi_opname
[COND_EXPR
])
1990 cp_error ("%s %D(%T, %T, %T) <builtin>", str
, candidates
->fn
,
1991 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
1992 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)),
1993 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 2)));
1994 else if (TREE_VEC_LENGTH (candidates
->convs
) == 2)
1995 cp_error ("%s %D(%T, %T) <builtin>", str
, candidates
->fn
,
1996 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
1997 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)));
1999 cp_error ("%s %D(%T) <builtin>", str
, candidates
->fn
,
2000 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)));
2003 cp_error_at ("%s %+D%s", str
, candidates
->fn
,
2004 candidates
->viable
== -1 ? " <near match>" : "");
2009 /* Returns the best overload candidate to perform the requested
2010 conversion. This function is used for three the overloading situations
2011 described in [over.match.copy], [over.match.conv], and [over.match.ref].
2012 If TOTYPE is a REFERENCE_TYPE, we're trying to find an lvalue binding as
2013 per [dcl.init.ref], so we ignore temporary bindings. */
2015 static struct z_candidate
*
2016 build_user_type_conversion_1 (totype
, expr
, flags
)
2020 struct z_candidate
*candidates
, *cand
;
2021 tree fromtype
= TREE_TYPE (expr
);
2022 tree ctors
= NULL_TREE
, convs
= NULL_TREE
, *p
;
2023 tree args
= NULL_TREE
;
2024 tree templates
= NULL_TREE
;
2026 if (IS_AGGR_TYPE (totype
))
2027 ctors
= lookup_fnfields (TYPE_BINFO (totype
), ctor_identifier
, 0);
2028 if (IS_AGGR_TYPE (fromtype
)
2029 && (! IS_AGGR_TYPE (totype
) || ! DERIVED_FROM_P (totype
, fromtype
)))
2030 convs
= lookup_conversions (fromtype
);
2033 flags
|= LOOKUP_NO_CONVERSION
;
2037 tree t
= build_int_2 (0, 0);
2038 TREE_TYPE (t
) = build_pointer_type (totype
);
2039 args
= build_scratch_list (NULL_TREE
, expr
);
2040 if (TYPE_USES_VIRTUAL_BASECLASSES (totype
))
2041 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
2042 args
= scratch_tree_cons (NULL_TREE
, t
, args
);
2044 ctors
= TREE_VALUE (ctors
);
2046 for (; ctors
; ctors
= DECL_CHAIN (ctors
))
2048 if (DECL_NONCONVERTING_P (ctors
))
2051 if (TREE_CODE (ctors
) == TEMPLATE_DECL
)
2053 templates
= scratch_tree_cons (NULL_TREE
, ctors
, templates
);
2055 add_template_candidate (candidates
, ctors
,
2056 NULL_TREE
, args
, NULL_TREE
, flags
);
2059 candidates
= add_function_candidate (candidates
, ctors
,
2064 candidates
->second_conv
= build1 (IDENTITY_CONV
, totype
, NULL_TREE
);
2065 candidates
->basetype_path
= TYPE_BINFO (totype
);
2070 args
= build_scratch_list (NULL_TREE
, build_this (expr
));
2072 for (; convs
; convs
= TREE_CHAIN (convs
))
2074 tree fn
= TREE_VALUE (convs
);
2075 int convflags
= LOOKUP_NO_CONVERSION
;
2078 /* If we are called to convert to a reference type, we are trying to
2079 find an lvalue binding, so don't even consider temporaries. If
2080 we don't find an lvalue binding, the caller will try again to
2081 look for a temporary binding. */
2082 if (TREE_CODE (totype
) == REFERENCE_TYPE
)
2083 convflags
|= LOOKUP_NO_TEMP_BIND
;
2085 if (TREE_CODE (fn
) != TEMPLATE_DECL
)
2086 ics
= implicit_conversion
2087 (totype
, TREE_TYPE (TREE_TYPE (fn
)), 0, convflags
);
2089 /* Here, the template conversion operator result must
2090 precisely match the TOTYPE. (FIXME: Actually, we're
2091 supposed to do some simple conversions here; see
2092 [temp.deduct.conv].). If the result of the conversion
2093 operator is not actually TOTYPE, then
2094 add_template_candidate will fail below. */
2095 ics
= implicit_conversion (totype
, totype
, 0, convflags
);
2097 if (TREE_CODE (totype
) == REFERENCE_TYPE
&& ics
&& ICS_BAD_FLAG (ics
))
2098 /* ignore the near match. */;
2100 for (; fn
; fn
= DECL_CHAIN (fn
))
2102 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2104 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2106 add_template_candidate (candidates
, fn
, NULL_TREE
,
2107 args
, totype
, flags
);
2110 candidates
= add_function_candidate (candidates
, fn
,
2115 candidates
->second_conv
= ics
;
2116 candidates
->basetype_path
= TREE_PURPOSE (convs
);
2117 if (candidates
->viable
== 1 && ICS_BAD_FLAG (ics
))
2118 candidates
->viable
= -1;
2123 if (! any_viable (candidates
))
2126 if (flags
& LOOKUP_COMPLAIN
)
2128 if (candidates
&& ! candidates
->next
)
2129 /* say why this one won't work or try to be loose */;
2131 cp_error ("no viable candidates");
2138 candidates
= splice_viable (candidates
);
2139 cand
= tourney (candidates
);
2143 if (flags
& LOOKUP_COMPLAIN
)
2145 cp_error ("conversion from `%T' to `%T' is ambiguous",
2147 print_z_candidates (candidates
);
2150 cand
= candidates
; /* any one will do */
2151 cand
->second_conv
= build1 (AMBIG_CONV
, totype
, expr
);
2152 ICS_USER_FLAG (cand
->second_conv
) = 1;
2153 ICS_BAD_FLAG (cand
->second_conv
) = 1;
2158 for (p
= &(cand
->second_conv
); TREE_CODE (*p
) != IDENTITY_CONV
; )
2159 p
= &(TREE_OPERAND (*p
, 0));
2161 /* Pedantically, normal function declarations are never considered
2162 to refer to template instantiations, so we only do this with
2164 if (flag_guiding_decls
&& templates
&& ! cand
->template
2165 && !DECL_INITIAL (cand
->fn
)
2166 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
2167 add_maybe_template (cand
->fn
, templates
);
2171 (DECL_CONSTRUCTOR_P (cand
->fn
)
2172 ? totype
: non_reference (TREE_TYPE (TREE_TYPE (cand
->fn
)))),
2173 expr
, build_expr_ptr_wrapper (cand
));
2174 ICS_USER_FLAG (cand
->second_conv
) = 1;
2175 if (cand
->viable
== -1)
2176 ICS_BAD_FLAG (cand
->second_conv
) = 1;
2182 build_user_type_conversion (totype
, expr
, flags
)
2186 struct z_candidate
*cand
2187 = build_user_type_conversion_1 (totype
, expr
, flags
);
2191 if (TREE_CODE (cand
->second_conv
) == AMBIG_CONV
)
2192 return error_mark_node
;
2193 return convert_from_reference (convert_like (cand
->second_conv
, expr
));
2198 /* Do any initial processing on the arguments to a function call. */
2205 for (t
= args
; t
; t
= TREE_CHAIN (t
))
2207 if (TREE_VALUE (t
) == error_mark_node
)
2208 return error_mark_node
;
2209 else if (TREE_CODE (TREE_TYPE (TREE_VALUE (t
))) == VOID_TYPE
)
2211 error ("invalid use of void expression");
2212 return error_mark_node
;
2214 else if (TREE_CODE (TREE_VALUE (t
)) == OFFSET_REF
)
2215 TREE_VALUE (t
) = resolve_offset_ref (TREE_VALUE (t
));
2221 build_new_function_call (fn
, args
)
2224 struct z_candidate
*candidates
= 0, *cand
;
2225 tree explicit_targs
= NULL_TREE
;
2226 int template_only
= 0;
2228 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2230 explicit_targs
= TREE_OPERAND (fn
, 1);
2231 fn
= TREE_OPERAND (fn
, 0);
2235 if (really_overloaded_fn (fn
))
2238 tree templates
= NULL_TREE
;
2240 args
= resolve_args (args
);
2242 if (args
== error_mark_node
)
2243 return error_mark_node
;
2245 for (t
= TREE_VALUE (fn
); t
; t
= DECL_CHAIN (t
))
2247 if (TREE_CODE (t
) == TEMPLATE_DECL
)
2249 templates
= scratch_tree_cons (NULL_TREE
, t
, templates
);
2250 candidates
= add_template_candidate
2251 (candidates
, t
, explicit_targs
, args
, NULL_TREE
,
2254 else if (! template_only
)
2255 candidates
= add_function_candidate
2256 (candidates
, t
, args
, LOOKUP_NORMAL
);
2259 if (! any_viable (candidates
))
2261 if (candidates
&& ! candidates
->next
)
2262 return build_function_call (candidates
->fn
, args
);
2263 cp_error ("no matching function for call to `%D (%A)'",
2264 TREE_PURPOSE (fn
), args
);
2266 print_z_candidates (candidates
);
2267 return error_mark_node
;
2269 candidates
= splice_viable (candidates
);
2270 cand
= tourney (candidates
);
2274 cp_error ("call of overloaded `%D (%A)' is ambiguous",
2275 TREE_PURPOSE (fn
), args
);
2276 print_z_candidates (candidates
);
2277 return error_mark_node
;
2280 /* Pedantically, normal function declarations are never considered
2281 to refer to template instantiations, so we only do this with
2283 if (flag_guiding_decls
&& templates
&& ! cand
->template
2284 && ! DECL_INITIAL (cand
->fn
))
2285 add_maybe_template (cand
->fn
, templates
);
2287 return build_over_call (cand
, args
, LOOKUP_NORMAL
);
2290 return build_function_call (fn
, args
);
2294 build_object_call (obj
, args
)
2297 struct z_candidate
*candidates
= 0, *cand
;
2298 tree fns
, convs
, mem_args
= NULL_TREE
;
2299 tree type
= TREE_TYPE (obj
);
2300 tree templates
= NULL_TREE
;
2302 if (TYPE_PTRMEMFUNC_P (type
))
2304 /* It's no good looking for an overloaded operator() on a
2305 pointer-to-member-function. */
2306 cp_error ("pointer-to-member function %E cannot be called", obj
);
2307 cp_error ("without an object; consider using .* or ->*");
2308 return error_mark_node
;
2311 fns
= lookup_fnfields (TYPE_BINFO (type
), ansi_opname
[CALL_EXPR
], 1);
2312 if (fns
== error_mark_node
)
2313 return error_mark_node
;
2315 args
= resolve_args (args
);
2317 if (args
== error_mark_node
)
2318 return error_mark_node
;
2322 tree fn
= TREE_VALUE (fns
);
2323 mem_args
= scratch_tree_cons (NULL_TREE
, build_this (obj
), args
);
2325 for (; fn
; fn
= DECL_CHAIN (fn
))
2327 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2329 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2331 = add_template_candidate (candidates
, fn
, NULL_TREE
,
2332 mem_args
, NULL_TREE
,
2336 candidates
= add_function_candidate
2337 (candidates
, fn
, mem_args
, LOOKUP_NORMAL
);
2340 candidates
->basetype_path
= TREE_PURPOSE (fns
);
2344 convs
= lookup_conversions (type
);
2346 for (; convs
; convs
= TREE_CHAIN (convs
))
2348 tree fn
= TREE_VALUE (convs
);
2349 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
2351 if (TREE_CODE (totype
) == POINTER_TYPE
2352 && TREE_CODE (TREE_TYPE (totype
)) == FUNCTION_TYPE
)
2353 for (; fn
; fn
= DECL_CHAIN (fn
))
2355 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2357 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2358 candidates
= add_template_conv_candidate (candidates
,
2365 candidates
= add_conv_candidate (candidates
, fn
, obj
, args
);
2368 candidates
->basetype_path
= TREE_PURPOSE (convs
);
2372 if (! any_viable (candidates
))
2374 cp_error ("no match for call to `(%T) (%A)'", TREE_TYPE (obj
), args
);
2375 print_z_candidates (candidates
);
2376 return error_mark_node
;
2379 candidates
= splice_viable (candidates
);
2380 cand
= tourney (candidates
);
2384 cp_error ("call of `(%T) (%A)' is ambiguous", TREE_TYPE (obj
), args
);
2385 print_z_candidates (candidates
);
2386 return error_mark_node
;
2389 if (DECL_NAME (cand
->fn
) == ansi_opname
[CALL_EXPR
])
2390 return build_over_call (cand
, mem_args
, LOOKUP_NORMAL
);
2392 obj
= convert_like (TREE_VEC_ELT (cand
->convs
, 0), obj
);
2395 return build_function_call (obj
, args
);
2399 op_error (code
, code2
, arg1
, arg2
, arg3
, problem
)
2400 enum tree_code code
, code2
;
2401 tree arg1
, arg2
, arg3
;
2405 = (code
== MODIFY_EXPR
? assignop_tab
[code2
] : opname_tab
[code
]);
2410 cp_error ("%s for `%T ? %T : %T'", problem
,
2411 error_type (arg1
), error_type (arg2
), error_type (arg3
));
2413 case POSTINCREMENT_EXPR
:
2414 case POSTDECREMENT_EXPR
:
2415 cp_error ("%s for `%T%s'", problem
, error_type (arg1
), opname
);
2418 cp_error ("%s for `%T[%T]'", problem
,
2419 error_type (arg1
), error_type (arg2
));
2423 cp_error ("%s for `%T %s %T'", problem
,
2424 error_type (arg1
), opname
, error_type (arg2
));
2426 cp_error ("%s for `%s%T'", problem
, opname
, error_type (arg1
));
2431 build_new_op (code
, flags
, arg1
, arg2
, arg3
)
2432 enum tree_code code
;
2434 tree arg1
, arg2
, arg3
;
2436 struct z_candidate
*candidates
= 0, *cand
;
2437 tree fns
, mem_arglist
= NULL_TREE
, arglist
, fnname
;
2438 enum tree_code code2
= NOP_EXPR
;
2439 tree templates
= NULL_TREE
;
2442 if (arg1
== error_mark_node
2443 || arg2
== error_mark_node
2444 || arg3
== error_mark_node
)
2445 return error_mark_node
;
2447 /* This can happen if a template takes all non-type parameters, e.g.
2448 undeclared_template<1, 5, 72>a; */
2449 if (code
== LT_EXPR
&& TREE_CODE (arg1
) == TEMPLATE_DECL
)
2451 cp_error ("`%D' must be declared before use", arg1
);
2452 return error_mark_node
;
2455 if (code
== MODIFY_EXPR
)
2457 code2
= TREE_CODE (arg3
);
2459 fnname
= ansi_assopname
[code2
];
2462 fnname
= ansi_opname
[code
];
2471 arglist
= scratch_tree_cons (NULL_TREE
, arg2
, arg3
);
2472 if (flags
& LOOKUP_GLOBAL
)
2473 return build_new_function_call
2474 (lookup_name_nonclass (fnname
), arglist
);
2477 rval
= build_method_call
2478 (build_indirect_ref (build1 (NOP_EXPR
, arg1
, error_mark_node
),
2480 fnname
, arglist
, NULL_TREE
, flags
);
2481 if (rval
== error_mark_node
)
2482 /* User might declare fancy operator new, but invoke it
2483 like standard one. */
2486 TREE_TYPE (rval
) = arg1
;
2490 case VEC_DELETE_EXPR
:
2495 if (flags
& LOOKUP_GLOBAL
)
2496 return build_new_function_call
2497 (lookup_name_nonclass (fnname
),
2498 build_scratch_list (NULL_TREE
, arg1
));
2500 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, build_scratch_list (NULL_TREE
, arg2
));
2502 arg1
= TREE_TYPE (arg1
);
2504 /* This handles the case where we're trying to delete
2509 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
2511 /* Strip off the pointer and the array. */
2512 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
2514 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
2515 arg1
= (TREE_TYPE (arg1
));
2517 arg1
= build_pointer_type (arg1
);
2521 rval
= build_method_call
2522 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
2525 fnname
, arglist
, NULL_TREE
, flags
);
2527 /* This can happen when operator delete is protected. */
2528 my_friendly_assert (rval
!= error_mark_node
, 250);
2529 TREE_TYPE (rval
) = void_type_node
;
2535 return build_object_call (arg1
, arg2
);
2541 /* The comma operator can have void args. */
2542 if (TREE_CODE (arg1
) == OFFSET_REF
)
2543 arg1
= resolve_offset_ref (arg1
);
2544 if (arg2
&& TREE_CODE (arg2
) == OFFSET_REF
)
2545 arg2
= resolve_offset_ref (arg2
);
2546 if (arg3
&& TREE_CODE (arg3
) == OFFSET_REF
)
2547 arg3
= resolve_offset_ref (arg3
);
2549 if (code
== COND_EXPR
)
2551 if (arg2
== NULL_TREE
2552 || TREE_CODE (TREE_TYPE (arg2
)) == VOID_TYPE
2553 || TREE_CODE (TREE_TYPE (arg3
)) == VOID_TYPE
2554 || (! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))
2555 && ! IS_OVERLOAD_TYPE (TREE_TYPE (arg3
))))
2558 else if (! IS_OVERLOAD_TYPE (TREE_TYPE (arg1
))
2559 && (! arg2
|| ! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))))
2562 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
2563 arg2
= integer_zero_node
;
2566 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, scratch_tree_cons
2567 (NULL_TREE
, arg2
, build_scratch_list (NULL_TREE
, arg3
)));
2569 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, build_scratch_list (NULL_TREE
, arg2
));
2571 arglist
= build_scratch_list (NULL_TREE
, arg1
);
2573 fns
= lookup_name_nonclass (fnname
);
2574 /* + Koenig lookup */
2576 if (fns
&& TREE_CODE (fns
) == TREE_LIST
)
2577 fns
= TREE_VALUE (fns
);
2578 for (; fns
; fns
= DECL_CHAIN (fns
))
2580 if (TREE_CODE (fns
) == TEMPLATE_DECL
)
2582 templates
= scratch_tree_cons (NULL_TREE
, fns
, templates
);
2584 = add_template_candidate (candidates
, fns
, NULL_TREE
,
2585 arglist
, TREE_TYPE (fnname
),
2589 candidates
= add_function_candidate (candidates
, fns
, arglist
, flags
);
2592 if (IS_AGGR_TYPE (TREE_TYPE (arg1
)))
2594 fns
= lookup_fnfields (TYPE_BINFO (TREE_TYPE (arg1
)), fnname
, 1);
2595 if (fns
== error_mark_node
)
2603 tree fn
= TREE_VALUE (fns
);
2604 mem_arglist
= scratch_tree_cons (NULL_TREE
, build_this (arg1
), TREE_CHAIN (arglist
));
2605 for (; fn
; fn
= DECL_CHAIN (fn
))
2609 if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
2610 this_arglist
= mem_arglist
;
2612 this_arglist
= arglist
;
2614 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
2616 /* A member template. */
2617 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
2619 = add_template_candidate (candidates
, fn
, NULL_TREE
,
2620 this_arglist
, TREE_TYPE (fnname
),
2624 candidates
= add_function_candidate
2625 (candidates
, fn
, this_arglist
, flags
);
2628 candidates
->basetype_path
= TREE_PURPOSE (fns
);
2635 /* Rearrange the arguments for ?: so that add_builtin_candidate only has
2636 to know about two args; a builtin candidate will always have a first
2637 parameter of type bool. We'll handle that in
2638 build_builtin_candidate. */
2639 if (code
== COND_EXPR
)
2649 args
[2] = NULL_TREE
;
2652 candidates
= add_builtin_candidates
2653 (candidates
, code
, code2
, fnname
, args
, flags
);
2656 if (! any_viable (candidates
))
2660 case POSTINCREMENT_EXPR
:
2661 case POSTDECREMENT_EXPR
:
2662 /* Look for an `operator++ (int)'. If they didn't have
2663 one, then we fall back to the old way of doing things. */
2664 if (flags
& LOOKUP_COMPLAIN
)
2665 cp_pedwarn ("no `%D (int)' declared for postfix `%s', trying prefix operator instead",
2666 fnname
, opname_tab
[code
]);
2667 if (code
== POSTINCREMENT_EXPR
)
2668 code
= PREINCREMENT_EXPR
;
2670 code
= PREDECREMENT_EXPR
;
2671 return build_new_op (code
, flags
, arg1
, NULL_TREE
, NULL_TREE
);
2673 /* The caller will deal with these. */
2682 if (flags
& LOOKUP_COMPLAIN
)
2684 op_error (code
, code2
, arg1
, arg2
, arg3
, "no match");
2685 print_z_candidates (candidates
);
2687 return error_mark_node
;
2689 candidates
= splice_viable (candidates
);
2690 cand
= tourney (candidates
);
2694 if (flags
& LOOKUP_COMPLAIN
)
2696 op_error (code
, code2
, arg1
, arg2
, arg3
, "ambiguous overload");
2697 print_z_candidates (candidates
);
2699 return error_mark_node
;
2702 if (TREE_CODE (cand
->fn
) == FUNCTION_DECL
)
2704 extern int warn_synth
;
2706 && fnname
== ansi_opname
[MODIFY_EXPR
]
2707 && DECL_ARTIFICIAL (cand
->fn
)
2709 && ! candidates
->next
->next
)
2711 cp_warning ("using synthesized `%#D' for copy assignment",
2713 cp_warning_at (" where cfront would use `%#D'",
2715 ? candidates
->next
->fn
2719 /* Pedantically, normal function declarations are never considered
2720 to refer to template instantiations, so we only do this with
2722 if (flag_guiding_decls
&& templates
&& ! cand
->template
2723 && ! DECL_INITIAL (cand
->fn
)
2724 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
2725 add_maybe_template (cand
->fn
, templates
);
2727 return build_over_call
2729 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
2730 ? mem_arglist
: arglist
,
2734 /* Check for comparison of different enum types. */
2743 if (flag_int_enum_equivalence
== 0
2744 && TREE_CODE (TREE_TYPE (arg1
)) == ENUMERAL_TYPE
2745 && TREE_CODE (TREE_TYPE (arg2
)) == ENUMERAL_TYPE
2746 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg1
))
2747 != TYPE_MAIN_VARIANT (TREE_TYPE (arg2
))))
2749 cp_warning ("comparison between `%#T' and `%#T'",
2750 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
2757 /* We need to strip any leading REF_BIND so that bitfields don't cause
2758 errors. This should not remove any important conversions, because
2759 builtins don't apply to class objects directly. */
2760 conv
= TREE_VEC_ELT (cand
->convs
, 0);
2761 if (TREE_CODE (conv
) == REF_BIND
)
2762 conv
= TREE_OPERAND (conv
, 0);
2763 arg1
= convert_like (conv
, arg1
);
2765 arg2
= convert_like (TREE_VEC_ELT (cand
->convs
, 1), arg2
);
2767 arg3
= convert_like (TREE_VEC_ELT (cand
->convs
, 2), arg3
);
2773 return build_modify_expr (arg1
, code2
, arg2
);
2776 return build_indirect_ref (arg1
, "unary *");
2781 case TRUNC_DIV_EXPR
:
2792 case TRUNC_MOD_EXPR
:
2796 case TRUTH_ANDIF_EXPR
:
2797 case TRUTH_ORIF_EXPR
:
2798 return build_binary_op_nodefault (code
, arg1
, arg2
, code
);
2803 case TRUTH_NOT_EXPR
:
2804 case PREINCREMENT_EXPR
:
2805 case POSTINCREMENT_EXPR
:
2806 case PREDECREMENT_EXPR
:
2807 case POSTDECREMENT_EXPR
:
2810 return build_unary_op (code
, arg1
, candidates
!= 0);
2813 return build_array_ref (arg1
, arg2
);
2816 return build_conditional_expr (arg1
, arg2
, arg3
);
2819 return build_m_component_ref
2820 (build_indirect_ref (arg1
, NULL_PTR
), arg2
);
2822 /* The caller will deal with these. */
2829 my_friendly_abort (367);
2834 /* Build up a call to operator new. This has to be handled differently
2835 from other operators in the way lookup is handled; first members are
2836 considered, then globals. CODE is either NEW_EXPR or VEC_NEW_EXPR.
2837 TYPE is the type to be created. ARGS are any new-placement args.
2838 FLAGS are the usual overloading flags. */
2841 build_op_new_call (code
, type
, args
, flags
)
2842 enum tree_code code
;
2846 tree fnname
= ansi_opname
[code
];
2848 if (IS_AGGR_TYPE (type
) && ! (flags
& LOOKUP_GLOBAL
)
2849 && (TYPE_GETS_NEW (type
) & (1 << (code
== VEC_NEW_EXPR
))))
2851 tree dummy
= build1 (NOP_EXPR
, build_pointer_type (type
),
2853 dummy
= build_indirect_ref (dummy
, "new");
2854 return build_method_call (dummy
, fnname
, args
, NULL_TREE
, flags
);
2857 return build_new_function_call (lookup_name_nonclass (fnname
), args
);
2860 /* Build a call to operator delete. This has to be handled very specially,
2861 because the restrictions on what signatures match are different from all
2862 other call instances. For a normal delete, only a delete taking (void *)
2863 or (void *, size_t) is accepted. For a placement delete, only an exact
2864 match with the placement new is accepted.
2866 CODE is either DELETE_EXPR or VEC_DELETE_EXPR.
2867 ADDR is the pointer to be deleted. For placement delete, it is also
2868 used to determine what the corresponding new looked like.
2869 SIZE is the size of the memory block to be deleted.
2870 FLAGS are the usual overloading flags. */
2873 build_op_delete_call (code
, addr
, size
, flags
)
2874 enum tree_code code
;
2878 tree fn
, fns
, fnname
, fntype
, argtypes
, args
, type
;
2881 if (addr
== error_mark_node
)
2882 return error_mark_node
;
2884 type
= TREE_TYPE (TREE_TYPE (addr
));
2885 fnname
= ansi_opname
[code
];
2887 if (IS_AGGR_TYPE (type
) && ! (flags
& LOOKUP_GLOBAL
))
2890 If the result of the lookup is ambiguous or inaccessible, or if
2891 the lookup selects a placement deallocation function, the
2892 program is ill-formed.
2894 Therefore, we ask lookup_fnfields to complain ambout ambiguity. */
2896 fns
= lookup_fnfields (TYPE_BINFO (type
), fnname
, 1);
2897 if (fns
== error_mark_node
)
2898 return error_mark_node
;
2905 /* Build this up like build_offset_ref does. */
2906 fns
= build_tree_list (error_mark_node
, fns
);
2907 TREE_TYPE (fns
) = build_offset_type (type
, unknown_type_node
);
2910 fns
= lookup_name_nonclass (fnname
);
2912 /* We can recognize a placement delete because of LOOKUP_SPECULATIVELY;
2913 if we are doing placement delete we do nothing if we don't find a
2914 matching op delete. */
2915 placement
= !!(flags
& LOOKUP_SPECULATIVELY
);
2918 /* If placement, we are coming from build_new, and we know that addr
2919 is the allocation expression, so extract the info we need from it.
2920 Obviously, if the build_new process changes this may have to
2924 tree t
= TREE_OPERAND (addr
, 1);
2925 /* The CALL_EXPR. */
2926 t
= TREE_OPERAND (t
, 0);
2928 argtypes
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
2929 /* The second parm type. */
2930 argtypes
= TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (argtypes
)));
2931 /* The second argument. */
2932 args
= TREE_CHAIN (TREE_OPERAND (t
, 1));
2934 /* Pull the dummy var out of the TARGET_EXPR for use in our call. */
2935 addr
= TREE_OPERAND (addr
, 0);
2939 /* First try it without the size argument. */
2940 argtypes
= void_list_node
;
2944 argtypes
= tree_cons (NULL_TREE
, ptr_type_node
, argtypes
);
2945 fntype
= build_function_type (void_type_node
, argtypes
);
2947 /* Strip const and volatile from addr. */
2948 if (type
!= TYPE_MAIN_VARIANT (type
))
2949 addr
= cp_convert (build_pointer_type (TYPE_MAIN_VARIANT (type
)), addr
);
2951 /* instantiate_type will always return a plain function; pretend it's
2953 if (TREE_CODE (fns
) == FUNCTION_DECL
)
2954 fns
= scratch_tree_cons (NULL_TREE
, fns
, NULL_TREE
);
2956 fn
= instantiate_type (fntype
, fns
, 0);
2958 if (fn
!= error_mark_node
)
2960 if (TREE_CODE (TREE_VALUE (fns
)) == TREE_LIST
)
2961 /* Member functions. */
2962 enforce_access (TREE_PURPOSE (TREE_VALUE (fns
)), fn
);
2963 return build_function_call (fn
, expr_tree_cons (NULL_TREE
, addr
, args
));
2969 /* Normal delete; now try to find a match including the size argument. */
2970 argtypes
= tree_cons (NULL_TREE
, ptr_type_node
,
2971 tree_cons (NULL_TREE
, sizetype
, void_list_node
));
2972 fntype
= build_function_type (void_type_node
, argtypes
);
2974 fn
= instantiate_type (fntype
, fns
, 0);
2976 if (fn
!= error_mark_node
)
2977 return build_function_call
2978 (fn
, expr_tree_cons (NULL_TREE
, addr
,
2979 build_expr_list (NULL_TREE
, size
)));
2981 cp_error ("no suitable operator delete for `%T'", type
);
2982 return error_mark_node
;
2985 /* If the current scope isn't allowed to access DECL along
2986 BASETYPE_PATH, give an error. */
2989 enforce_access (basetype_path
, decl
)
2990 tree basetype_path
, decl
;
2992 tree access
= compute_access (basetype_path
, decl
);
2994 if (access
== access_private_node
)
2996 cp_error_at ("`%+#D' is %s", decl
,
2997 TREE_PRIVATE (decl
) ? "private"
2998 : "from private base class");
2999 error ("within this context");
3001 else if (access
== access_protected_node
)
3003 cp_error_at ("`%+#D' %s", decl
,
3004 TREE_PROTECTED (decl
) ? "is protected"
3005 : "has protected accessibility");
3006 error ("within this context");
3010 /* Perform the conversions in CONVS on the expression EXPR. */
3013 convert_like (convs
, expr
)
3016 if (ICS_BAD_FLAG (convs
)
3017 && TREE_CODE (convs
) != USER_CONV
3018 && TREE_CODE (convs
) != AMBIG_CONV
)
3021 for (; t
; t
= TREE_OPERAND (t
, 0))
3023 if (TREE_CODE (t
) == USER_CONV
)
3025 expr
= convert_like (t
, expr
);
3028 else if (TREE_CODE (t
) == AMBIG_CONV
)
3029 return convert_like (t
, expr
);
3030 else if (TREE_CODE (t
) == IDENTITY_CONV
)
3033 return convert_for_initialization
3034 (NULL_TREE
, TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
,
3035 "conversion", NULL_TREE
, 0);
3038 switch (TREE_CODE (convs
))
3042 struct z_candidate
*cand
3043 = WRAPPER_PTR (TREE_OPERAND (convs
, 1));
3047 if (DECL_CONSTRUCTOR_P (fn
))
3049 tree t
= build_int_2 (0, 0);
3050 TREE_TYPE (t
) = build_pointer_type (DECL_CONTEXT (fn
));
3052 args
= build_scratch_list (NULL_TREE
, expr
);
3053 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3054 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
3055 args
= scratch_tree_cons (NULL_TREE
, t
, args
);
3058 args
= build_this (expr
);
3059 expr
= build_over_call (cand
, args
, LOOKUP_NORMAL
);
3061 /* If this is a constructor or a function returning an aggr type,
3062 we need to build up a TARGET_EXPR. */
3063 if (DECL_CONSTRUCTOR_P (fn
))
3064 expr
= build_cplus_new (TREE_TYPE (convs
), expr
);
3069 if (type_unknown_p (expr
))
3070 expr
= instantiate_type (TREE_TYPE (convs
), expr
, 1);
3071 if (TREE_READONLY_DECL_P (expr
))
3072 expr
= decl_constant_value (expr
);
3075 /* Call build_user_type_conversion again for the error. */
3076 return build_user_type_conversion
3077 (TREE_TYPE (convs
), TREE_OPERAND (convs
, 0), LOOKUP_NORMAL
);
3083 expr
= convert_like (TREE_OPERAND (convs
, 0), expr
);
3084 if (expr
== error_mark_node
)
3085 return error_mark_node
;
3087 switch (TREE_CODE (convs
))
3090 if (! IS_AGGR_TYPE (TREE_TYPE (convs
)))
3092 /* else fall through */
3094 return build_user_type_conversion
3095 (TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
);
3097 return convert_to_reference
3098 (TREE_TYPE (convs
), expr
,
3099 CONV_IMPLICIT
, LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
,
3102 return decay_conversion (expr
);
3107 return ocp_convert (TREE_TYPE (convs
), expr
, CONV_IMPLICIT
,
3108 LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
);
3112 convert_default_arg (type
, arg
)
3115 arg
= break_out_target_exprs (arg
);
3117 if (TREE_CODE (arg
) == CONSTRUCTOR
)
3119 arg
= digest_init (type
, arg
, 0);
3120 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
3121 "default argument", 0, 0);
3125 /* This could get clobbered by the following call. */
3126 if (TREE_HAS_CONSTRUCTOR (arg
))
3127 arg
= copy_node (arg
);
3129 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
3130 "default argument", 0, 0);
3131 #ifdef PROMOTE_PROTOTYPES
3132 if ((TREE_CODE (type
) == INTEGER_TYPE
3133 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3134 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
3135 arg
= default_conversion (arg
);
3143 build_over_call (cand
, args
, flags
)
3144 struct z_candidate
*cand
;
3149 tree convs
= cand
->convs
;
3150 tree converted_args
= NULL_TREE
;
3151 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
3152 tree conv
, arg
, val
;
3156 /* Give any warnings we noticed during overload resolution. */
3158 for (val
= cand
->warnings
; val
; val
= TREE_CHAIN (val
))
3159 joust (cand
, WRAPPER_PTR (TREE_VALUE (val
)), 1);
3161 if (DECL_FUNCTION_MEMBER_P (fn
))
3162 enforce_access (cand
->basetype_path
, fn
);
3164 if (args
&& TREE_CODE (args
) != TREE_LIST
)
3165 args
= build_scratch_list (NULL_TREE
, args
);
3168 /* The implicit parameters to a constructor are not considered by overload
3169 resolution, and must be of the proper type. */
3170 if (DECL_CONSTRUCTOR_P (fn
))
3172 converted_args
= expr_tree_cons (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
3173 arg
= TREE_CHAIN (arg
);
3174 parm
= TREE_CHAIN (parm
);
3175 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3177 converted_args
= expr_tree_cons
3178 (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
3179 arg
= TREE_CHAIN (arg
);
3180 parm
= TREE_CHAIN (parm
);
3183 /* Bypass access control for 'this' parameter. */
3184 else if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
3186 tree parmtype
= TREE_VALUE (parm
);
3187 tree argtype
= TREE_TYPE (TREE_VALUE (arg
));
3188 if (ICS_BAD_FLAG (TREE_VEC_ELT (convs
, i
)))
3190 int dv
= (TYPE_VOLATILE (TREE_TYPE (parmtype
))
3191 < TYPE_VOLATILE (TREE_TYPE (argtype
)));
3192 int dc
= (TYPE_READONLY (TREE_TYPE (parmtype
))
3193 < TYPE_READONLY (TREE_TYPE (argtype
)));
3194 char *p
= (dv
&& dc
? "const and volatile"
3195 : dc
? "const" : dv
? "volatile" : "");
3197 cp_pedwarn ("passing `%T' as `this' argument of `%#D' discards %s",
3198 TREE_TYPE (argtype
), fn
, p
);
3200 converted_args
= expr_tree_cons
3201 (NULL_TREE
, convert_force (TREE_VALUE (parm
), TREE_VALUE (arg
), CONV_C_CAST
),
3203 parm
= TREE_CHAIN (parm
);
3204 arg
= TREE_CHAIN (arg
);
3210 parm
= TREE_CHAIN (parm
), arg
= TREE_CHAIN (arg
), ++i
)
3212 tree type
= TREE_VALUE (parm
);
3214 conv
= TREE_VEC_ELT (convs
, i
);
3215 if (ICS_BAD_FLAG (conv
))
3218 val
= TREE_VALUE (arg
);
3220 for (; t
; t
= TREE_OPERAND (t
, 0))
3222 if (TREE_CODE (t
) == USER_CONV
3223 || TREE_CODE (t
) == AMBIG_CONV
)
3225 val
= convert_like (t
, val
);
3228 else if (TREE_CODE (t
) == IDENTITY_CONV
)
3231 val
= convert_for_initialization
3232 (NULL_TREE
, type
, val
, LOOKUP_NORMAL
,
3233 "argument passing", fn
, i
- is_method
);
3236 val
= convert_like (conv
, TREE_VALUE (arg
));
3238 #ifdef PROMOTE_PROTOTYPES
3239 if ((TREE_CODE (type
) == INTEGER_TYPE
3240 || TREE_CODE (type
) == ENUMERAL_TYPE
)
3241 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
3242 val
= default_conversion (val
);
3244 converted_args
= expr_tree_cons (NULL_TREE
, val
, converted_args
);
3247 /* Default arguments */
3248 for (; parm
&& parm
!= void_list_node
; parm
= TREE_CHAIN (parm
))
3250 tree arg
= TREE_PURPOSE (parm
);
3252 if (DECL_TEMPLATE_INFO (fn
))
3254 /* This came from a template. Instantiate the default arg here,
3255 not in tsubst. In the case of something like:
3263 we must be careful to do name lookup in the scope of
3264 S<T>, rather than in the current class. */
3265 if (DECL_REAL_CONTEXT (fn
))
3266 pushclass (DECL_REAL_CONTEXT (fn
), 2);
3268 arg
= tsubst_expr (arg
, DECL_TI_ARGS (fn
), NULL_TREE
);
3270 if (DECL_REAL_CONTEXT (fn
))
3273 converted_args
= expr_tree_cons
3274 (NULL_TREE
, convert_default_arg (TREE_VALUE (parm
), arg
),
3279 for (; arg
; arg
= TREE_CHAIN (arg
))
3281 val
= TREE_VALUE (arg
);
3283 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
3284 && (TYPE_PRECISION (TREE_TYPE (val
))
3285 < TYPE_PRECISION (double_type_node
)))
3286 /* Convert `float' to `double'. */
3287 val
= cp_convert (double_type_node
, val
);
3288 else if (IS_AGGR_TYPE (TREE_TYPE (val
))
3289 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
3290 cp_warning ("cannot pass objects of type `%T' through `...'",
3293 /* Convert `short' and `char' to full-size `int'. */
3294 val
= default_conversion (val
);
3296 converted_args
= expr_tree_cons (NULL_TREE
, val
, converted_args
);
3299 converted_args
= nreverse (converted_args
);
3301 /* Avoid actually calling copy constructors and copy assignment operators,
3303 if (DECL_CONSTRUCTOR_P (fn
)
3304 && TREE_VEC_LENGTH (convs
) == 1
3305 && copy_args_p (fn
))
3308 arg
= TREE_CHAIN (converted_args
);
3309 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3310 arg
= TREE_CHAIN (arg
);
3311 arg
= TREE_VALUE (arg
);
3313 /* Pull out the real argument, disregarding const-correctness. */
3315 while (TREE_CODE (targ
) == NOP_EXPR
3316 || TREE_CODE (targ
) == NON_LVALUE_EXPR
3317 || TREE_CODE (targ
) == CONVERT_EXPR
)
3318 targ
= TREE_OPERAND (targ
, 0);
3319 if (TREE_CODE (targ
) == ADDR_EXPR
)
3321 targ
= TREE_OPERAND (targ
, 0);
3322 if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg
))),
3323 TYPE_MAIN_VARIANT (TREE_TYPE (targ
)), 1))
3332 arg
= build_indirect_ref (arg
, 0);
3334 /* [class.copy]: the copy constructor is implicitly defined even if
3335 the implementation elided its use. */
3336 if (TYPE_HAS_COMPLEX_INIT_REF (DECL_CONTEXT (fn
)))
3339 /* If we're creating a temp and we already have one, don't create a
3340 new one. If we're not creating a temp but we get one, use
3341 INIT_EXPR to collapse the temp into our target. Otherwise, if the
3342 ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
3343 temp or an INIT_EXPR otherwise. */
3344 if (integer_zerop (TREE_VALUE (args
)))
3346 if (! real_lvalue_p (arg
))
3348 else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
3350 val
= build (VAR_DECL
, DECL_CONTEXT (fn
));
3351 layout_decl (val
, 0);
3352 val
= build (TARGET_EXPR
, DECL_CONTEXT (fn
), val
, arg
, 0, 0);
3353 TREE_SIDE_EFFECTS (val
) = 1;
3357 else if (! real_lvalue_p (arg
)
3358 || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
3360 tree to
= stabilize_reference
3361 (build_indirect_ref (TREE_VALUE (args
), 0));
3363 /* Don't copy the padding byte; it might not have been allocated
3364 if to is a base subobject. */
3365 if (is_empty_class (DECL_CLASS_CONTEXT (fn
)))
3368 val
= build (INIT_EXPR
, DECL_CONTEXT (fn
), to
, arg
);
3369 TREE_SIDE_EFFECTS (val
) = 1;
3370 return build_unary_op (ADDR_EXPR
, val
, 0);
3373 else if (DECL_NAME (fn
) == ansi_opname
[MODIFY_EXPR
]
3375 && TYPE_HAS_TRIVIAL_ASSIGN_REF (DECL_CLASS_CONTEXT (fn
)))
3377 tree to
= stabilize_reference
3378 (build_indirect_ref (TREE_VALUE (converted_args
), 0));
3380 /* Don't copy the padding byte; it might not have been allocated
3381 if to is a base subobject. */
3382 if (is_empty_class (DECL_CLASS_CONTEXT (fn
)))
3385 arg
= build_indirect_ref (TREE_VALUE (TREE_CHAIN (converted_args
)), 0);
3386 val
= build (MODIFY_EXPR
, TREE_TYPE (to
), to
, arg
);
3387 TREE_SIDE_EFFECTS (val
) = 1;
3393 if (DECL_CONTEXT (fn
) && IS_SIGNATURE (DECL_CONTEXT (fn
)))
3394 return build_signature_method_call (fn
, converted_args
);
3395 else if (DECL_VINDEX (fn
) && (flags
& LOOKUP_NONVIRTUAL
) == 0)
3397 tree t
, *p
= &TREE_VALUE (converted_args
);
3398 tree binfo
= get_binfo
3399 (DECL_CONTEXT (fn
), TREE_TYPE (TREE_TYPE (*p
)), 0);
3400 *p
= convert_pointer_to_real (binfo
, *p
);
3401 if (TREE_SIDE_EFFECTS (*p
))
3402 *p
= save_expr (*p
);
3403 t
= build_pointer_type (TREE_TYPE (fn
));
3404 fn
= build_vfn_ref (p
, build_indirect_ref (*p
, 0), DECL_VINDEX (fn
));
3407 else if (DECL_INLINE (fn
))
3408 fn
= inline_conversion (fn
);
3410 fn
= build_addr_func (fn
);
3412 /* Recognize certain built-in functions so we can make tree-codes
3413 other than CALL_EXPR. We do this when it enables fold-const.c
3414 to do something useful. */
3416 if (TREE_CODE (fn
) == ADDR_EXPR
3417 && TREE_CODE (TREE_OPERAND (fn
, 0)) == FUNCTION_DECL
3418 && DECL_BUILT_IN (TREE_OPERAND (fn
, 0)))
3419 switch (DECL_FUNCTION_CODE (TREE_OPERAND (fn
, 0)))
3424 if (converted_args
== 0)
3425 return integer_zero_node
;
3426 return build_unary_op (ABS_EXPR
, TREE_VALUE (converted_args
), 0);
3431 fn
= build_call (fn
, TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))), converted_args
);
3432 if (TREE_TYPE (fn
) == void_type_node
)
3434 fn
= require_complete_type (fn
);
3435 if (IS_AGGR_TYPE (TREE_TYPE (fn
)))
3436 fn
= build_cplus_new (TREE_TYPE (fn
), fn
);
3437 return convert_from_reference (fn
);
3441 build_new_method_call (instance
, name
, args
, basetype_path
, flags
)
3442 tree instance
, name
, args
, basetype_path
;
3445 struct z_candidate
*candidates
= 0, *cand
;
3446 tree explicit_targs
= NULL_TREE
;
3447 tree basetype
, mem_args
= NULL_TREE
, fns
, instance_ptr
;
3449 tree user_args
= args
;
3450 tree templates
= NULL_TREE
;
3451 int template_only
= 0;
3453 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
3455 explicit_targs
= TREE_OPERAND (name
, 1);
3456 name
= TREE_OPERAND (name
, 0);
3457 if (TREE_CODE (name
) == TEMPLATE_DECL
)
3458 name
= DECL_NAME (name
);
3462 /* If there is an extra argument for controlling virtual bases,
3463 remove it for error reporting. */
3464 if (flags
& LOOKUP_HAS_IN_CHARGE
)
3465 user_args
= TREE_CHAIN (args
);
3467 args
= resolve_args (args
);
3469 if (args
== error_mark_node
)
3470 return error_mark_node
;
3472 if (instance
== NULL_TREE
)
3473 basetype
= BINFO_TYPE (basetype_path
);
3476 if (TREE_CODE (instance
) == OFFSET_REF
)
3477 instance
= resolve_offset_ref (instance
);
3478 if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
3479 instance
= convert_from_reference (instance
);
3480 basetype
= TREE_TYPE (instance
);
3482 /* XXX this should be handled before we get here. */
3483 if (! IS_AGGR_TYPE (basetype
)
3484 && ! (TYPE_LANG_SPECIFIC (basetype
)
3485 && (IS_SIGNATURE_POINTER (basetype
)
3486 || IS_SIGNATURE_REFERENCE (basetype
))))
3488 if ((flags
& LOOKUP_COMPLAIN
) && basetype
!= error_mark_node
)
3489 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
3490 name
, instance
, basetype
);
3492 return error_mark_node
;
3495 /* If `instance' is a signature pointer/reference and `name' is
3496 not a constructor, we are calling a signature member function.
3497 In that case set the `basetype' to the signature type. */
3498 if ((IS_SIGNATURE_POINTER (basetype
)
3499 || IS_SIGNATURE_REFERENCE (basetype
))
3500 && TYPE_IDENTIFIER (basetype
) != name
)
3501 basetype
= SIGNATURE_TYPE (basetype
);
3504 if (basetype_path
== NULL_TREE
)
3505 basetype_path
= TYPE_BINFO (basetype
);
3509 instance_ptr
= build_this (instance
);
3511 if (! template_only
)
3513 /* XXX this should be handled before we get here. */
3514 fns
= build_field_call (basetype_path
, instance_ptr
, name
, args
);
3521 instance_ptr
= build_int_2 (0, 0);
3522 TREE_TYPE (instance_ptr
) = build_pointer_type (basetype
);
3526 = (name
== ctor_identifier
? constructor_name (basetype
) : name
);
3528 fns
= lookup_fnfields (basetype_path
, name
, 1);
3530 if (fns
== error_mark_node
)
3531 return error_mark_node
;
3534 tree t
= TREE_VALUE (fns
);
3535 if (name
== ctor_identifier
&& TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
3536 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
3538 flags
|= LOOKUP_HAS_IN_CHARGE
;
3539 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
3541 mem_args
= scratch_tree_cons (NULL_TREE
, instance_ptr
, args
);
3542 for (; t
; t
= DECL_CHAIN (t
))
3546 /* We can end up here for copy-init of same or base class. */
3547 if (name
== ctor_identifier
3548 && (flags
& LOOKUP_ONLYCONVERTING
)
3549 && DECL_NONCONVERTING_P (t
))
3551 if (TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)
3552 this_arglist
= mem_args
;
3554 this_arglist
= args
;
3556 if (TREE_CODE (t
) == TEMPLATE_DECL
)
3558 /* A member template. */
3559 templates
= scratch_tree_cons (NULL_TREE
, t
, templates
);
3561 add_template_candidate (candidates
, t
, explicit_targs
,
3563 TREE_TYPE (name
), flags
);
3565 else if (! template_only
)
3566 candidates
= add_function_candidate (candidates
, t
,
3567 this_arglist
, flags
);
3570 candidates
->basetype_path
= TREE_PURPOSE (fns
);
3574 if (! any_viable (candidates
))
3576 /* XXX will LOOKUP_SPECULATIVELY be needed when this is done? */
3577 if (flags
& LOOKUP_SPECULATIVELY
)
3579 cp_error ("no matching function for call to `%T::%D (%A)%V'", basetype
,
3580 pretty_name
, user_args
, TREE_TYPE (TREE_TYPE (instance_ptr
)));
3581 print_z_candidates (candidates
);
3582 return error_mark_node
;
3584 candidates
= splice_viable (candidates
);
3585 cand
= tourney (candidates
);
3589 cp_error ("call of overloaded `%D(%A)' is ambiguous", pretty_name
,
3591 print_z_candidates (candidates
);
3592 return error_mark_node
;
3595 if (DECL_ABSTRACT_VIRTUAL_P (cand
->fn
)
3596 && instance
== current_class_ref
3597 && DECL_CONSTRUCTOR_P (current_function_decl
)
3598 && ! (flags
& LOOKUP_NONVIRTUAL
)
3599 && value_member (cand
->fn
, get_abstract_virtuals (basetype
)))
3600 cp_error ("abstract virtual `%#D' called from constructor", cand
->fn
);
3601 if (TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
3602 && TREE_CODE (instance_ptr
) == NOP_EXPR
3603 && TREE_OPERAND (instance_ptr
, 0) == error_mark_node
)
3604 cp_error ("cannot call member function `%D' without object", cand
->fn
);
3606 if (DECL_VINDEX (cand
->fn
) && ! (flags
& LOOKUP_NONVIRTUAL
)
3607 && ((instance
== current_class_ref
&& (dtor_label
|| ctor_label
))
3608 || resolves_to_fixed_type_p (instance
, 0)))
3609 flags
|= LOOKUP_NONVIRTUAL
;
3611 /* Pedantically, normal function declarations are never considered
3612 to refer to template instantiations, so we only do this with
3614 if (flag_guiding_decls
&& templates
&& ! cand
->template
3615 && ! DECL_INITIAL (cand
->fn
))
3616 add_maybe_template (cand
->fn
, templates
);
3618 return build_over_call
3620 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
? mem_args
: args
,
3624 /* Compare two implicit conversion sequences that differ only in their
3625 qualification conversion. Subroutine of compare_ics. */
3628 compare_qual (ics1
, ics2
)
3631 tree to1
= TREE_TYPE (ics1
);
3632 tree to2
= TREE_TYPE (ics2
);
3634 if (TYPE_PTRMEMFUNC_P (to1
))
3635 to1
= TYPE_PTRMEMFUNC_FN_TYPE (to1
);
3636 if (TYPE_PTRMEMFUNC_P (to2
))
3637 to2
= TYPE_PTRMEMFUNC_FN_TYPE (to2
);
3639 to1
= TREE_TYPE (to1
);
3640 to2
= TREE_TYPE (to2
);
3642 if (TREE_CODE (to1
) == OFFSET_TYPE
)
3644 to1
= TREE_TYPE (to1
);
3645 to2
= TREE_TYPE (to2
);
3648 if (TYPE_READONLY (to1
) >= TYPE_READONLY (to2
)
3649 && TYPE_VOLATILE (to1
) > TYPE_VOLATILE (to2
))
3651 else if (TYPE_READONLY (to1
) > TYPE_READONLY (to2
)
3652 && TYPE_VOLATILE (to1
) == TYPE_VOLATILE (to2
))
3654 else if (TYPE_READONLY (to1
) <= TYPE_READONLY (to2
)
3655 && TYPE_VOLATILE (to1
) < TYPE_VOLATILE (to2
))
3657 else if (TYPE_READONLY (to1
) < TYPE_READONLY (to2
)
3658 && TYPE_VOLATILE (to1
) == TYPE_VOLATILE (to2
))
3663 /* Determine whether standard conversion sequence ICS1 is a proper
3664 subsequence of ICS2. We assume that a conversion of the same code
3665 between the same types indicates a subsequence. */
3668 is_subseq (ics1
, ics2
)
3671 /* Do not consider lvalue transformations here. */
3672 if (TREE_CODE (ics2
) == RVALUE_CONV
3673 || TREE_CODE (ics2
) == LVALUE_CONV
)
3676 for (;; ics2
= TREE_OPERAND (ics2
, 0))
3678 if (TREE_CODE (ics2
) == TREE_CODE (ics1
)
3679 && comptypes (TREE_TYPE (ics2
), TREE_TYPE (ics1
), 1)
3680 && comptypes (TREE_TYPE (TREE_OPERAND (ics2
, 0)),
3681 TREE_TYPE (TREE_OPERAND (ics1
, 0)), 1))
3684 if (TREE_CODE (ics2
) == USER_CONV
3685 || TREE_CODE (ics2
) == AMBIG_CONV
3686 || TREE_CODE (ics2
) == IDENTITY_CONV
)
3691 /* Compare two implicit conversion sequences according to the rules set out in
3692 [over.ics.rank]. Return values:
3694 1: ics1 is better than ics2
3695 -1: ics2 is better than ics1
3696 0: ics1 and ics2 are indistinguishable */
3699 compare_ics (ics1
, ics2
)
3704 if (TREE_CODE (ics1
) == QUAL_CONV
)
3705 main1
= TREE_OPERAND (ics1
, 0);
3709 if (TREE_CODE (ics2
) == QUAL_CONV
)
3710 main2
= TREE_OPERAND (ics2
, 0);
3714 /* Conversions for `this' are PTR_CONVs, but we compare them as though
3715 they were REF_BINDs. */
3716 if (ICS_THIS_FLAG (ics1
))
3719 if (TREE_CODE (t
) == PTR_CONV
)
3720 t
= TREE_OPERAND (t
, 0);
3721 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
3722 t
= build_conv (REF_BIND
, TREE_TYPE (ics1
), t
);
3723 ICS_STD_RANK (t
) = ICS_STD_RANK (main1
);
3726 if (ICS_THIS_FLAG (ics2
))
3729 if (TREE_CODE (t
) == PTR_CONV
)
3730 t
= TREE_OPERAND (t
, 0);
3731 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
3732 t
= build_conv (REF_BIND
, TREE_TYPE (ics2
), t
);
3733 ICS_STD_RANK (t
) = ICS_STD_RANK (main2
);
3737 if (ICS_RANK (ics1
) > ICS_RANK (ics2
))
3739 else if (ICS_RANK (ics1
) < ICS_RANK (ics2
))
3742 if (ICS_RANK (ics1
) == BAD_RANK
)
3744 if (ICS_USER_FLAG (ics1
) > ICS_USER_FLAG (ics2
)
3745 || ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
3747 else if (ICS_USER_FLAG (ics1
) < ICS_USER_FLAG (ics2
)
3748 || ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
3751 /* else fall through */
3754 /* User-defined conversion sequence U1 is a better conversion sequence
3755 than another user-defined conversion sequence U2 if they contain the
3756 same user-defined conversion operator or constructor and if the sec-
3757 ond standard conversion sequence of U1 is better than the second
3758 standard conversion sequence of U2. */
3760 if (ICS_USER_FLAG (ics1
))
3764 for (t1
= ics1
; TREE_CODE (t1
) != USER_CONV
; t1
= TREE_OPERAND (t1
, 0))
3765 if (TREE_CODE (t1
) == AMBIG_CONV
)
3767 for (t2
= ics2
; TREE_CODE (t2
) != USER_CONV
; t2
= TREE_OPERAND (t2
, 0))
3768 if (TREE_CODE (t2
) == AMBIG_CONV
)
3771 if (USER_CONV_FN (t1
) != USER_CONV_FN (t2
))
3773 else if (ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
3775 else if (ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
3778 /* else fall through */
3781 #if 0 /* Handled by ranking */
3782 /* A conversion that is not a conversion of a pointer, or pointer to
3783 member, to bool is better than another conversion that is such a
3787 if (TREE_CODE (main1
) != TREE_CODE (main2
))
3789 /* ...if S1 is a proper subsequence of S2 */
3790 if (is_subseq (main1
, main2
))
3792 if (is_subseq (main2
, main1
))
3797 if (TREE_CODE (main1
) == PTR_CONV
|| TREE_CODE (main1
) == PMEM_CONV
3798 || TREE_CODE (main1
) == REF_BIND
|| TREE_CODE (main1
) == BASE_CONV
)
3800 tree to1
= TREE_TYPE (main1
);
3801 tree from1
= TREE_TYPE (TREE_OPERAND (main1
, 0));
3802 tree to2
= TREE_TYPE (main2
);
3803 tree from2
= TREE_TYPE (TREE_OPERAND (main2
, 0));
3806 /* Standard conversion sequence S1 is a better conversion sequence than
3807 standard conversion sequence S2 if...
3809 S1 and S2 differ only in their qualification conversion and they
3810 yield types identical except for cv-qualifiers and S2 adds all the
3811 qualifiers that S1 adds (and in the same places) and S2 adds yet
3812 more cv-qualifiers than S1, or the similar case with reference
3814 if (TREE_CODE (main1
) == REF_BIND
)
3816 if (TYPE_MAIN_VARIANT (TREE_TYPE (to1
))
3817 == TYPE_MAIN_VARIANT (TREE_TYPE (to2
)))
3818 return compare_qual (ics1
, ics2
);
3820 else if (TREE_CODE (main1
) != BASE_CONV
&& from1
== from2
&& to1
== to2
)
3821 return compare_qual (ics1
, ics2
);
3823 if (TYPE_PTRMEMFUNC_P (to1
))
3825 to1
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to1
)));
3826 from1
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from1
)));
3828 else if (TREE_CODE (main1
) != BASE_CONV
)
3830 to1
= TREE_TYPE (to1
);
3831 if (TREE_CODE (main1
) != REF_BIND
)
3832 from1
= TREE_TYPE (from1
);
3834 if (TREE_CODE (to1
) == OFFSET_TYPE
)
3836 to1
= TYPE_OFFSET_BASETYPE (to1
);
3837 from1
= TYPE_OFFSET_BASETYPE (from1
);
3841 if (TYPE_PTRMEMFUNC_P (to2
))
3843 to2
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to2
)));
3844 from2
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from2
)));
3846 else if (TREE_CODE (main1
) != BASE_CONV
)
3848 to2
= TREE_TYPE (to2
);
3849 if (TREE_CODE (main1
) != REF_BIND
)
3850 from2
= TREE_TYPE (from2
);
3852 if (TREE_CODE (to2
) == OFFSET_TYPE
)
3854 to2
= TYPE_OFFSET_BASETYPE (to2
);
3855 from2
= TYPE_OFFSET_BASETYPE (from2
);
3859 if (! (IS_AGGR_TYPE (from1
) && IS_AGGR_TYPE (from2
)))
3862 /* The sense of pmem conversions is reversed from that of the other
3864 if (TREE_CODE (main1
) == PMEM_CONV
)
3866 tree t
= from1
; from1
= from2
; from2
= t
;
3867 t
= to1
; to1
= to2
; to2
= t
;
3870 distf
= get_base_distance (from1
, from2
, 0, 0);
3873 distf
= -get_base_distance (from2
, from1
, 0, 0);
3878 /* If class B is derived directly or indirectly from class A,
3879 conver- sion of B* to A* is better than conversion of B* to
3880 void*, and conversion of A* to void* is better than
3881 conversion of B* to void*. */
3883 if (TREE_CODE (to1
) == VOID_TYPE
&& TREE_CODE (to2
) == VOID_TYPE
)
3890 else if (TREE_CODE (to2
) == VOID_TYPE
&& IS_AGGR_TYPE (to1
)
3891 && get_base_distance (to1
, from1
, 0, 0) != -1)
3893 else if (TREE_CODE (to1
) == VOID_TYPE
&& IS_AGGR_TYPE (to2
)
3894 && get_base_distance (to2
, from2
, 0, 0) != -1)
3897 if (! (IS_AGGR_TYPE (to1
) && IS_AGGR_TYPE (to2
)))
3900 /* If class B is derived directly or indirectly from class A and class
3901 C is derived directly or indirectly from B */
3903 distt
= get_base_distance (to1
, to2
, 0, 0);
3906 distt
= -get_base_distance (to2
, to1
, 0, 0);
3911 /* --conversion of C* to B* is better than conversion of C* to A*, */
3919 /* --conversion of B* to A* is better than conversion of C* to A*, */
3920 else if (distt
== 0)
3928 else if (TREE_CODE (TREE_TYPE (main1
)) == POINTER_TYPE
3929 || TYPE_PTRMEMFUNC_P (TREE_TYPE (main1
)))
3931 if (TREE_TYPE (main1
) == TREE_TYPE (main2
))
3932 return compare_qual (ics1
, ics2
);
3934 #if 0 /* This is now handled by making identity better than anything else. */
3935 /* existing practice, not WP-endorsed: const char * -> const char *
3936 is better than char * -> const char *. (jason 6/29/96) */
3937 if (TREE_TYPE (ics1
) == TREE_TYPE (ics2
))
3938 return -compare_qual (main1
, main2
);
3945 /* The source type for this standard conversion sequence. */
3951 for (;; t
= TREE_OPERAND (t
, 0))
3953 if (TREE_CODE (t
) == USER_CONV
3954 || TREE_CODE (t
) == AMBIG_CONV
3955 || TREE_CODE (t
) == IDENTITY_CONV
)
3956 return TREE_TYPE (t
);
3958 my_friendly_abort (1823);
3961 /* Note a warning about preferring WINNER to LOSER. We do this by storing
3962 a pointer to LOSER and re-running joust to produce the warning if WINNER
3963 is actually used. */
3966 add_warning (winner
, loser
)
3967 struct z_candidate
*winner
, *loser
;
3969 winner
->warnings
= expr_tree_cons (NULL_PTR
,
3970 build_expr_ptr_wrapper (loser
),
3974 /* Compare two candidates for overloading as described in
3975 [over.match.best]. Return values:
3977 1: cand1 is better than cand2
3978 -1: cand2 is better than cand1
3979 0: cand1 and cand2 are indistinguishable */
3982 joust (cand1
, cand2
, warn
)
3983 struct z_candidate
*cand1
, *cand2
;
3987 int i
, off1
= 0, off2
= 0, len
;
3989 /* Candidates that involve bad conversions are always worse than those
3991 if (cand1
->viable
> cand2
->viable
)
3993 if (cand1
->viable
< cand2
->viable
)
3996 /* a viable function F1
3997 is defined to be a better function than another viable function F2 if
3998 for all arguments i, ICSi(F1) is not a worse conversion sequence than
3999 ICSi(F2), and then */
4001 /* for some argument j, ICSj(F1) is a better conversion sequence than
4004 /* For comparing static and non-static member functions, we ignore the
4005 implicit object parameter of the non-static function. The WP says to
4006 pretend that the static function has an object parm, but that won't
4007 work with operator overloading. */
4008 len
= TREE_VEC_LENGTH (cand1
->convs
);
4009 if (len
!= TREE_VEC_LENGTH (cand2
->convs
))
4011 if (DECL_STATIC_FUNCTION_P (cand1
->fn
)
4012 && ! DECL_STATIC_FUNCTION_P (cand2
->fn
))
4014 else if (! DECL_STATIC_FUNCTION_P (cand1
->fn
)
4015 && DECL_STATIC_FUNCTION_P (cand2
->fn
))
4021 my_friendly_abort (42);
4024 for (i
= 0; i
< len
; ++i
)
4026 tree t1
= TREE_VEC_ELT (cand1
->convs
, i
+off1
);
4027 tree t2
= TREE_VEC_ELT (cand2
->convs
, i
+off2
);
4028 int comp
= compare_ics (t1
, t2
);
4033 && ICS_RANK (t1
) + ICS_RANK (t2
) == STD_RANK
+ PROMO_RANK
4034 && TREE_CODE (t1
) == STD_CONV
4035 && TREE_CODE (t2
) == STD_CONV
4036 && TREE_CODE (TREE_TYPE (t1
)) == INTEGER_TYPE
4037 && TREE_CODE (TREE_TYPE (t2
)) == INTEGER_TYPE
4038 && (TYPE_PRECISION (TREE_TYPE (t1
))
4039 == TYPE_PRECISION (TREE_TYPE (t2
)))
4040 && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (t1
, 0)))
4041 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (t1
, 0)))
4044 tree type
= TREE_TYPE (TREE_OPERAND (t1
, 0));
4046 struct z_candidate
*w
, *l
;
4048 type1
= TREE_TYPE (t1
), type2
= TREE_TYPE (t2
),
4049 w
= cand1
, l
= cand2
;
4051 type1
= TREE_TYPE (t2
), type2
= TREE_TYPE (t1
),
4052 w
= cand2
, l
= cand1
;
4056 cp_warning ("passing `%T' chooses `%T' over `%T'",
4057 type
, type1
, type2
);
4058 cp_warning (" in call to `%D'", w
->fn
);
4064 if (winner
&& comp
!= winner
)
4073 /* warn about confusing overload resolution */
4074 if (winner
&& cand1
->second_conv
4075 && ! DECL_CONSTRUCTOR_P (cand1
->fn
)
4076 && ! DECL_CONSTRUCTOR_P (cand2
->fn
))
4078 int comp
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
4079 if (comp
&& comp
!= winner
)
4081 struct z_candidate
*w
, *l
;
4083 w
= cand1
, l
= cand2
;
4085 w
= cand2
, l
= cand1
;
4088 cp_warning ("choosing `%D' over `%D'", w
->fn
, l
->fn
);
4089 cp_warning (" for conversion from `%T' to `%T'",
4090 TREE_TYPE (source_type (TREE_VEC_ELT (w
->convs
, 0))),
4091 TREE_TYPE (w
->second_conv
));
4092 cp_warning (" because conversion sequence for `this' argument is better");
4103 F1 is a non-template function and F2 is a template function */
4105 if (! cand1
->template && cand2
->template)
4107 else if (cand1
->template && ! cand2
->template)
4109 else if (cand1
->template && cand2
->template)
4110 winner
= more_specialized
4111 (TI_TEMPLATE (cand1
->template), TI_TEMPLATE (cand2
->template),
4115 the context is an initialization by user-defined conversion (see
4116 _dcl.init_ and _over.match.user_) and the standard conversion
4117 sequence from the return type of F1 to the destination type (i.e.,
4118 the type of the entity being initialized) is a better conversion
4119 sequence than the standard conversion sequence from the return type
4120 of F2 to the destination type. */
4122 if (! winner
&& cand1
->second_conv
)
4123 winner
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
4125 /* If the built-in candidates are the same, arbitrarily pick one. */
4126 if (! winner
&& cand1
->fn
== cand2
->fn
4127 && TREE_CODE (cand1
->fn
) == IDENTIFIER_NODE
)
4129 for (i
= 0; i
< len
; ++i
)
4130 if (! comptypes (TREE_TYPE (TREE_VEC_ELT (cand1
->convs
, i
)),
4131 TREE_TYPE (TREE_VEC_ELT (cand2
->convs
, i
)), 1))
4133 if (i
== TREE_VEC_LENGTH (cand1
->convs
))
4136 /* Kludge around broken overloading rules whereby
4137 Integer a, b; test ? a : b; is ambiguous, since there's a builtin
4138 that takes references and another that takes values. */
4139 if (cand1
->fn
== ansi_opname
[COND_EXPR
])
4141 tree c1
= TREE_VEC_ELT (cand1
->convs
, 1);
4142 tree c2
= TREE_VEC_ELT (cand2
->convs
, 1);
4143 tree t1
= strip_top_quals (non_reference (TREE_TYPE (c1
)));
4144 tree t2
= strip_top_quals (non_reference (TREE_TYPE (c2
)));
4146 if (comptypes (t1
, t2
, 1))
4148 if (TREE_CODE (c1
) == REF_BIND
&& TREE_CODE (c2
) != REF_BIND
)
4150 if (TREE_CODE (c1
) != REF_BIND
&& TREE_CODE (c2
) == REF_BIND
)
4158 /* Extension: If the worst conversion for one candidate is worse than the
4159 worst conversion for the other, take the first. */
4160 if (! winner
&& ! pedantic
)
4162 int rank1
= IDENTITY_RANK
, rank2
= IDENTITY_RANK
;
4164 for (i
= 0; i
< len
; ++i
)
4166 if (ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
)) > rank1
)
4167 rank1
= ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
));
4168 if (ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
)) > rank2
)
4169 rank2
= ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
));
4181 /* Given a list of candidates for overloading, find the best one, if any.
4182 This algorithm has a worst case of O(2n) (winner is last), and a best
4183 case of O(n/2) (totally ambiguous); much better than a sorting
4186 static struct z_candidate
*
4187 tourney (candidates
)
4188 struct z_candidate
*candidates
;
4190 struct z_candidate
*champ
= candidates
, *challenger
;
4193 /* Walk through the list once, comparing each current champ to the next
4194 candidate, knocking out a candidate or two with each comparison. */
4196 for (challenger
= champ
->next
; challenger
; )
4198 fate
= joust (champ
, challenger
, 0);
4200 challenger
= challenger
->next
;
4205 champ
= challenger
->next
;
4212 challenger
= champ
->next
;
4216 /* Make sure the champ is better than all the candidates it hasn't yet
4217 been compared to. This may do one more comparison than necessary. Oh
4220 for (challenger
= candidates
; challenger
!= champ
;
4221 challenger
= challenger
->next
)
4223 fate
= joust (champ
, challenger
, 0);
4232 can_convert (to
, from
)
4235 tree t
= implicit_conversion (to
, from
, NULL_TREE
, LOOKUP_NORMAL
);
4236 return (t
&& ! ICS_BAD_FLAG (t
));
4240 can_convert_arg (to
, from
, arg
)
4243 tree t
= implicit_conversion (to
, from
, arg
, LOOKUP_NORMAL
);
4244 return (t
&& ! ICS_BAD_FLAG (t
));