1 /* Functions related to invoking methods and overloaded functions.
2 Copyright (C) 1987, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com) and
4 hacked by Brendan Kehoe (brendan@cygnus.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 /* High-level class interface. */
39 #define obstack_chunk_alloc xmalloc
40 #define obstack_chunk_free free
42 extern int inhibit_warnings
;
43 extern tree ctor_label
, dtor_label
;
45 /* Compute the ease with which a conversion can be performed
46 between an expected and the given type. */
48 static struct harshness_code convert_harshness
PROTO((register tree
, register tree
, tree
));
49 static tree build_new_method_call
PROTO((tree
, tree
, tree
, tree
, int));
51 static int rank_for_ideal
PROTO((struct candidate
*,
53 static int user_harshness
PROTO((tree
, tree
));
54 static int strictly_better
PROTO((unsigned int, unsigned int));
55 static struct candidate
* ideal_candidate
PROTO((struct candidate
*,
57 static int may_be_remote
PROTO((tree
));
58 static tree build_field_call
PROTO((tree
, tree
, tree
, tree
));
59 static tree find_scoped_type
PROTO((tree
, tree
, tree
));
60 static void print_candidates
PROTO((tree
));
61 static struct z_candidate
* tourney
PROTO((struct z_candidate
*));
62 static int joust
PROTO((struct z_candidate
*, struct z_candidate
*));
63 static int compare_qual
PROTO((tree
, tree
));
64 static int compare_ics
PROTO((tree
, tree
));
65 static tree build_over_call
PROTO((tree
, tree
, tree
, int));
66 static tree convert_default_arg
PROTO((tree
, tree
));
67 static void enforce_access
PROTO((tree
, tree
));
68 static tree convert_like
PROTO((tree
, tree
));
69 static void op_error
PROTO((enum tree_code
, enum tree_code
, tree
, tree
,
71 static tree build_object_call
PROTO((tree
, tree
));
72 static tree resolve_args
PROTO((tree
));
73 static struct z_candidate
* build_user_type_conversion_1
74 PROTO ((tree
, tree
, int));
75 static void print_z_candidates
PROTO((struct z_candidate
*));
76 static tree build_this
PROTO((tree
));
77 static struct z_candidate
* splice_viable
PROTO((struct z_candidate
*));
78 static int any_viable
PROTO((struct z_candidate
*));
79 static struct z_candidate
* add_template_candidate
80 PROTO((struct z_candidate
*, tree
, tree
, int));
81 static struct z_candidate
* add_builtin_candidates
82 PROTO((struct z_candidate
*, enum tree_code
, enum tree_code
,
84 static struct z_candidate
* add_builtin_candidate
85 PROTO((struct z_candidate
*, enum tree_code
, enum tree_code
,
86 tree
, tree
, tree
, tree
*, tree
*, int));
87 static int is_complete
PROTO((tree
));
88 static struct z_candidate
* build_builtin_candidate
89 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
*, tree
*,
91 static struct z_candidate
* add_conv_candidate
92 PROTO((struct z_candidate
*, tree
, tree
, tree
));
93 static struct z_candidate
* add_function_candidate
94 PROTO((struct z_candidate
*, tree
, tree
, int));
95 static tree implicit_conversion
PROTO((tree
, tree
, tree
, int));
96 static tree standard_conversion
PROTO((tree
, tree
, tree
));
97 static tree reference_binding
PROTO((tree
, tree
, tree
, int));
98 static tree strip_top_quals
PROTO((tree
));
99 static tree non_reference
PROTO((tree
));
100 static tree build_conv
PROTO((enum tree_code
, tree
, tree
));
101 static void print_n_candidates
PROTO((struct candidate
*, int));
102 static tree default_parm_conversions
PROTO((tree
, tree
*));
104 #define EVIL_RETURN(ARG) ((ARG).code = EVIL_CODE, (ARG))
105 #define STD_RETURN(ARG) ((ARG).code = STD_CODE, (ARG))
106 #define QUAL_RETURN(ARG) ((ARG).code = QUAL_CODE, (ARG))
107 #define TRIVIAL_RETURN(ARG) ((ARG).code = TRIVIAL_CODE, (ARG))
108 #define ZERO_RETURN(ARG) ((ARG).code = 0, (ARG))
110 /* Ordering function for overload resolution. Compare two candidates
114 rank_for_overload (x
, y
)
115 struct candidate
*x
, *y
;
117 if (y
->h
.code
& (EVIL_CODE
|ELLIPSIS_CODE
|USER_CODE
))
118 return y
->h
.code
- x
->h
.code
;
119 if (x
->h
.code
& (EVIL_CODE
|ELLIPSIS_CODE
|USER_CODE
))
122 /* This is set by compute_conversion_costs, for calling a non-const
123 member function from a const member function. */
124 if ((y
->harshness
[0].code
& CONST_CODE
) ^ (x
->harshness
[0].code
& CONST_CODE
))
125 return y
->harshness
[0].code
- x
->harshness
[0].code
;
127 if (y
->h
.code
& STD_CODE
)
129 if (x
->h
.code
& STD_CODE
)
130 return y
->h
.distance
- x
->h
.distance
;
133 if (x
->h
.code
& STD_CODE
)
136 return y
->h
.code
- x
->h
.code
;
139 /* Compare two candidates, argument by argument. */
142 rank_for_ideal (x
, y
)
143 struct candidate
*x
, *y
;
147 if (x
->h_len
!= y
->h_len
)
150 for (i
= 0; i
< x
->h_len
; i
++)
152 if (y
->harshness
[i
].code
- x
->harshness
[i
].code
)
153 return y
->harshness
[i
].code
- x
->harshness
[i
].code
;
154 if ((y
->harshness
[i
].code
& STD_CODE
)
155 && (y
->harshness
[i
].distance
- x
->harshness
[i
].distance
))
156 return y
->harshness
[i
].distance
- x
->harshness
[i
].distance
;
158 /* They're both the same code. Now see if we're dealing with an
159 integral promotion that needs a finer grain of accuracy. */
160 if (y
->harshness
[0].code
& PROMO_CODE
161 && (y
->harshness
[i
].int_penalty
^ x
->harshness
[i
].int_penalty
))
162 return y
->harshness
[i
].int_penalty
- x
->harshness
[i
].int_penalty
;
167 /* TYPE is the type we wish to convert to. PARM is the parameter
168 we have to work with. We use a somewhat arbitrary cost function
169 to measure this conversion. */
171 static struct harshness_code
172 convert_harshness (type
, parmtype
, parm
)
173 register tree type
, parmtype
;
176 struct harshness_code h
;
177 register enum tree_code codel
;
178 register enum tree_code coder
;
185 #ifdef GATHER_STATISTICS
186 n_convert_harshness
++;
189 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
192 parm
= convert_from_reference (parm
);
193 parmtype
= TREE_TYPE (parmtype
);
197 lvalue
= lvalue_p (parm
);
201 if (TYPE_PTRMEMFUNC_P (type
))
202 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
203 if (TYPE_PTRMEMFUNC_P (parmtype
))
204 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
206 codel
= TREE_CODE (type
);
207 coder
= TREE_CODE (parmtype
);
209 if (TYPE_MAIN_VARIANT (parmtype
) == TYPE_MAIN_VARIANT (type
))
210 return ZERO_RETURN (h
);
212 if (coder
== ERROR_MARK
)
213 return EVIL_RETURN (h
);
215 if (codel
== REFERENCE_TYPE
)
218 int constp
= parm
? TREE_READONLY (parm
) : TYPE_READONLY (parmtype
);
219 int volatilep
= (parm
? TREE_THIS_VOLATILE (parm
)
220 : TYPE_VOLATILE (parmtype
));
221 register tree intype
= TYPE_MAIN_VARIANT (parmtype
);
222 register enum tree_code form
= TREE_CODE (intype
);
225 ttl
= TREE_TYPE (type
);
227 /* Only allow const reference binding if we were given a parm to deal
228 with, since it isn't really a conversion. This is a hack to
229 prevent build_type_conversion from finding this conversion, but
230 still allow overloading to find it. */
231 if (! lvalue
&& ! (parm
&& TYPE_READONLY (ttl
)))
232 return EVIL_RETURN (h
);
234 if ((TYPE_READONLY (ttl
) < constp
)
235 || (TYPE_VOLATILE (ttl
) < volatilep
))
236 return EVIL_RETURN (h
);
238 /* When passing a non-const argument into a const reference, dig it a
239 little, so a non-const reference is preferred over this one. */
240 penalty
= ((TYPE_READONLY (ttl
) > constp
)
241 + (TYPE_VOLATILE (ttl
) > volatilep
));
243 ttl
= TYPE_MAIN_VARIANT (ttl
);
245 if (form
== OFFSET_TYPE
)
247 intype
= TREE_TYPE (intype
);
248 form
= TREE_CODE (intype
);
253 if (TREE_CODE (ttl
) == ARRAY_TYPE
&& TREE_CODE (ttr
) == ARRAY_TYPE
)
255 if (comptypes (ttl
, ttr
, 1))
256 return ZERO_RETURN (h
);
257 return EVIL_RETURN (h
);
260 h
= convert_harshness (ttl
, ttr
, NULL_TREE
);
261 if (penalty
&& h
.code
== 0)
264 h
.int_penalty
= penalty
;
269 if (codel
== POINTER_TYPE
&& fntype_p (parmtype
))
272 struct harshness_code h1
, h2
;
274 /* Get to the METHOD_TYPE or FUNCTION_TYPE that this might be. */
275 type
= TREE_TYPE (type
);
277 if (coder
== POINTER_TYPE
)
279 parmtype
= TREE_TYPE (parmtype
);
280 coder
= TREE_CODE (parmtype
);
283 if (coder
!= TREE_CODE (type
))
284 return EVIL_RETURN (h
);
286 if (type
!= parmtype
&& coder
== METHOD_TYPE
)
288 tree ttl
= TYPE_METHOD_BASETYPE (type
);
289 tree ttr
= TYPE_METHOD_BASETYPE (parmtype
);
291 int b_or_d
= get_base_distance (ttr
, ttl
, 0, (tree
*)0);
294 b_or_d
= get_base_distance (ttl
, ttr
, 0, (tree
*)0);
296 return EVIL_RETURN (h
);
297 h
.distance
= -b_or_d
;
303 type
= build_function_type
304 (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
305 parmtype
= build_function_type
306 (TREE_TYPE (parmtype
), TREE_CHAIN (TYPE_ARG_TYPES (parmtype
)));
309 /* We allow the default conversion between function type
310 and pointer-to-function type for free. */
311 if (comptypes (type
, parmtype
, 1))
315 return EVIL_RETURN (h
);
317 /* Compare return types. */
318 p1
= TREE_TYPE (type
);
319 p2
= TREE_TYPE (parmtype
);
320 h2
= convert_harshness (p1
, p2
, NULL_TREE
);
321 if (h2
.code
& EVIL_CODE
)
324 h1
.code
= TRIVIAL_CODE
;
327 if (h2
.distance
!= 0)
331 /* This only works for pointers. */
332 if (TREE_CODE (p1
) != POINTER_TYPE
333 && TREE_CODE (p1
) != REFERENCE_TYPE
)
334 return EVIL_RETURN (h
);
338 /* Don't die if we happen to be dealing with void*. */
339 if (!IS_AGGR_TYPE (p1
) || !IS_AGGR_TYPE (p2
))
340 return EVIL_RETURN (h
);
342 binfo
= get_binfo (p2
, p1
, 0);
344 binfo
= get_binfo (p1
, p2
, 0);
346 if (! BINFO_OFFSET_ZEROP (binfo
))
349 static int explained
= 0;
351 message_2_types (sorry
, "cannot cast `%s' to `%s' at function call site", p2
, p1
);
353 message_2_types (sorry
, "cannot cast `%s' to `%s' at function call site", p1
, p2
);
356 sorry ("(because pointer values change during conversion)");
358 return EVIL_RETURN (h
);
363 if (h2
.distance
> h1
.distance
)
364 h1
.distance
= h2
.distance
;
366 p1
= TYPE_ARG_TYPES (type
);
367 p2
= TYPE_ARG_TYPES (parmtype
);
368 while (p1
&& TREE_VALUE (p1
) != void_type_node
369 && p2
&& TREE_VALUE (p2
) != void_type_node
)
371 h2
= convert_harshness (TREE_VALUE (p1
), TREE_VALUE (p2
),
373 if (h2
.code
& EVIL_CODE
)
378 /* This only works for pointers and references. */
379 if (TREE_CODE (TREE_VALUE (p1
)) != POINTER_TYPE
380 && TREE_CODE (TREE_VALUE (p1
)) != REFERENCE_TYPE
)
381 return EVIL_RETURN (h
);
382 h2
.distance
= - h2
.distance
;
386 if (h2
.distance
> h1
.distance
)
387 h1
.distance
= h2
.distance
;
388 p1
= TREE_CHAIN (p1
);
389 p2
= TREE_CHAIN (p2
);
396 return EVIL_RETURN (h
);
397 h1
.code
|= ELLIPSIS_CODE
;
402 if (TREE_PURPOSE (p1
) == NULL_TREE
)
403 h1
.code
|= EVIL_CODE
;
407 else if (codel
== POINTER_TYPE
&& coder
== OFFSET_TYPE
)
411 /* Get to the OFFSET_TYPE that this might be. */
412 type
= TREE_TYPE (type
);
414 if (coder
!= TREE_CODE (type
))
415 return EVIL_RETURN (h
);
417 ttl
= TYPE_OFFSET_BASETYPE (type
);
418 ttr
= TYPE_OFFSET_BASETYPE (parmtype
);
424 int b_or_d
= get_base_distance (ttr
, ttl
, 0, (tree
*)0);
427 b_or_d
= get_base_distance (ttl
, ttr
, 0, (tree
*)0);
429 return EVIL_RETURN (h
);
430 h
.distance
= -b_or_d
;
437 /* Now test the OFFSET_TYPE's target compatibility. */
438 type
= TREE_TYPE (type
);
439 parmtype
= TREE_TYPE (parmtype
);
442 if (coder
== UNKNOWN_TYPE
)
444 if (codel
== FUNCTION_TYPE
445 || codel
== METHOD_TYPE
446 || (codel
== POINTER_TYPE
447 && (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
448 || TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)))
449 return TRIVIAL_RETURN (h
);
450 return EVIL_RETURN (h
);
453 if (coder
== VOID_TYPE
)
454 return EVIL_RETURN (h
);
456 if (codel
== BOOLEAN_TYPE
)
458 if (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
)
459 return STD_RETURN (h
);
460 else if (coder
== POINTER_TYPE
|| coder
== OFFSET_TYPE
)
462 /* Make this worse than any conversion to another pointer.
463 FIXME this is how I think the language should work, but it may not
464 end up being how the language is standardized (jason 1/30/95). */
466 return STD_RETURN (h
);
468 return EVIL_RETURN (h
);
471 if (INTEGRAL_CODE_P (codel
))
473 /* Control equivalence of ints an enums. */
475 if (codel
== ENUMERAL_TYPE
476 && flag_int_enum_equivalence
== 0)
478 /* Enums can be converted to ints, but not vice-versa. */
479 if (coder
!= ENUMERAL_TYPE
480 || TYPE_MAIN_VARIANT (type
) != TYPE_MAIN_VARIANT (parmtype
))
481 return EVIL_RETURN (h
);
484 /* else enums and ints (almost) freely interconvert. */
486 if (INTEGRAL_CODE_P (coder
))
488 if (TYPE_MAIN_VARIANT (type
)
489 == TYPE_MAIN_VARIANT (type_promotes_to (parmtype
)))
498 else if (coder
== REAL_TYPE
)
506 if (codel
== REAL_TYPE
)
508 if (coder
== REAL_TYPE
)
510 if (TYPE_MAIN_VARIANT (type
)
511 == TYPE_MAIN_VARIANT (type_promotes_to (parmtype
)))
518 else if (INTEGRAL_CODE_P (coder
))
526 /* Convert arrays which have not previously been converted. */
527 if (coder
== ARRAY_TYPE
)
529 coder
= POINTER_TYPE
;
532 parm
= decay_conversion (parm
);
533 parmtype
= TREE_TYPE (parm
);
536 parmtype
= build_pointer_type (TREE_TYPE (parmtype
));
539 /* Conversions among pointers */
540 if (codel
== POINTER_TYPE
&& coder
== POINTER_TYPE
)
542 register tree ttl
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
543 register tree ttr
= TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
));
544 int penalty
= 4 * (ttl
!= ttr
);
546 /* Anything converts to void *. Since this may be `const void *'
547 (etc.) use VOID_TYPE instead of void_type_node. Otherwise, the
548 targets must be the same, except that we do allow (at some cost)
549 conversion between signed and unsigned pointer types. */
551 if ((TREE_CODE (ttl
) == METHOD_TYPE
552 || TREE_CODE (ttl
) == FUNCTION_TYPE
)
553 && TREE_CODE (ttl
) == TREE_CODE (ttr
))
555 if (comptypes (ttl
, ttr
, -1))
557 h
.code
= penalty
? STD_CODE
: 0;
566 if (TREE_CODE (ttl
) != VOID_TYPE
567 && (TREE_CODE (ttr
) != VOID_TYPE
|| !parm
|| !null_ptr_cst_p (parm
)))
569 if (comp_target_types (type
, parmtype
, 1) <= 0)
570 return EVIL_RETURN (h
);
573 if (!(TREE_CODE (ttl
) == VOID_TYPE
574 || TREE_CODE (ttr
) == VOID_TYPE
575 || (TREE_UNSIGNED (ttl
) ^ TREE_UNSIGNED (ttr
)
576 && (ttl
= unsigned_type (ttl
),
577 ttr
= unsigned_type (ttr
),
579 || (comp_target_types (ttl
, ttr
, 0) > 0)))
580 return EVIL_RETURN (h
);
585 tree tmp1
= TREE_TYPE (type
), tmp2
= TREE_TYPE (parmtype
);
588 /* Note conversion from `T*' to `const T*',
589 or `T*' to `volatile T*'. */
590 if ((TYPE_READONLY (tmp1
) < TREE_READONLY (tmp2
))
591 || (TYPE_VOLATILE (tmp1
) < TYPE_VOLATILE (tmp2
)))
593 else if ((TYPE_READONLY (tmp1
) != TREE_READONLY (tmp2
))
594 || (TYPE_VOLATILE (tmp1
) != TYPE_VOLATILE (tmp2
)))
602 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
604 int b_or_d
= get_base_distance (ttl
, ttr
, 0, (tree
*)0);
607 b_or_d
= get_base_distance (ttr
, ttl
, 0, (tree
*)0);
609 return EVIL_RETURN (h
);
610 h
.distance
= -b_or_d
;
618 /* If converting from a `class*' to a `void*', make it
619 less favorable than any inheritance relationship. */
620 if (TREE_CODE (ttl
) == VOID_TYPE
&& IS_AGGR_TYPE (ttr
))
623 h
.distance
= CLASSTYPE_MAX_DEPTH (ttr
)+1;
627 h
.code
= penalty
? STD_CODE
: PROMO_CODE
;
628 /* Catch things like `const char *' -> `const void *'
629 vs `const char *' -> `void *'. */
632 tree tmp1
= TREE_TYPE (type
), tmp2
= TREE_TYPE (parmtype
);
633 if ((TYPE_READONLY (tmp1
) < TREE_READONLY (tmp2
))
634 || (TYPE_VOLATILE (tmp1
) < TYPE_VOLATILE (tmp2
)))
636 else if ((TYPE_READONLY (tmp1
) > TREE_READONLY (tmp2
))
637 || (TYPE_VOLATILE (tmp1
) > TYPE_VOLATILE (tmp2
)))
643 if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
645 /* This is not a bad match, but don't let it beat
646 integer-enum combinations. */
647 if (parm
&& integer_zerop (parm
))
655 /* C++: Since the `this' parameter of a signature member function
656 is represented as a signature pointer to handle default implementations
657 correctly, we can have the case that `type' is a signature pointer
658 while `parmtype' is a pointer to a signature table. We don't really
659 do any conversions in this case, so just return 0. */
661 if (codel
== RECORD_TYPE
&& coder
== POINTER_TYPE
662 && IS_SIGNATURE_POINTER (type
) && IS_SIGNATURE (TREE_TYPE (parmtype
)))
663 return ZERO_RETURN (h
);
665 if (codel
== RECORD_TYPE
&& coder
== RECORD_TYPE
)
667 int b_or_d
= get_base_distance (type
, parmtype
, 0, (tree
*)0);
670 b_or_d
= get_base_distance (parmtype
, type
, 0, (tree
*)0);
672 return EVIL_RETURN (h
);
673 h
.distance
= -b_or_d
;
680 return EVIL_RETURN (h
);
683 /* A clone of build_type_conversion for checking user-defined conversions in
684 overload resolution. */
687 user_harshness (type
, parmtype
)
688 register tree type
, parmtype
;
691 tree winner
= NULL_TREE
;
695 tree typename
= build_typename_overload (type
);
696 if (lookup_fnfields (TYPE_BINFO (parmtype
), typename
, 0))
700 for (conv
= lookup_conversions (parmtype
); conv
; conv
= TREE_CHAIN (conv
))
702 struct harshness_code tmp
;
703 tree cand
= TREE_VALUE (conv
);
705 if (winner
&& winner
== cand
)
708 tmp
= convert_harshness (type
, TREE_TYPE (TREE_TYPE (cand
)), NULL_TREE
);
709 if ((tmp
.code
< USER_CODE
) && (tmp
.distance
>= 0))
727 #ifdef DEBUG_MATCHING
730 struct harshness_code
*h
;
732 static char buf
[1024];
735 bzero (buf
, 1024 * sizeof (char));
736 strcat (buf
, "codes=[");
737 if (h
->code
& EVIL_CODE
)
738 strcat (buf
, "EVIL");
739 if (h
->code
& CONST_CODE
)
740 strcat (buf
, " CONST");
741 if (h
->code
& ELLIPSIS_CODE
)
742 strcat (buf
, " ELLIPSIS");
743 if (h
->code
& USER_CODE
)
744 strcat (buf
, " USER");
745 if (h
->code
& STD_CODE
)
746 strcat (buf
, " STD");
747 if (h
->code
& PROMO_CODE
)
748 strcat (buf
, " PROMO");
749 if (h
->code
& QUAL_CODE
)
750 strcat (buf
, " QUAL");
751 if (h
->code
& TRIVIAL_CODE
)
752 strcat (buf
, " TRIVIAL");
756 sprintf (tmp
, "] distance=%d int_penalty=%d", h
->distance
, h
->int_penalty
);
764 /* Algorithm: For each argument, calculate how difficult it is to
765 make FUNCTION accept that argument. If we can easily tell that
766 FUNCTION won't be acceptable to one of the arguments, then we
767 don't need to compute the ease of converting the other arguments,
768 since it will never show up in the intersection of all arguments'
771 Conversions between builtin and user-defined types are allowed, but
772 no function involving such a conversion is preferred to one which
773 does not require such a conversion. Furthermore, such conversions
777 compute_conversion_costs (function
, tta_in
, cp
, arglen
)
780 struct candidate
*cp
;
783 tree ttf_in
= TYPE_ARG_TYPES (TREE_TYPE (function
));
787 /* Start out with no strikes against. */
788 int evil_strikes
= 0;
789 int ellipsis_strikes
= 0;
790 int user_strikes
= 0;
791 int b_or_d_strikes
= 0;
792 int easy_strikes
= 0;
794 int strike_index
= 0, win
;
795 struct harshness_code lose
;
796 extern int cp_silent
;
798 #ifdef GATHER_STATISTICS
799 n_compute_conversion_costs
++;
802 #ifndef DEBUG_MATCHING
803 /* We don't emit any warnings or errors while trying out each candidate. */
807 cp
->function
= function
;
808 cp
->arg
= tta
? TREE_VALUE (tta
) : NULL_TREE
;
809 cp
->u
.bad_arg
= 0; /* optimistic! */
813 cp
->h
.int_penalty
= 0;
814 bzero ((char *) cp
->harshness
,
815 (cp
->h_len
+ 1) * sizeof (struct harshness_code
));
819 struct harshness_code h
;
821 if (ttf
== void_list_node
)
824 if (type_unknown_p (TREE_VALUE (tta
)))
826 /* Must perform some instantiation here. */
827 tree rhs
= TREE_VALUE (tta
);
828 tree lhstype
= TREE_VALUE (ttf
);
830 /* Keep quiet about possible contravariance violations. */
831 int old_inhibit_warnings
= inhibit_warnings
;
832 inhibit_warnings
= 1;
834 /* @@ This is to undo what `grokdeclarator' does to
835 parameter types. It really should go through
836 something more general. */
838 TREE_TYPE (tta
) = unknown_type_node
;
839 rhs
= instantiate_type (lhstype
, rhs
, 0);
840 inhibit_warnings
= old_inhibit_warnings
;
842 if (TREE_CODE (rhs
) == ERROR_MARK
)
845 h
= convert_harshness (lhstype
, TREE_TYPE (rhs
), rhs
);
849 #ifdef DEBUG_MATCHING
850 static tree old_function
= NULL_TREE
;
852 if (!old_function
|| function
!= old_function
)
854 cp_error ("trying %D", function
);
855 old_function
= function
;
858 cp_error (" doing (%T) %E against arg %T",
859 TREE_TYPE (TREE_VALUE (tta
)), TREE_VALUE (tta
),
863 h
= convert_harshness (TREE_VALUE (ttf
),
864 TREE_TYPE (TREE_VALUE (tta
)),
867 #ifdef DEBUG_MATCHING
868 cp_error (" evaluated %s", print_harshness (&h
));
872 cp
->harshness
[strike_index
] = h
;
873 if ((h
.code
& EVIL_CODE
)
874 || ((h
.code
& STD_CODE
) && h
.distance
< 0))
876 cp
->u
.bad_arg
= strike_index
;
879 else if (h
.code
& ELLIPSIS_CODE
)
880 ellipsis_strikes
+= 1;
882 /* This is never set by `convert_harshness'. */
883 else if (h
.code
& USER_CODE
)
890 if ((h
.code
& STD_CODE
) && h
.distance
)
892 if (h
.distance
> b_or_d_strikes
)
893 b_or_d_strikes
= h
.distance
;
896 easy_strikes
+= (h
.code
& (STD_CODE
|PROMO_CODE
|TRIVIAL_CODE
));
897 cp
->h
.code
|= h
.code
;
898 /* Make sure we communicate this. */
899 cp
->h
.int_penalty
+= h
.int_penalty
;
902 ttf
= TREE_CHAIN (ttf
);
903 tta
= TREE_CHAIN (tta
);
909 /* ran out of formals, and parmlist is fixed size. */
910 if (ttf
/* == void_type_node */)
912 cp
->h
.code
= EVIL_CODE
;
919 struct harshness_code h
;
920 int l
= list_length (tta
);
921 ellipsis_strikes
+= l
;
922 h
.code
= ELLIPSIS_CODE
;
926 cp
->harshness
[strike_index
++] = h
;
929 else if (ttf
&& ttf
!= void_list_node
)
931 /* ran out of actuals, and no defaults. */
932 if (TREE_PURPOSE (ttf
) == NULL_TREE
)
934 cp
->h
.code
= EVIL_CODE
;
939 /* Store index of first default. */
940 cp
->harshness
[arglen
].distance
= strike_index
+1;
943 cp
->harshness
[arglen
].distance
= 0;
945 /* Argument list lengths work out, so don't need to check them again. */
948 /* We do not check for derived->base conversions here, since in
949 no case would they give evil strike counts, unless such conversions
950 are somehow ambiguous. */
952 /* See if any user-defined conversions apply.
953 But make sure that we do not loop. */
954 static int dont_convert_types
= 0;
956 if (dont_convert_types
)
958 cp
->h
.code
= EVIL_CODE
;
963 win
= 0; /* Only get one chance to win. */
964 ttf
= TYPE_ARG_TYPES (TREE_TYPE (function
));
971 if (ttf
== void_list_node
)
974 lose
= cp
->harshness
[strike_index
];
975 if ((lose
.code
& EVIL_CODE
)
976 || ((lose
.code
& STD_CODE
) && lose
.distance
< 0))
978 tree actual_type
= TREE_TYPE (TREE_VALUE (tta
));
979 tree formal_type
= TREE_VALUE (ttf
);
980 int extra_conversions
= 0;
982 dont_convert_types
= 1;
984 if (TREE_CODE (formal_type
) == REFERENCE_TYPE
)
985 formal_type
= TREE_TYPE (formal_type
);
986 if (TREE_CODE (actual_type
) == REFERENCE_TYPE
)
987 actual_type
= TREE_TYPE (actual_type
);
989 if (formal_type
!= error_mark_node
990 && actual_type
!= error_mark_node
)
992 formal_type
= complete_type (TYPE_MAIN_VARIANT (formal_type
));
993 actual_type
= complete_type (TYPE_MAIN_VARIANT (actual_type
));
995 if (TYPE_HAS_CONSTRUCTOR (formal_type
))
997 /* If it has a constructor for this type,
999 /* @@ There is no way to save this result yet, so
1000 success is a NULL_TREE for now. */
1001 if (convert_to_aggr (formal_type
, TREE_VALUE (tta
), 0, 1)
1005 if (TYPE_LANG_SPECIFIC (actual_type
)
1006 && TYPE_HAS_CONVERSION (actual_type
))
1008 int extra
= user_harshness (formal_type
, actual_type
);
1010 if (extra
== EVIL_CODE
)
1012 else if (extra
>= 0)
1015 extra_conversions
= extra
;
1019 dont_convert_types
= 0;
1024 cp
->harshness
[strike_index
].code
1025 = USER_CODE
| (extra_conversions
? STD_CODE
: 0);
1030 if (cp
->u
.bad_arg
> strike_index
)
1031 cp
->u
.bad_arg
= strike_index
;
1033 evil_strikes
= win
? 2 : 1;
1038 ttf
= TREE_CHAIN (ttf
);
1039 tta
= TREE_CHAIN (tta
);
1044 /* Const member functions get a small penalty because defaulting
1045 to const is less useful than defaulting to non-const. */
1046 /* This is bogus, it does not correspond to anything in the ARM.
1047 This code will be fixed when this entire section is rewritten
1048 to conform to the ARM. (mrs) */
1049 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1051 tree this_parm
= TREE_VALUE (ttf_in
);
1053 if (TREE_CODE (this_parm
) == RECORD_TYPE
/* Is `this' a sig ptr? */
1054 ? TYPE_READONLY (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (this_parm
))))
1055 : TYPE_READONLY (TREE_TYPE (this_parm
)))
1057 cp
->harshness
[0].code
|= TRIVIAL_CODE
;
1062 /* Calling a non-const member function from a const member function
1063 is probably invalid, but for now we let it only draw a warning.
1064 We indicate that such a mismatch has occurred by setting the
1065 harshness to a maximum value. */
1066 if (TREE_CODE (TREE_TYPE (TREE_VALUE (tta_in
))) == POINTER_TYPE
1067 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (TREE_VALUE (tta_in
))))))
1068 cp
->harshness
[0].code
|= CONST_CODE
;
1073 cp
->h
.code
= EVIL_CODE
;
1074 if (ellipsis_strikes
)
1075 cp
->h
.code
|= ELLIPSIS_CODE
;
1077 cp
->h
.code
|= USER_CODE
;
1079 #ifdef DEBUG_MATCHING
1080 cp_error ("final eval %s", print_harshness (&cp
->h
));
1084 /* Subroutine of ideal_candidate. See if X or Y is a better match
1088 strictly_better (x
, y
)
1097 if (xor >= x
|| xor >= y
)
1102 /* When one of several possible overloaded functions and/or methods
1103 can be called, choose the best candidate for overloading.
1105 BASETYPE is the context from which we start method resolution
1106 or NULL if we are comparing overloaded functions.
1107 CANDIDATES is the array of candidates we have to choose from.
1108 N_CANDIDATES is the length of CANDIDATES.
1109 PARMS is a TREE_LIST of parameters to the function we'll ultimately
1110 choose. It is modified in place when resolving methods. It is not
1111 modified in place when resolving overloaded functions.
1112 LEN is the length of the parameter list. */
1114 static struct candidate
*
1115 ideal_candidate (candidates
, n_candidates
, len
)
1116 struct candidate
*candidates
;
1120 struct candidate
*cp
= candidates
+n_candidates
;
1121 int i
, j
= -1, best_code
;
1123 /* For each argument, sort the functions from best to worst for the arg.
1124 For each function that's not best for this arg, set its overall
1125 harshness to EVIL so that other args won't like it. The candidate
1126 list for the last argument is the intersection of all the best-liked
1129 qsort (candidates
, n_candidates
, sizeof (struct candidate
),
1130 (int (*) PROTO((const void *, const void *))) rank_for_overload
);
1131 best_code
= cp
[-1].h
.code
;
1133 /* If they're at least as good as each other, do an arg-by-arg check. */
1134 if (! strictly_better (cp
[-1].h
.code
, cp
[-2].h
.code
))
1139 for (j
= 0; j
< n_candidates
; j
++)
1140 if (! strictly_better (candidates
[j
].h
.code
, best_code
))
1143 qsort (candidates
+j
, n_candidates
-j
, sizeof (struct candidate
),
1144 (int (*) PROTO((const void *, const void *))) rank_for_ideal
);
1145 for (i
= 0; i
< len
; i
++)
1147 if (cp
[-1].harshness
[i
].code
< cp
[-2].harshness
[i
].code
)
1149 else if (cp
[-1].harshness
[i
].code
> cp
[-2].harshness
[i
].code
)
1151 else if (cp
[-1].harshness
[i
].code
& STD_CODE
)
1153 /* If it involves a standard conversion, let the
1154 inheritance lattice be the final arbiter. */
1155 if (cp
[-1].harshness
[i
].distance
> cp
[-2].harshness
[i
].distance
)
1157 else if (cp
[-1].harshness
[i
].distance
< cp
[-2].harshness
[i
].distance
)
1160 else if (cp
[-1].harshness
[i
].code
& PROMO_CODE
)
1162 /* For integral promotions, take into account a finer
1163 granularity for determining which types should be favored
1164 over others in such promotions. */
1165 if (cp
[-1].harshness
[i
].int_penalty
> cp
[-2].harshness
[i
].int_penalty
)
1167 else if (cp
[-1].harshness
[i
].int_penalty
< cp
[-2].harshness
[i
].int_penalty
)
1172 if (! better
|| worse
)
1178 /* Assume that if the class referred to is not in the
1179 current class hierarchy, that it may be remote.
1180 PARENT is assumed to be of aggregate type here. */
1183 may_be_remote (parent
)
1186 if (TYPE_OVERLOADS_METHOD_CALL_EXPR (parent
) == 0)
1189 if (current_class_type
== NULL_TREE
)
1192 if (parent
== current_class_type
)
1195 if (UNIQUELY_DERIVED_FROM_P (parent
, current_class_type
))
1201 build_vfield_ref (datum
, type
)
1205 int old_assume_nonnull_objects
= flag_assume_nonnull_objects
;
1207 if (datum
== error_mark_node
)
1208 return error_mark_node
;
1210 /* Vtable references are always made from non-null objects. */
1211 flag_assume_nonnull_objects
= 1;
1212 if (TREE_CODE (TREE_TYPE (datum
)) == REFERENCE_TYPE
)
1213 datum
= convert_from_reference (datum
);
1215 if (! TYPE_USES_COMPLEX_INHERITANCE (type
))
1216 rval
= build (COMPONENT_REF
, TREE_TYPE (CLASSTYPE_VFIELD (type
)),
1217 datum
, CLASSTYPE_VFIELD (type
));
1219 rval
= build_component_ref (datum
, DECL_NAME (CLASSTYPE_VFIELD (type
)), NULL_TREE
, 0);
1220 flag_assume_nonnull_objects
= old_assume_nonnull_objects
;
1225 /* Build a call to a member of an object. I.e., one that overloads
1226 operator ()(), or is a pointer-to-function or pointer-to-method. */
1229 build_field_call (basetype_path
, instance_ptr
, name
, parms
)
1230 tree basetype_path
, instance_ptr
, name
, parms
;
1232 tree field
, instance
;
1234 if (name
== ctor_identifier
|| name
== dtor_identifier
)
1237 if (instance_ptr
== current_class_ptr
)
1239 /* Check to see if we really have a reference to an instance variable
1240 with `operator()()' overloaded. */
1241 field
= IDENTIFIER_CLASS_VALUE (name
);
1243 if (field
== NULL_TREE
)
1245 cp_error ("`this' has no member named `%D'", name
);
1246 return error_mark_node
;
1249 if (TREE_CODE (field
) == FIELD_DECL
)
1251 /* If it's a field, try overloading operator (),
1252 or calling if the field is a pointer-to-function. */
1253 instance
= build_component_ref_1 (current_class_ref
, field
, 0);
1254 if (instance
== error_mark_node
)
1255 return error_mark_node
;
1257 if (TYPE_LANG_SPECIFIC (TREE_TYPE (instance
))
1258 && (TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (instance
))
1259 || flag_ansi_overloading
))
1260 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, instance
, parms
, NULL_TREE
);
1262 if (TREE_CODE (TREE_TYPE (instance
)) == POINTER_TYPE
)
1264 if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == FUNCTION_TYPE
)
1265 return build_function_call (instance
, parms
);
1266 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == METHOD_TYPE
)
1267 return build_function_call (instance
, tree_cons (NULL_TREE
, current_class_ptr
, parms
));
1273 /* Check to see if this is not really a reference to an instance variable
1274 with `operator()()' overloaded. */
1275 field
= lookup_field (basetype_path
, name
, 1, 0);
1277 /* This can happen if the reference was ambiguous or for access
1279 if (field
== error_mark_node
)
1280 return error_mark_node
;
1285 tree ftype
= TREE_TYPE (field
);
1287 if (TREE_CODE (ftype
) == REFERENCE_TYPE
)
1288 ftype
= TREE_TYPE (ftype
);
1290 if (TYPE_LANG_SPECIFIC (ftype
)
1291 && (TYPE_OVERLOADS_CALL_EXPR (ftype
) || flag_ansi_overloading
))
1293 /* Make the next search for this field very short. */
1294 basetype
= DECL_FIELD_CONTEXT (field
);
1295 instance_ptr
= convert_pointer_to (basetype
, instance_ptr
);
1297 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
1298 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
,
1299 build_component_ref_1 (instance
, field
, 0),
1302 if (TREE_CODE (ftype
) == POINTER_TYPE
)
1304 if (TREE_CODE (TREE_TYPE (ftype
)) == FUNCTION_TYPE
1305 || TREE_CODE (TREE_TYPE (ftype
)) == METHOD_TYPE
)
1307 /* This is a member which is a pointer to function. */
1309 = build_component_ref_1 (build_indirect_ref (instance_ptr
,
1311 field
, LOOKUP_COMPLAIN
);
1312 if (ref
== error_mark_node
)
1313 return error_mark_node
;
1314 return build_function_call (ref
, parms
);
1317 else if (TREE_CODE (ftype
) == METHOD_TYPE
)
1319 error ("invalid call via pointer-to-member function");
1320 return error_mark_node
;
1329 find_scoped_type (type
, inner_name
, inner_types
)
1330 tree type
, inner_name
, inner_types
;
1332 tree tags
= CLASSTYPE_TAGS (type
);
1336 /* The TREE_PURPOSE of an enum tag (which becomes a member of the
1337 enclosing class) is set to the name for the enum type. So, if
1338 inner_name is `bar', and we strike `baz' for `enum bar { baz }',
1339 then this test will be true. */
1340 if (TREE_PURPOSE (tags
) == inner_name
)
1342 if (inner_types
== NULL_TREE
)
1343 return TYPE_MAIN_DECL (TREE_VALUE (tags
));
1344 return resolve_scope_to_name (TREE_VALUE (tags
), inner_types
);
1346 tags
= TREE_CHAIN (tags
);
1349 /* Look for a TYPE_DECL. */
1350 for (tags
= TYPE_FIELDS (type
); tags
; tags
= TREE_CHAIN (tags
))
1351 if (TREE_CODE (tags
) == TYPE_DECL
&& DECL_NAME (tags
) == inner_name
)
1353 /* Code by raeburn. */
1354 if (inner_types
== NULL_TREE
)
1356 return resolve_scope_to_name (TREE_TYPE (tags
), inner_types
);
1362 /* Resolve an expression NAME1::NAME2::...::NAMEn to
1363 the name that names the above nested type. INNER_TYPES
1364 is a chain of nested type names (held together by SCOPE_REFs);
1365 OUTER_TYPE is the type we know to enclose INNER_TYPES.
1366 Returns NULL_TREE if there is an error. */
1369 resolve_scope_to_name (outer_type
, inner_stuff
)
1370 tree outer_type
, inner_stuff
;
1373 tree inner_name
, inner_type
;
1375 if (outer_type
== NULL_TREE
&& current_class_type
!= NULL_TREE
)
1377 /* We first try to look for a nesting in our current class context,
1378 then try any enclosing classes. */
1379 tree type
= current_class_type
;
1381 while (type
&& (TREE_CODE (type
) == RECORD_TYPE
1382 || TREE_CODE (type
) == UNION_TYPE
))
1384 tree rval
= resolve_scope_to_name (type
, inner_stuff
);
1386 if (rval
!= NULL_TREE
)
1388 type
= DECL_CONTEXT (TYPE_MAIN_DECL (type
));
1392 if (TREE_CODE (inner_stuff
) == SCOPE_REF
)
1394 inner_name
= TREE_OPERAND (inner_stuff
, 0);
1395 inner_type
= TREE_OPERAND (inner_stuff
, 1);
1399 inner_name
= inner_stuff
;
1400 inner_type
= NULL_TREE
;
1403 if (outer_type
== NULL_TREE
)
1406 /* If we have something that's already a type by itself,
1408 if (IDENTIFIER_HAS_TYPE_VALUE (inner_name
))
1411 return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name
),
1416 x
= lookup_name (inner_name
, 0);
1418 if (x
&& TREE_CODE (x
) == NAMESPACE_DECL
)
1420 x
= lookup_namespace_name (x
, inner_type
);
1426 if (! IS_AGGR_TYPE (outer_type
))
1429 /* Look for member classes or enums. */
1430 tmp
= find_scoped_type (outer_type
, inner_name
, inner_type
);
1432 /* If it's not a type in this class, then go down into the
1433 base classes and search there. */
1434 if (! tmp
&& TYPE_BINFO (outer_type
))
1436 tree binfos
= TYPE_BINFO_BASETYPES (outer_type
);
1437 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1439 for (i
= 0; i
< n_baselinks
; i
++)
1441 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1442 tmp
= resolve_scope_to_name (BINFO_TYPE (base_binfo
), inner_stuff
);
1452 /* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'.
1453 This is how virtual function calls are avoided. */
1456 build_scoped_method_call (exp
, basetype
, name
, parms
)
1457 tree exp
, basetype
, name
, parms
;
1459 /* Because this syntactic form does not allow
1460 a pointer to a base class to be `stolen',
1461 we need not protect the derived->base conversion
1464 @@ But we do have to check access privileges later. */
1466 tree type
= TREE_TYPE (exp
);
1468 if (type
== error_mark_node
1469 || basetype
== error_mark_node
)
1470 return error_mark_node
;
1472 if (processing_template_decl
)
1474 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1476 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 1);
1477 name
= build_min_nt (BIT_NOT_EXPR
, type
);
1479 name
= build_min_nt (SCOPE_REF
, basetype
, name
);
1480 return build_min_nt (METHOD_CALL_EXPR
, name
, exp
, parms
, NULL_TREE
);
1483 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1484 type
= TREE_TYPE (type
);
1486 if (TREE_CODE (basetype
) == TREE_VEC
)
1489 basetype
= BINFO_TYPE (binfo
);
1494 /* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
1495 that explicit ~int is caught in the parser; this deals with typedefs
1496 and template parms. */
1497 if (TREE_CODE (name
) == BIT_NOT_EXPR
&& ! IS_AGGR_TYPE (basetype
))
1499 if (type
!= basetype
)
1500 cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
1501 exp
, basetype
, type
);
1502 name
= TREE_OPERAND (name
, 0);
1503 if (basetype
!= name
&& basetype
!= get_type_value (name
))
1504 cp_error ("qualified type `%T' does not match destructor name `~%T'",
1506 return cp_convert (void_type_node
, exp
);
1509 if (! is_aggr_type (basetype
, 1))
1510 return error_mark_node
;
1512 if (! IS_AGGR_TYPE (type
))
1514 cp_error ("base object `%E' of scoped method call is of non-aggregate type `%T'",
1516 return error_mark_node
;
1521 binfo
= get_binfo (basetype
, type
, 1);
1522 if (binfo
== error_mark_node
)
1523 return error_mark_node
;
1525 error_not_base_type (basetype
, type
);
1530 if (TREE_CODE (exp
) == INDIRECT_REF
)
1531 decl
= build_indirect_ref
1532 (convert_pointer_to_real
1533 (binfo
, build_unary_op (ADDR_EXPR
, exp
, 0)), NULL_PTR
);
1535 decl
= build_scoped_ref (exp
, basetype
);
1537 /* Call to a destructor. */
1538 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1540 /* Explicit call to destructor. */
1541 name
= TREE_OPERAND (name
, 0);
1542 if (! (name
== TYPE_MAIN_VARIANT (TREE_TYPE (decl
))
1543 || name
== constructor_name (TREE_TYPE (decl
))
1544 || TREE_TYPE (decl
) == get_type_value (name
)))
1547 ("qualified type `%T' does not match destructor name `~%T'",
1548 TREE_TYPE (decl
), name
);
1549 return error_mark_node
;
1551 if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl
)))
1552 return cp_convert (void_type_node
, exp
);
1554 return build_delete (TREE_TYPE (decl
), decl
, integer_two_node
,
1555 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
,
1559 /* Call to a method. */
1560 return build_method_call (decl
, name
, parms
, binfo
,
1561 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
);
1563 return error_mark_node
;
1567 print_candidates (candidates
)
1570 cp_error_at ("candidates are: %D", TREE_VALUE (candidates
));
1571 candidates
= TREE_CHAIN (candidates
);
1575 cp_error_at (" %D", TREE_VALUE (candidates
));
1576 candidates
= TREE_CHAIN (candidates
);
1581 print_n_candidates (candidates
, n
)
1582 struct candidate
*candidates
;
1587 cp_error_at ("candidates are: %D", candidates
[0].function
);
1588 for (i
= 1; i
< n
; i
++)
1589 cp_error_at (" %D", candidates
[i
].function
);
1592 /* We want the address of a function or method. We avoid creating a
1593 pointer-to-member function. */
1596 build_addr_func (function
)
1599 tree type
= TREE_TYPE (function
);
1601 /* We have to do these by hand to avoid real pointer to member
1603 if (TREE_CODE (type
) == METHOD_TYPE
)
1607 type
= build_pointer_type (type
);
1609 if (mark_addressable (function
) == 0)
1610 return error_mark_node
;
1612 addr
= build1 (ADDR_EXPR
, type
, function
);
1614 /* Address of a static or external variable or function counts
1616 if (staticp (function
))
1617 TREE_CONSTANT (addr
) = 1;
1622 function
= default_conversion (function
);
1627 /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
1628 POINTER_TYPE to those. Note, pointer to member function types
1629 (TYPE_PTRMEMFUNC_P) must be handled by our callers. */
1632 build_call (function
, result_type
, parms
)
1633 tree function
, result_type
, parms
;
1635 int is_constructor
= 0;
1637 function
= build_addr_func (function
);
1639 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
1641 sorry ("unable to call pointer to member function here");
1642 return error_mark_node
;
1645 if (TREE_CODE (function
) == ADDR_EXPR
1646 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
1647 && DECL_CONSTRUCTOR_P (TREE_OPERAND (function
, 0)))
1650 function
= build_nt (CALL_EXPR
, function
, parms
, NULL_TREE
);
1651 TREE_HAS_CONSTRUCTOR (function
) = is_constructor
;
1652 TREE_TYPE (function
) = result_type
;
1653 TREE_SIDE_EFFECTS (function
) = 1;
1659 default_parm_conversions (parms
, last
)
1662 tree parm
, parmtypes
= NULL_TREE
;
1666 for (parm
= parms
; parm
; parm
= TREE_CHAIN (parm
))
1668 tree t
= TREE_TYPE (TREE_VALUE (parm
));
1670 if (TREE_CODE (t
) == OFFSET_TYPE
1671 || TREE_CODE (t
) == METHOD_TYPE
1672 || TREE_CODE (t
) == FUNCTION_TYPE
)
1674 TREE_VALUE (parm
) = default_conversion (TREE_VALUE (parm
));
1675 t
= TREE_TYPE (TREE_VALUE (parm
));
1678 if (t
== error_mark_node
)
1679 return error_mark_node
;
1681 *last
= build_tree_list (NULL_TREE
, t
);
1682 parmtypes
= chainon (parmtypes
, *last
);
1689 /* Build something of the form ptr->method (args)
1690 or object.method (args). This can also build
1691 calls to constructors, and find friends.
1693 Member functions always take their class variable
1696 INSTANCE is a class instance.
1698 NAME is the name of the method desired, usually an IDENTIFIER_NODE.
1700 PARMS help to figure out what that NAME really refers to.
1702 BASETYPE_PATH, if non-NULL, contains a chain from the type of INSTANCE
1703 down to the real instance type to use for access checking. We need this
1704 information to get protected accesses correct. This parameter is used
1705 by build_member_call.
1707 FLAGS is the logical disjunction of zero or more LOOKUP_
1708 flags. See cp-tree.h for more info.
1710 If this is all OK, calls build_function_call with the resolved
1713 This function must also handle being called to perform
1714 initialization, promotion/coercion of arguments, and
1715 instantiation of default parameters.
1717 Note that NAME may refer to an instance variable name. If
1718 `operator()()' is defined for the type of that field, then we return
1722 build_method_call (instance
, name
, parms
, basetype_path
, flags
)
1723 tree instance
, name
, parms
, basetype_path
;
1726 register tree function
, fntype
, value_type
;
1727 register tree basetype
, save_basetype
;
1728 register tree baselink
, result
, parmtypes
;
1731 tree access
= access_public_node
;
1732 tree orig_basetype
= basetype_path
? BINFO_TYPE (basetype_path
) : NULL_TREE
;
1734 /* Range of cases for vtable optimization. */
1735 enum vtable_needs
{ not_needed
, maybe_needed
, unneeded
, needed
};
1736 enum vtable_needs need_vtbl
= not_needed
;
1739 tree save_name
= name
;
1741 tree instance_ptr
= NULL_TREE
;
1742 int all_virtual
= flag_all_virtual
;
1743 int static_call_context
= 0;
1744 tree found_fns
= NULL_TREE
;
1746 /* Keep track of `const' and `volatile' objects. */
1747 int constp
, volatilep
;
1749 #ifdef GATHER_STATISTICS
1750 n_build_method_call
++;
1753 if (instance
== error_mark_node
1754 || name
== error_mark_node
1755 || parms
== error_mark_node
1756 || (instance
!= NULL_TREE
&& TREE_TYPE (instance
) == error_mark_node
))
1757 return error_mark_node
;
1759 if (processing_template_decl
)
1761 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1763 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 1);
1764 name
= build_min_nt (BIT_NOT_EXPR
, type
);
1767 return build_min_nt (METHOD_CALL_EXPR
, name
, instance
, parms
, NULL_TREE
);
1770 /* This is the logic that magically deletes the second argument to
1771 operator delete, if it is not needed. */
1772 if (name
== ansi_opname
[(int) DELETE_EXPR
] && list_length (parms
)==2)
1774 tree save_last
= TREE_CHAIN (parms
);
1776 /* get rid of unneeded argument */
1777 TREE_CHAIN (parms
) = NULL_TREE
;
1778 result
= build_method_call (instance
, name
, parms
, basetype_path
,
1779 (LOOKUP_SPECULATIVELY
|flags
)
1781 /* If it finds a match, return it. */
1783 return build_method_call (instance
, name
, parms
, basetype_path
, flags
);
1784 /* If it doesn't work, two argument delete must work */
1785 TREE_CHAIN (parms
) = save_last
;
1787 /* We already know whether it's needed or not for vec delete. */
1788 else if (name
== ansi_opname
[(int) VEC_DELETE_EXPR
]
1789 && TYPE_LANG_SPECIFIC (TREE_TYPE (instance
))
1790 && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance
)))
1791 TREE_CHAIN (parms
) = NULL_TREE
;
1793 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1795 flags
|= LOOKUP_DESTRUCTOR
;
1796 name
= TREE_OPERAND (name
, 0);
1798 error ("destructors take no parameters");
1799 basetype
= TREE_TYPE (instance
);
1800 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
1801 basetype
= TREE_TYPE (basetype
);
1802 if (! (name
== basetype
1803 || (IS_AGGR_TYPE (basetype
)
1804 && name
== constructor_name (basetype
))
1805 || basetype
== get_type_value (name
)))
1807 cp_error ("destructor name `~%D' does not match type `%T' of expression",
1809 return cp_convert (void_type_node
, instance
);
1812 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1813 return cp_convert (void_type_node
, instance
);
1814 instance
= default_conversion (instance
);
1815 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
1816 return build_delete (build_pointer_type (basetype
),
1817 instance_ptr
, integer_two_node
,
1818 LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
, 0);
1821 if (flag_ansi_overloading
)
1822 return build_new_method_call (instance
, name
, parms
, basetype_path
, flags
);
1827 /* Initialize name for error reporting. */
1828 if (IDENTIFIER_OPNAME_P (name
) && ! IDENTIFIER_TYPENAME_P (name
))
1830 char *p
= operator_name_string (name
);
1831 xref_name
= (char *)alloca (strlen (p
) + 10);
1832 sprintf (xref_name
, "operator %s", p
);
1834 else if (TREE_CODE (name
) == SCOPE_REF
)
1835 xref_name
= IDENTIFIER_POINTER (TREE_OPERAND (name
, 1));
1837 xref_name
= IDENTIFIER_POINTER (name
);
1839 GNU_xref_call (current_function_decl
, xref_name
);
1842 if (instance
== NULL_TREE
)
1844 basetype
= NULL_TREE
;
1845 /* Check cases where this is really a call to raise
1847 if (current_class_type
&& TREE_CODE (name
) == IDENTIFIER_NODE
)
1849 basetype
= purpose_member (name
, CLASSTYPE_TAGS (current_class_type
));
1851 basetype
= TREE_VALUE (basetype
);
1853 else if (TREE_CODE (name
) == SCOPE_REF
1854 && TREE_CODE (TREE_OPERAND (name
, 0)) == IDENTIFIER_NODE
)
1856 if (! is_aggr_typedef (TREE_OPERAND (name
, 0), 1))
1857 return error_mark_node
;
1858 basetype
= purpose_member (TREE_OPERAND (name
, 1),
1859 CLASSTYPE_TAGS (IDENTIFIER_TYPE_VALUE (TREE_OPERAND (name
, 0))));
1861 basetype
= TREE_VALUE (basetype
);
1864 if (basetype
!= NULL_TREE
)
1866 /* call to a constructor... */
1867 else if (basetype_path
)
1869 basetype
= BINFO_TYPE (basetype_path
);
1870 if (name
== TYPE_IDENTIFIER (basetype
))
1871 name
= ctor_identifier
;
1873 else if (IDENTIFIER_HAS_TYPE_VALUE (name
))
1875 basetype
= IDENTIFIER_TYPE_VALUE (name
);
1876 name
= ctor_identifier
;
1880 tree typedef_name
= lookup_name (name
, 1);
1881 if (typedef_name
&& TREE_CODE (typedef_name
) == TYPE_DECL
)
1883 /* Canonicalize the typedef name. */
1884 basetype
= TREE_TYPE (typedef_name
);
1885 name
= ctor_identifier
;
1889 cp_error ("no constructor named `%T' in scope",
1891 return error_mark_node
;
1895 if (! IS_AGGR_TYPE (basetype
))
1898 if ((flags
& LOOKUP_COMPLAIN
) && basetype
!= error_mark_node
)
1899 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1900 name
, instance
, basetype
);
1902 return error_mark_node
;
1905 else if (instance
== current_class_ref
|| instance
== current_class_ptr
)
1907 /* When doing initialization, we side-effect the TREE_TYPE of
1908 current_class_ref, hence we cannot set up BASETYPE from CURRENT_CLASS_TYPE. */
1909 basetype
= TREE_TYPE (current_class_ref
);
1911 /* Anything manifestly `this' in constructors and destructors
1912 has a known type, so virtual function tables are not needed. */
1913 if (TYPE_VIRTUAL_P (basetype
)
1914 && !(flags
& LOOKUP_NONVIRTUAL
))
1915 need_vtbl
= (dtor_label
|| ctor_label
)
1916 ? unneeded
: maybe_needed
;
1918 /* If `this' is a signature pointer and `name' is not a constructor,
1919 we are calling a signature member function. In that case, set the
1920 `basetype' to the signature type and dereference the `optr' field. */
1921 if (IS_SIGNATURE_POINTER (basetype
)
1922 && TYPE_IDENTIFIER (basetype
) != name
)
1924 basetype
= SIGNATURE_TYPE (basetype
);
1925 instance_ptr
= instance
;
1926 basetype_path
= TYPE_BINFO (basetype
);
1930 instance
= current_class_ref
;
1931 instance_ptr
= current_class_ptr
;
1932 basetype_path
= TYPE_BINFO (current_class_type
);
1934 result
= build_field_call (basetype_path
, instance_ptr
, name
, parms
);
1939 else if (TREE_CODE (instance
) == RESULT_DECL
)
1941 basetype
= TREE_TYPE (instance
);
1942 /* Should we ever have to make a virtual function reference
1943 from a RESULT_DECL, know that it must be of fixed type
1944 within the scope of this function. */
1945 if (!(flags
& LOOKUP_NONVIRTUAL
) && TYPE_VIRTUAL_P (basetype
))
1946 need_vtbl
= maybe_needed
;
1947 instance_ptr
= build1 (ADDR_EXPR
, build_pointer_type (basetype
), instance
);
1951 /* The MAIN_VARIANT of the type that `instance_ptr' winds up being. */
1952 tree inst_ptr_basetype
;
1955 = (TREE_CODE (instance
) == INDIRECT_REF
1956 && TREE_CODE (TREE_OPERAND (instance
, 0)) == NOP_EXPR
1957 && TREE_OPERAND (TREE_OPERAND (instance
, 0), 0) == error_mark_node
);
1959 if (TREE_CODE (instance
) == OFFSET_REF
)
1960 instance
= resolve_offset_ref (instance
);
1962 /* the base type of an instance variable is pointer to class */
1963 basetype
= TREE_TYPE (instance
);
1965 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
1967 basetype
= TREE_TYPE (basetype
);
1968 if (! IS_AGGR_TYPE (basetype
))
1969 goto non_aggr_error
;
1970 /* Call to convert not needed because we are remaining
1971 within the same type. */
1972 instance_ptr
= build1 (NOP_EXPR
, build_pointer_type (basetype
),
1974 inst_ptr_basetype
= TYPE_MAIN_VARIANT (basetype
);
1978 if (! IS_AGGR_TYPE (basetype
)
1979 && ! (TYPE_LANG_SPECIFIC (basetype
)
1980 && (IS_SIGNATURE_POINTER (basetype
)
1981 || IS_SIGNATURE_REFERENCE (basetype
))))
1982 goto non_aggr_error
;
1984 /* If `instance' is a signature pointer/reference and `name' is
1985 not a constructor, we are calling a signature member function.
1986 In that case set the `basetype' to the signature type. */
1987 if ((IS_SIGNATURE_POINTER (basetype
)
1988 || IS_SIGNATURE_REFERENCE (basetype
))
1989 && TYPE_IDENTIFIER (basetype
) != name
)
1990 basetype
= SIGNATURE_TYPE (basetype
);
1992 basetype
= complete_type (basetype
);
1994 if ((IS_SIGNATURE (basetype
)
1995 && (instance_ptr
= instance
))
1996 || (lvalue_p (instance
)
1997 && (instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0)))
1998 || (instance_ptr
= unary_complex_lvalue (ADDR_EXPR
, instance
)))
2000 if (instance_ptr
== error_mark_node
)
2001 return error_mark_node
;
2003 else if (TREE_CODE (instance
) == NOP_EXPR
2004 || TREE_CODE (instance
) == CONSTRUCTOR
)
2006 /* A cast is not an lvalue. Initialize a fresh temp
2007 with the value we are casting from, and proceed with
2008 that temporary. We can't cast to a reference type,
2009 so that simplifies the initialization to something
2011 tree temp
= get_temp_name (TREE_TYPE (instance
), 0);
2012 if (IS_AGGR_TYPE (TREE_TYPE (instance
)))
2013 expand_aggr_init (temp
, instance
, 0, flags
);
2016 store_init_value (temp
, instance
);
2017 expand_decl_init (temp
);
2020 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
2024 if (TREE_CODE (instance
) != CALL_EXPR
)
2025 my_friendly_abort (125);
2026 if (TYPE_NEEDS_CONSTRUCTING (basetype
))
2027 instance
= build_cplus_new (basetype
, instance
);
2030 instance
= get_temp_name (basetype
, 0);
2031 TREE_ADDRESSABLE (instance
) = 1;
2033 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
2035 /* @@ Should we call comp_target_types here? */
2036 if (IS_SIGNATURE (basetype
))
2037 inst_ptr_basetype
= basetype
;
2039 inst_ptr_basetype
= TREE_TYPE (TREE_TYPE (instance_ptr
));
2040 if (TYPE_MAIN_VARIANT (basetype
) == TYPE_MAIN_VARIANT (inst_ptr_basetype
))
2041 basetype
= inst_ptr_basetype
;
2044 instance_ptr
= cp_convert (build_pointer_type (basetype
), instance_ptr
);
2045 if (instance_ptr
== error_mark_node
)
2046 return error_mark_node
;
2050 /* After converting `instance_ptr' above, `inst_ptr_basetype' was
2051 not updated, so we use `basetype' instead. */
2052 if (basetype_path
== NULL_TREE
2053 && IS_SIGNATURE (basetype
))
2054 basetype_path
= TYPE_BINFO (basetype
);
2055 else if (basetype_path
== NULL_TREE
2056 || (BINFO_TYPE (basetype_path
)
2057 != TYPE_MAIN_VARIANT (inst_ptr_basetype
)))
2058 basetype_path
= TYPE_BINFO (inst_ptr_basetype
);
2060 result
= build_field_call (basetype_path
, instance_ptr
, name
, parms
);
2064 if (!(flags
& LOOKUP_NONVIRTUAL
) && TYPE_VIRTUAL_P (basetype
))
2066 if (TREE_SIDE_EFFECTS (instance_ptr
))
2068 /* This action is needed because the instance is needed
2069 for providing the base of the virtual function table.
2070 Without using a SAVE_EXPR, the function we are building
2071 may be called twice, or side effects on the instance
2072 variable (such as a post-increment), may happen twice. */
2073 instance_ptr
= save_expr (instance_ptr
);
2074 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2076 else if (TREE_CODE (TREE_TYPE (instance
)) == POINTER_TYPE
)
2078 /* This happens when called for operator new (). */
2079 instance
= build_indirect_ref (instance
, NULL_PTR
);
2082 need_vtbl
= maybe_needed
;
2086 if (save_name
== ctor_identifier
)
2087 save_name
= TYPE_IDENTIFIER (basetype
);
2089 if (TYPE_SIZE (complete_type (basetype
)) == 0)
2091 /* This is worth complaining about, I think. */
2092 cp_error ("cannot lookup method in incomplete type `%T'", basetype
);
2093 return error_mark_node
;
2096 save_basetype
= TYPE_MAIN_VARIANT (basetype
);
2098 parmtypes
= default_parm_conversions (parms
, &last
);
2099 if (parmtypes
== error_mark_node
)
2101 return error_mark_node
;
2104 if (instance
&& IS_SIGNATURE (basetype
))
2106 /* @@ Should this be the constp/volatilep flags for the optr field
2107 of the signature pointer? */
2108 constp
= TYPE_READONLY (basetype
);
2109 volatilep
= TYPE_VOLATILE (basetype
);
2110 parms
= tree_cons (NULL_TREE
, instance_ptr
, parms
);
2114 /* TREE_READONLY (instance) fails for references. */
2115 constp
= TYPE_READONLY (TREE_TYPE (TREE_TYPE (instance_ptr
)));
2116 volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (instance_ptr
)));
2117 parms
= tree_cons (NULL_TREE
, instance_ptr
, parms
);
2121 /* Raw constructors are always in charge. */
2122 if (TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
2123 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
2125 flags
|= LOOKUP_HAS_IN_CHARGE
;
2126 parms
= tree_cons (NULL_TREE
, integer_one_node
, parms
);
2127 parmtypes
= tree_cons (NULL_TREE
, integer_type_node
, parmtypes
);
2132 instance_ptr
= build_int_2 (0, 0);
2133 TREE_TYPE (instance_ptr
) = build_pointer_type (basetype
);
2134 parms
= tree_cons (NULL_TREE
, instance_ptr
, parms
);
2137 parmtypes
= tree_cons (NULL_TREE
, TREE_TYPE (instance_ptr
), parmtypes
);
2139 if (last
== NULL_TREE
)
2142 /* Look up function name in the structure type definition. */
2144 /* FIXME Axe most of this now? */
2145 if ((IDENTIFIER_HAS_TYPE_VALUE (name
)
2146 && ! IDENTIFIER_OPNAME_P (name
)
2147 && IS_AGGR_TYPE (IDENTIFIER_TYPE_VALUE (name
)))
2148 || name
== constructor_name (basetype
)
2149 || name
== ctor_identifier
)
2151 tree tmp
= NULL_TREE
;
2152 if (IDENTIFIER_TYPE_VALUE (name
) == basetype
2153 || name
== constructor_name (basetype
)
2154 || name
== ctor_identifier
)
2155 tmp
= TYPE_BINFO (basetype
);
2157 tmp
= get_binfo (IDENTIFIER_TYPE_VALUE (name
), basetype
, 0);
2159 if (tmp
!= NULL_TREE
)
2161 name_kind
= "constructor";
2163 if (TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
2164 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
2166 /* Constructors called for initialization
2167 only are never in charge. */
2170 flags
|= LOOKUP_HAS_IN_CHARGE
;
2171 tmplist
= tree_cons (NULL_TREE
, integer_zero_node
,
2172 TREE_CHAIN (parms
));
2173 TREE_CHAIN (parms
) = tmplist
;
2174 tmplist
= tree_cons (NULL_TREE
, integer_type_node
, TREE_CHAIN (parmtypes
));
2175 TREE_CHAIN (parmtypes
) = tmplist
;
2177 basetype
= BINFO_TYPE (tmp
);
2180 name_kind
= "method";
2183 name_kind
= "method";
2185 if (basetype_path
== NULL_TREE
2186 || BINFO_TYPE (basetype_path
) != TYPE_MAIN_VARIANT (basetype
))
2187 basetype_path
= TYPE_BINFO (basetype
);
2188 result
= lookup_fnfields (basetype_path
, name
,
2189 (flags
& LOOKUP_COMPLAIN
));
2190 if (result
== error_mark_node
)
2191 return error_mark_node
;
2193 for (pass
= 0; pass
< 2; pass
++)
2195 struct candidate
*candidates
;
2196 struct candidate
*cp
;
2205 = (struct candidate
*) alloca ((ever_seen
+1)
2206 * sizeof (struct candidate
));
2207 bzero ((char *) candidates
, (ever_seen
+ 1) * sizeof (struct candidate
));
2209 len
= list_length (parms
);
2212 /* First see if a global function has a shot at it. */
2213 if (flags
& LOOKUP_GLOBAL
)
2216 tree parm
= instance_ptr
;
2218 if (TREE_CODE (TREE_TYPE (parm
)) == REFERENCE_TYPE
)
2219 parm
= convert_from_reference (parm
);
2220 else if (TREE_CODE (TREE_TYPE (parm
)) == POINTER_TYPE
)
2221 parm
= build_indirect_ref (parm
, "friendifying parms (compiler error)");
2223 my_friendly_abort (167);
2225 friend_parms
= tree_cons (NULL_TREE
, parm
, TREE_CHAIN (parms
));
2228 cp
->harshness
= (struct harshness_code
*)
2229 alloca ((len
+ 1) * sizeof (struct harshness_code
));
2231 result
= build_overload_call_real (name
, friend_parms
, 0, cp
, 1);
2233 /* If it turns out to be the one we were actually looking for
2234 (it was probably a friend function), the return the
2236 if (TREE_CODE (result
) == CALL_EXPR
)
2239 while ((cp
->h
.code
& EVIL_CODE
) == 0)
2241 /* non-standard uses: set the field to 0 to indicate
2242 we are using a non-member function. */
2244 if (cp
->harshness
[len
].distance
== 0
2245 && cp
->h
.code
< best
)
2254 /* We have a hit (of sorts). If the parameter list is
2255 "error_mark_node", or some variant thereof, it won't
2256 match any methods. Since we have verified that the is
2257 some method vaguely matching this one (in name at least),
2260 Don't stop for friends, however. */
2261 basetype_path
= TREE_PURPOSE (baselink
);
2263 function
= TREE_VALUE (baselink
);
2264 if (TREE_CODE (basetype_path
) == TREE_LIST
)
2265 basetype_path
= TREE_VALUE (basetype_path
);
2266 basetype
= BINFO_TYPE (basetype_path
);
2268 for (; function
; function
= DECL_CHAIN (function
))
2270 #ifdef GATHER_STATISTICS
2271 n_inner_fields_searched
++;
2275 found_fns
= tree_cons (NULL_TREE
, function
, found_fns
);
2277 /* Not looking for friends here. */
2278 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
2279 && ! DECL_STATIC_FUNCTION_P (function
))
2284 tree these_parms
= parms
;
2286 #ifdef GATHER_STATISTICS
2287 n_inner_fields_searched
++;
2290 cp
->harshness
= (struct harshness_code
*)
2291 alloca ((len
+ 1) * sizeof (struct harshness_code
));
2293 if (DECL_STATIC_FUNCTION_P (function
))
2294 these_parms
= TREE_CHAIN (these_parms
);
2295 compute_conversion_costs (function
, these_parms
, cp
, len
);
2297 if ((cp
->h
.code
& EVIL_CODE
) == 0)
2299 cp
->u
.field
= function
;
2300 cp
->function
= function
;
2301 cp
->basetypes
= basetype_path
;
2303 /* Don't allow non-converting constructors to convert. */
2304 if (flags
& LOOKUP_ONLYCONVERTING
2305 && DECL_LANG_SPECIFIC (function
)
2306 && DECL_NONCONVERTING_P (function
))
2309 /* No "two-level" conversions. */
2310 if (flags
& LOOKUP_NO_CONVERSION
2311 && (cp
->h
.code
& USER_CODE
))
2322 tree igv
= lookup_name_nonclass (name
);
2324 /* No exact match could be found. Now try to find match
2325 using default conversions. */
2326 if ((flags
& LOOKUP_GLOBAL
) && igv
)
2328 if (TREE_CODE (igv
) == FUNCTION_DECL
)
2330 else if (TREE_CODE (igv
) == TREE_LIST
)
2331 ever_seen
+= count_functions (igv
);
2336 if ((flags
& (LOOKUP_SPECULATIVELY
|LOOKUP_COMPLAIN
))
2337 == LOOKUP_SPECULATIVELY
)
2340 TREE_CHAIN (last
) = void_list_node
;
2341 if (flags
& LOOKUP_GLOBAL
)
2342 cp_error ("no global or member function `%D(%A)' defined",
2343 save_name
, parmtypes
);
2345 cp_error ("no member function `%T::%D(%A)' defined",
2346 save_basetype
, save_name
, TREE_CHAIN (parmtypes
));
2347 return error_mark_node
;
2352 if (cp
- candidates
!= 0)
2354 /* Rank from worst to best. Then cp will point to best one.
2355 Private fields have their bits flipped. For unsigned
2356 numbers, this should make them look very large.
2357 If the best alternate has a (signed) negative value,
2358 then all we ever saw were private members. */
2359 if (cp
- candidates
> 1)
2361 int n_candidates
= cp
- candidates
;
2362 extern int warn_synth
;
2363 TREE_VALUE (parms
) = instance_ptr
;
2364 cp
= ideal_candidate (candidates
, n_candidates
, len
);
2365 if (cp
== (struct candidate
*)0)
2367 if (flags
& LOOKUP_COMPLAIN
)
2369 TREE_CHAIN (last
) = void_list_node
;
2370 cp_error ("call of overloaded %s `%D(%A)' is ambiguous",
2371 name_kind
, save_name
, TREE_CHAIN (parmtypes
));
2372 print_n_candidates (candidates
, n_candidates
);
2374 return error_mark_node
;
2376 if (cp
->h
.code
& EVIL_CODE
)
2377 return error_mark_node
;
2379 && DECL_NAME (cp
->function
) == ansi_opname
[MODIFY_EXPR
]
2380 && DECL_ARTIFICIAL (cp
->function
)
2381 && n_candidates
== 2)
2383 cp_warning ("using synthesized `%#D' for copy assignment",
2385 cp_warning_at (" where cfront would use `%#D'",
2386 candidates
->function
);
2389 else if (cp
[-1].h
.code
& EVIL_CODE
)
2391 if (flags
& LOOKUP_COMPLAIN
)
2392 cp_error ("ambiguous type conversion requested for %s `%D'",
2393 name_kind
, save_name
);
2394 return error_mark_node
;
2399 /* The global function was the best, so use it. */
2400 if (cp
->u
.field
== 0)
2402 /* We must convert the instance pointer into a reference type.
2403 Global overloaded functions can only either take
2404 aggregate objects (which come for free from references)
2405 or reference data types anyway. */
2406 TREE_VALUE (parms
) = copy_node (instance_ptr
);
2407 TREE_TYPE (TREE_VALUE (parms
)) = build_reference_type (TREE_TYPE (TREE_TYPE (instance_ptr
)));
2408 return build_function_call (cp
->function
, parms
);
2411 function
= cp
->function
;
2412 basetype_path
= cp
->basetypes
;
2413 if (! DECL_STATIC_FUNCTION_P (function
))
2414 TREE_VALUE (parms
) = cp
->arg
;
2415 goto found_and_maybe_warn
;
2418 if (flags
& (LOOKUP_COMPLAIN
|LOOKUP_SPECULATIVELY
))
2420 if ((flags
& (LOOKUP_SPECULATIVELY
|LOOKUP_COMPLAIN
))
2421 == LOOKUP_SPECULATIVELY
)
2424 if (DECL_STATIC_FUNCTION_P (cp
->function
))
2425 parms
= TREE_CHAIN (parms
);
2428 if (flags
& LOOKUP_SPECULATIVELY
)
2430 if (static_call_context
2431 && TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
2432 cp_error ("object missing in call to `%D'", cp
->function
);
2433 else if (ever_seen
> 1)
2435 TREE_CHAIN (last
) = void_list_node
;
2436 cp_error ("no matching function for call to `%T::%D (%A)%V'",
2437 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (instance_ptr
))),
2438 save_name
, TREE_CHAIN (parmtypes
),
2439 TREE_TYPE (TREE_TYPE (instance_ptr
)));
2440 TREE_CHAIN (last
) = NULL_TREE
;
2441 print_candidates (found_fns
);
2444 report_type_mismatch (cp
, parms
, name_kind
);
2445 return error_mark_node
;
2448 if ((flags
& (LOOKUP_SPECULATIVELY
|LOOKUP_COMPLAIN
))
2451 cp_error ("%T has no method named %D", save_basetype
, save_name
);
2452 return error_mark_node
;
2458 found_and_maybe_warn
:
2459 if ((cp
->harshness
[0].code
& CONST_CODE
)
2460 /* 12.1p2: Constructors can be called for const objects. */
2461 && ! DECL_CONSTRUCTOR_P (cp
->function
))
2463 if (flags
& LOOKUP_COMPLAIN
)
2465 cp_error_at ("non-const member function `%D'", cp
->function
);
2466 error ("called for const object at this point in file");
2468 /* Not good enough for a match. */
2470 return error_mark_node
;
2474 /* Silently return error_mark_node. */
2475 return error_mark_node
;
2478 if (flags
& LOOKUP_PROTECT
)
2479 access
= compute_access (basetype_path
, function
);
2481 if (access
== access_private_node
)
2483 if (flags
& LOOKUP_COMPLAIN
)
2485 cp_error_at ("%s `%+#D' is %s", name_kind
, function
,
2486 TREE_PRIVATE (function
) ? "private"
2487 : "from private base class");
2488 error ("within this context");
2490 return error_mark_node
;
2492 else if (access
== access_protected_node
)
2494 if (flags
& LOOKUP_COMPLAIN
)
2496 cp_error_at ("%s `%+#D' %s", name_kind
, function
,
2497 TREE_PROTECTED (function
) ? "is protected"
2498 : "has protected accessibility");
2499 error ("within this context");
2501 return error_mark_node
;
2504 /* From here on down, BASETYPE is the type that INSTANCE_PTR's
2505 type (if it exists) is a pointer to. */
2507 if (DECL_ABSTRACT_VIRTUAL_P (function
)
2508 && instance
== current_class_ref
2509 && DECL_CONSTRUCTOR_P (current_function_decl
)
2510 && ! (flags
& LOOKUP_NONVIRTUAL
)
2511 && value_member (function
, get_abstract_virtuals (basetype
)))
2512 cp_error ("abstract virtual `%#D' called from constructor", function
);
2514 if (IS_SIGNATURE (basetype
))
2516 if (static_call_context
)
2518 cp_error ("cannot call signature member function `%T::%D' without signature pointer/reference",
2519 basetype
, save_name
);
2520 return error_mark_node
;
2522 return build_signature_method_call (function
, parms
);
2525 function
= DECL_MAIN_VARIANT (function
);
2526 mark_used (function
);
2528 fntype
= TREE_TYPE (function
);
2529 if (TREE_CODE (fntype
) == POINTER_TYPE
)
2530 fntype
= TREE_TYPE (fntype
);
2531 basetype
= DECL_CLASS_CONTEXT (function
);
2533 /* If we are referencing a virtual function from an object
2534 of effectively static type, then there is no need
2535 to go through the virtual function table. */
2536 if (need_vtbl
== maybe_needed
)
2538 int fixed_type
= resolves_to_fixed_type_p (instance
, 0);
2540 if (all_virtual
== 1
2541 && DECL_VINDEX (function
)
2542 && may_be_remote (basetype
))
2544 else if (DECL_VINDEX (function
))
2545 need_vtbl
= fixed_type
? unneeded
: needed
;
2547 need_vtbl
= not_needed
;
2550 if (TREE_CODE (fntype
) == METHOD_TYPE
&& static_call_context
2551 && !DECL_CONSTRUCTOR_P (function
))
2553 /* Let's be nasty to the user now, and give reasonable
2555 instance_ptr
= current_class_ptr
;
2558 if (basetype
!= current_class_type
)
2560 if (basetype
== error_mark_node
)
2561 return error_mark_node
;
2564 if (orig_basetype
!= NULL_TREE
)
2565 error_not_base_type (orig_basetype
, current_class_type
);
2567 error_not_base_type (function
, current_class_type
);
2568 return error_mark_node
;
2572 /* Only allow a static member function to call another static member
2574 else if (DECL_LANG_SPECIFIC (function
)
2575 && !DECL_STATIC_FUNCTION_P (function
))
2577 cp_error ("cannot call member function `%D' without object",
2579 return error_mark_node
;
2583 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2585 if (TYPE_SIZE (complete_type (value_type
)) == 0)
2587 if (flags
& LOOKUP_COMPLAIN
)
2588 incomplete_type_error (0, value_type
);
2589 return error_mark_node
;
2592 if (DECL_STATIC_FUNCTION_P (function
))
2593 parms
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2594 TREE_CHAIN (parms
), function
, LOOKUP_NORMAL
);
2595 else if (need_vtbl
== unneeded
)
2597 int sub_flags
= DECL_CONSTRUCTOR_P (function
) ? flags
: LOOKUP_NORMAL
;
2598 basetype
= TREE_TYPE (instance
);
2599 if (TYPE_METHOD_BASETYPE (TREE_TYPE (function
))
2600 != TYPE_MAIN_VARIANT (basetype
))
2602 basetype
= DECL_CLASS_CONTEXT (function
);
2603 instance_ptr
= convert_pointer_to (basetype
, instance_ptr
);
2604 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2606 parms
= tree_cons (NULL_TREE
, instance_ptr
,
2607 convert_arguments (NULL_TREE
, TREE_CHAIN (TYPE_ARG_TYPES (fntype
)), TREE_CHAIN (parms
), function
, sub_flags
));
2611 if ((flags
& LOOKUP_NONVIRTUAL
) == 0)
2612 basetype
= DECL_CONTEXT (function
);
2614 /* First parm could be integer_zerop with casts like
2615 ((Object*)0)->Object::IsA() */
2616 if (!integer_zerop (TREE_VALUE (parms
)))
2618 /* Since we can't have inheritance with a union, doing get_binfo
2619 on it won't work. We do all the convert_pointer_to_real
2620 stuff to handle MI correctly...for unions, that's not
2621 an issue, so we must short-circuit that extra work here. */
2622 tree tmp
= TREE_TYPE (TREE_TYPE (TREE_VALUE (parms
)));
2623 if (tmp
!= NULL_TREE
&& TREE_CODE (tmp
) == UNION_TYPE
)
2624 instance_ptr
= TREE_VALUE (parms
);
2627 tree binfo
= get_binfo (basetype
,
2628 TREE_TYPE (TREE_TYPE (TREE_VALUE (parms
))),
2630 instance_ptr
= convert_pointer_to_real (binfo
, TREE_VALUE (parms
));
2633 = convert_pointer_to (build_type_variant (basetype
,
2637 if (TREE_CODE (instance_ptr
) == COND_EXPR
)
2639 instance_ptr
= save_expr (instance_ptr
);
2640 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2642 else if (TREE_CODE (instance_ptr
) == NOP_EXPR
2643 && TREE_CODE (TREE_OPERAND (instance_ptr
, 0)) == ADDR_EXPR
2644 && TREE_OPERAND (TREE_OPERAND (instance_ptr
, 0), 0) == instance
)
2646 /* The call to `convert_pointer_to' may return error_mark_node. */
2647 else if (instance_ptr
== error_mark_node
)
2648 return instance_ptr
;
2649 else if (instance
== NULL_TREE
2650 || TREE_CODE (instance
) != INDIRECT_REF
2651 || TREE_OPERAND (instance
, 0) != instance_ptr
)
2652 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2654 parms
= tree_cons (NULL_TREE
, instance_ptr
,
2655 convert_arguments (NULL_TREE
, TREE_CHAIN (TYPE_ARG_TYPES (fntype
)), TREE_CHAIN (parms
), function
, LOOKUP_NORMAL
));
2658 if (parms
== error_mark_node
2659 || (parms
&& TREE_CHAIN (parms
) == error_mark_node
))
2660 return error_mark_node
;
2662 if (need_vtbl
== needed
)
2664 function
= build_vfn_ref (&TREE_VALUE (parms
), instance
,
2665 DECL_VINDEX (function
));
2666 TREE_TYPE (function
) = build_pointer_type (fntype
);
2669 if (TREE_CODE (function
) == FUNCTION_DECL
)
2670 GNU_xref_call (current_function_decl
,
2671 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function
)));
2673 result
= build_call (function
, value_type
, parms
);
2674 if (IS_AGGR_TYPE (value_type
))
2675 result
= build_cplus_new (value_type
, result
);
2676 result
= convert_from_reference (result
);
2680 /* Similar to `build_method_call', but for overloaded non-member functions.
2681 The name of this function comes through NAME. The name depends
2684 Note that this function must handle simple `C' promotions,
2685 as well as variable numbers of arguments (...), and
2686 default arguments to boot.
2688 If the overloading is successful, we return a tree node which
2689 contains the call to the function.
2691 If overloading produces candidates which are probable, but not definite,
2692 we hold these candidates. If FINAL_CP is non-zero, then we are free
2693 to assume that final_cp points to enough storage for all candidates that
2694 this function might generate. The `harshness' array is preallocated for
2695 the first candidate, but not for subsequent ones.
2697 Note that the DECL_RTL of FUNCTION must be made to agree with this
2698 function's new name. */
2701 build_overload_call_real (fnname
, parms
, flags
, final_cp
, require_complete
)
2704 struct candidate
*final_cp
;
2705 int require_complete
;
2707 /* must check for overloading here */
2708 tree functions
, function
;
2709 tree parmtypes
, last
;
2710 register tree outer
;
2712 int parmlength
= list_length (parms
);
2714 struct candidate
*candidates
, *cp
;
2718 final_cp
[0].h
.code
= 0;
2719 final_cp
[0].h
.distance
= 0;
2720 final_cp
[0].function
= 0;
2722 final_cp
[1].h
.code
= EVIL_CODE
;
2725 parmtypes
= default_parm_conversions (parms
, &last
);
2726 if (parmtypes
== error_mark_node
)
2729 final_cp
->h
.code
= EVIL_CODE
;
2730 return error_mark_node
;
2734 TREE_CHAIN (last
) = void_list_node
;
2736 parmtypes
= void_list_node
;
2738 if (is_overloaded_fn (fnname
))
2741 if (TREE_CODE (fnname
) == TREE_LIST
)
2742 fnname
= TREE_PURPOSE (functions
);
2743 else if (TREE_CODE (fnname
) == FUNCTION_DECL
)
2744 fnname
= DECL_NAME (functions
);
2747 functions
= lookup_name_nonclass (fnname
);
2749 if (functions
== NULL_TREE
)
2751 if (flags
& LOOKUP_SPECULATIVELY
)
2753 if (flags
& LOOKUP_COMPLAIN
)
2754 error ("only member functions apply");
2756 final_cp
->h
.code
= EVIL_CODE
;
2757 return error_mark_node
;
2760 if (TREE_CODE (functions
) == FUNCTION_DECL
&& ! IDENTIFIER_OPNAME_P (fnname
))
2762 functions
= DECL_MAIN_VARIANT (functions
);
2765 /* We are just curious whether this is a viable alternative or
2767 compute_conversion_costs (functions
, parms
, final_cp
, parmlength
);
2771 return build_function_call_real (functions
, parms
, 1, flags
);
2774 if (TREE_CODE (functions
) == TREE_LIST
2775 && TREE_VALUE (functions
) == NULL_TREE
)
2777 if (flags
& LOOKUP_SPECULATIVELY
)
2780 if (flags
& LOOKUP_COMPLAIN
)
2781 cp_error ("function `%D' declared overloaded, but no instances of that function declared",
2782 TREE_PURPOSE (functions
));
2784 final_cp
->h
.code
= EVIL_CODE
;
2785 return error_mark_node
;
2788 length
= count_functions (functions
);
2791 candidates
= final_cp
;
2795 = (struct candidate
*)alloca ((length
+1) * sizeof (struct candidate
));
2796 bzero ((char *) candidates
, (length
+ 1) * sizeof (struct candidate
));
2801 my_friendly_assert (is_overloaded_fn (functions
), 169);
2803 functions
= get_first_fn (functions
);
2805 /* OUTER is the list of FUNCTION_DECLS, in a TREE_LIST. */
2806 for (outer
= functions
; outer
; outer
= DECL_CHAIN (outer
))
2808 int template_cost
= 0;
2810 if (TREE_CODE (function
) != FUNCTION_DECL
2811 && ! (TREE_CODE (function
) == TEMPLATE_DECL
2812 && TREE_CODE (DECL_TEMPLATE_RESULT (function
)) == FUNCTION_DECL
))
2814 enum tree_code code
= TREE_CODE (function
);
2815 if (code
== TEMPLATE_DECL
)
2816 code
= TREE_CODE (DECL_TEMPLATE_RESULT (function
));
2817 if (code
== CONST_DECL
)
2819 ("enumeral value `%D' conflicts with function of same name",
2821 else if (code
== VAR_DECL
)
2823 if (TREE_STATIC (function
))
2825 ("variable `%D' conflicts with function of same name",
2829 ("constant field `%D' conflicts with function of same name",
2832 else if (code
== TYPE_DECL
)
2835 my_friendly_abort (2);
2836 error ("at this point in file");
2839 if (TREE_CODE (function
) == TEMPLATE_DECL
)
2841 int ntparms
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (function
));
2842 tree
*targs
= (tree
*) alloca (sizeof (tree
) * ntparms
);
2845 i
= type_unification (DECL_TEMPLATE_PARMS (function
), targs
,
2846 TYPE_ARG_TYPES (TREE_TYPE (function
)),
2847 parms
, &template_cost
, 0, 0);
2850 function
= instantiate_template (function
, targs
);
2851 if (function
== error_mark_node
)
2856 if (TREE_CODE (function
) == TEMPLATE_DECL
)
2858 /* Unconverted template -- failed match. */
2859 cp
->function
= function
;
2861 cp
->h
.code
= EVIL_CODE
;
2865 struct candidate
*cp2
;
2867 /* Check that this decl is not the same as a function that's in
2868 the list due to some template instantiation. */
2871 if (cp2
->function
== function
)
2875 if (cp2
->function
== function
)
2878 function
= DECL_MAIN_VARIANT (function
);
2880 /* Can't use alloca here, since result might be
2881 passed to calling function. */
2882 cp
->h_len
= parmlength
;
2883 cp
->harshness
= (struct harshness_code
*)
2884 oballoc ((parmlength
+ 1) * sizeof (struct harshness_code
));
2886 compute_conversion_costs (function
, parms
, cp
, parmlength
);
2888 /* Make sure this is clear as well. */
2889 cp
->h
.int_penalty
+= template_cost
;
2891 if ((cp
[0].h
.code
& EVIL_CODE
) == 0)
2893 cp
[1].h
.code
= EVIL_CODE
;
2899 if (cp
- candidates
)
2901 tree rval
= error_mark_node
;
2904 cp
[0].h
.code
= EVIL_CODE
;
2905 if (cp
- candidates
> 1)
2907 struct candidate
*best_cp
2908 = ideal_candidate (candidates
, cp
- candidates
, parmlength
);
2909 if (best_cp
== (struct candidate
*)0)
2911 if (flags
& LOOKUP_COMPLAIN
)
2913 cp_error ("call of overloaded `%D' is ambiguous", fnname
);
2914 print_n_candidates (candidates
, cp
- candidates
);
2916 return error_mark_node
;
2919 rval
= best_cp
->function
;
2924 if (cp
->h
.code
& EVIL_CODE
)
2926 if (flags
& LOOKUP_COMPLAIN
)
2927 error ("type conversion ambiguous");
2930 rval
= cp
->function
;
2936 return build_function_call_real (rval
, parms
, require_complete
, flags
);
2939 if (flags
& LOOKUP_SPECULATIVELY
)
2942 if (flags
& LOOKUP_COMPLAIN
)
2943 report_type_mismatch (cp
, parms
, "function");
2945 return error_mark_node
;
2948 /* This requires a complete type on the result of the call. */
2951 build_overload_call (fnname
, parms
, flags
)
2955 return build_overload_call_real (fnname
, parms
, flags
, (struct candidate
*)0, 1);
2958 /* New overloading code. */
2960 struct z_candidate
{
2967 struct z_candidate
*next
;
2970 #define IDENTITY_RANK 0
2971 #define EXACT_RANK 1
2972 #define PROMO_RANK 2
2974 #define PBOOL_RANK 4
2976 #define ELLIPSIS_RANK 6
2979 #define ICS_RANK(NODE) \
2980 (ICS_BAD_FLAG (NODE) ? BAD_RANK \
2981 : ICS_ELLIPSIS_FLAG (NODE) ? ELLIPSIS_RANK \
2982 : ICS_USER_FLAG (NODE) ? USER_RANK \
2983 : ICS_STD_RANK (NODE))
2985 #define ICS_STD_RANK(NODE) TREE_COMPLEXITY (NODE)
2987 #define ICS_USER_FLAG(NODE) TREE_LANG_FLAG_0 (NODE)
2988 #define ICS_ELLIPSIS_FLAG(NODE) TREE_LANG_FLAG_1 (NODE)
2989 #define ICS_THIS_FLAG(NODE) TREE_LANG_FLAG_2 (NODE)
2990 #define ICS_BAD_FLAG(NODE) TREE_LANG_FLAG_3 (NODE)
2992 #define USER_CONV_FN(NODE) TREE_OPERAND (NODE, 1)
2999 || integer_zerop (t
) && INTEGRAL_TYPE_P (TREE_TYPE (t
)))
3005 build_conv (code
, type
, from
)
3006 enum tree_code code
;
3009 tree t
= build1 (code
, type
, from
);
3010 int rank
= ICS_STD_RANK (from
);
3017 if (rank
< STD_RANK
)
3024 if (rank
< EXACT_RANK
)
3030 ICS_STD_RANK (t
) = rank
;
3031 ICS_USER_FLAG (t
) = ICS_USER_FLAG (from
);
3032 ICS_BAD_FLAG (t
) = ICS_BAD_FLAG (from
);
3040 if (TREE_CODE (t
) == REFERENCE_TYPE
)
3049 if (TREE_CODE (t
) == ARRAY_TYPE
)
3051 return TYPE_MAIN_VARIANT (t
);
3054 /* Returns the standard conversion path (see [conv]) from type FROM to type
3055 TO, if any. For proper handling of null pointer constants, you must
3056 also pass the expression EXPR to convert from. */
3059 standard_conversion (to
, from
, expr
)
3060 tree to
, from
, expr
;
3062 enum tree_code fcode
, tcode
;
3066 if (TREE_CODE (to
) == REFERENCE_TYPE
)
3067 to
= TREE_TYPE (to
);
3068 if (TREE_CODE (from
) == REFERENCE_TYPE
)
3071 from
= TREE_TYPE (from
);
3073 to
= strip_top_quals (to
);
3074 from
= strip_top_quals (from
);
3076 fcode
= TREE_CODE (from
);
3077 tcode
= TREE_CODE (to
);
3079 conv
= build1 (IDENTITY_CONV
, from
, expr
);
3081 if (fcode
== FUNCTION_TYPE
)
3083 from
= build_pointer_type (from
);
3084 fcode
= TREE_CODE (from
);
3085 conv
= build_conv (LVALUE_CONV
, from
, conv
);
3087 else if (fcode
== ARRAY_TYPE
)
3089 from
= build_pointer_type (TREE_TYPE (from
));
3090 fcode
= TREE_CODE (from
);
3091 conv
= build_conv (LVALUE_CONV
, from
, conv
);
3093 else if (fromref
|| (expr
&& real_lvalue_p (expr
)))
3094 conv
= build_conv (RVALUE_CONV
, from
, conv
);
3099 if ((tcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (to
))
3100 && expr
&& null_ptr_cst_p (expr
))
3102 conv
= build_conv (STD_CONV
, to
, conv
);
3104 else if (tcode
== POINTER_TYPE
&& fcode
== POINTER_TYPE
)
3106 enum tree_code ufcode
= TREE_CODE (TREE_TYPE (from
));
3107 enum tree_code utcode
= TREE_CODE (TREE_TYPE (to
));
3108 tree nconv
= NULL_TREE
;
3110 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (from
)),
3111 TYPE_MAIN_VARIANT (TREE_TYPE (to
)), 1))
3113 else if (utcode
== VOID_TYPE
&& ufcode
!= OFFSET_TYPE
3114 && ufcode
!= FUNCTION_TYPE
)
3116 from
= build_pointer_type
3117 (cp_build_type_variant (void_type_node
,
3118 TYPE_READONLY (TREE_TYPE (from
)),
3119 TYPE_VOLATILE (TREE_TYPE (from
))));
3120 nconv
= build_conv (PTR_CONV
, from
, conv
);
3122 else if (ufcode
== OFFSET_TYPE
&& utcode
== OFFSET_TYPE
)
3124 tree fbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from
));
3125 tree tbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to
));
3127 if (DERIVED_FROM_P (fbase
, tbase
)
3128 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (from
))),
3129 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (to
))),
3132 from
= build_offset_type (tbase
, TREE_TYPE (TREE_TYPE (from
)));
3133 from
= build_pointer_type (from
);
3134 nconv
= build_conv (PMEM_CONV
, from
, conv
);
3137 else if (IS_AGGR_TYPE (TREE_TYPE (from
))
3138 && IS_AGGR_TYPE (TREE_TYPE (to
)))
3140 if (DERIVED_FROM_P (TREE_TYPE (to
), TREE_TYPE (from
)))
3142 from
= cp_build_type_variant (TREE_TYPE (to
),
3143 TYPE_READONLY (TREE_TYPE (from
)),
3144 TYPE_VOLATILE (TREE_TYPE (from
)));
3145 from
= build_pointer_type (from
);
3146 nconv
= build_conv (PTR_CONV
, from
, conv
);
3150 if (nconv
&& comptypes (from
, to
, 1))
3152 else if (nconv
&& comp_ptr_ttypes (TREE_TYPE (to
), TREE_TYPE (from
)))
3153 conv
= build_conv (QUAL_CONV
, to
, nconv
);
3154 else if (ptr_reasonably_similar (TREE_TYPE (to
), TREE_TYPE (from
)))
3156 conv
= build_conv (PTR_CONV
, to
, conv
);
3157 ICS_BAD_FLAG (conv
) = 1;
3164 else if (TYPE_PTRMEMFUNC_P (to
) && TYPE_PTRMEMFUNC_P (from
))
3166 tree fromfn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from
));
3167 tree tofn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to
));
3168 tree fbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn
)));
3169 tree tbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn
)));
3171 if (! DERIVED_FROM_P (fbase
, tbase
)
3172 || ! comptypes (TREE_TYPE (fromfn
), TREE_TYPE (tofn
), 1)
3173 || ! compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)),
3174 TREE_CHAIN (TYPE_ARG_TYPES (tofn
)), 1)
3175 || TYPE_READONLY (fbase
) != TYPE_READONLY (tbase
)
3176 || TYPE_VOLATILE (fbase
) != TYPE_VOLATILE (tbase
))
3179 from
= cp_build_type_variant (tbase
, TYPE_READONLY (fbase
),
3180 TYPE_VOLATILE (fbase
));
3181 from
= build_cplus_method_type (from
, TREE_TYPE (fromfn
),
3182 TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)));
3183 from
= build_ptrmemfunc_type (build_pointer_type (from
));
3184 conv
= build_conv (PMEM_CONV
, from
, conv
);
3186 else if (tcode
== BOOLEAN_TYPE
)
3188 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
3189 || fcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (from
)))
3192 conv
= build_conv (STD_CONV
, to
, conv
);
3193 if (fcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (from
)
3194 && ICS_STD_RANK (conv
) < PBOOL_RANK
)
3195 ICS_STD_RANK (conv
) = PBOOL_RANK
;
3197 /* We don't check for ENUMERAL_TYPE here because there are no standard
3198 conversions to enum type. */
3199 else if (tcode
== INTEGER_TYPE
|| tcode
== BOOLEAN_TYPE
3200 || tcode
== REAL_TYPE
)
3202 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
))
3204 conv
= build_conv (STD_CONV
, to
, conv
);
3206 /* Give this a better rank if it's a promotion. */
3207 if (to
== type_promotes_to (from
)
3208 && ICS_STD_RANK (TREE_OPERAND (conv
, 0)) <= PROMO_RANK
)
3209 ICS_STD_RANK (conv
) = PROMO_RANK
;
3211 else if (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
3212 && DERIVED_FROM_P (to
, from
))
3213 conv
= build_conv (BASE_CONV
, to
, conv
);
3220 /* Returns the conversion path from type FROM to reference type TO for
3221 purposes of reference binding. For lvalue binding, either pass a
3222 reference type to FROM or an lvalue expression to EXPR.
3224 Currently does not distinguish in the generated trees between binding to
3225 an lvalue and a temporary. Should it? */
3228 reference_binding (rto
, rfrom
, expr
, flags
)
3229 tree rto
, rfrom
, expr
;
3234 tree to
= TREE_TYPE (rto
);
3238 if (TREE_CODE (from
) == REFERENCE_TYPE
)
3239 from
= TREE_TYPE (from
);
3240 else if (! expr
|| ! real_lvalue_p (expr
))
3243 related
= (TYPE_MAIN_VARIANT (to
) == TYPE_MAIN_VARIANT (from
)
3244 || (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
3245 && DERIVED_FROM_P (to
, from
)));
3247 if (lvalue
&& related
3248 && TYPE_READONLY (to
) >= TYPE_READONLY (from
)
3249 && TYPE_VOLATILE (to
) >= TYPE_VOLATILE (from
))
3251 conv
= build1 (IDENTITY_CONV
, from
, expr
);
3253 if (TYPE_MAIN_VARIANT (to
) == TYPE_MAIN_VARIANT (from
))
3254 conv
= build_conv (REF_BIND
, rto
, conv
);
3257 conv
= build_conv (REF_BIND
, rto
, conv
);
3258 ICS_STD_RANK (conv
) = STD_RANK
;
3266 conv
= standard_conversion (to
, rfrom
, expr
);
3269 conv
= build_conv (REF_BIND
, rto
, conv
);
3271 /* Bind directly to a base subobject of a class rvalue. Do it
3272 after building the conversion for proper handling of ICS_RANK. */
3273 if (TREE_CODE (TREE_OPERAND (conv
, 0)) == BASE_CONV
)
3274 TREE_OPERAND (conv
, 0) = TREE_OPERAND (TREE_OPERAND (conv
, 0), 0);
3277 && ((! (TYPE_READONLY (to
) && ! TYPE_VOLATILE (to
)
3278 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0))
3279 /* If T1 is reference-related to T2, cv1 must be the same
3280 cv-qualification as, or greater cv-qualification than,
3281 cv2; otherwise, the program is ill-formed. */
3283 && (TYPE_READONLY (to
) < TYPE_READONLY (from
)
3284 || TYPE_VOLATILE (to
) < TYPE_VOLATILE (from
)))))
3285 ICS_BAD_FLAG (conv
) = 1;
3291 /* Returns the implicit conversion sequence (see [over.ics]) from type FROM
3292 to type TO. The optional expression EXPR may affect the conversion.
3293 FLAGS are the usual overloading flags. Only LOOKUP_NO_CONVERSION is
3297 implicit_conversion (to
, from
, expr
, flags
)
3298 tree to
, from
, expr
;
3302 struct z_candidate
*cand
;
3304 if (expr
&& type_unknown_p (expr
))
3306 expr
= instantiate_type (to
, expr
, 0);
3307 if (expr
== error_mark_node
)
3309 from
= TREE_TYPE (expr
);
3312 if (TREE_CODE (to
) == REFERENCE_TYPE
)
3313 conv
= reference_binding (to
, from
, expr
, flags
);
3315 conv
= standard_conversion (to
, from
, expr
);
3319 else if ((IS_AGGR_TYPE (non_reference (from
))
3320 || IS_AGGR_TYPE (non_reference (to
)))
3321 && (flags
& LOOKUP_NO_CONVERSION
) == 0)
3323 cand
= build_user_type_conversion_1
3324 (to
, expr
, LOOKUP_ONLYCONVERTING
);
3326 conv
= cand
->second_conv
;
3327 if ((! conv
|| ICS_BAD_FLAG (conv
))
3328 && TREE_CODE (to
) == REFERENCE_TYPE
3329 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0)
3331 cand
= build_user_type_conversion_1
3332 (TYPE_MAIN_VARIANT (TREE_TYPE (to
)), expr
, LOOKUP_ONLYCONVERTING
);
3335 if (! TYPE_READONLY (TREE_TYPE (to
))
3336 || TYPE_VOLATILE (TREE_TYPE (to
)))
3337 ICS_BAD_FLAG (cand
->second_conv
) = 1;
3338 if (!conv
|| (ICS_BAD_FLAG (conv
)
3339 > ICS_BAD_FLAG (cand
->second_conv
)))
3340 conv
= build_conv (REF_BIND
, to
, cand
->second_conv
);
3348 /* Create an overload candidate for the function or method FN called with
3349 the argument list ARGLIST and add it to CANDIDATES. FLAGS is passed on
3350 to implicit_conversion. */
3352 static struct z_candidate
*
3353 add_function_candidate (candidates
, fn
, arglist
, flags
)
3354 struct z_candidate
*candidates
;
3358 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
3361 tree parmnode
= parmlist
;
3362 tree argnode
= arglist
;
3364 struct z_candidate
*cand
;
3366 /* The `this' and `in_chrg' arguments to constructors are not considered
3367 in overload resolution. */
3368 if (DECL_CONSTRUCTOR_P (fn
))
3370 parmnode
= TREE_CHAIN (parmnode
);
3371 argnode
= TREE_CHAIN (argnode
);
3372 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3374 parmnode
= TREE_CHAIN (parmnode
);
3375 argnode
= TREE_CHAIN (argnode
);
3379 len
= list_length (argnode
);
3380 convs
= make_tree_vec (len
);
3382 for (i
= 0; i
< len
; ++i
)
3384 tree arg
= TREE_VALUE (argnode
);
3385 tree argtype
= TREE_TYPE (arg
);
3388 argtype
= cp_build_type_variant
3389 (argtype
, TREE_READONLY (arg
), TREE_THIS_VOLATILE (arg
));
3391 if (parmnode
== void_list_node
)
3394 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
3397 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
3398 ICS_ELLIPSIS_FLAG (t
) = 1;
3401 if (i
== 0 && t
&& TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
3402 && ! DECL_CONSTRUCTOR_P (fn
))
3403 ICS_THIS_FLAG (t
) = 1;
3405 TREE_VEC_ELT (convs
, i
) = t
;
3409 if (ICS_BAD_FLAG (t
))
3413 parmnode
= TREE_CHAIN (parmnode
);
3414 argnode
= TREE_CHAIN (argnode
);
3420 /* Make sure there are default args for the rest of the parms. */
3421 for (; parmnode
&& parmnode
!= void_list_node
;
3422 parmnode
= TREE_CHAIN (parmnode
))
3423 if (! TREE_PURPOSE (parmnode
))
3429 cand
= (struct z_candidate
*) oballoc (sizeof (struct z_candidate
));
3432 cand
->convs
= convs
;
3433 cand
->second_conv
= NULL_TREE
;
3434 cand
->viable
= viable
;
3435 cand
->basetype_path
= NULL_TREE
;
3436 cand
->template = NULL_TREE
;
3437 cand
->next
= candidates
;
3442 /* Create an overload candidate for the conversion function FN which will
3443 be invoked for expression OBJ, producing a pointer-to-function which
3444 will in turn be called with the argument list ARGLIST, and add it to
3445 CANDIDATES. FLAGS is passed on to implicit_conversion. */
3447 static struct z_candidate
*
3448 add_conv_candidate (candidates
, fn
, obj
, arglist
)
3449 struct z_candidate
*candidates
;
3450 tree fn
, obj
, arglist
;
3452 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
3453 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (totype
));
3454 int i
, len
= list_length (arglist
) + 1;
3455 tree convs
= make_tree_vec (len
);
3456 tree parmnode
= parmlist
;
3457 tree argnode
= arglist
;
3459 struct z_candidate
*cand
;
3460 int flags
= LOOKUP_NORMAL
;
3462 for (i
= 0; i
< len
; ++i
)
3464 tree arg
= i
== 0 ? obj
: TREE_VALUE (argnode
);
3465 tree argtype
= lvalue_type (arg
);
3469 t
= implicit_conversion (totype
, argtype
, arg
, flags
);
3470 else if (parmnode
== void_list_node
)
3473 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
3476 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
3477 ICS_ELLIPSIS_FLAG (t
) = 1;
3480 TREE_VEC_ELT (convs
, i
) = t
;
3484 if (ICS_BAD_FLAG (t
))
3491 parmnode
= TREE_CHAIN (parmnode
);
3492 argnode
= TREE_CHAIN (argnode
);
3498 for (; parmnode
&& parmnode
!= void_list_node
;
3499 parmnode
= TREE_CHAIN (parmnode
))
3500 if (! TREE_PURPOSE (parmnode
))
3506 cand
= (struct z_candidate
*) oballoc (sizeof (struct z_candidate
));
3509 cand
->convs
= convs
;
3510 cand
->second_conv
= NULL_TREE
;
3511 cand
->viable
= viable
;
3512 cand
->basetype_path
= NULL_TREE
;
3513 cand
->template = NULL_TREE
;
3514 cand
->next
= candidates
;
3519 static struct z_candidate
*
3520 build_builtin_candidate (candidates
, fnname
, type1
, type2
,
3521 args
, argtypes
, flags
)
3522 struct z_candidate
*candidates
;
3523 tree fnname
, type1
, type2
, *args
, *argtypes
;
3529 struct z_candidate
*cand
;
3535 convs
= make_tree_vec (args
[2] ? 3 : (args
[1] ? 2 : 1));
3537 for (i
= 0; i
< 2; ++i
)
3542 t
= implicit_conversion (types
[i
], argtypes
[i
], args
[i
], flags
);
3546 /* We need something for printing the candidate. */
3547 t
= build1 (IDENTITY_CONV
, types
[i
], NULL_TREE
);
3549 else if (ICS_BAD_FLAG (t
))
3551 TREE_VEC_ELT (convs
, i
) = t
;
3554 /* For COND_EXPR we rearranged the arguments; undo that now. */
3557 TREE_VEC_ELT (convs
, 2) = TREE_VEC_ELT (convs
, 1);
3558 TREE_VEC_ELT (convs
, 1) = TREE_VEC_ELT (convs
, 0);
3559 t
= implicit_conversion (boolean_type_node
, argtypes
[2], args
[2], flags
);
3561 TREE_VEC_ELT (convs
, 0) = t
;
3566 cand
= (struct z_candidate
*) oballoc (sizeof (struct z_candidate
));
3569 cand
->convs
= convs
;
3570 cand
->second_conv
= NULL_TREE
;
3571 cand
->viable
= viable
;
3572 cand
->basetype_path
= NULL_TREE
;
3573 cand
->template = NULL_TREE
;
3574 cand
->next
= candidates
;
3583 return TYPE_SIZE (complete_type (t
)) != NULL_TREE
;
3586 /* Create any builtin operator overload candidates for the operator in
3587 question given the converted operand types TYPE1 and TYPE2. The other
3588 args are passed through from add_builtin_candidates to
3589 build_builtin_candidate. */
3591 static struct z_candidate
*
3592 add_builtin_candidate (candidates
, code
, code2
, fnname
, type1
, type2
,
3593 args
, argtypes
, flags
)
3594 struct z_candidate
*candidates
;
3595 enum tree_code code
, code2
;
3596 tree fnname
, type1
, type2
, *args
, *argtypes
;
3601 case POSTINCREMENT_EXPR
:
3602 case POSTDECREMENT_EXPR
:
3603 args
[1] = integer_zero_node
;
3604 type2
= integer_type_node
;
3610 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
3611 and VQ is either volatile or empty, there exist candidate operator
3612 functions of the form
3613 VQ T& operator++(VQ T&);
3614 T operator++(VQ T&, int);
3615 5 For every pair T, VQ), where T is an enumeration type or an arithmetic
3616 type other than bool, and VQ is either volatile or empty, there exist
3617 candidate operator functions of the form
3618 VQ T& operator--(VQ T&);
3619 T operator--(VQ T&, int);
3620 6 For every pair T, VQ), where T is a cv-qualified or cv-unqualified
3621 complete object type, and VQ is either volatile or empty, there exist
3622 candidate operator functions of the form
3623 T*VQ& operator++(T*VQ&);
3624 T*VQ& operator--(T*VQ&);
3625 T* operator++(T*VQ&, int);
3626 T* operator--(T*VQ&, int); */
3628 case POSTDECREMENT_EXPR
:
3629 case PREDECREMENT_EXPR
:
3630 if (TREE_CODE (type1
) == BOOLEAN_TYPE
)
3632 case POSTINCREMENT_EXPR
:
3633 case PREINCREMENT_EXPR
:
3634 if ((ARITHMETIC_TYPE_P (type1
) && TREE_CODE (type1
) != ENUMERAL_TYPE
)
3635 || TYPE_PTROB_P (type1
))
3637 type1
= build_reference_type (type1
);
3642 /* 7 For every cv-qualified or cv-unqualified complete object type T, there
3643 exist candidate operator functions of the form
3647 8 For every function type T, there exist candidate operator functions of
3649 T& operator*(T*); */
3652 if (TREE_CODE (type1
) == POINTER_TYPE
3653 && (TYPE_PTROB_P (type1
)
3654 || TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
))
3658 /* 9 For every type T, there exist candidate operator functions of the form
3661 10For every promoted arithmetic type T, there exist candidate operator
3662 functions of the form
3666 case CONVERT_EXPR
: /* unary + */
3667 if (TREE_CODE (type1
) == POINTER_TYPE
3668 && TREE_CODE (TREE_TYPE (type1
)) != OFFSET_TYPE
)
3671 if (ARITHMETIC_TYPE_P (type1
))
3675 /* 11For every promoted integral type T, there exist candidate operator
3676 functions of the form
3680 if (INTEGRAL_TYPE_P (type1
))
3684 /* 12For every quintuple C1, C2, T, CV1, CV2), where C2 is a class type, C1
3685 is the same type as C2 or is a derived class of C2, T is a complete
3686 object type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
3687 there exist candidate operator functions of the form
3688 CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
3689 where CV12 is the union of CV1 and CV2. */
3692 if (TREE_CODE (type1
) == POINTER_TYPE
3693 && (TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
)))
3695 tree c1
= TREE_TYPE (type1
);
3696 tree c2
= (TYPE_PTRMEMFUNC_P (type2
)
3697 ? TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type2
)))
3698 : TYPE_OFFSET_BASETYPE (TREE_TYPE (type2
)));
3700 if (IS_AGGR_TYPE (c1
) && DERIVED_FROM_P (c2
, c1
)
3701 && (TYPE_PTRMEMFUNC_P (type2
)
3702 || is_complete (TREE_TYPE (TREE_TYPE (type2
)))))
3707 /* 13For every pair of promoted arithmetic types L and R, there exist can-
3708 didate operator functions of the form
3713 bool operator<(L, R);
3714 bool operator>(L, R);
3715 bool operator<=(L, R);
3716 bool operator>=(L, R);
3717 bool operator==(L, R);
3718 bool operator!=(L, R);
3719 where LR is the result of the usual arithmetic conversions between
3722 14For every pair of types T and I, where T is a cv-qualified or cv-
3723 unqualified complete object type and I is a promoted integral type,
3724 there exist candidate operator functions of the form
3725 T* operator+(T*, I);
3726 T& operator[](T*, I);
3727 T* operator-(T*, I);
3728 T* operator+(I, T*);
3729 T& operator[](I, T*);
3731 15For every T, where T is a pointer to complete object type, there exist
3732 candidate operator functions of the form112)
3733 ptrdiff_t operator-(T, T);
3735 16For every pointer type T, there exist candidate operator functions of
3737 bool operator<(T, T);
3738 bool operator>(T, T);
3739 bool operator<=(T, T);
3740 bool operator>=(T, T);
3741 bool operator==(T, T);
3742 bool operator!=(T, T);
3744 17For every pointer to member type T, there exist candidate operator
3745 functions of the form
3746 bool operator==(T, T);
3747 bool operator!=(T, T); */
3750 if (TYPE_PTROB_P (type1
) && TYPE_PTROB_P (type2
))
3752 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
3754 type2
= ptrdiff_type_node
;
3758 case TRUNC_DIV_EXPR
:
3759 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3765 if (TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
)
3766 || TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
))
3768 if ((TYPE_PTRMEMFUNC_P (type1
) || TYPE_PTRMEM_P (type1
))
3769 && null_ptr_cst_p (args
[1]))
3774 if ((TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
))
3775 && null_ptr_cst_p (args
[0]))
3786 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
)
3787 || TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
3789 if (TYPE_PTR_P (type1
) && null_ptr_cst_p (args
[1]))
3794 if (null_ptr_cst_p (args
[0]) && TYPE_PTR_P (type2
))
3802 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3805 if (INTEGRAL_TYPE_P (type1
) && TYPE_PTROB_P (type2
))
3807 type1
= ptrdiff_type_node
;
3810 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
3812 type2
= ptrdiff_type_node
;
3817 /* 18For every pair of promoted integral types L and R, there exist candi-
3818 date operator functions of the form
3825 where LR is the result of the usual arithmetic conversions between
3828 case TRUNC_MOD_EXPR
:
3834 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
3838 /* 19For every triple L, VQ, R), where L is an arithmetic or enumeration
3839 type, VQ is either volatile or empty, and R is a promoted arithmetic
3840 type, there exist candidate operator functions of the form
3841 VQ L& operator=(VQ L&, R);
3842 VQ L& operator*=(VQ L&, R);
3843 VQ L& operator/=(VQ L&, R);
3844 VQ L& operator+=(VQ L&, R);
3845 VQ L& operator-=(VQ L&, R);
3847 20For every pair T, VQ), where T is any type and VQ is either volatile
3848 or empty, there exist candidate operator functions of the form
3849 T*VQ& operator=(T*VQ&, T*);
3851 21For every pair T, VQ), where T is a pointer to member type and VQ is
3852 either volatile or empty, there exist candidate operator functions of
3854 VQ T& operator=(VQ T&, T);
3856 22For every triple T, VQ, I), where T is a cv-qualified or cv-
3857 unqualified complete object type, VQ is either volatile or empty, and
3858 I is a promoted integral type, there exist candidate operator func-
3860 T*VQ& operator+=(T*VQ&, I);
3861 T*VQ& operator-=(T*VQ&, I);
3863 23For every triple L, VQ, R), where L is an integral or enumeration
3864 type, VQ is either volatile or empty, and R is a promoted integral
3865 type, there exist candidate operator functions of the form
3867 VQ L& operator%=(VQ L&, R);
3868 VQ L& operator<<=(VQ L&, R);
3869 VQ L& operator>>=(VQ L&, R);
3870 VQ L& operator&=(VQ L&, R);
3871 VQ L& operator^=(VQ L&, R);
3872 VQ L& operator|=(VQ L&, R); */
3879 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
3881 type2
= ptrdiff_type_node
;
3885 case TRUNC_DIV_EXPR
:
3886 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3890 case TRUNC_MOD_EXPR
:
3896 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
3901 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3903 if ((TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
))
3904 || (TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
3905 || (TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
))
3906 || ((TYPE_PTRMEMFUNC_P (type1
)
3907 || TREE_CODE (type1
) == POINTER_TYPE
)
3908 && null_ptr_cst_p (args
[1])))
3916 my_friendly_abort (367);
3918 type1
= build_reference_type (type1
);
3922 /* Kludge around broken overloading rules whereby
3923 bool ? const char& : enum is ambiguous
3924 (between int and const char&). */
3925 flags
|= LOOKUP_NO_TEMP_BIND
;
3927 /* Extension: Support ?: of enumeral type. Hopefully this will not
3928 be an extension for long. */
3929 if (TREE_CODE (type1
) == ENUMERAL_TYPE
&& type1
== type2
)
3931 else if (TREE_CODE (type1
) == ENUMERAL_TYPE
3932 || TREE_CODE (type2
) == ENUMERAL_TYPE
)
3934 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3936 if (TREE_CODE (type1
) == TREE_CODE (type2
)
3937 && (TREE_CODE (type1
) == REFERENCE_TYPE
3938 || TREE_CODE (type1
) == POINTER_TYPE
3939 || TYPE_PTRMEMFUNC_P (type1
)
3940 || IS_AGGR_TYPE (type1
)))
3942 if (TREE_CODE (type1
) == REFERENCE_TYPE
3943 || TREE_CODE (type2
) == REFERENCE_TYPE
)
3945 if (((TYPE_PTRMEMFUNC_P (type1
) || TREE_CODE (type1
) == POINTER_TYPE
)
3946 && null_ptr_cst_p (args
[1]))
3947 || IS_AGGR_TYPE (type1
))
3952 if (((TYPE_PTRMEMFUNC_P (type2
) || TREE_CODE (type2
) == POINTER_TYPE
)
3953 && null_ptr_cst_p (args
[0]))
3954 || IS_AGGR_TYPE (type2
))
3962 my_friendly_abort (367);
3965 /* If we're dealing with two pointer types, we need candidates
3966 for both of them. */
3967 if (type2
&& type1
!= type2
3968 && TREE_CODE (type1
) == TREE_CODE (type2
)
3969 && (TREE_CODE (type1
) == REFERENCE_TYPE
3970 || (TREE_CODE (type1
) == POINTER_TYPE
3971 && TYPE_PTRMEM_P (type1
) == TYPE_PTRMEM_P (type2
))
3972 || TYPE_PTRMEMFUNC_P (type1
)
3973 || IS_AGGR_TYPE (type1
)))
3975 candidates
= build_builtin_candidate
3976 (candidates
, fnname
, type1
, type1
, args
, argtypes
, flags
);
3977 return build_builtin_candidate
3978 (candidates
, fnname
, type2
, type2
, args
, argtypes
, flags
);
3981 return build_builtin_candidate
3982 (candidates
, fnname
, type1
, type2
, args
, argtypes
, flags
);
3986 type_decays_to (type
)
3989 if (TREE_CODE (type
) == ARRAY_TYPE
)
3990 return build_pointer_type (TREE_TYPE (type
));
3991 if (TREE_CODE (type
) == FUNCTION_TYPE
)
3992 return build_pointer_type (type
);
3996 /* There are three conditions of builtin candidates:
3998 1) bool-taking candidates. These are the same regardless of the input.
3999 2) pointer-pair taking candidates. These are generated for each type
4000 one of the input types converts to.
4001 3) arithmetic candidates. According to the WP, we should generate
4002 all of these, but I'm trying not to... */
4004 static struct z_candidate
*
4005 add_builtin_candidates (candidates
, code
, code2
, fnname
, args
, flags
)
4006 struct z_candidate
*candidates
;
4007 enum tree_code code
, code2
;
4012 tree type
, argtypes
[3], types
[2];
4014 for (i
= 0; i
< 3; ++i
)
4017 argtypes
[i
] = lvalue_type (args
[i
]);
4019 argtypes
[i
] = NULL_TREE
;
4024 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
4025 and VQ is either volatile or empty, there exist candidate operator
4026 functions of the form
4027 VQ T& operator++(VQ T&); */
4029 case POSTINCREMENT_EXPR
:
4030 case PREINCREMENT_EXPR
:
4031 case POSTDECREMENT_EXPR
:
4032 case PREDECREMENT_EXPR
:
4037 /* 24There also exist candidate operator functions of the form
4038 bool operator!(bool);
4039 bool operator&&(bool, bool);
4040 bool operator||(bool, bool); */
4042 case TRUTH_NOT_EXPR
:
4043 return build_builtin_candidate
4044 (candidates
, fnname
, boolean_type_node
,
4045 NULL_TREE
, args
, argtypes
, flags
);
4047 case TRUTH_ORIF_EXPR
:
4048 case TRUTH_ANDIF_EXPR
:
4049 return build_builtin_candidate
4050 (candidates
, fnname
, boolean_type_node
,
4051 boolean_type_node
, args
, argtypes
, flags
);
4062 types
[0] = types
[1] = NULL_TREE
;
4064 for (i
= 0; i
< 2; ++i
)
4068 else if (IS_AGGR_TYPE (argtypes
[i
]))
4070 tree convs
= lookup_conversions (argtypes
[i
]);
4072 if (code
== COND_EXPR
)
4074 if (real_lvalue_p (args
[i
]))
4075 types
[i
] = tree_cons
4076 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
4078 types
[i
] = tree_cons
4079 (NULL_TREE
, TYPE_MAIN_VARIANT (argtypes
[i
]), types
[i
]);
4082 else if (! convs
|| (i
== 0 && code
== MODIFY_EXPR
4083 && code2
== NOP_EXPR
))
4086 for (; convs
; convs
= TREE_CHAIN (convs
))
4088 type
= TREE_TYPE (TREE_TYPE (TREE_VALUE (convs
)));
4091 && (TREE_CODE (type
) != REFERENCE_TYPE
4092 || TYPE_READONLY (TREE_TYPE (type
))))
4095 if (code
== COND_EXPR
&& TREE_CODE (type
) == REFERENCE_TYPE
)
4096 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4098 type
= non_reference (type
);
4099 if (i
!= 0 || ! ref1
)
4101 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
4102 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
4103 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4104 if (INTEGRAL_TYPE_P (type
))
4105 type
= type_promotes_to (type
);
4108 if (! value_member (type
, types
[i
]))
4109 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4114 if (code
== COND_EXPR
&& real_lvalue_p (args
[i
]))
4115 types
[i
] = tree_cons
4116 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
4117 type
= non_reference (argtypes
[i
]);
4118 if (i
!= 0 || ! ref1
)
4120 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
4121 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
4122 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4123 if (INTEGRAL_TYPE_P (type
))
4124 type
= type_promotes_to (type
);
4126 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4130 for (; types
[0]; types
[0] = TREE_CHAIN (types
[0]))
4133 for (type
= types
[1]; type
; type
= TREE_CHAIN (type
))
4134 candidates
= add_builtin_candidate
4135 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
4136 TREE_VALUE (type
), args
, argtypes
, flags
);
4138 candidates
= add_builtin_candidate
4139 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
4140 NULL_TREE
, args
, argtypes
, flags
);
4146 static struct z_candidate
*
4147 add_template_candidate (candidates
, tmpl
, arglist
, flags
)
4148 struct z_candidate
*candidates
;
4152 int ntparms
= TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (tmpl
));
4153 tree
*targs
= (tree
*) alloca (sizeof (tree
) * ntparms
);
4154 struct z_candidate
*cand
;
4158 i
= type_unification (DECL_TEMPLATE_PARMS (tmpl
), targs
,
4159 TYPE_ARG_TYPES (TREE_TYPE (tmpl
)),
4160 arglist
, &dummy
, 0, 0);
4164 fn
= instantiate_template (tmpl
, targs
);
4165 if (fn
== error_mark_node
)
4168 cand
= add_function_candidate (candidates
, fn
, arglist
, flags
);
4169 cand
->template = DECL_TEMPLATE_INFO (fn
);
4175 struct z_candidate
*cands
;
4177 for (; cands
; cands
= cands
->next
)
4178 if (pedantic
? cands
->viable
== 1 : cands
->viable
)
4183 static struct z_candidate
*
4184 splice_viable (cands
)
4185 struct z_candidate
*cands
;
4187 struct z_candidate
**p
= &cands
;
4191 if (pedantic
? (*p
)->viable
== 1 : (*p
)->viable
)
4204 /* Fix this to work on non-lvalues. */
4205 if (IS_SIGNATURE_POINTER (TREE_TYPE (obj
))
4206 || IS_SIGNATURE_REFERENCE (TREE_TYPE (obj
)))
4209 return build_unary_op (ADDR_EXPR
, obj
, 0);
4213 print_z_candidates (candidates
)
4214 struct z_candidate
*candidates
;
4216 char *str
= "candidates are:";
4217 for (; candidates
; candidates
= candidates
->next
)
4219 if (TREE_CODE (candidates
->fn
) == IDENTIFIER_NODE
)
4221 if (candidates
->fn
== ansi_opname
[COND_EXPR
])
4222 cp_error ("%s %D(%T, %T, %T) <builtin>", str
, candidates
->fn
,
4223 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
4224 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)),
4225 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 2)));
4226 else if (TREE_VEC_LENGTH (candidates
->convs
) == 2)
4227 cp_error ("%s %D(%T, %T) <builtin>", str
, candidates
->fn
,
4228 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
4229 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)));
4231 cp_error ("%s %D(%T) <builtin>", str
, candidates
->fn
,
4232 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)));
4235 cp_error_at ("%s %+D%s", str
, candidates
->fn
,
4236 candidates
->viable
== -1 ? " <near match>" : "");
4241 /* Returns the best overload candidate to perform the requested
4242 conversion. This function is used for three the overloading situations
4243 described in [over.match.copy], [over.match.conv], and [over.match.ref].
4244 If TOTYPE is a REFERENCE_TYPE, we're trying to find an lvalue binding as
4245 per [dcl.init.ref], so we ignore temporary bindings. */
4247 static struct z_candidate
*
4248 build_user_type_conversion_1 (totype
, expr
, flags
)
4252 struct z_candidate
*candidates
, *cand
;
4253 tree fromtype
= TREE_TYPE (expr
);
4254 tree ctors
= NULL_TREE
, convs
= NULL_TREE
, *p
;
4257 if (IS_AGGR_TYPE (totype
))
4258 ctors
= lookup_fnfields (TYPE_BINFO (totype
), ctor_identifier
, 0);
4259 if (IS_AGGR_TYPE (fromtype
)
4260 && (! IS_AGGR_TYPE (totype
) || ! DERIVED_FROM_P (totype
, fromtype
)))
4261 convs
= lookup_conversions (fromtype
);
4264 flags
|= LOOKUP_NO_CONVERSION
;
4268 tree t
= build_int_2 (0, 0);
4269 TREE_TYPE (t
) = build_pointer_type (totype
);
4270 args
= build_tree_list (NULL_TREE
, expr
);
4271 if (TYPE_USES_VIRTUAL_BASECLASSES (totype
))
4272 args
= tree_cons (NULL_TREE
, integer_one_node
, args
);
4273 args
= tree_cons (NULL_TREE
, t
, args
);
4275 ctors
= TREE_VALUE (ctors
);
4277 for (; ctors
; ctors
= DECL_CHAIN (ctors
))
4279 if (DECL_NONCONVERTING_P (ctors
))
4282 candidates
= add_function_candidate (candidates
, ctors
, args
, flags
);
4283 candidates
->second_conv
= build1 (IDENTITY_CONV
, totype
, NULL_TREE
);
4284 candidates
->basetype_path
= TYPE_BINFO (totype
);
4288 args
= build_tree_list (NULL_TREE
, build_this (expr
));
4290 for (; convs
; convs
= TREE_CHAIN (convs
))
4292 tree fn
= TREE_VALUE (convs
);
4293 int convflags
= LOOKUP_NO_CONVERSION
;
4296 /* If we are called to convert to a reference type, we are trying to
4297 find an lvalue binding, so don't even consider temporaries. If
4298 we don't find an lvalue binding, the caller will try again to
4299 look for a temporary binding. */
4300 if (TREE_CODE (totype
) == REFERENCE_TYPE
)
4301 convflags
|= LOOKUP_NO_TEMP_BIND
;
4303 ics
= implicit_conversion
4304 (totype
, TREE_TYPE (TREE_TYPE (fn
)), 0, convflags
);
4306 if (TREE_CODE (totype
) == REFERENCE_TYPE
&& ics
&& ICS_BAD_FLAG (ics
))
4307 /* ignore the near match. */;
4309 for (; fn
; fn
= DECL_CHAIN (fn
))
4311 candidates
= add_function_candidate (candidates
, fn
, args
, flags
);
4312 candidates
->second_conv
= ics
;
4313 candidates
->basetype_path
= TREE_PURPOSE (convs
);
4314 if (candidates
->viable
== 1 && ICS_BAD_FLAG (ics
))
4315 candidates
->viable
= -1;
4319 if (! any_viable (candidates
))
4322 if (flags
& LOOKUP_COMPLAIN
)
4324 if (candidates
&& ! candidates
->next
)
4325 /* say why this one won't work or try to be loose */;
4327 cp_error ("no viable candidates");
4334 candidates
= splice_viable (candidates
);
4335 cand
= tourney (candidates
);
4339 if (flags
& LOOKUP_COMPLAIN
)
4341 cp_error ("conversion from `%T' to `%T' is ambiguous",
4343 print_z_candidates (candidates
);
4346 cand
= candidates
; /* any one will do */
4347 cand
->second_conv
= build1 (AMBIG_CONV
, totype
, expr
);
4348 ICS_USER_FLAG (cand
->second_conv
) = 1;
4349 ICS_BAD_FLAG (cand
->second_conv
) = 1;
4354 for (p
= &(cand
->second_conv
); TREE_CODE (*p
) != IDENTITY_CONV
; )
4355 p
= &(TREE_OPERAND (*p
, 0));
4359 (DECL_CONSTRUCTOR_P (cand
->fn
)
4360 ? totype
: non_reference (TREE_TYPE (TREE_TYPE (cand
->fn
)))),
4361 NULL_TREE
, cand
->fn
, cand
->convs
, cand
->basetype_path
);
4362 ICS_USER_FLAG (cand
->second_conv
) = 1;
4363 if (cand
->viable
== -1)
4364 ICS_BAD_FLAG (cand
->second_conv
) = 1;
4370 build_user_type_conversion (totype
, expr
, flags
)
4374 struct z_candidate
*cand
4375 = build_user_type_conversion_1 (totype
, expr
, flags
);
4379 if (TREE_CODE (cand
->second_conv
) == AMBIG_CONV
)
4380 return error_mark_node
;
4381 return convert_from_reference (convert_like (cand
->second_conv
, expr
));
4386 /* Do any initial processing on the arguments to a function call. */
4393 for (t
= args
; t
; t
= TREE_CHAIN (t
))
4395 if (TREE_VALUE (t
) == error_mark_node
)
4396 return error_mark_node
;
4397 else if (TREE_CODE (TREE_TYPE (TREE_VALUE (t
))) == VOID_TYPE
)
4399 error ("invalid use of void expression");
4400 return error_mark_node
;
4402 else if (TREE_CODE (TREE_VALUE (t
)) == OFFSET_REF
)
4403 TREE_VALUE (t
) = resolve_offset_ref (TREE_VALUE (t
));
4409 build_new_function_call (fn
, args
, obj
)
4412 struct z_candidate
*candidates
= 0, *cand
;
4414 if (obj
== NULL_TREE
&& TREE_CODE (fn
) == TREE_LIST
)
4417 tree templates
= NULL_TREE
;
4419 args
= resolve_args (args
);
4421 if (args
== error_mark_node
)
4422 return error_mark_node
;
4424 for (t
= TREE_VALUE (fn
); t
; t
= DECL_CHAIN (t
))
4426 if (TREE_CODE (t
) == TEMPLATE_DECL
)
4428 templates
= decl_tree_cons (NULL_TREE
, t
, templates
);
4429 candidates
= add_template_candidate
4430 (candidates
, t
, args
, LOOKUP_NORMAL
);
4433 candidates
= add_function_candidate
4434 (candidates
, t
, args
, LOOKUP_NORMAL
);
4437 if (! any_viable (candidates
))
4439 if (candidates
&& ! candidates
->next
)
4440 return build_function_call (candidates
->fn
, args
);
4441 cp_error ("no matching function for call to `%D (%A)'",
4442 TREE_PURPOSE (fn
), args
);
4444 print_z_candidates (candidates
);
4445 return error_mark_node
;
4447 candidates
= splice_viable (candidates
);
4448 cand
= tourney (candidates
);
4452 cp_error ("call of overloaded `%D (%A)' is ambiguous",
4453 TREE_PURPOSE (fn
), args
);
4454 print_z_candidates (candidates
);
4455 return error_mark_node
;
4458 /* Pedantically, it is ill-formed to define a function that could
4459 also be a template instantiation, but we won't implement that
4460 until things settle down. */
4461 if (templates
&& ! cand
->template && ! DECL_INITIAL (cand
->fn
))
4462 add_maybe_template (cand
->fn
, templates
);
4464 return build_over_call (cand
->fn
, cand
->convs
, args
, LOOKUP_NORMAL
);
4467 return build_function_call (fn
, args
);
4471 build_object_call (obj
, args
)
4474 struct z_candidate
*candidates
= 0, *cand
;
4475 tree fns
, convs
, mem_args
;
4476 tree type
= TREE_TYPE (obj
);
4478 fns
= lookup_fnfields (TYPE_BINFO (type
), ansi_opname
[CALL_EXPR
], 0);
4480 args
= resolve_args (args
);
4482 if (args
== error_mark_node
)
4483 return error_mark_node
;
4487 tree fn
= TREE_VALUE (fns
);
4488 mem_args
= tree_cons (NULL_TREE
, build_this (obj
), args
);
4490 for (; fn
; fn
= DECL_CHAIN (fn
))
4492 candidates
= add_function_candidate
4493 (candidates
, fn
, mem_args
, LOOKUP_NORMAL
);
4494 candidates
->basetype_path
= TREE_PURPOSE (fns
);
4498 convs
= lookup_conversions (type
);
4500 for (; convs
; convs
= TREE_CHAIN (convs
))
4502 tree fn
= TREE_VALUE (convs
);
4503 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
4505 if (TREE_CODE (totype
) == POINTER_TYPE
4506 && TREE_CODE (TREE_TYPE (totype
)) == FUNCTION_TYPE
)
4507 for (; fn
; fn
= DECL_CHAIN (fn
))
4509 candidates
= add_conv_candidate (candidates
, fn
, obj
, args
);
4510 candidates
->basetype_path
= TREE_PURPOSE (convs
);
4514 if (! any_viable (candidates
))
4516 cp_error ("no match for call to `(%T) (%A)'", TREE_TYPE (obj
), args
);
4517 print_z_candidates (candidates
);
4518 return error_mark_node
;
4521 candidates
= splice_viable (candidates
);
4522 cand
= tourney (candidates
);
4526 cp_error ("call of `(%T) (%A)' is ambiguous", TREE_TYPE (obj
), args
);
4527 print_z_candidates (candidates
);
4528 return error_mark_node
;
4531 if (DECL_NAME (cand
->fn
) == ansi_opname
[CALL_EXPR
])
4532 return build_over_call (cand
->fn
, cand
->convs
, mem_args
, LOOKUP_NORMAL
);
4534 obj
= convert_like (TREE_VEC_ELT (cand
->convs
, 0), obj
);
4537 return build_function_call (obj
, args
);
4541 op_error (code
, code2
, arg1
, arg2
, arg3
, problem
)
4542 enum tree_code code
, code2
;
4543 tree arg1
, arg2
, arg3
;
4547 = (code
== MODIFY_EXPR
? assignop_tab
[code2
] : opname_tab
[code
]);
4552 cp_error ("%s for `%T ? %T : %T'", problem
,
4553 error_type (arg1
), error_type (arg2
), error_type (arg3
));
4555 case POSTINCREMENT_EXPR
:
4556 case POSTDECREMENT_EXPR
:
4557 cp_error ("%s for `%T%s'", problem
, error_type (arg1
), opname
);
4560 cp_error ("%s for `%T[%T]'", problem
,
4561 error_type (arg1
), error_type (arg2
));
4565 cp_error ("%s for `%T %s %T'", problem
,
4566 error_type (arg1
), opname
, error_type (arg2
));
4568 cp_error ("%s for `%s%T'", problem
, opname
, error_type (arg1
));
4573 build_new_op (code
, flags
, arg1
, arg2
, arg3
)
4574 enum tree_code code
;
4576 tree arg1
, arg2
, arg3
;
4578 struct z_candidate
*candidates
= 0, *cand
;
4579 tree fns
, mem_arglist
, arglist
, fnname
;
4580 enum tree_code code2
= NOP_EXPR
;
4581 tree templates
= NULL_TREE
;
4584 if (arg1
== error_mark_node
4585 || arg2
== error_mark_node
4586 || arg3
== error_mark_node
)
4587 return error_mark_node
;
4589 if (code
== MODIFY_EXPR
)
4591 code2
= TREE_CODE (arg3
);
4593 fnname
= ansi_assopname
[code2
];
4596 fnname
= ansi_opname
[code
];
4605 arglist
= tree_cons (NULL_TREE
, arg2
, arg3
);
4606 if (flags
& LOOKUP_GLOBAL
)
4607 return build_new_function_call
4608 (lookup_name_nonclass (fnname
), arglist
, NULL_TREE
);
4611 rval
= build_method_call
4612 (build_indirect_ref (build1 (NOP_EXPR
, arg1
, error_mark_node
),
4614 fnname
, arglist
, NULL_TREE
, flags
);
4615 if (rval
== error_mark_node
)
4616 /* User might declare fancy operator new, but invoke it
4617 like standard one. */
4620 TREE_TYPE (rval
) = arg1
;
4621 TREE_CALLS_NEW (rval
) = 1;
4625 case VEC_DELETE_EXPR
:
4630 if (flags
& LOOKUP_GLOBAL
)
4631 return build_new_function_call
4632 (lookup_name_nonclass (fnname
),
4633 build_tree_list (NULL_TREE
, arg1
), NULL_TREE
);
4635 arglist
= tree_cons (NULL_TREE
, arg1
, build_tree_list (NULL_TREE
, arg2
));
4637 arg1
= TREE_TYPE (arg1
);
4639 /* This handles the case where we're trying to delete
4644 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
4646 /* Strip off the pointer and the array. */
4647 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
4649 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
4650 arg1
= (TREE_TYPE (arg1
));
4652 arg1
= build_pointer_type (arg1
);
4656 rval
= build_method_call
4657 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
4660 fnname
, arglist
, NULL_TREE
, flags
);
4662 /* This can happen when operator delete is protected. */
4663 my_friendly_assert (rval
!= error_mark_node
, 250);
4664 TREE_TYPE (rval
) = void_type_node
;
4670 return build_object_call (arg1
, arg2
);
4673 /* The comma operator can have void args. */
4674 if (TREE_CODE (arg1
) == OFFSET_REF
)
4675 arg1
= resolve_offset_ref (arg1
);
4676 if (arg2
&& TREE_CODE (arg2
) == OFFSET_REF
)
4677 arg2
= resolve_offset_ref (arg2
);
4678 if (arg3
&& TREE_CODE (arg3
) == OFFSET_REF
)
4679 arg3
= resolve_offset_ref (arg3
);
4681 if (code
== COND_EXPR
)
4683 if (arg2
== NULL_TREE
4684 || TREE_CODE (TREE_TYPE (arg2
)) == VOID_TYPE
4685 || TREE_CODE (TREE_TYPE (arg3
)) == VOID_TYPE
4686 || (! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))
4687 && ! IS_OVERLOAD_TYPE (TREE_TYPE (arg3
))))
4690 else if (! IS_OVERLOAD_TYPE (TREE_TYPE (arg1
))
4691 && (! arg2
|| ! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))))
4694 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
4695 arg2
= integer_zero_node
;
4697 fns
= lookup_name_nonclass (fnname
);
4698 /* + Koenig lookup */
4701 arglist
= tree_cons (NULL_TREE
, arg1
, tree_cons
4702 (NULL_TREE
, arg2
, build_tree_list (NULL_TREE
, arg3
)));
4704 arglist
= tree_cons (NULL_TREE
, arg1
, build_tree_list (NULL_TREE
, arg2
));
4706 arglist
= build_tree_list (NULL_TREE
, arg1
);
4708 if (fns
&& TREE_CODE (fns
) == TREE_LIST
)
4709 fns
= TREE_VALUE (fns
);
4710 for (; fns
; fns
= DECL_CHAIN (fns
))
4712 if (TREE_CODE (fns
) == TEMPLATE_DECL
)
4714 templates
= decl_tree_cons (NULL_TREE
, fns
, templates
);
4715 candidates
= add_template_candidate
4716 (candidates
, fns
, arglist
, flags
);
4719 candidates
= add_function_candidate (candidates
, fns
, arglist
, flags
);
4722 if (IS_AGGR_TYPE (TREE_TYPE (arg1
)))
4723 fns
= lookup_fnfields (TYPE_BINFO (TREE_TYPE (arg1
)), fnname
, 0);
4729 tree fn
= TREE_VALUE (fns
);
4730 mem_arglist
= tree_cons (NULL_TREE
, build_this (arg1
), TREE_CHAIN (arglist
));
4731 for (; fn
; fn
= DECL_CHAIN (fn
))
4733 if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
4734 candidates
= add_function_candidate
4735 (candidates
, fn
, mem_arglist
, flags
);
4737 candidates
= add_function_candidate (candidates
, fn
, arglist
, flags
);
4739 candidates
->basetype_path
= TREE_PURPOSE (fns
);
4746 /* Rearrange the arguments for ?: so that add_builtin_candidate only has
4747 to know about two args; a builtin candidate will always have a first
4748 parameter of type bool. We'll handle that in
4749 build_builtin_candidate. */
4750 if (code
== COND_EXPR
)
4760 args
[2] = NULL_TREE
;
4763 candidates
= add_builtin_candidates
4764 (candidates
, code
, code2
, fnname
, args
, flags
);
4767 if (! any_viable (candidates
))
4771 case POSTINCREMENT_EXPR
:
4772 case POSTDECREMENT_EXPR
:
4773 /* Look for an `operator++ (int)'. If they didn't have
4774 one, then we fall back to the old way of doing things. */
4775 if (flags
& LOOKUP_COMPLAIN
)
4776 cp_pedwarn ("no `%D (int)' declared for postfix `%s', trying prefix operator instead",
4777 fnname
, opname_tab
[code
]);
4778 if (code
== POSTINCREMENT_EXPR
)
4779 code
= PREINCREMENT_EXPR
;
4781 code
= PREDECREMENT_EXPR
;
4782 return build_new_op (code
, flags
, arg1
, NULL_TREE
, NULL_TREE
);
4784 /* The caller will deal with these. */
4790 if (flags
& LOOKUP_COMPLAIN
)
4792 op_error (code
, code2
, arg1
, arg2
, arg3
, "no match");
4793 print_z_candidates (candidates
);
4795 return error_mark_node
;
4797 candidates
= splice_viable (candidates
);
4798 cand
= tourney (candidates
);
4802 if (flags
& LOOKUP_COMPLAIN
)
4804 op_error (code
, code2
, arg1
, arg2
, arg3
, "ambiguous overload");
4805 print_z_candidates (candidates
);
4807 return error_mark_node
;
4810 if (TREE_CODE (cand
->fn
) == FUNCTION_DECL
)
4812 extern int warn_synth
;
4814 && fnname
== ansi_opname
[MODIFY_EXPR
]
4815 && DECL_ARTIFICIAL (cand
->fn
)
4817 && ! candidates
->next
->next
)
4819 cp_warning ("using synthesized `%#D' for copy assignment",
4821 cp_warning_at (" where cfront would use `%#D'",
4823 ? candidates
->next
->fn
4827 if (DECL_FUNCTION_MEMBER_P (cand
->fn
))
4828 enforce_access (cand
->basetype_path
, cand
->fn
);
4830 /* Pedantically, it is ill-formed to define a function that could
4831 also be a template instantiation, but we won't implement that
4832 until things settle down. */
4833 if (templates
&& ! cand
->template && ! DECL_INITIAL (cand
->fn
)
4834 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
4835 add_maybe_template (cand
->fn
, templates
);
4837 return build_over_call
4838 (cand
->fn
, cand
->convs
,
4839 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
4840 ? mem_arglist
: arglist
,
4844 /* Check for comparison of different enum types. */
4853 if (flag_int_enum_equivalence
== 0
4854 && TREE_CODE (TREE_TYPE (arg1
)) == ENUMERAL_TYPE
4855 && TREE_CODE (TREE_TYPE (arg2
)) == ENUMERAL_TYPE
4856 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg1
))
4857 != TYPE_MAIN_VARIANT (TREE_TYPE (arg2
))))
4859 cp_warning ("comparison between `%#T' and `%#T'",
4860 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
4864 /* We need to strip any leading REF_BIND so that bitfields don't cause
4865 errors. This should not remove any important conversions, because
4866 builtins don't apply to class objects directly. */
4867 conv
= TREE_VEC_ELT (cand
->convs
, 0);
4868 if (TREE_CODE (conv
) == REF_BIND
)
4869 conv
= TREE_OPERAND (conv
, 0);
4870 arg1
= convert_like (conv
, arg1
);
4872 arg2
= convert_like (TREE_VEC_ELT (cand
->convs
, 1), arg2
);
4874 arg3
= convert_like (TREE_VEC_ELT (cand
->convs
, 2), arg3
);
4880 return build_modify_expr (arg1
, code2
, arg2
);
4883 return build_indirect_ref (arg1
, "unary *");
4888 case TRUNC_DIV_EXPR
:
4899 case TRUNC_MOD_EXPR
:
4903 case TRUTH_ANDIF_EXPR
:
4904 case TRUTH_ORIF_EXPR
:
4905 return build_binary_op_nodefault (code
, arg1
, arg2
, code
);
4910 case TRUTH_NOT_EXPR
:
4911 case PREINCREMENT_EXPR
:
4912 case POSTINCREMENT_EXPR
:
4913 case PREDECREMENT_EXPR
:
4914 case POSTDECREMENT_EXPR
:
4917 return build_unary_op (code
, arg1
, candidates
!= 0);
4920 return build_array_ref (arg1
, arg2
);
4923 return build_conditional_expr (arg1
, arg2
, arg3
);
4926 return build_m_component_ref
4927 (build_indirect_ref (arg1
, NULL_PTR
), arg2
);
4929 /* The caller will deal with these. */
4936 my_friendly_abort (367);
4941 enforce_access (basetype_path
, function
)
4942 tree basetype_path
, function
;
4944 tree access
= compute_access (basetype_path
, function
);
4946 if (access
== access_private_node
)
4948 cp_error_at ("`%+#D' is %s", function
,
4949 TREE_PRIVATE (function
) ? "private"
4950 : "from private base class");
4951 error ("within this context");
4953 else if (access
== access_protected_node
)
4955 cp_error_at ("`%+#D' %s", function
,
4956 TREE_PROTECTED (function
) ? "is protected"
4957 : "has protected accessibility");
4958 error ("within this context");
4962 /* Perform the conversions in CONVS on the expression EXPR. */
4965 convert_like (convs
, expr
)
4968 if (ICS_BAD_FLAG (convs
)
4969 && TREE_CODE (convs
) != USER_CONV
4970 && TREE_CODE (convs
) != AMBIG_CONV
)
4973 for (; t
; t
= TREE_OPERAND (t
, 0))
4975 if (TREE_CODE (t
) == USER_CONV
)
4977 expr
= convert_like (t
, expr
);
4980 else if (TREE_CODE (t
) == AMBIG_CONV
)
4981 return convert_like (t
, expr
);
4982 else if (TREE_CODE (t
) == IDENTITY_CONV
)
4985 return convert_for_initialization
4986 (NULL_TREE
, TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
,
4987 "conversion", NULL_TREE
, 0);
4990 switch (TREE_CODE (convs
))
4994 tree fn
= TREE_OPERAND (convs
, 1);
4996 enforce_access (TREE_OPERAND (convs
, 3), fn
);
4998 if (DECL_CONSTRUCTOR_P (fn
))
5000 tree t
= build_int_2 (0, 0);
5001 TREE_TYPE (t
) = build_pointer_type (DECL_CONTEXT (fn
));
5003 args
= build_tree_list (NULL_TREE
, expr
);
5004 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
5005 args
= tree_cons (NULL_TREE
, integer_one_node
, args
);
5006 args
= tree_cons (NULL_TREE
, t
, args
);
5009 args
= build_this (expr
);
5010 expr
= build_over_call
5011 (TREE_OPERAND (convs
, 1), TREE_OPERAND (convs
, 2),
5012 args
, LOOKUP_NORMAL
);
5014 /* If this is a constructor or a function returning an aggr type,
5015 we need to build up a TARGET_EXPR. */
5016 if (DECL_CONSTRUCTOR_P (fn
))
5017 expr
= build_cplus_new (TREE_TYPE (convs
), expr
);
5022 if (type_unknown_p (expr
))
5023 expr
= instantiate_type (TREE_TYPE (convs
), expr
, 1);
5024 if (TREE_READONLY_DECL_P (expr
))
5025 expr
= decl_constant_value (expr
);
5028 /* Call build_user_type_conversion again for the error. */
5029 return build_user_type_conversion
5030 (TREE_TYPE (convs
), TREE_OPERAND (convs
, 0), LOOKUP_NORMAL
);
5033 expr
= convert_like (TREE_OPERAND (convs
, 0), expr
);
5034 if (expr
== error_mark_node
)
5035 return error_mark_node
;
5037 switch (TREE_CODE (convs
))
5040 if (! IS_AGGR_TYPE (TREE_TYPE (convs
)))
5042 /* else fall through */
5044 return build_user_type_conversion
5045 (TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
);
5047 return convert_to_reference
5048 (TREE_TYPE (convs
), expr
,
5049 CONV_IMPLICIT
, LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
,
5052 return decay_conversion (expr
);
5054 return ocp_convert (TREE_TYPE (convs
), expr
, CONV_IMPLICIT
,
5055 LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
);
5059 convert_default_arg (type
, arg
)
5062 arg
= break_out_target_exprs (arg
);
5064 if (TREE_CODE (arg
) == CONSTRUCTOR
)
5066 arg
= digest_init (type
, arg
, 0);
5067 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
5068 "default argument", 0, 0);
5072 /* This could get clobbered by the following call. */
5073 if (TREE_HAS_CONSTRUCTOR (arg
))
5074 arg
= copy_node (arg
);
5076 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
5077 "default argument", 0, 0);
5078 #ifdef PROMOTE_PROTOTYPES
5079 if ((TREE_CODE (type
) == INTEGER_TYPE
5080 || TREE_CODE (type
) == ENUMERAL_TYPE
)
5081 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
5082 arg
= default_conversion (arg
);
5090 build_over_call (fn
, convs
, args
, flags
)
5091 tree fn
, convs
, args
;
5094 tree converted_args
= NULL_TREE
;
5095 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
5096 tree conv
, arg
, val
;
5100 if (args
&& TREE_CODE (args
) != TREE_LIST
)
5101 args
= build_tree_list (NULL_TREE
, args
);
5104 /* The implicit parameters to a constructor are not considered by overload
5105 resolution, and must be of the proper type. */
5106 if (DECL_CONSTRUCTOR_P (fn
))
5108 converted_args
= tree_cons (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
5109 arg
= TREE_CHAIN (arg
);
5110 parm
= TREE_CHAIN (parm
);
5111 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
5113 converted_args
= tree_cons
5114 (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
5115 arg
= TREE_CHAIN (arg
);
5116 parm
= TREE_CHAIN (parm
);
5119 /* Bypass access control for 'this' parameter. */
5120 else if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
5122 tree parmtype
= TREE_VALUE (parm
);
5123 tree argtype
= TREE_TYPE (TREE_VALUE (arg
));
5124 if (ICS_BAD_FLAG (TREE_VEC_ELT (convs
, i
)))
5126 int dv
= (TYPE_VOLATILE (TREE_TYPE (parmtype
))
5127 < TYPE_VOLATILE (TREE_TYPE (argtype
)));
5128 int dc
= (TYPE_READONLY (TREE_TYPE (parmtype
))
5129 < TYPE_READONLY (TREE_TYPE (argtype
)));
5130 char *p
= (dv
&& dc
? "const and volatile"
5131 : dc
? "const" : dv
? "volatile" : "");
5133 cp_pedwarn ("passing `%T' as `this' argument of `%#D' discards %s",
5134 TREE_TYPE (argtype
), fn
, p
);
5136 converted_args
= tree_cons
5137 (NULL_TREE
, convert_force (TREE_VALUE (parm
), TREE_VALUE (arg
), CONV_C_CAST
),
5139 parm
= TREE_CHAIN (parm
);
5140 arg
= TREE_CHAIN (arg
);
5146 parm
= TREE_CHAIN (parm
), arg
= TREE_CHAIN (arg
), ++i
)
5148 tree type
= TREE_VALUE (parm
);
5150 conv
= TREE_VEC_ELT (convs
, i
);
5151 if (ICS_BAD_FLAG (conv
))
5154 val
= TREE_VALUE (arg
);
5156 for (; t
; t
= TREE_OPERAND (t
, 0))
5158 if (TREE_CODE (t
) == USER_CONV
5159 || TREE_CODE (t
) == AMBIG_CONV
)
5161 val
= convert_like (t
, val
);
5164 else if (TREE_CODE (t
) == IDENTITY_CONV
)
5167 val
= convert_for_initialization
5168 (NULL_TREE
, type
, val
, LOOKUP_NORMAL
,
5169 "argument passing", fn
, i
- is_method
);
5172 val
= convert_like (conv
, TREE_VALUE (arg
));
5174 #ifdef PROMOTE_PROTOTYPES
5175 if ((TREE_CODE (type
) == INTEGER_TYPE
5176 || TREE_CODE (type
) == ENUMERAL_TYPE
)
5177 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
5178 val
= default_conversion (val
);
5180 converted_args
= tree_cons (NULL_TREE
, val
, converted_args
);
5183 /* Default arguments */
5184 for (; parm
&& parm
!= void_list_node
; parm
= TREE_CHAIN (parm
))
5186 tree arg
= TREE_PURPOSE (parm
);
5188 if (DECL_TEMPLATE_INFO (fn
))
5189 /* This came from a template. Instantiate the default arg here,
5191 arg
= tsubst_expr (arg
,
5192 &TREE_VEC_ELT (DECL_TI_ARGS (fn
), 0),
5193 TREE_VEC_LENGTH (DECL_TI_ARGS (fn
)), NULL_TREE
);
5194 converted_args
= tree_cons
5195 (NULL_TREE
, convert_default_arg (TREE_VALUE (parm
), arg
),
5200 for (; arg
; arg
= TREE_CHAIN (arg
))
5202 val
= TREE_VALUE (arg
);
5204 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
5205 && (TYPE_PRECISION (TREE_TYPE (val
))
5206 < TYPE_PRECISION (double_type_node
)))
5207 /* Convert `float' to `double'. */
5208 val
= cp_convert (double_type_node
, val
);
5209 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
5210 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
5211 cp_warning ("cannot pass objects of type `%T' through `...'",
5214 /* Convert `short' and `char' to full-size `int'. */
5215 val
= default_conversion (val
);
5217 converted_args
= tree_cons (NULL_TREE
, val
, converted_args
);
5220 converted_args
= nreverse (converted_args
);
5222 /* Avoid actually calling copy constructors and copy assignment operators,
5224 if (DECL_CONSTRUCTOR_P (fn
)
5225 && TREE_VEC_LENGTH (convs
) == 1
5226 && copy_args_p (fn
))
5229 arg
= TREE_VALUE (TREE_CHAIN (converted_args
));
5231 /* Pull out the real argument, disregarding const-correctness. */
5233 while (TREE_CODE (targ
) == NOP_EXPR
5234 || TREE_CODE (targ
) == NON_LVALUE_EXPR
5235 || TREE_CODE (targ
) == CONVERT_EXPR
)
5236 targ
= TREE_OPERAND (targ
, 0);
5237 if (TREE_CODE (targ
) == ADDR_EXPR
)
5239 targ
= TREE_OPERAND (targ
, 0);
5240 if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg
))),
5241 TYPE_MAIN_VARIANT (TREE_TYPE (targ
)), 1))
5250 arg
= build_indirect_ref (arg
, 0);
5252 /* [class.copy]: the copy constructor is implicitly defined even if
5253 the implementation elided its use. */
5254 if (TYPE_HAS_COMPLEX_INIT_REF (DECL_CONTEXT (fn
)))
5257 /* If we're creating a temp and we already have one, don't create a
5258 new one. If we're not creating a temp but we get one, use
5259 INIT_EXPR to collapse the temp into our target. Otherwise, if the
5260 ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
5261 temp or an INIT_EXPR otherwise. */
5262 if (integer_zerop (TREE_VALUE (args
)))
5264 if (! real_lvalue_p (arg
))
5266 else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
5268 val
= build (VAR_DECL
, DECL_CONTEXT (fn
));
5269 layout_decl (val
, 0);
5270 val
= build (TARGET_EXPR
, DECL_CONTEXT (fn
), val
, arg
, 0, 0);
5271 TREE_SIDE_EFFECTS (val
) = 1;
5275 else if (! real_lvalue_p (arg
)
5276 || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
5278 tree to
= stabilize_reference
5279 (build_indirect_ref (TREE_VALUE (args
), 0));
5280 val
= build (INIT_EXPR
, DECL_CONTEXT (fn
), to
, arg
);
5281 TREE_SIDE_EFFECTS (val
) = 1;
5282 return build_unary_op (ADDR_EXPR
, val
, 0);
5285 else if (DECL_NAME (fn
) == ansi_opname
[MODIFY_EXPR
]
5287 && TYPE_HAS_TRIVIAL_ASSIGN_REF (DECL_CONTEXT (fn
)))
5289 tree to
= stabilize_reference
5290 (build_indirect_ref (TREE_VALUE (converted_args
), 0));
5291 arg
= build_indirect_ref (TREE_VALUE (TREE_CHAIN (converted_args
)), 0);
5292 val
= build (MODIFY_EXPR
, TREE_TYPE (to
), to
, arg
);
5293 TREE_SIDE_EFFECTS (val
) = 1;
5299 if (DECL_CONTEXT (fn
) && IS_SIGNATURE (DECL_CONTEXT (fn
)))
5300 return build_signature_method_call (fn
, converted_args
);
5301 else if (DECL_VINDEX (fn
) && (flags
& LOOKUP_NONVIRTUAL
) == 0)
5303 tree t
, *p
= &TREE_VALUE (converted_args
);
5304 tree binfo
= get_binfo
5305 (DECL_CONTEXT (fn
), TREE_TYPE (TREE_TYPE (*p
)), 0);
5306 *p
= convert_pointer_to_real (binfo
, *p
);
5307 if (TREE_SIDE_EFFECTS (*p
))
5308 *p
= save_expr (*p
);
5309 t
= build_pointer_type (TREE_TYPE (fn
));
5310 fn
= build_vfn_ref (p
, build_indirect_ref (*p
, 0), DECL_VINDEX (fn
));
5313 else if (DECL_INLINE (fn
))
5314 fn
= inline_conversion (fn
);
5316 fn
= build_addr_func (fn
);
5318 fn
= build_call (fn
, TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))), converted_args
);
5319 if (TREE_TYPE (fn
) == void_type_node
)
5321 if (IS_AGGR_TYPE (TREE_TYPE (fn
)))
5322 fn
= build_cplus_new (TREE_TYPE (fn
), fn
);
5323 return convert_from_reference (require_complete_type (fn
));
5327 build_new_method_call (instance
, name
, args
, basetype_path
, flags
)
5328 tree instance
, name
, args
, basetype_path
;
5331 struct z_candidate
*candidates
= 0, *cand
;
5332 tree basetype
, mem_args
, fns
, instance_ptr
;
5334 tree user_args
= args
;
5336 /* If there is an extra argument for controlling virtual bases,
5337 remove it for error reporting. */
5338 if (flags
& LOOKUP_HAS_IN_CHARGE
)
5339 user_args
= TREE_CHAIN (args
);
5341 args
= resolve_args (args
);
5343 if (args
== error_mark_node
)
5344 return error_mark_node
;
5346 if (instance
== NULL_TREE
)
5347 basetype
= BINFO_TYPE (basetype_path
);
5350 if (TREE_CODE (instance
) == OFFSET_REF
)
5351 instance
= resolve_offset_ref (instance
);
5352 if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
5353 instance
= convert_from_reference (instance
);
5354 basetype
= TREE_TYPE (instance
);
5356 /* XXX this should be handled before we get here. */
5357 if (! IS_AGGR_TYPE (basetype
)
5358 && ! (TYPE_LANG_SPECIFIC (basetype
)
5359 && (IS_SIGNATURE_POINTER (basetype
)
5360 || IS_SIGNATURE_REFERENCE (basetype
))))
5362 if ((flags
& LOOKUP_COMPLAIN
) && basetype
!= error_mark_node
)
5363 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
5364 name
, instance
, basetype
);
5366 return error_mark_node
;
5369 /* If `instance' is a signature pointer/reference and `name' is
5370 not a constructor, we are calling a signature member function.
5371 In that case set the `basetype' to the signature type. */
5372 if ((IS_SIGNATURE_POINTER (basetype
)
5373 || IS_SIGNATURE_REFERENCE (basetype
))
5374 && TYPE_IDENTIFIER (basetype
) != name
)
5375 basetype
= SIGNATURE_TYPE (basetype
);
5378 if (basetype_path
== NULL_TREE
)
5379 basetype_path
= TYPE_BINFO (basetype
);
5383 instance_ptr
= build_this (instance
);
5385 /* XXX this should be handled before we get here. */
5386 fns
= build_field_call (basetype_path
, instance_ptr
, name
, args
);
5392 instance_ptr
= build_int_2 (0, 0);
5393 TREE_TYPE (instance_ptr
) = build_pointer_type (basetype
);
5397 = (name
== ctor_identifier
? constructor_name_full (basetype
) : name
);
5399 fns
= lookup_fnfields (basetype_path
, name
, 1);
5401 if (fns
== error_mark_node
)
5402 return error_mark_node
;
5405 tree t
= TREE_VALUE (fns
);
5406 if (name
== ctor_identifier
&& TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
5407 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
5409 flags
|= LOOKUP_HAS_IN_CHARGE
;
5410 args
= tree_cons (NULL_TREE
, integer_one_node
, args
);
5412 mem_args
= tree_cons (NULL_TREE
, instance_ptr
, args
);
5413 for (; t
; t
= DECL_CHAIN (t
))
5415 /* We can end up here for copy-init of same or base class. */
5416 if (name
== ctor_identifier
5417 && (flags
& LOOKUP_ONLYCONVERTING
)
5418 && DECL_NONCONVERTING_P (t
))
5420 if (TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)
5421 candidates
= add_function_candidate
5422 (candidates
, t
, mem_args
, flags
);
5424 candidates
= add_function_candidate (candidates
, t
, args
, flags
);
5425 candidates
->basetype_path
= TREE_PURPOSE (fns
);
5429 if (! any_viable (candidates
))
5431 /* XXX will LOOKUP_SPECULATIVELY be needed when this is done? */
5432 if (flags
& LOOKUP_SPECULATIVELY
)
5434 cp_error ("no matching function for call to `%T::%D (%A)%V'", basetype
,
5435 pretty_name
, user_args
, TREE_TYPE (TREE_TYPE (instance_ptr
)));
5436 print_z_candidates (candidates
);
5437 return error_mark_node
;
5439 candidates
= splice_viable (candidates
);
5440 cand
= tourney (candidates
);
5444 cp_error ("call of overloaded `%D(%A)' is ambiguous", pretty_name
,
5446 print_z_candidates (candidates
);
5447 return error_mark_node
;
5450 enforce_access (cand
->basetype_path
, cand
->fn
);
5451 if (DECL_ABSTRACT_VIRTUAL_P (cand
->fn
)
5452 && instance
== current_class_ref
5453 && DECL_CONSTRUCTOR_P (current_function_decl
)
5454 && ! (flags
& LOOKUP_NONVIRTUAL
)
5455 && value_member (cand
->fn
, get_abstract_virtuals (basetype
)))
5456 cp_error ("abstract virtual `%#D' called from constructor", cand
->fn
);
5457 if (TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
5458 && TREE_CODE (instance_ptr
) == NOP_EXPR
5459 && TREE_OPERAND (instance_ptr
, 0) == error_mark_node
)
5460 cp_error ("cannot call member function `%D' without object", cand
->fn
);
5462 if (DECL_VINDEX (cand
->fn
) && ! (flags
& LOOKUP_NONVIRTUAL
)
5463 && ((instance
== current_class_ref
&& (dtor_label
|| ctor_label
))
5464 || resolves_to_fixed_type_p (instance
, 0)))
5465 flags
|= LOOKUP_NONVIRTUAL
;
5467 return build_over_call
5468 (cand
->fn
, cand
->convs
,
5469 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
? mem_args
: args
,
5473 /* Compare two implicit conversion sequences that differ only in their
5474 qualification conversion. Subroutine of compare_ics. */
5477 compare_qual (ics1
, ics2
)
5480 tree to1
= TREE_TYPE (ics1
);
5481 tree to2
= TREE_TYPE (ics2
);
5483 to1
= TREE_TYPE (to1
);
5484 to2
= TREE_TYPE (to2
);
5486 if (TREE_CODE (to1
) == OFFSET_TYPE
)
5488 to1
= TREE_TYPE (to1
);
5489 to2
= TREE_TYPE (to2
);
5492 if (TYPE_READONLY (to1
) >= TYPE_READONLY (to2
)
5493 && TYPE_VOLATILE (to1
) > TYPE_VOLATILE (to2
))
5495 else if (TYPE_READONLY (to1
) > TYPE_READONLY (to2
)
5496 && TYPE_VOLATILE (to1
) == TYPE_VOLATILE (to2
))
5498 else if (TYPE_READONLY (to1
) <= TYPE_READONLY (to2
)
5499 && TYPE_VOLATILE (to1
) < TYPE_VOLATILE (to2
))
5501 else if (TYPE_READONLY (to1
) < TYPE_READONLY (to2
)
5502 && TYPE_VOLATILE (to1
) == TYPE_VOLATILE (to2
))
5507 /* Determine whether standard conversion sequence ICS1 is a proper
5508 subsequence of ICS2. We assume that a conversion of the same code
5509 between the same types indicates a subsequence. */
5512 is_subseq (ics1
, ics2
)
5515 for (;; ics2
= TREE_OPERAND (ics2
, 0))
5517 if (TREE_CODE (ics2
) == TREE_CODE (ics1
)
5518 && comptypes (TREE_TYPE (ics2
), TREE_TYPE (ics1
), 1)
5519 && comptypes (TREE_TYPE (TREE_OPERAND (ics2
, 0)),
5520 TREE_TYPE (TREE_OPERAND (ics1
, 0)), 1))
5523 if (TREE_CODE (ics2
) == USER_CONV
5524 || TREE_CODE (ics2
) == AMBIG_CONV
5525 || TREE_CODE (ics2
) == IDENTITY_CONV
)
5530 /* Compare two implicit conversion sequences according to the rules set out in
5531 [over.ics.rank]. Return values:
5533 1: ics1 is better than ics2
5534 -1: ics2 is better than ics1
5535 0: ics1 and ics2 are indistinguishable */
5538 compare_ics (ics1
, ics2
)
5543 if (TREE_CODE (ics1
) == QUAL_CONV
)
5544 main1
= TREE_OPERAND (ics1
, 0);
5548 if (TREE_CODE (ics2
) == QUAL_CONV
)
5549 main2
= TREE_OPERAND (ics2
, 0);
5553 /* Conversions for `this' are PTR_CONVs, but we compare them as though
5554 they were REF_BINDs. */
5555 if (ICS_THIS_FLAG (ics1
))
5558 if (TREE_CODE (t
) == PTR_CONV
)
5559 t
= TREE_OPERAND (t
, 0);
5560 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
5561 t
= build_conv (REF_BIND
, TREE_TYPE (ics1
), t
);
5562 ICS_STD_RANK (t
) = ICS_STD_RANK (main1
);
5565 if (ICS_THIS_FLAG (ics2
))
5568 if (TREE_CODE (t
) == PTR_CONV
)
5569 t
= TREE_OPERAND (t
, 0);
5570 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
5571 t
= build_conv (REF_BIND
, TREE_TYPE (ics2
), t
);
5572 ICS_STD_RANK (t
) = ICS_STD_RANK (main2
);
5576 if (ICS_RANK (ics1
) > ICS_RANK (ics2
))
5578 else if (ICS_RANK (ics1
) < ICS_RANK (ics2
))
5581 if (ICS_RANK (ics1
) == BAD_RANK
)
5583 if (ICS_USER_FLAG (ics1
) > ICS_USER_FLAG (ics2
)
5584 || ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
5586 else if (ICS_USER_FLAG (ics1
) < ICS_USER_FLAG (ics2
)
5587 || ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
5590 /* else fall through */
5593 /* User-defined conversion sequence U1 is a better conversion sequence
5594 than another user-defined conversion sequence U2 if they contain the
5595 same user-defined conversion operator or constructor and if the sec-
5596 ond standard conversion sequence of U1 is better than the second
5597 standard conversion sequence of U2. */
5599 if (ICS_USER_FLAG (ics1
))
5603 for (t1
= ics1
; TREE_CODE (t1
) != USER_CONV
; t1
= TREE_OPERAND (t1
, 0))
5604 if (TREE_CODE (t1
) == AMBIG_CONV
)
5606 for (t2
= ics2
; TREE_CODE (t2
) != USER_CONV
; t2
= TREE_OPERAND (t2
, 0))
5607 if (TREE_CODE (t2
) == AMBIG_CONV
)
5610 if (USER_CONV_FN (t1
) != USER_CONV_FN (t2
))
5612 else if (ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
5614 else if (ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
5617 /* else fall through */
5620 #if 0 /* Handled by ranking */
5621 /* A conversion that is not a conversion of a pointer, or pointer to
5622 member, to bool is better than another conversion that is such a
5626 if (TREE_CODE (main1
) != TREE_CODE (main2
))
5628 /* ...if S1 is a proper subsequence of S2 */
5629 if (is_subseq (main1
, main2
))
5631 if (is_subseq (main2
, main1
))
5636 if (TREE_CODE (main1
) == PTR_CONV
|| TREE_CODE (main1
) == PMEM_CONV
5637 || TREE_CODE (main1
) == REF_BIND
|| TREE_CODE (main1
) == BASE_CONV
)
5639 tree to1
= TREE_TYPE (main1
);
5640 tree from1
= TREE_TYPE (TREE_OPERAND (main1
, 0));
5641 tree to2
= TREE_TYPE (main2
);
5642 tree from2
= TREE_TYPE (TREE_OPERAND (main2
, 0));
5645 /* Standard conversion sequence S1 is a better conversion sequence than
5646 standard conversion sequence S2 if...
5648 S1 and S2 differ only in their qualification conversion and they
5649 yield types identical except for cv-qualifiers and S2 adds all the
5650 qualifiers that S1 adds (and in the same places) and S2 adds yet
5651 more cv-qualifiers than S1, or the similar case with reference
5653 if (TREE_CODE (main1
) == REF_BIND
)
5655 if (TYPE_MAIN_VARIANT (TREE_TYPE (to1
))
5656 == TYPE_MAIN_VARIANT (TREE_TYPE (to2
)))
5657 return compare_qual (ics1
, ics2
);
5659 else if (TREE_CODE (main1
) != BASE_CONV
&& from1
== from2
&& to1
== to2
)
5660 return compare_qual (ics1
, ics2
);
5662 if (TYPE_PTRMEMFUNC_P (to1
))
5664 to1
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to1
)));
5665 from1
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from1
)));
5667 else if (TREE_CODE (main1
) != BASE_CONV
)
5669 to1
= TREE_TYPE (to1
);
5670 if (TREE_CODE (main1
) != REF_BIND
)
5671 from1
= TREE_TYPE (from1
);
5673 if (TREE_CODE (to1
) == OFFSET_TYPE
)
5675 to1
= TYPE_OFFSET_BASETYPE (to1
);
5676 from1
= TYPE_OFFSET_BASETYPE (from1
);
5680 if (TYPE_PTRMEMFUNC_P (to2
))
5682 to2
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to2
)));
5683 from2
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from2
)));
5685 else if (TREE_CODE (main1
) != BASE_CONV
)
5687 to2
= TREE_TYPE (to2
);
5688 if (TREE_CODE (main1
) != REF_BIND
)
5689 from2
= TREE_TYPE (from2
);
5691 if (TREE_CODE (to2
) == OFFSET_TYPE
)
5693 to2
= TYPE_OFFSET_BASETYPE (to2
);
5694 from2
= TYPE_OFFSET_BASETYPE (from2
);
5698 if (! (IS_AGGR_TYPE (from1
) && IS_AGGR_TYPE (from2
)))
5701 /* The sense of pmem conversions is reversed from that of the other
5703 if (TREE_CODE (main1
) == PMEM_CONV
)
5705 tree t
= from1
; from1
= from2
; from2
= t
;
5706 t
= to1
; to1
= to2
; to2
= t
;
5709 distf
= get_base_distance (from1
, from2
, 0, 0);
5712 distf
= -get_base_distance (from2
, from1
, 0, 0);
5717 /* If class B is derived directly or indirectly from class A,
5718 conver- sion of B* to A* is better than conversion of B* to
5719 void*, and conversion of A* to void* is better than
5720 conversion of B* to void*. */
5722 if (TREE_CODE (to1
) == VOID_TYPE
&& TREE_CODE (to2
) == VOID_TYPE
)
5729 else if (TREE_CODE (to2
) == VOID_TYPE
&& IS_AGGR_TYPE (to1
)
5730 && get_base_distance (to1
, from1
, 0, 0) != -1)
5732 else if (TREE_CODE (to1
) == VOID_TYPE
&& IS_AGGR_TYPE (to2
)
5733 && get_base_distance (to2
, from2
, 0, 0) != -1)
5736 if (! (IS_AGGR_TYPE (to1
) && IS_AGGR_TYPE (to2
)))
5739 /* If class B is derived directly or indirectly from class A and class
5740 C is derived directly or indirectly from B */
5742 distt
= get_base_distance (to1
, to2
, 0, 0);
5745 distt
= -get_base_distance (to2
, to1
, 0, 0);
5750 /* --conversion of C* to B* is better than conversion of C* to A*, */
5758 /* --conversion of B* to A* is better than conversion of C* to A*, */
5759 else if (distt
== 0)
5767 else if (TREE_CODE (TREE_TYPE (main1
)) == POINTER_TYPE
5768 || TYPE_PTRMEMFUNC_P (TREE_TYPE (main1
)))
5770 if (TREE_TYPE (main1
) == TREE_TYPE (main2
))
5771 return compare_qual (ics1
, ics2
);
5773 #if 0 /* This is now handled by making identity better than anything else. */
5774 /* existing practice, not WP-endorsed: const char * -> const char *
5775 is better than char * -> const char *. (jason 6/29/96) */
5776 if (TREE_TYPE (ics1
) == TREE_TYPE (ics2
))
5777 return -compare_qual (main1
, main2
);
5788 for (;; t
= TREE_OPERAND (t
, 0))
5790 if (TREE_CODE (t
) == USER_CONV
5791 || TREE_CODE (t
) == AMBIG_CONV
5792 || TREE_CODE (t
) == IDENTITY_CONV
)
5793 return TREE_TYPE (t
);
5795 my_friendly_abort (1823);
5798 /* Compare two candidates for overloading as described in
5799 [over.match.best]. Return values:
5801 1: cand1 is better than cand2
5802 -1: cand2 is better than cand1
5803 0: cand1 and cand2 are indistinguishable */
5806 joust (cand1
, cand2
)
5807 struct z_candidate
*cand1
, *cand2
;
5810 int i
, off1
= 0, off2
= 0, len
;
5812 /* Candidates that involve bad conversions are always worse than those
5814 if (cand1
->viable
> cand2
->viable
)
5816 if (cand1
->viable
< cand2
->viable
)
5819 /* a viable function F1
5820 is defined to be a better function than another viable function F2 if
5821 for all arguments i, ICSi(F1) is not a worse conversion sequence than
5822 ICSi(F2), and then */
5824 /* for some argument j, ICSj(F1) is a better conversion sequence than
5827 /* For comparing static and non-static member functions, we ignore the
5828 implicit object parameter of the non-static function. The WP says to
5829 pretend that the static function has an object parm, but that won't
5830 work with operator overloading. */
5831 len
= TREE_VEC_LENGTH (cand1
->convs
);
5832 if (len
!= TREE_VEC_LENGTH (cand2
->convs
))
5834 if (DECL_STATIC_FUNCTION_P (cand1
->fn
)
5835 && ! DECL_STATIC_FUNCTION_P (cand2
->fn
))
5837 else if (! DECL_STATIC_FUNCTION_P (cand1
->fn
)
5838 && DECL_STATIC_FUNCTION_P (cand2
->fn
))
5844 my_friendly_abort (42);
5847 for (i
= 0; i
< len
; ++i
)
5849 tree t1
= TREE_VEC_ELT (cand1
->convs
, i
+off1
);
5850 tree t2
= TREE_VEC_ELT (cand2
->convs
, i
+off2
);
5851 int comp
= compare_ics (t1
, t2
);
5856 && ICS_RANK (t1
) + ICS_RANK (t2
) == STD_RANK
+ PROMO_RANK
5857 && TREE_CODE (t1
) == STD_CONV
5858 && TREE_CODE (t2
) == STD_CONV
5859 && TREE_CODE (TREE_TYPE (t1
)) == INTEGER_TYPE
5860 && TREE_CODE (TREE_TYPE (t2
)) == INTEGER_TYPE
5861 && (TYPE_PRECISION (TREE_TYPE (t1
))
5862 == TYPE_PRECISION (TREE_TYPE (t2
)))
5863 && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (t1
, 0)))
5864 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (t1
, 0)))
5867 tree type
= TREE_TYPE (TREE_OPERAND (t1
, 0));
5870 type1
= TREE_TYPE (t1
), type2
= TREE_TYPE (t2
);
5872 type1
= TREE_TYPE (t2
), type2
= TREE_TYPE (t1
);
5874 cp_warning ("passing `%T' chooses `%T' over `%T'",
5875 type
, type1
, type2
);
5876 cp_warning (" in call to `%D'", DECL_NAME (cand1
->fn
));
5879 if (winner
&& comp
!= winner
)
5888 /* warn about confusing overload resolution */
5889 if (winner
&& cand1
->second_conv
5890 && ! DECL_CONSTRUCTOR_P (cand1
->fn
)
5891 && ! DECL_CONSTRUCTOR_P (cand2
->fn
))
5893 int comp
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
5894 if (comp
&& comp
!= winner
)
5896 struct z_candidate
*w
, *l
;
5898 w
= cand1
, l
= cand2
;
5900 w
= cand2
, l
= cand1
;
5901 cp_warning ("choosing `%D' over `%D'", w
->fn
, l
->fn
);
5902 cp_warning (" for conversion from `%T' to `%T'",
5903 TREE_TYPE (source_type (TREE_VEC_ELT (w
->convs
, 0))),
5904 TREE_TYPE (w
->second_conv
));
5905 cp_warning (" because conversion sequence for `this' argument is better");
5913 F1 is a non-template function and F2 is a template function */
5915 if (! cand1
->template && cand2
->template)
5917 else if (cand1
->template && ! cand2
->template)
5919 else if (cand1
->template && cand2
->template)
5920 winner
= more_specialized
5921 (TI_TEMPLATE (cand1
->template), TI_TEMPLATE (cand2
->template));
5924 the context is an initialization by user-defined conversion (see
5925 _dcl.init_ and _over.match.user_) and the standard conversion
5926 sequence from the return type of F1 to the destination type (i.e.,
5927 the type of the entity being initialized) is a better conversion
5928 sequence than the standard conversion sequence from the return type
5929 of F2 to the destination type. */
5931 if (! winner
&& cand1
->second_conv
)
5932 winner
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
5934 /* If the built-in candidates are the same, arbitrarily pick one. */
5935 if (! winner
&& cand1
->fn
== cand2
->fn
5936 && TREE_CODE (cand1
->fn
) == IDENTIFIER_NODE
)
5938 for (i
= 0; i
< len
; ++i
)
5939 if (! comptypes (TREE_TYPE (TREE_VEC_ELT (cand1
->convs
, i
)),
5940 TREE_TYPE (TREE_VEC_ELT (cand2
->convs
, i
)), 1))
5942 if (i
== TREE_VEC_LENGTH (cand1
->convs
))
5945 /* Kludge around broken overloading rules whereby
5946 bool ? void *const & : void *const & is ambiguous. */
5947 /* Huh? Explain the problem better. */
5948 if (cand1
->fn
== ansi_opname
[COND_EXPR
])
5950 tree c1
= TREE_VEC_ELT (cand1
->convs
, 1);
5951 tree c2
= TREE_VEC_ELT (cand2
->convs
, 1);
5952 tree t1
= strip_top_quals (non_reference (TREE_TYPE (c1
)));
5953 tree t2
= strip_top_quals (non_reference (TREE_TYPE (c2
)));
5955 if (comptypes (t1
, t2
, 1))
5957 if (TREE_CODE (c1
) == REF_BIND
&& TREE_CODE (c2
) != REF_BIND
)
5959 if (TREE_CODE (c1
) != REF_BIND
&& TREE_CODE (c2
) == REF_BIND
)
5968 /* Extension: If the worst conversion for one candidate is worse than the
5969 worst conversion for the other, take the first. */
5970 if (! winner
&& ! pedantic
)
5972 int rank1
= IDENTITY_RANK
, rank2
= IDENTITY_RANK
;
5974 for (i
= 0; i
< len
; ++i
)
5976 if (ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
)) > rank1
)
5977 rank1
= ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
));
5978 if (ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
)) > rank2
)
5979 rank2
= ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
));
5991 /* Given a list of candidates for overloading, find the best one, if any.
5992 This algorithm has a worst case of O(2n) (winner is last), and a best
5993 case of O(n/2) (totally ambiguous); much better than a sorting
5996 static struct z_candidate
*
5997 tourney (candidates
)
5998 struct z_candidate
*candidates
;
6000 struct z_candidate
*champ
= candidates
, *challenger
;
6003 /* Walk through the list once, comparing each current champ to the next
6004 candidate, knocking out a candidate or two with each comparison. */
6006 for (challenger
= champ
->next
; challenger
; )
6008 fate
= joust (champ
, challenger
);
6010 challenger
= challenger
->next
;
6015 champ
= challenger
->next
;
6022 challenger
= champ
->next
;
6026 /* Make sure the champ is better than all the candidates it hasn't yet
6027 been compared to. This may do one more comparison than necessary. Oh
6030 for (challenger
= candidates
; challenger
!= champ
;
6031 challenger
= challenger
->next
)
6033 fate
= joust (champ
, challenger
);
6042 can_convert (to
, from
)
6045 if (flag_ansi_overloading
)
6047 tree t
= implicit_conversion (to
, from
, NULL_TREE
, LOOKUP_NORMAL
);
6048 return (t
&& ! ICS_BAD_FLAG (t
));
6052 struct harshness_code h
;
6053 h
= convert_harshness (to
, from
, NULL_TREE
);
6054 return (h
.code
< USER_CODE
) && (h
.distance
>= 0);
6059 can_convert_arg (to
, from
, arg
)
6062 if (flag_ansi_overloading
)
6064 tree t
= implicit_conversion (to
, from
, arg
, LOOKUP_NORMAL
);
6065 return (t
&& ! ICS_BAD_FLAG (t
));
6069 struct harshness_code h
;
6070 h
= convert_harshness (to
, from
, arg
);
6071 return (h
.code
< USER_CODE
) && (h
.distance
>= 0);