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
, tree
, tree
, int));
81 static struct z_candidate
* add_template_conv_candidate
82 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
));
83 static struct z_candidate
* add_builtin_candidates
84 PROTO((struct z_candidate
*, enum tree_code
, enum tree_code
,
86 static struct z_candidate
* add_builtin_candidate
87 PROTO((struct z_candidate
*, enum tree_code
, enum tree_code
,
88 tree
, tree
, tree
, tree
*, tree
*, int));
89 static int is_complete
PROTO((tree
));
90 static struct z_candidate
* build_builtin_candidate
91 PROTO((struct z_candidate
*, tree
, tree
, tree
, tree
*, tree
*,
93 static struct z_candidate
* add_conv_candidate
94 PROTO((struct z_candidate
*, tree
, tree
, tree
));
95 static struct z_candidate
* add_function_candidate
96 PROTO((struct z_candidate
*, tree
, tree
, int));
97 static tree implicit_conversion
PROTO((tree
, tree
, tree
, int));
98 static tree standard_conversion
PROTO((tree
, tree
, tree
));
99 static tree reference_binding
PROTO((tree
, tree
, tree
, int));
100 static tree strip_top_quals
PROTO((tree
));
101 static tree non_reference
PROTO((tree
));
102 static tree build_conv
PROTO((enum tree_code
, tree
, tree
));
103 static void print_n_candidates
PROTO((struct candidate
*, int));
104 static tree default_parm_conversions
PROTO((tree
, tree
*));
105 static int is_subseq
PROTO((tree
, tree
));
107 #define EVIL_RETURN(ARG) ((ARG).code = EVIL_CODE, (ARG))
108 #define STD_RETURN(ARG) ((ARG).code = STD_CODE, (ARG))
109 #define QUAL_RETURN(ARG) ((ARG).code = QUAL_CODE, (ARG))
110 #define TRIVIAL_RETURN(ARG) ((ARG).code = TRIVIAL_CODE, (ARG))
111 #define ZERO_RETURN(ARG) ((ARG).code = 0, (ARG))
113 /* Ordering function for overload resolution. Compare two candidates
117 rank_for_overload (x
, y
)
118 struct candidate
*x
, *y
;
120 if (y
->h
.code
& (EVIL_CODE
|ELLIPSIS_CODE
|USER_CODE
))
121 return y
->h
.code
- x
->h
.code
;
122 if (x
->h
.code
& (EVIL_CODE
|ELLIPSIS_CODE
|USER_CODE
))
125 /* This is set by compute_conversion_costs, for calling a non-const
126 member function from a const member function. */
127 if ((y
->harshness
[0].code
& CONST_CODE
) ^ (x
->harshness
[0].code
& CONST_CODE
))
128 return y
->harshness
[0].code
- x
->harshness
[0].code
;
130 if (y
->h
.code
& STD_CODE
)
132 if (x
->h
.code
& STD_CODE
)
133 return y
->h
.distance
- x
->h
.distance
;
136 if (x
->h
.code
& STD_CODE
)
139 return y
->h
.code
- x
->h
.code
;
142 /* Compare two candidates, argument by argument. */
145 rank_for_ideal (x
, y
)
146 struct candidate
*x
, *y
;
150 if (x
->h_len
!= y
->h_len
)
153 for (i
= 0; i
< x
->h_len
; i
++)
155 if (y
->harshness
[i
].code
- x
->harshness
[i
].code
)
156 return y
->harshness
[i
].code
- x
->harshness
[i
].code
;
157 if ((y
->harshness
[i
].code
& STD_CODE
)
158 && (y
->harshness
[i
].distance
- x
->harshness
[i
].distance
))
159 return y
->harshness
[i
].distance
- x
->harshness
[i
].distance
;
161 /* They're both the same code. Now see if we're dealing with an
162 integral promotion that needs a finer grain of accuracy. */
163 if (y
->harshness
[0].code
& PROMO_CODE
164 && (y
->harshness
[i
].int_penalty
^ x
->harshness
[i
].int_penalty
))
165 return y
->harshness
[i
].int_penalty
- x
->harshness
[i
].int_penalty
;
170 /* TYPE is the type we wish to convert to. PARM is the parameter
171 we have to work with. We use a somewhat arbitrary cost function
172 to measure this conversion. */
174 static struct harshness_code
175 convert_harshness (type
, parmtype
, parm
)
176 register tree type
, parmtype
;
179 struct harshness_code h
;
180 register enum tree_code codel
;
181 register enum tree_code coder
;
188 #ifdef GATHER_STATISTICS
189 n_convert_harshness
++;
192 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
195 parm
= convert_from_reference (parm
);
196 parmtype
= TREE_TYPE (parmtype
);
200 lvalue
= lvalue_p (parm
);
204 if (TYPE_PTRMEMFUNC_P (type
))
205 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
206 if (TYPE_PTRMEMFUNC_P (parmtype
))
207 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
209 codel
= TREE_CODE (type
);
210 coder
= TREE_CODE (parmtype
);
212 if (TYPE_MAIN_VARIANT (parmtype
) == TYPE_MAIN_VARIANT (type
))
213 return ZERO_RETURN (h
);
215 if (coder
== ERROR_MARK
)
216 return EVIL_RETURN (h
);
218 if (codel
== REFERENCE_TYPE
)
221 int constp
= parm
? TREE_READONLY (parm
) : TYPE_READONLY (parmtype
);
222 int volatilep
= (parm
? TREE_THIS_VOLATILE (parm
)
223 : TYPE_VOLATILE (parmtype
));
224 register tree intype
= TYPE_MAIN_VARIANT (parmtype
);
225 register enum tree_code form
= TREE_CODE (intype
);
228 ttl
= TREE_TYPE (type
);
230 /* Only allow const reference binding if we were given a parm to deal
231 with, since it isn't really a conversion. This is a hack to
232 prevent build_type_conversion from finding this conversion, but
233 still allow overloading to find it. */
234 if (! lvalue
&& ! (parm
&& TYPE_READONLY (ttl
)))
235 return EVIL_RETURN (h
);
237 if ((TYPE_READONLY (ttl
) < constp
)
238 || (TYPE_VOLATILE (ttl
) < volatilep
))
239 return EVIL_RETURN (h
);
241 /* When passing a non-const argument into a const reference, dig it a
242 little, so a non-const reference is preferred over this one. */
243 penalty
= ((TYPE_READONLY (ttl
) > constp
)
244 + (TYPE_VOLATILE (ttl
) > volatilep
));
246 ttl
= TYPE_MAIN_VARIANT (ttl
);
248 if (form
== OFFSET_TYPE
)
250 intype
= TREE_TYPE (intype
);
251 form
= TREE_CODE (intype
);
256 if (TREE_CODE (ttl
) == ARRAY_TYPE
&& TREE_CODE (ttr
) == ARRAY_TYPE
)
258 if (comptypes (ttl
, ttr
, 1))
259 return ZERO_RETURN (h
);
260 return EVIL_RETURN (h
);
263 h
= convert_harshness (ttl
, ttr
, NULL_TREE
);
264 if (penalty
&& h
.code
== 0)
267 h
.int_penalty
= penalty
;
272 if (codel
== POINTER_TYPE
&& fntype_p (parmtype
))
275 struct harshness_code h1
, h2
;
277 /* Get to the METHOD_TYPE or FUNCTION_TYPE that this might be. */
278 type
= TREE_TYPE (type
);
280 if (coder
== POINTER_TYPE
)
282 parmtype
= TREE_TYPE (parmtype
);
283 coder
= TREE_CODE (parmtype
);
286 if (coder
!= TREE_CODE (type
))
287 return EVIL_RETURN (h
);
289 if (type
!= parmtype
&& coder
== METHOD_TYPE
)
291 tree ttl
= TYPE_METHOD_BASETYPE (type
);
292 tree ttr
= TYPE_METHOD_BASETYPE (parmtype
);
294 int b_or_d
= get_base_distance (ttr
, ttl
, 0, (tree
*)0);
297 b_or_d
= get_base_distance (ttl
, ttr
, 0, (tree
*)0);
299 return EVIL_RETURN (h
);
300 h
.distance
= -b_or_d
;
306 type
= build_function_type
307 (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
308 parmtype
= build_function_type
309 (TREE_TYPE (parmtype
), TREE_CHAIN (TYPE_ARG_TYPES (parmtype
)));
312 /* We allow the default conversion between function type
313 and pointer-to-function type for free. */
314 if (comptypes (type
, parmtype
, 1))
318 return EVIL_RETURN (h
);
320 /* Compare return types. */
321 p1
= TREE_TYPE (type
);
322 p2
= TREE_TYPE (parmtype
);
323 h2
= convert_harshness (p1
, p2
, NULL_TREE
);
324 if (h2
.code
& EVIL_CODE
)
327 h1
.code
= TRIVIAL_CODE
;
330 if (h2
.distance
!= 0)
334 /* This only works for pointers. */
335 if (TREE_CODE (p1
) != POINTER_TYPE
336 && TREE_CODE (p1
) != REFERENCE_TYPE
)
337 return EVIL_RETURN (h
);
341 /* Don't die if we happen to be dealing with void*. */
342 if (!IS_AGGR_TYPE (p1
) || !IS_AGGR_TYPE (p2
))
343 return EVIL_RETURN (h
);
345 binfo
= get_binfo (p2
, p1
, 0);
347 binfo
= get_binfo (p1
, p2
, 0);
349 if (! BINFO_OFFSET_ZEROP (binfo
))
352 static int explained
= 0;
354 message_2_types (sorry
, "cannot cast `%s' to `%s' at function call site", p2
, p1
);
356 message_2_types (sorry
, "cannot cast `%s' to `%s' at function call site", p1
, p2
);
359 sorry ("(because pointer values change during conversion)");
361 return EVIL_RETURN (h
);
366 if (h2
.distance
> h1
.distance
)
367 h1
.distance
= h2
.distance
;
369 p1
= TYPE_ARG_TYPES (type
);
370 p2
= TYPE_ARG_TYPES (parmtype
);
371 while (p1
&& TREE_VALUE (p1
) != void_type_node
372 && p2
&& TREE_VALUE (p2
) != void_type_node
)
374 h2
= convert_harshness (TREE_VALUE (p1
), TREE_VALUE (p2
),
376 if (h2
.code
& EVIL_CODE
)
381 /* This only works for pointers and references. */
382 if (TREE_CODE (TREE_VALUE (p1
)) != POINTER_TYPE
383 && TREE_CODE (TREE_VALUE (p1
)) != REFERENCE_TYPE
)
384 return EVIL_RETURN (h
);
385 h2
.distance
= - h2
.distance
;
389 if (h2
.distance
> h1
.distance
)
390 h1
.distance
= h2
.distance
;
391 p1
= TREE_CHAIN (p1
);
392 p2
= TREE_CHAIN (p2
);
399 return EVIL_RETURN (h
);
400 h1
.code
|= ELLIPSIS_CODE
;
405 if (TREE_PURPOSE (p1
) == NULL_TREE
)
406 h1
.code
|= EVIL_CODE
;
410 else if (codel
== POINTER_TYPE
&& coder
== OFFSET_TYPE
)
414 /* Get to the OFFSET_TYPE that this might be. */
415 type
= TREE_TYPE (type
);
417 if (coder
!= TREE_CODE (type
))
418 return EVIL_RETURN (h
);
420 ttl
= TYPE_OFFSET_BASETYPE (type
);
421 ttr
= TYPE_OFFSET_BASETYPE (parmtype
);
427 int b_or_d
= get_base_distance (ttr
, ttl
, 0, (tree
*)0);
430 b_or_d
= get_base_distance (ttl
, ttr
, 0, (tree
*)0);
432 return EVIL_RETURN (h
);
433 h
.distance
= -b_or_d
;
440 /* Now test the OFFSET_TYPE's target compatibility. */
441 type
= TREE_TYPE (type
);
442 parmtype
= TREE_TYPE (parmtype
);
445 if (coder
== UNKNOWN_TYPE
)
447 if (codel
== FUNCTION_TYPE
448 || codel
== METHOD_TYPE
449 || (codel
== POINTER_TYPE
450 && (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
451 || TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)))
452 return TRIVIAL_RETURN (h
);
453 return EVIL_RETURN (h
);
456 if (coder
== VOID_TYPE
)
457 return EVIL_RETURN (h
);
459 if (codel
== BOOLEAN_TYPE
)
461 if (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
)
462 return STD_RETURN (h
);
463 else if (coder
== POINTER_TYPE
|| coder
== OFFSET_TYPE
)
465 /* Make this worse than any conversion to another pointer.
466 FIXME this is how I think the language should work, but it may not
467 end up being how the language is standardized (jason 1/30/95). */
469 return STD_RETURN (h
);
471 return EVIL_RETURN (h
);
474 if (INTEGRAL_CODE_P (codel
))
476 /* Control equivalence of ints an enums. */
478 if (codel
== ENUMERAL_TYPE
479 && flag_int_enum_equivalence
== 0)
481 /* Enums can be converted to ints, but not vice-versa. */
482 if (coder
!= ENUMERAL_TYPE
483 || TYPE_MAIN_VARIANT (type
) != TYPE_MAIN_VARIANT (parmtype
))
484 return EVIL_RETURN (h
);
487 /* else enums and ints (almost) freely interconvert. */
489 if (INTEGRAL_CODE_P (coder
))
491 if (TYPE_MAIN_VARIANT (type
)
492 == TYPE_MAIN_VARIANT (type_promotes_to (parmtype
)))
501 else if (coder
== REAL_TYPE
)
509 if (codel
== REAL_TYPE
)
511 if (coder
== REAL_TYPE
)
513 if (TYPE_MAIN_VARIANT (type
)
514 == TYPE_MAIN_VARIANT (type_promotes_to (parmtype
)))
521 else if (INTEGRAL_CODE_P (coder
))
529 /* Convert arrays which have not previously been converted. */
530 if (coder
== ARRAY_TYPE
)
532 coder
= POINTER_TYPE
;
535 parm
= decay_conversion (parm
);
536 parmtype
= TREE_TYPE (parm
);
539 parmtype
= build_pointer_type (TREE_TYPE (parmtype
));
542 /* Conversions among pointers */
543 if (codel
== POINTER_TYPE
&& coder
== POINTER_TYPE
)
545 register tree ttl
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
546 register tree ttr
= TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
));
547 int penalty
= 4 * (ttl
!= ttr
);
549 /* Anything converts to void *. Since this may be `const void *'
550 (etc.) use VOID_TYPE instead of void_type_node. Otherwise, the
551 targets must be the same, except that we do allow (at some cost)
552 conversion between signed and unsigned pointer types. */
554 if ((TREE_CODE (ttl
) == METHOD_TYPE
555 || TREE_CODE (ttl
) == FUNCTION_TYPE
)
556 && TREE_CODE (ttl
) == TREE_CODE (ttr
))
558 if (comptypes (ttl
, ttr
, -1))
560 h
.code
= penalty
? STD_CODE
: 0;
569 if (TREE_CODE (ttl
) != VOID_TYPE
570 && (TREE_CODE (ttr
) != VOID_TYPE
|| !parm
|| !null_ptr_cst_p (parm
)))
572 if (comp_target_types (type
, parmtype
, 1) <= 0)
573 return EVIL_RETURN (h
);
576 if (!(TREE_CODE (ttl
) == VOID_TYPE
577 || TREE_CODE (ttr
) == VOID_TYPE
578 || (TREE_UNSIGNED (ttl
) ^ TREE_UNSIGNED (ttr
)
579 && (ttl
= unsigned_type (ttl
),
580 ttr
= unsigned_type (ttr
),
582 || (comp_target_types (ttl
, ttr
, 0) > 0)))
583 return EVIL_RETURN (h
);
588 tree tmp1
= TREE_TYPE (type
), tmp2
= TREE_TYPE (parmtype
);
591 /* Note conversion from `T*' to `const T*',
592 or `T*' to `volatile T*'. */
593 if ((TYPE_READONLY (tmp1
) < TREE_READONLY (tmp2
))
594 || (TYPE_VOLATILE (tmp1
) < TYPE_VOLATILE (tmp2
)))
596 else if ((TYPE_READONLY (tmp1
) != TREE_READONLY (tmp2
))
597 || (TYPE_VOLATILE (tmp1
) != TYPE_VOLATILE (tmp2
)))
605 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
607 int b_or_d
= get_base_distance (ttl
, ttr
, 0, (tree
*)0);
610 b_or_d
= get_base_distance (ttr
, ttl
, 0, (tree
*)0);
612 return EVIL_RETURN (h
);
613 h
.distance
= -b_or_d
;
621 /* If converting from a `class*' to a `void*', make it
622 less favorable than any inheritance relationship. */
623 if (TREE_CODE (ttl
) == VOID_TYPE
&& IS_AGGR_TYPE (ttr
))
626 h
.distance
= CLASSTYPE_MAX_DEPTH (ttr
)+1;
630 h
.code
= penalty
? STD_CODE
: PROMO_CODE
;
631 /* Catch things like `const char *' -> `const void *'
632 vs `const char *' -> `void *'. */
635 tree tmp1
= TREE_TYPE (type
), tmp2
= TREE_TYPE (parmtype
);
636 if ((TYPE_READONLY (tmp1
) < TREE_READONLY (tmp2
))
637 || (TYPE_VOLATILE (tmp1
) < TYPE_VOLATILE (tmp2
)))
639 else if ((TYPE_READONLY (tmp1
) > TREE_READONLY (tmp2
))
640 || (TYPE_VOLATILE (tmp1
) > TYPE_VOLATILE (tmp2
)))
646 if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
648 /* This is not a bad match, but don't let it beat
649 integer-enum combinations. */
650 if (parm
&& integer_zerop (parm
))
658 /* C++: Since the `this' parameter of a signature member function
659 is represented as a signature pointer to handle default implementations
660 correctly, we can have the case that `type' is a signature pointer
661 while `parmtype' is a pointer to a signature table. We don't really
662 do any conversions in this case, so just return 0. */
664 if (codel
== RECORD_TYPE
&& coder
== POINTER_TYPE
665 && IS_SIGNATURE_POINTER (type
) && IS_SIGNATURE (TREE_TYPE (parmtype
)))
666 return ZERO_RETURN (h
);
668 if (codel
== RECORD_TYPE
&& coder
== RECORD_TYPE
)
670 int b_or_d
= get_base_distance (type
, parmtype
, 0, (tree
*)0);
673 b_or_d
= get_base_distance (parmtype
, type
, 0, (tree
*)0);
675 return EVIL_RETURN (h
);
676 h
.distance
= -b_or_d
;
683 return EVIL_RETURN (h
);
686 /* A clone of build_type_conversion for checking user-defined conversions in
687 overload resolution. */
690 user_harshness (type
, parmtype
)
691 register tree type
, parmtype
;
694 tree winner
= NULL_TREE
;
698 tree typename
= build_typename_overload (type
);
699 if (lookup_fnfields (TYPE_BINFO (parmtype
), typename
, 0))
703 for (conv
= lookup_conversions (parmtype
); conv
; conv
= TREE_CHAIN (conv
))
705 struct harshness_code tmp
;
706 tree cand
= TREE_VALUE (conv
);
708 if (winner
&& winner
== cand
)
711 tmp
= convert_harshness (type
, TREE_TYPE (TREE_TYPE (cand
)), NULL_TREE
);
712 if ((tmp
.code
< USER_CODE
) && (tmp
.distance
>= 0))
730 #ifdef DEBUG_MATCHING
733 struct harshness_code
*h
;
735 static char buf
[1024];
738 bzero (buf
, 1024 * sizeof (char));
739 strcat (buf
, "codes=[");
740 if (h
->code
& EVIL_CODE
)
741 strcat (buf
, "EVIL");
742 if (h
->code
& CONST_CODE
)
743 strcat (buf
, " CONST");
744 if (h
->code
& ELLIPSIS_CODE
)
745 strcat (buf
, " ELLIPSIS");
746 if (h
->code
& USER_CODE
)
747 strcat (buf
, " USER");
748 if (h
->code
& STD_CODE
)
749 strcat (buf
, " STD");
750 if (h
->code
& PROMO_CODE
)
751 strcat (buf
, " PROMO");
752 if (h
->code
& QUAL_CODE
)
753 strcat (buf
, " QUAL");
754 if (h
->code
& TRIVIAL_CODE
)
755 strcat (buf
, " TRIVIAL");
759 sprintf (tmp
, "] distance=%d int_penalty=%d", h
->distance
, h
->int_penalty
);
767 /* Algorithm: For each argument, calculate how difficult it is to
768 make FUNCTION accept that argument. If we can easily tell that
769 FUNCTION won't be acceptable to one of the arguments, then we
770 don't need to compute the ease of converting the other arguments,
771 since it will never show up in the intersection of all arguments'
774 Conversions between builtin and user-defined types are allowed, but
775 no function involving such a conversion is preferred to one which
776 does not require such a conversion. Furthermore, such conversions
780 compute_conversion_costs (function
, tta_in
, cp
, arglen
)
783 struct candidate
*cp
;
786 tree ttf_in
= TYPE_ARG_TYPES (TREE_TYPE (function
));
790 /* Start out with no strikes against. */
791 int evil_strikes
= 0;
792 int ellipsis_strikes
= 0;
793 int user_strikes
= 0;
794 int b_or_d_strikes
= 0;
795 int easy_strikes
= 0;
797 int strike_index
= 0, win
;
798 struct harshness_code lose
;
799 extern int cp_silent
;
801 #ifdef GATHER_STATISTICS
802 n_compute_conversion_costs
++;
805 #ifndef DEBUG_MATCHING
806 /* We don't emit any warnings or errors while trying out each candidate. */
810 cp
->function
= function
;
811 cp
->arg
= tta
? TREE_VALUE (tta
) : NULL_TREE
;
812 cp
->u
.bad_arg
= 0; /* optimistic! */
816 cp
->h
.int_penalty
= 0;
817 bzero ((char *) cp
->harshness
,
818 (cp
->h_len
+ 1) * sizeof (struct harshness_code
));
822 struct harshness_code h
;
824 if (ttf
== void_list_node
)
827 if (type_unknown_p (TREE_VALUE (tta
)))
829 /* Must perform some instantiation here. */
830 tree rhs
= TREE_VALUE (tta
);
831 tree lhstype
= TREE_VALUE (ttf
);
833 /* Keep quiet about possible contravariance violations. */
834 int old_inhibit_warnings
= inhibit_warnings
;
835 inhibit_warnings
= 1;
837 /* @@ This is to undo what `grokdeclarator' does to
838 parameter types. It really should go through
839 something more general. */
841 TREE_TYPE (tta
) = unknown_type_node
;
842 rhs
= instantiate_type (lhstype
, rhs
, 0);
843 inhibit_warnings
= old_inhibit_warnings
;
845 if (TREE_CODE (rhs
) == ERROR_MARK
)
848 h
= convert_harshness (lhstype
, TREE_TYPE (rhs
), rhs
);
852 #ifdef DEBUG_MATCHING
853 static tree old_function
= NULL_TREE
;
855 if (!old_function
|| function
!= old_function
)
857 cp_error ("trying %D", function
);
858 old_function
= function
;
861 cp_error (" doing (%T) %E against arg %T",
862 TREE_TYPE (TREE_VALUE (tta
)), TREE_VALUE (tta
),
866 h
= convert_harshness (TREE_VALUE (ttf
),
867 TREE_TYPE (TREE_VALUE (tta
)),
870 #ifdef DEBUG_MATCHING
871 cp_error (" evaluated %s", print_harshness (&h
));
875 cp
->harshness
[strike_index
] = h
;
876 if ((h
.code
& EVIL_CODE
)
877 || ((h
.code
& STD_CODE
) && h
.distance
< 0))
879 cp
->u
.bad_arg
= strike_index
;
882 else if (h
.code
& ELLIPSIS_CODE
)
883 ellipsis_strikes
+= 1;
885 /* This is never set by `convert_harshness'. */
886 else if (h
.code
& USER_CODE
)
893 if ((h
.code
& STD_CODE
) && h
.distance
)
895 if (h
.distance
> b_or_d_strikes
)
896 b_or_d_strikes
= h
.distance
;
899 easy_strikes
+= (h
.code
& (STD_CODE
|PROMO_CODE
|TRIVIAL_CODE
));
900 cp
->h
.code
|= h
.code
;
901 /* Make sure we communicate this. */
902 cp
->h
.int_penalty
+= h
.int_penalty
;
905 ttf
= TREE_CHAIN (ttf
);
906 tta
= TREE_CHAIN (tta
);
912 /* ran out of formals, and parmlist is fixed size. */
913 if (ttf
/* == void_type_node */)
915 cp
->h
.code
= EVIL_CODE
;
922 struct harshness_code h
;
923 int l
= list_length (tta
);
924 ellipsis_strikes
+= l
;
925 h
.code
= ELLIPSIS_CODE
;
929 cp
->harshness
[strike_index
++] = h
;
932 else if (ttf
&& ttf
!= void_list_node
)
934 /* ran out of actuals, and no defaults. */
935 if (TREE_PURPOSE (ttf
) == NULL_TREE
)
937 cp
->h
.code
= EVIL_CODE
;
942 /* Store index of first default. */
943 cp
->harshness
[arglen
].distance
= strike_index
+1;
946 cp
->harshness
[arglen
].distance
= 0;
948 /* Argument list lengths work out, so don't need to check them again. */
951 /* We do not check for derived->base conversions here, since in
952 no case would they give evil strike counts, unless such conversions
953 are somehow ambiguous. */
955 /* See if any user-defined conversions apply.
956 But make sure that we do not loop. */
957 static int dont_convert_types
= 0;
959 if (dont_convert_types
)
961 cp
->h
.code
= EVIL_CODE
;
966 win
= 0; /* Only get one chance to win. */
967 ttf
= TYPE_ARG_TYPES (TREE_TYPE (function
));
974 if (ttf
== void_list_node
)
977 lose
= cp
->harshness
[strike_index
];
978 if ((lose
.code
& EVIL_CODE
)
979 || ((lose
.code
& STD_CODE
) && lose
.distance
< 0))
981 tree actual_type
= TREE_TYPE (TREE_VALUE (tta
));
982 tree formal_type
= TREE_VALUE (ttf
);
983 int extra_conversions
= 0;
985 dont_convert_types
= 1;
987 if (TREE_CODE (formal_type
) == REFERENCE_TYPE
)
988 formal_type
= TREE_TYPE (formal_type
);
989 if (TREE_CODE (actual_type
) == REFERENCE_TYPE
)
990 actual_type
= TREE_TYPE (actual_type
);
992 if (formal_type
!= error_mark_node
993 && actual_type
!= error_mark_node
)
995 formal_type
= complete_type (TYPE_MAIN_VARIANT (formal_type
));
996 actual_type
= complete_type (TYPE_MAIN_VARIANT (actual_type
));
998 if (TYPE_HAS_CONSTRUCTOR (formal_type
))
1000 /* If it has a constructor for this type,
1002 /* @@ There is no way to save this result yet, so
1003 success is a NULL_TREE for now. */
1004 if (convert_to_aggr (formal_type
, TREE_VALUE (tta
), 0, 1)
1008 if (TYPE_LANG_SPECIFIC (actual_type
)
1009 && TYPE_HAS_CONVERSION (actual_type
))
1011 int extra
= user_harshness (formal_type
, actual_type
);
1013 if (extra
== EVIL_CODE
)
1015 else if (extra
>= 0)
1018 extra_conversions
= extra
;
1022 dont_convert_types
= 0;
1027 cp
->harshness
[strike_index
].code
1028 = USER_CODE
| (extra_conversions
? STD_CODE
: 0);
1033 if (cp
->u
.bad_arg
> strike_index
)
1034 cp
->u
.bad_arg
= strike_index
;
1036 evil_strikes
= win
? 2 : 1;
1041 ttf
= TREE_CHAIN (ttf
);
1042 tta
= TREE_CHAIN (tta
);
1047 /* Const member functions get a small penalty because defaulting
1048 to const is less useful than defaulting to non-const. */
1049 /* This is bogus, it does not correspond to anything in the ARM.
1050 This code will be fixed when this entire section is rewritten
1051 to conform to the ARM. (mrs) */
1052 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1054 tree this_parm
= TREE_VALUE (ttf_in
);
1056 if (TREE_CODE (this_parm
) == RECORD_TYPE
/* Is `this' a sig ptr? */
1057 ? TYPE_READONLY (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (this_parm
))))
1058 : TYPE_READONLY (TREE_TYPE (this_parm
)))
1060 cp
->harshness
[0].code
|= TRIVIAL_CODE
;
1065 /* Calling a non-const member function from a const member function
1066 is probably invalid, but for now we let it only draw a warning.
1067 We indicate that such a mismatch has occurred by setting the
1068 harshness to a maximum value. */
1069 if (TREE_CODE (TREE_TYPE (TREE_VALUE (tta_in
))) == POINTER_TYPE
1070 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (TREE_VALUE (tta_in
))))))
1071 cp
->harshness
[0].code
|= CONST_CODE
;
1076 cp
->h
.code
= EVIL_CODE
;
1077 if (ellipsis_strikes
)
1078 cp
->h
.code
|= ELLIPSIS_CODE
;
1080 cp
->h
.code
|= USER_CODE
;
1082 #ifdef DEBUG_MATCHING
1083 cp_error ("final eval %s", print_harshness (&cp
->h
));
1087 /* Subroutine of ideal_candidate. See if X or Y is a better match
1091 strictly_better (x
, y
)
1100 if (xor >= x
|| xor >= y
)
1105 /* When one of several possible overloaded functions and/or methods
1106 can be called, choose the best candidate for overloading.
1108 BASETYPE is the context from which we start method resolution
1109 or NULL if we are comparing overloaded functions.
1110 CANDIDATES is the array of candidates we have to choose from.
1111 N_CANDIDATES is the length of CANDIDATES.
1112 PARMS is a TREE_LIST of parameters to the function we'll ultimately
1113 choose. It is modified in place when resolving methods. It is not
1114 modified in place when resolving overloaded functions.
1115 LEN is the length of the parameter list. */
1117 static struct candidate
*
1118 ideal_candidate (candidates
, n_candidates
, len
)
1119 struct candidate
*candidates
;
1123 struct candidate
*cp
= candidates
+n_candidates
;
1124 int i
, j
= -1, best_code
;
1126 /* For each argument, sort the functions from best to worst for the arg.
1127 For each function that's not best for this arg, set its overall
1128 harshness to EVIL so that other args won't like it. The candidate
1129 list for the last argument is the intersection of all the best-liked
1132 qsort (candidates
, n_candidates
, sizeof (struct candidate
),
1133 (int (*) PROTO((const void *, const void *))) rank_for_overload
);
1134 best_code
= cp
[-1].h
.code
;
1136 /* If they're at least as good as each other, do an arg-by-arg check. */
1137 if (! strictly_better (cp
[-1].h
.code
, cp
[-2].h
.code
))
1142 for (j
= 0; j
< n_candidates
; j
++)
1143 if (! strictly_better (candidates
[j
].h
.code
, best_code
))
1146 qsort (candidates
+j
, n_candidates
-j
, sizeof (struct candidate
),
1147 (int (*) PROTO((const void *, const void *))) rank_for_ideal
);
1148 for (i
= 0; i
< len
; i
++)
1150 if (cp
[-1].harshness
[i
].code
< cp
[-2].harshness
[i
].code
)
1152 else if (cp
[-1].harshness
[i
].code
> cp
[-2].harshness
[i
].code
)
1154 else if (cp
[-1].harshness
[i
].code
& STD_CODE
)
1156 /* If it involves a standard conversion, let the
1157 inheritance lattice be the final arbiter. */
1158 if (cp
[-1].harshness
[i
].distance
> cp
[-2].harshness
[i
].distance
)
1160 else if (cp
[-1].harshness
[i
].distance
< cp
[-2].harshness
[i
].distance
)
1163 else if (cp
[-1].harshness
[i
].code
& PROMO_CODE
)
1165 /* For integral promotions, take into account a finer
1166 granularity for determining which types should be favored
1167 over others in such promotions. */
1168 if (cp
[-1].harshness
[i
].int_penalty
> cp
[-2].harshness
[i
].int_penalty
)
1170 else if (cp
[-1].harshness
[i
].int_penalty
< cp
[-2].harshness
[i
].int_penalty
)
1175 if (! better
|| worse
)
1181 /* Assume that if the class referred to is not in the
1182 current class hierarchy, that it may be remote.
1183 PARENT is assumed to be of aggregate type here. */
1186 may_be_remote (parent
)
1189 if (TYPE_OVERLOADS_METHOD_CALL_EXPR (parent
) == 0)
1192 if (current_class_type
== NULL_TREE
)
1195 if (parent
== current_class_type
)
1198 if (UNIQUELY_DERIVED_FROM_P (parent
, current_class_type
))
1204 build_vfield_ref (datum
, type
)
1208 int old_assume_nonnull_objects
= flag_assume_nonnull_objects
;
1210 if (datum
== error_mark_node
)
1211 return error_mark_node
;
1213 /* Vtable references are always made from non-null objects. */
1214 flag_assume_nonnull_objects
= 1;
1215 if (TREE_CODE (TREE_TYPE (datum
)) == REFERENCE_TYPE
)
1216 datum
= convert_from_reference (datum
);
1218 if (! TYPE_USES_COMPLEX_INHERITANCE (type
))
1219 rval
= build (COMPONENT_REF
, TREE_TYPE (CLASSTYPE_VFIELD (type
)),
1220 datum
, CLASSTYPE_VFIELD (type
));
1222 rval
= build_component_ref (datum
, DECL_NAME (CLASSTYPE_VFIELD (type
)), NULL_TREE
, 0);
1223 flag_assume_nonnull_objects
= old_assume_nonnull_objects
;
1228 /* Build a call to a member of an object. I.e., one that overloads
1229 operator ()(), or is a pointer-to-function or pointer-to-method. */
1232 build_field_call (basetype_path
, instance_ptr
, name
, parms
)
1233 tree basetype_path
, instance_ptr
, name
, parms
;
1235 tree field
, instance
;
1237 if (name
== ctor_identifier
|| name
== dtor_identifier
)
1240 if (instance_ptr
== current_class_ptr
)
1242 /* Check to see if we really have a reference to an instance variable
1243 with `operator()()' overloaded. */
1244 field
= IDENTIFIER_CLASS_VALUE (name
);
1246 if (field
== NULL_TREE
)
1248 cp_error ("`this' has no member named `%D'", name
);
1249 return error_mark_node
;
1252 if (TREE_CODE (field
) == FIELD_DECL
)
1254 /* If it's a field, try overloading operator (),
1255 or calling if the field is a pointer-to-function. */
1256 instance
= build_component_ref_1 (current_class_ref
, field
, 0);
1257 if (instance
== error_mark_node
)
1258 return error_mark_node
;
1260 if (TYPE_LANG_SPECIFIC (TREE_TYPE (instance
))
1261 && (TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (instance
))
1262 || flag_ansi_overloading
))
1263 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, instance
, parms
, NULL_TREE
);
1265 if (TREE_CODE (TREE_TYPE (instance
)) == POINTER_TYPE
)
1267 if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == FUNCTION_TYPE
)
1268 return build_function_call (instance
, parms
);
1269 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == METHOD_TYPE
)
1270 return build_function_call (instance
, expr_tree_cons (NULL_TREE
, current_class_ptr
, parms
));
1276 /* Check to see if this is not really a reference to an instance variable
1277 with `operator()()' overloaded. */
1278 field
= lookup_field (basetype_path
, name
, 1, 0);
1280 /* This can happen if the reference was ambiguous or for access
1282 if (field
== error_mark_node
)
1283 return error_mark_node
;
1288 tree ftype
= TREE_TYPE (field
);
1290 if (TREE_CODE (ftype
) == REFERENCE_TYPE
)
1291 ftype
= TREE_TYPE (ftype
);
1293 if (TYPE_LANG_SPECIFIC (ftype
)
1294 && (TYPE_OVERLOADS_CALL_EXPR (ftype
) || flag_ansi_overloading
))
1296 /* Make the next search for this field very short. */
1297 basetype
= DECL_FIELD_CONTEXT (field
);
1298 instance_ptr
= convert_pointer_to (basetype
, instance_ptr
);
1300 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
1301 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
,
1302 build_component_ref_1 (instance
, field
, 0),
1305 if (TREE_CODE (ftype
) == POINTER_TYPE
)
1307 if (TREE_CODE (TREE_TYPE (ftype
)) == FUNCTION_TYPE
1308 || TREE_CODE (TREE_TYPE (ftype
)) == METHOD_TYPE
)
1310 /* This is a member which is a pointer to function. */
1312 = build_component_ref_1 (build_indirect_ref (instance_ptr
,
1314 field
, LOOKUP_COMPLAIN
);
1315 if (ref
== error_mark_node
)
1316 return error_mark_node
;
1317 return build_function_call (ref
, parms
);
1320 else if (TREE_CODE (ftype
) == METHOD_TYPE
)
1322 error ("invalid call via pointer-to-member function");
1323 return error_mark_node
;
1332 find_scoped_type (type
, inner_name
, inner_types
)
1333 tree type
, inner_name
, inner_types
;
1335 tree tags
= CLASSTYPE_TAGS (type
);
1339 /* The TREE_PURPOSE of an enum tag (which becomes a member of the
1340 enclosing class) is set to the name for the enum type. So, if
1341 inner_name is `bar', and we strike `baz' for `enum bar { baz }',
1342 then this test will be true. */
1343 if (TREE_PURPOSE (tags
) == inner_name
)
1345 if (inner_types
== NULL_TREE
)
1346 return TYPE_MAIN_DECL (TREE_VALUE (tags
));
1347 return resolve_scope_to_name (TREE_VALUE (tags
), inner_types
);
1349 tags
= TREE_CHAIN (tags
);
1352 /* Look for a TYPE_DECL. */
1353 for (tags
= TYPE_FIELDS (type
); tags
; tags
= TREE_CHAIN (tags
))
1354 if (TREE_CODE (tags
) == TYPE_DECL
&& DECL_NAME (tags
) == inner_name
)
1356 /* Code by raeburn. */
1357 if (inner_types
== NULL_TREE
)
1359 return resolve_scope_to_name (TREE_TYPE (tags
), inner_types
);
1365 /* Resolve an expression NAME1::NAME2::...::NAMEn to
1366 the name that names the above nested type. INNER_TYPES
1367 is a chain of nested type names (held together by SCOPE_REFs);
1368 OUTER_TYPE is the type we know to enclose INNER_TYPES.
1369 Returns NULL_TREE if there is an error. */
1372 resolve_scope_to_name (outer_type
, inner_stuff
)
1373 tree outer_type
, inner_stuff
;
1376 tree inner_name
, inner_type
;
1378 if (outer_type
== NULL_TREE
&& current_class_type
!= NULL_TREE
)
1380 /* We first try to look for a nesting in our current class context,
1381 then try any enclosing classes. */
1382 tree type
= current_class_type
;
1384 while (type
&& (TREE_CODE (type
) == RECORD_TYPE
1385 || TREE_CODE (type
) == UNION_TYPE
))
1387 tree rval
= resolve_scope_to_name (type
, inner_stuff
);
1389 if (rval
!= NULL_TREE
)
1391 type
= DECL_CONTEXT (TYPE_MAIN_DECL (type
));
1395 if (TREE_CODE (inner_stuff
) == SCOPE_REF
)
1397 inner_name
= TREE_OPERAND (inner_stuff
, 0);
1398 inner_type
= TREE_OPERAND (inner_stuff
, 1);
1402 inner_name
= inner_stuff
;
1403 inner_type
= NULL_TREE
;
1406 if (outer_type
== NULL_TREE
)
1409 /* If we have something that's already a type by itself,
1411 if (IDENTIFIER_HAS_TYPE_VALUE (inner_name
))
1414 return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name
),
1419 x
= lookup_name (inner_name
, 0);
1421 if (x
&& TREE_CODE (x
) == NAMESPACE_DECL
)
1423 x
= lookup_namespace_name (x
, inner_type
);
1429 if (! IS_AGGR_TYPE (outer_type
))
1432 /* Look for member classes or enums. */
1433 tmp
= find_scoped_type (outer_type
, inner_name
, inner_type
);
1435 /* If it's not a type in this class, then go down into the
1436 base classes and search there. */
1437 if (! tmp
&& TYPE_BINFO (outer_type
))
1439 tree binfos
= TYPE_BINFO_BASETYPES (outer_type
);
1440 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1442 for (i
= 0; i
< n_baselinks
; i
++)
1444 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1445 tmp
= resolve_scope_to_name (BINFO_TYPE (base_binfo
), inner_stuff
);
1455 /* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'.
1456 This is how virtual function calls are avoided. */
1459 build_scoped_method_call (exp
, basetype
, name
, parms
)
1460 tree exp
, basetype
, name
, parms
;
1462 /* Because this syntactic form does not allow
1463 a pointer to a base class to be `stolen',
1464 we need not protect the derived->base conversion
1467 @@ But we do have to check access privileges later. */
1469 tree type
= TREE_TYPE (exp
);
1471 if (type
== error_mark_node
1472 || basetype
== error_mark_node
)
1473 return error_mark_node
;
1475 if (processing_template_decl
)
1477 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1479 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 1);
1480 name
= build_min_nt (BIT_NOT_EXPR
, type
);
1482 name
= build_min_nt (SCOPE_REF
, basetype
, name
);
1483 return build_min_nt (METHOD_CALL_EXPR
, name
, exp
, parms
, NULL_TREE
);
1486 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1487 type
= TREE_TYPE (type
);
1489 if (TREE_CODE (basetype
) == TREE_VEC
)
1492 basetype
= BINFO_TYPE (binfo
);
1497 /* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
1498 that explicit ~int is caught in the parser; this deals with typedefs
1499 and template parms. */
1500 if (TREE_CODE (name
) == BIT_NOT_EXPR
&& ! IS_AGGR_TYPE (basetype
))
1502 if (type
!= basetype
)
1503 cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
1504 exp
, basetype
, type
);
1505 name
= TREE_OPERAND (name
, 0);
1506 if (basetype
!= name
&& basetype
!= get_type_value (name
))
1507 cp_error ("qualified type `%T' does not match destructor name `~%T'",
1509 return cp_convert (void_type_node
, exp
);
1512 if (! is_aggr_type (basetype
, 1))
1513 return error_mark_node
;
1515 if (! IS_AGGR_TYPE (type
))
1517 cp_error ("base object `%E' of scoped method call is of non-aggregate type `%T'",
1519 return error_mark_node
;
1524 binfo
= get_binfo (basetype
, type
, 1);
1525 if (binfo
== error_mark_node
)
1526 return error_mark_node
;
1528 error_not_base_type (basetype
, type
);
1533 if (TREE_CODE (exp
) == INDIRECT_REF
)
1534 decl
= build_indirect_ref
1535 (convert_pointer_to_real
1536 (binfo
, build_unary_op (ADDR_EXPR
, exp
, 0)), NULL_PTR
);
1538 decl
= build_scoped_ref (exp
, basetype
);
1540 /* Call to a destructor. */
1541 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1543 /* Explicit call to destructor. */
1544 name
= TREE_OPERAND (name
, 0);
1545 if (! (name
== TYPE_MAIN_VARIANT (TREE_TYPE (decl
))
1546 || name
== constructor_name (TREE_TYPE (decl
))
1547 || TREE_TYPE (decl
) == get_type_value (name
)))
1550 ("qualified type `%T' does not match destructor name `~%T'",
1551 TREE_TYPE (decl
), name
);
1552 return error_mark_node
;
1554 if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl
)))
1555 return cp_convert (void_type_node
, exp
);
1557 return build_delete (TREE_TYPE (decl
), decl
, integer_two_node
,
1558 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
,
1562 /* Call to a method. */
1563 return build_method_call (decl
, name
, parms
, binfo
,
1564 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
);
1566 return error_mark_node
;
1570 print_candidates (candidates
)
1573 cp_error_at ("candidates are: %D", TREE_VALUE (candidates
));
1574 candidates
= TREE_CHAIN (candidates
);
1578 cp_error_at (" %D", TREE_VALUE (candidates
));
1579 candidates
= TREE_CHAIN (candidates
);
1584 print_n_candidates (candidates
, n
)
1585 struct candidate
*candidates
;
1590 cp_error_at ("candidates are: %D", candidates
[0].function
);
1591 for (i
= 1; i
< n
; i
++)
1592 cp_error_at (" %D", candidates
[i
].function
);
1595 /* We want the address of a function or method. We avoid creating a
1596 pointer-to-member function. */
1599 build_addr_func (function
)
1602 tree type
= TREE_TYPE (function
);
1604 /* We have to do these by hand to avoid real pointer to member
1606 if (TREE_CODE (type
) == METHOD_TYPE
)
1610 type
= build_pointer_type (type
);
1612 if (mark_addressable (function
) == 0)
1613 return error_mark_node
;
1615 addr
= build1 (ADDR_EXPR
, type
, function
);
1617 /* Address of a static or external variable or function counts
1619 if (staticp (function
))
1620 TREE_CONSTANT (addr
) = 1;
1625 function
= default_conversion (function
);
1630 /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
1631 POINTER_TYPE to those. Note, pointer to member function types
1632 (TYPE_PTRMEMFUNC_P) must be handled by our callers. */
1635 build_call (function
, result_type
, parms
)
1636 tree function
, result_type
, parms
;
1638 int is_constructor
= 0;
1640 function
= build_addr_func (function
);
1642 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
1644 sorry ("unable to call pointer to member function here");
1645 return error_mark_node
;
1648 if (TREE_CODE (function
) == ADDR_EXPR
1649 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
1650 && DECL_CONSTRUCTOR_P (TREE_OPERAND (function
, 0)))
1653 function
= build_nt (CALL_EXPR
, function
, parms
, NULL_TREE
);
1654 TREE_HAS_CONSTRUCTOR (function
) = is_constructor
;
1655 TREE_TYPE (function
) = result_type
;
1656 TREE_SIDE_EFFECTS (function
) = 1;
1662 default_parm_conversions (parms
, last
)
1665 tree parm
, parmtypes
= NULL_TREE
;
1669 for (parm
= parms
; parm
; parm
= TREE_CHAIN (parm
))
1671 tree t
= TREE_TYPE (TREE_VALUE (parm
));
1673 if (TREE_CODE (t
) == OFFSET_TYPE
1674 || TREE_CODE (t
) == METHOD_TYPE
1675 || TREE_CODE (t
) == FUNCTION_TYPE
)
1677 TREE_VALUE (parm
) = default_conversion (TREE_VALUE (parm
));
1678 t
= TREE_TYPE (TREE_VALUE (parm
));
1681 if (t
== error_mark_node
)
1682 return error_mark_node
;
1684 *last
= build_tree_list (NULL_TREE
, t
);
1685 parmtypes
= chainon (parmtypes
, *last
);
1692 /* Build something of the form ptr->method (args)
1693 or object.method (args). This can also build
1694 calls to constructors, and find friends.
1696 Member functions always take their class variable
1699 INSTANCE is a class instance.
1701 NAME is the name of the method desired, usually an IDENTIFIER_NODE.
1703 PARMS help to figure out what that NAME really refers to.
1705 BASETYPE_PATH, if non-NULL, contains a chain from the type of INSTANCE
1706 down to the real instance type to use for access checking. We need this
1707 information to get protected accesses correct. This parameter is used
1708 by build_member_call.
1710 FLAGS is the logical disjunction of zero or more LOOKUP_
1711 flags. See cp-tree.h for more info.
1713 If this is all OK, calls build_function_call with the resolved
1716 This function must also handle being called to perform
1717 initialization, promotion/coercion of arguments, and
1718 instantiation of default parameters.
1720 Note that NAME may refer to an instance variable name. If
1721 `operator()()' is defined for the type of that field, then we return
1725 build_method_call (instance
, name
, parms
, basetype_path
, flags
)
1726 tree instance
, name
, parms
, basetype_path
;
1729 register tree function
, fntype
, value_type
;
1730 register tree basetype
, save_basetype
;
1731 register tree baselink
, result
, parmtypes
;
1734 tree access
= access_public_node
;
1735 tree orig_basetype
= basetype_path
? BINFO_TYPE (basetype_path
) : NULL_TREE
;
1737 /* Range of cases for vtable optimization. */
1738 enum vtable_needs
{ not_needed
, maybe_needed
, unneeded
, needed
};
1739 enum vtable_needs need_vtbl
= not_needed
;
1742 tree save_name
= name
;
1744 tree instance_ptr
= NULL_TREE
;
1745 int all_virtual
= flag_all_virtual
;
1746 int static_call_context
= 0;
1747 tree found_fns
= NULL_TREE
;
1749 /* Keep track of `const' and `volatile' objects. */
1750 int constp
, volatilep
;
1752 #ifdef GATHER_STATISTICS
1753 n_build_method_call
++;
1756 if (instance
== error_mark_node
1757 || name
== error_mark_node
1758 || parms
== error_mark_node
1759 || (instance
!= NULL_TREE
&& TREE_TYPE (instance
) == error_mark_node
))
1760 return error_mark_node
;
1762 if (processing_template_decl
)
1764 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1766 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 1);
1767 name
= build_min_nt (BIT_NOT_EXPR
, type
);
1770 return build_min_nt (METHOD_CALL_EXPR
, name
, instance
, parms
, NULL_TREE
);
1773 /* This is the logic that magically deletes the second argument to
1774 operator delete, if it is not needed. */
1775 if (name
== ansi_opname
[(int) DELETE_EXPR
] && list_length (parms
)==2)
1777 tree save_last
= TREE_CHAIN (parms
);
1779 /* get rid of unneeded argument */
1780 TREE_CHAIN (parms
) = NULL_TREE
;
1781 result
= build_method_call (instance
, name
, parms
, basetype_path
,
1782 (LOOKUP_SPECULATIVELY
|flags
)
1784 /* If it finds a match, return it. */
1786 return build_method_call (instance
, name
, parms
, basetype_path
, flags
);
1787 /* If it doesn't work, two argument delete must work */
1788 TREE_CHAIN (parms
) = save_last
;
1790 /* We already know whether it's needed or not for vec delete. */
1791 else if (name
== ansi_opname
[(int) VEC_DELETE_EXPR
]
1792 && TYPE_LANG_SPECIFIC (TREE_TYPE (instance
))
1793 && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance
)))
1794 TREE_CHAIN (parms
) = NULL_TREE
;
1796 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1798 flags
|= LOOKUP_DESTRUCTOR
;
1799 name
= TREE_OPERAND (name
, 0);
1801 error ("destructors take no parameters");
1802 basetype
= TREE_TYPE (instance
);
1803 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
1804 basetype
= TREE_TYPE (basetype
);
1805 if (! (name
== basetype
1806 || (IS_AGGR_TYPE (basetype
)
1807 && name
== constructor_name (basetype
))
1808 || basetype
== get_type_value (name
)))
1810 cp_error ("destructor name `~%D' does not match type `%T' of expression",
1812 return cp_convert (void_type_node
, instance
);
1815 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1816 return cp_convert (void_type_node
, instance
);
1817 instance
= default_conversion (instance
);
1818 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
1819 return build_delete (build_pointer_type (basetype
),
1820 instance_ptr
, integer_two_node
,
1821 LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
, 0);
1824 if (flag_ansi_overloading
)
1825 return build_new_method_call (instance
, name
, parms
, basetype_path
, flags
);
1830 /* Initialize name for error reporting. */
1831 if (IDENTIFIER_OPNAME_P (name
) && ! IDENTIFIER_TYPENAME_P (name
))
1833 char *p
= operator_name_string (name
);
1834 xref_name
= (char *)alloca (strlen (p
) + 10);
1835 sprintf (xref_name
, "operator %s", p
);
1837 else if (TREE_CODE (name
) == SCOPE_REF
)
1838 xref_name
= IDENTIFIER_POINTER (TREE_OPERAND (name
, 1));
1840 xref_name
= IDENTIFIER_POINTER (name
);
1842 GNU_xref_call (current_function_decl
, xref_name
);
1845 if (instance
== NULL_TREE
)
1847 basetype
= NULL_TREE
;
1848 /* Check cases where this is really a call to raise
1850 if (current_class_type
&& TREE_CODE (name
) == IDENTIFIER_NODE
)
1852 basetype
= purpose_member (name
, CLASSTYPE_TAGS (current_class_type
));
1854 basetype
= TREE_VALUE (basetype
);
1856 else if (TREE_CODE (name
) == SCOPE_REF
1857 && TREE_CODE (TREE_OPERAND (name
, 0)) == IDENTIFIER_NODE
)
1859 if (! is_aggr_typedef (TREE_OPERAND (name
, 0), 1))
1860 return error_mark_node
;
1861 basetype
= purpose_member (TREE_OPERAND (name
, 1),
1862 CLASSTYPE_TAGS (IDENTIFIER_TYPE_VALUE (TREE_OPERAND (name
, 0))));
1864 basetype
= TREE_VALUE (basetype
);
1867 if (basetype
!= NULL_TREE
)
1869 /* call to a constructor... */
1870 else if (basetype_path
)
1872 basetype
= BINFO_TYPE (basetype_path
);
1873 if (name
== TYPE_IDENTIFIER (basetype
))
1874 name
= ctor_identifier
;
1876 else if (IDENTIFIER_HAS_TYPE_VALUE (name
))
1878 basetype
= IDENTIFIER_TYPE_VALUE (name
);
1879 name
= ctor_identifier
;
1883 tree typedef_name
= lookup_name (name
, 1);
1884 if (typedef_name
&& TREE_CODE (typedef_name
) == TYPE_DECL
)
1886 /* Canonicalize the typedef name. */
1887 basetype
= TREE_TYPE (typedef_name
);
1888 name
= ctor_identifier
;
1892 cp_error ("no constructor named `%T' in scope",
1894 return error_mark_node
;
1898 if (! IS_AGGR_TYPE (basetype
))
1901 if ((flags
& LOOKUP_COMPLAIN
) && basetype
!= error_mark_node
)
1902 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1903 name
, instance
, basetype
);
1905 return error_mark_node
;
1908 else if (instance
== current_class_ref
|| instance
== current_class_ptr
)
1910 /* When doing initialization, we side-effect the TREE_TYPE of
1911 current_class_ref, hence we cannot set up BASETYPE from CURRENT_CLASS_TYPE. */
1912 basetype
= TREE_TYPE (current_class_ref
);
1914 /* Anything manifestly `this' in constructors and destructors
1915 has a known type, so virtual function tables are not needed. */
1916 if (TYPE_VIRTUAL_P (basetype
)
1917 && !(flags
& LOOKUP_NONVIRTUAL
))
1918 need_vtbl
= (dtor_label
|| ctor_label
)
1919 ? unneeded
: maybe_needed
;
1921 /* If `this' is a signature pointer and `name' is not a constructor,
1922 we are calling a signature member function. In that case, set the
1923 `basetype' to the signature type and dereference the `optr' field. */
1924 if (IS_SIGNATURE_POINTER (basetype
)
1925 && TYPE_IDENTIFIER (basetype
) != name
)
1927 basetype
= SIGNATURE_TYPE (basetype
);
1928 instance_ptr
= instance
;
1929 basetype_path
= TYPE_BINFO (basetype
);
1933 instance
= current_class_ref
;
1934 instance_ptr
= current_class_ptr
;
1935 basetype_path
= TYPE_BINFO (current_class_type
);
1937 result
= build_field_call (basetype_path
, instance_ptr
, name
, parms
);
1942 else if (TREE_CODE (instance
) == RESULT_DECL
)
1944 basetype
= TREE_TYPE (instance
);
1945 /* Should we ever have to make a virtual function reference
1946 from a RESULT_DECL, know that it must be of fixed type
1947 within the scope of this function. */
1948 if (!(flags
& LOOKUP_NONVIRTUAL
) && TYPE_VIRTUAL_P (basetype
))
1949 need_vtbl
= maybe_needed
;
1950 instance_ptr
= build1 (ADDR_EXPR
, build_pointer_type (basetype
), instance
);
1954 /* The MAIN_VARIANT of the type that `instance_ptr' winds up being. */
1955 tree inst_ptr_basetype
;
1958 = (TREE_CODE (instance
) == INDIRECT_REF
1959 && TREE_CODE (TREE_OPERAND (instance
, 0)) == NOP_EXPR
1960 && TREE_OPERAND (TREE_OPERAND (instance
, 0), 0) == error_mark_node
);
1962 if (TREE_CODE (instance
) == OFFSET_REF
)
1963 instance
= resolve_offset_ref (instance
);
1965 /* the base type of an instance variable is pointer to class */
1966 basetype
= TREE_TYPE (instance
);
1968 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
1970 basetype
= TREE_TYPE (basetype
);
1971 if (! IS_AGGR_TYPE (basetype
))
1972 goto non_aggr_error
;
1973 /* Call to convert not needed because we are remaining
1974 within the same type. */
1975 instance_ptr
= build1 (NOP_EXPR
, build_pointer_type (basetype
),
1977 inst_ptr_basetype
= TYPE_MAIN_VARIANT (basetype
);
1981 if (! IS_AGGR_TYPE (basetype
)
1982 && ! (TYPE_LANG_SPECIFIC (basetype
)
1983 && (IS_SIGNATURE_POINTER (basetype
)
1984 || IS_SIGNATURE_REFERENCE (basetype
))))
1985 goto non_aggr_error
;
1987 /* If `instance' is a signature pointer/reference and `name' is
1988 not a constructor, we are calling a signature member function.
1989 In that case set the `basetype' to the signature type. */
1990 if ((IS_SIGNATURE_POINTER (basetype
)
1991 || IS_SIGNATURE_REFERENCE (basetype
))
1992 && TYPE_IDENTIFIER (basetype
) != name
)
1993 basetype
= SIGNATURE_TYPE (basetype
);
1995 basetype
= complete_type (basetype
);
1997 if ((IS_SIGNATURE (basetype
)
1998 && (instance_ptr
= instance
))
1999 || (lvalue_p (instance
)
2000 && (instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0)))
2001 || (instance_ptr
= unary_complex_lvalue (ADDR_EXPR
, instance
)))
2003 if (instance_ptr
== error_mark_node
)
2004 return error_mark_node
;
2006 else if (TREE_CODE (instance
) == NOP_EXPR
2007 || TREE_CODE (instance
) == CONSTRUCTOR
)
2009 /* A cast is not an lvalue. Initialize a fresh temp
2010 with the value we are casting from, and proceed with
2011 that temporary. We can't cast to a reference type,
2012 so that simplifies the initialization to something
2014 tree temp
= get_temp_name (TREE_TYPE (instance
), 0);
2015 if (IS_AGGR_TYPE (TREE_TYPE (instance
)))
2016 expand_aggr_init (temp
, instance
, 0, flags
);
2019 store_init_value (temp
, instance
);
2020 expand_decl_init (temp
);
2023 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
2027 if (TREE_CODE (instance
) != CALL_EXPR
)
2028 my_friendly_abort (125);
2029 if (TYPE_NEEDS_CONSTRUCTING (basetype
))
2030 instance
= build_cplus_new (basetype
, instance
);
2033 instance
= get_temp_name (basetype
, 0);
2034 TREE_ADDRESSABLE (instance
) = 1;
2036 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
2038 /* @@ Should we call comp_target_types here? */
2039 if (IS_SIGNATURE (basetype
))
2040 inst_ptr_basetype
= basetype
;
2042 inst_ptr_basetype
= TREE_TYPE (TREE_TYPE (instance_ptr
));
2043 if (TYPE_MAIN_VARIANT (basetype
) == TYPE_MAIN_VARIANT (inst_ptr_basetype
))
2044 basetype
= inst_ptr_basetype
;
2047 instance_ptr
= cp_convert (build_pointer_type (basetype
), instance_ptr
);
2048 if (instance_ptr
== error_mark_node
)
2049 return error_mark_node
;
2053 /* After converting `instance_ptr' above, `inst_ptr_basetype' was
2054 not updated, so we use `basetype' instead. */
2055 if (basetype_path
== NULL_TREE
2056 && IS_SIGNATURE (basetype
))
2057 basetype_path
= TYPE_BINFO (basetype
);
2058 else if (basetype_path
== NULL_TREE
2059 || (BINFO_TYPE (basetype_path
)
2060 != TYPE_MAIN_VARIANT (inst_ptr_basetype
)))
2061 basetype_path
= TYPE_BINFO (inst_ptr_basetype
);
2063 result
= build_field_call (basetype_path
, instance_ptr
, name
, parms
);
2067 if (!(flags
& LOOKUP_NONVIRTUAL
) && TYPE_VIRTUAL_P (basetype
))
2069 if (TREE_SIDE_EFFECTS (instance_ptr
))
2071 /* This action is needed because the instance is needed
2072 for providing the base of the virtual function table.
2073 Without using a SAVE_EXPR, the function we are building
2074 may be called twice, or side effects on the instance
2075 variable (such as a post-increment), may happen twice. */
2076 instance_ptr
= save_expr (instance_ptr
);
2077 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2079 else if (TREE_CODE (TREE_TYPE (instance
)) == POINTER_TYPE
)
2081 /* This happens when called for operator new (). */
2082 instance
= build_indirect_ref (instance
, NULL_PTR
);
2085 need_vtbl
= maybe_needed
;
2089 if (save_name
== ctor_identifier
)
2090 save_name
= TYPE_IDENTIFIER (basetype
);
2092 if (TYPE_SIZE (complete_type (basetype
)) == 0)
2094 /* This is worth complaining about, I think. */
2095 cp_error ("cannot lookup method in incomplete type `%T'", basetype
);
2096 return error_mark_node
;
2099 save_basetype
= TYPE_MAIN_VARIANT (basetype
);
2101 parmtypes
= default_parm_conversions (parms
, &last
);
2102 if (parmtypes
== error_mark_node
)
2104 return error_mark_node
;
2107 if (instance
&& IS_SIGNATURE (basetype
))
2109 /* @@ Should this be the constp/volatilep flags for the optr field
2110 of the signature pointer? */
2111 constp
= TYPE_READONLY (basetype
);
2112 volatilep
= TYPE_VOLATILE (basetype
);
2113 parms
= expr_tree_cons (NULL_TREE
, instance_ptr
, parms
);
2117 /* TREE_READONLY (instance) fails for references. */
2118 constp
= TYPE_READONLY (TREE_TYPE (TREE_TYPE (instance_ptr
)));
2119 volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (instance_ptr
)));
2120 parms
= expr_tree_cons (NULL_TREE
, instance_ptr
, parms
);
2124 /* Raw constructors are always in charge. */
2125 if (TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
2126 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
2128 flags
|= LOOKUP_HAS_IN_CHARGE
;
2129 parms
= expr_tree_cons (NULL_TREE
, integer_one_node
, parms
);
2130 parmtypes
= scratch_tree_cons (NULL_TREE
, integer_type_node
, parmtypes
);
2135 instance_ptr
= build_int_2 (0, 0);
2136 TREE_TYPE (instance_ptr
) = build_pointer_type (basetype
);
2137 parms
= expr_tree_cons (NULL_TREE
, instance_ptr
, parms
);
2140 parmtypes
= scratch_tree_cons (NULL_TREE
, TREE_TYPE (instance_ptr
), parmtypes
);
2142 if (last
== NULL_TREE
)
2145 /* Look up function name in the structure type definition. */
2147 /* FIXME Axe most of this now? */
2148 if ((IDENTIFIER_HAS_TYPE_VALUE (name
)
2149 && ! IDENTIFIER_OPNAME_P (name
)
2150 && IS_AGGR_TYPE (IDENTIFIER_TYPE_VALUE (name
)))
2151 || name
== constructor_name (basetype
)
2152 || name
== ctor_identifier
)
2154 tree tmp
= NULL_TREE
;
2155 if (IDENTIFIER_TYPE_VALUE (name
) == basetype
2156 || name
== constructor_name (basetype
)
2157 || name
== ctor_identifier
)
2158 tmp
= TYPE_BINFO (basetype
);
2160 tmp
= get_binfo (IDENTIFIER_TYPE_VALUE (name
), basetype
, 0);
2162 if (tmp
!= NULL_TREE
)
2164 name_kind
= "constructor";
2166 if (TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
2167 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
2169 /* Constructors called for initialization
2170 only are never in charge. */
2173 flags
|= LOOKUP_HAS_IN_CHARGE
;
2174 tmplist
= expr_tree_cons (NULL_TREE
, integer_zero_node
,
2175 TREE_CHAIN (parms
));
2176 TREE_CHAIN (parms
) = tmplist
;
2177 tmplist
= scratch_tree_cons (NULL_TREE
, integer_type_node
, TREE_CHAIN (parmtypes
));
2178 TREE_CHAIN (parmtypes
) = tmplist
;
2180 basetype
= BINFO_TYPE (tmp
);
2183 name_kind
= "method";
2186 name_kind
= "method";
2188 if (basetype_path
== NULL_TREE
2189 || BINFO_TYPE (basetype_path
) != TYPE_MAIN_VARIANT (basetype
))
2190 basetype_path
= TYPE_BINFO (basetype
);
2191 result
= lookup_fnfields (basetype_path
, name
,
2192 (flags
& LOOKUP_COMPLAIN
));
2193 if (result
== error_mark_node
)
2194 return error_mark_node
;
2196 for (pass
= 0; pass
< 2; pass
++)
2198 struct candidate
*candidates
;
2199 struct candidate
*cp
;
2208 = (struct candidate
*) alloca ((ever_seen
+1)
2209 * sizeof (struct candidate
));
2210 bzero ((char *) candidates
, (ever_seen
+ 1) * sizeof (struct candidate
));
2212 len
= list_length (parms
);
2215 /* First see if a global function has a shot at it. */
2216 if (flags
& LOOKUP_GLOBAL
)
2219 tree parm
= instance_ptr
;
2221 if (TREE_CODE (TREE_TYPE (parm
)) == REFERENCE_TYPE
)
2222 parm
= convert_from_reference (parm
);
2223 else if (TREE_CODE (TREE_TYPE (parm
)) == POINTER_TYPE
)
2224 parm
= build_indirect_ref (parm
, "friendifying parms (compiler error)");
2226 my_friendly_abort (167);
2228 friend_parms
= expr_tree_cons (NULL_TREE
, parm
, TREE_CHAIN (parms
));
2231 cp
->harshness
= (struct harshness_code
*)
2232 alloca ((len
+ 1) * sizeof (struct harshness_code
));
2234 result
= build_overload_call_real (name
, friend_parms
, 0, cp
, 1);
2236 /* If it turns out to be the one we were actually looking for
2237 (it was probably a friend function), the return the
2239 if (TREE_CODE (result
) == CALL_EXPR
)
2242 while ((cp
->h
.code
& EVIL_CODE
) == 0)
2244 /* non-standard uses: set the field to 0 to indicate
2245 we are using a non-member function. */
2247 if (cp
->harshness
[len
].distance
== 0
2248 && cp
->h
.code
< best
)
2257 /* We have a hit (of sorts). If the parameter list is
2258 "error_mark_node", or some variant thereof, it won't
2259 match any methods. Since we have verified that the is
2260 some method vaguely matching this one (in name at least),
2263 Don't stop for friends, however. */
2264 basetype_path
= TREE_PURPOSE (baselink
);
2266 function
= TREE_VALUE (baselink
);
2267 if (TREE_CODE (basetype_path
) == TREE_LIST
)
2268 basetype_path
= TREE_VALUE (basetype_path
);
2269 basetype
= BINFO_TYPE (basetype_path
);
2271 for (; function
; function
= DECL_CHAIN (function
))
2273 #ifdef GATHER_STATISTICS
2274 n_inner_fields_searched
++;
2278 found_fns
= scratch_tree_cons (NULL_TREE
, function
, found_fns
);
2280 /* Not looking for friends here. */
2281 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
2282 && ! DECL_STATIC_FUNCTION_P (function
))
2287 tree these_parms
= parms
;
2289 #ifdef GATHER_STATISTICS
2290 n_inner_fields_searched
++;
2293 cp
->harshness
= (struct harshness_code
*)
2294 alloca ((len
+ 1) * sizeof (struct harshness_code
));
2296 if (DECL_STATIC_FUNCTION_P (function
))
2297 these_parms
= TREE_CHAIN (these_parms
);
2298 compute_conversion_costs (function
, these_parms
, cp
, len
);
2300 if ((cp
->h
.code
& EVIL_CODE
) == 0)
2302 cp
->u
.field
= function
;
2303 cp
->function
= function
;
2304 cp
->basetypes
= basetype_path
;
2306 /* Don't allow non-converting constructors to convert. */
2307 if (flags
& LOOKUP_ONLYCONVERTING
2308 && DECL_LANG_SPECIFIC (function
)
2309 && DECL_NONCONVERTING_P (function
))
2312 /* No "two-level" conversions. */
2313 if (flags
& LOOKUP_NO_CONVERSION
2314 && (cp
->h
.code
& USER_CODE
))
2325 tree igv
= lookup_name_nonclass (name
);
2327 /* No exact match could be found. Now try to find match
2328 using default conversions. */
2329 if ((flags
& LOOKUP_GLOBAL
) && igv
)
2331 if (TREE_CODE (igv
) == FUNCTION_DECL
)
2333 else if (TREE_CODE (igv
) == TREE_LIST
)
2334 ever_seen
+= count_functions (igv
);
2339 if ((flags
& (LOOKUP_SPECULATIVELY
|LOOKUP_COMPLAIN
))
2340 == LOOKUP_SPECULATIVELY
)
2343 TREE_CHAIN (last
) = void_list_node
;
2344 if (flags
& LOOKUP_GLOBAL
)
2345 cp_error ("no global or member function `%D(%A)' defined",
2346 save_name
, parmtypes
);
2348 cp_error ("no member function `%T::%D(%A)' defined",
2349 save_basetype
, save_name
, TREE_CHAIN (parmtypes
));
2350 return error_mark_node
;
2355 if (cp
- candidates
!= 0)
2357 /* Rank from worst to best. Then cp will point to best one.
2358 Private fields have their bits flipped. For unsigned
2359 numbers, this should make them look very large.
2360 If the best alternate has a (signed) negative value,
2361 then all we ever saw were private members. */
2362 if (cp
- candidates
> 1)
2364 int n_candidates
= cp
- candidates
;
2365 extern int warn_synth
;
2366 TREE_VALUE (parms
) = instance_ptr
;
2367 cp
= ideal_candidate (candidates
, n_candidates
, len
);
2368 if (cp
== (struct candidate
*)0)
2370 if (flags
& LOOKUP_COMPLAIN
)
2372 TREE_CHAIN (last
) = void_list_node
;
2373 cp_error ("call of overloaded %s `%D(%A)' is ambiguous",
2374 name_kind
, save_name
, TREE_CHAIN (parmtypes
));
2375 print_n_candidates (candidates
, n_candidates
);
2377 return error_mark_node
;
2379 if (cp
->h
.code
& EVIL_CODE
)
2380 return error_mark_node
;
2382 && DECL_NAME (cp
->function
) == ansi_opname
[MODIFY_EXPR
]
2383 && DECL_ARTIFICIAL (cp
->function
)
2384 && n_candidates
== 2)
2386 cp_warning ("using synthesized `%#D' for copy assignment",
2388 cp_warning_at (" where cfront would use `%#D'",
2389 candidates
->function
);
2392 else if (cp
[-1].h
.code
& EVIL_CODE
)
2394 if (flags
& LOOKUP_COMPLAIN
)
2395 cp_error ("ambiguous type conversion requested for %s `%D'",
2396 name_kind
, save_name
);
2397 return error_mark_node
;
2402 /* The global function was the best, so use it. */
2403 if (cp
->u
.field
== 0)
2405 /* We must convert the instance pointer into a reference type.
2406 Global overloaded functions can only either take
2407 aggregate objects (which come for free from references)
2408 or reference data types anyway. */
2409 TREE_VALUE (parms
) = copy_node (instance_ptr
);
2410 TREE_TYPE (TREE_VALUE (parms
)) = build_reference_type (TREE_TYPE (TREE_TYPE (instance_ptr
)));
2411 return build_function_call (cp
->function
, parms
);
2414 function
= cp
->function
;
2415 basetype_path
= cp
->basetypes
;
2416 if (! DECL_STATIC_FUNCTION_P (function
))
2417 TREE_VALUE (parms
) = cp
->arg
;
2418 goto found_and_maybe_warn
;
2421 if (flags
& (LOOKUP_COMPLAIN
|LOOKUP_SPECULATIVELY
))
2423 if ((flags
& (LOOKUP_SPECULATIVELY
|LOOKUP_COMPLAIN
))
2424 == LOOKUP_SPECULATIVELY
)
2427 if (DECL_STATIC_FUNCTION_P (cp
->function
))
2428 parms
= TREE_CHAIN (parms
);
2431 if (flags
& LOOKUP_SPECULATIVELY
)
2433 if (static_call_context
2434 && TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
2435 cp_error ("object missing in call to `%D'", cp
->function
);
2436 else if (ever_seen
> 1)
2438 TREE_CHAIN (last
) = void_list_node
;
2439 cp_error ("no matching function for call to `%T::%D (%A)%V'",
2440 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (instance_ptr
))),
2441 save_name
, TREE_CHAIN (parmtypes
),
2442 TREE_TYPE (TREE_TYPE (instance_ptr
)));
2443 TREE_CHAIN (last
) = NULL_TREE
;
2444 print_candidates (found_fns
);
2447 report_type_mismatch (cp
, parms
, name_kind
);
2448 return error_mark_node
;
2451 if ((flags
& (LOOKUP_SPECULATIVELY
|LOOKUP_COMPLAIN
))
2454 cp_error ("%T has no method named %D", save_basetype
, save_name
);
2455 return error_mark_node
;
2461 found_and_maybe_warn
:
2462 if ((cp
->harshness
[0].code
& CONST_CODE
)
2463 /* 12.1p2: Constructors can be called for const objects. */
2464 && ! DECL_CONSTRUCTOR_P (cp
->function
))
2466 if (flags
& LOOKUP_COMPLAIN
)
2468 cp_error_at ("non-const member function `%D'", cp
->function
);
2469 error ("called for const object at this point in file");
2471 /* Not good enough for a match. */
2473 return error_mark_node
;
2477 /* Silently return error_mark_node. */
2478 return error_mark_node
;
2481 if (flags
& LOOKUP_PROTECT
)
2482 access
= compute_access (basetype_path
, function
);
2484 if (access
== access_private_node
)
2486 if (flags
& LOOKUP_COMPLAIN
)
2488 cp_error_at ("%s `%+#D' is %s", name_kind
, function
,
2489 TREE_PRIVATE (function
) ? "private"
2490 : "from private base class");
2491 error ("within this context");
2493 return error_mark_node
;
2495 else if (access
== access_protected_node
)
2497 if (flags
& LOOKUP_COMPLAIN
)
2499 cp_error_at ("%s `%+#D' %s", name_kind
, function
,
2500 TREE_PROTECTED (function
) ? "is protected"
2501 : "has protected accessibility");
2502 error ("within this context");
2504 return error_mark_node
;
2507 /* From here on down, BASETYPE is the type that INSTANCE_PTR's
2508 type (if it exists) is a pointer to. */
2510 if (DECL_ABSTRACT_VIRTUAL_P (function
)
2511 && instance
== current_class_ref
2512 && DECL_CONSTRUCTOR_P (current_function_decl
)
2513 && ! (flags
& LOOKUP_NONVIRTUAL
)
2514 && value_member (function
, get_abstract_virtuals (basetype
)))
2515 cp_error ("abstract virtual `%#D' called from constructor", function
);
2517 if (IS_SIGNATURE (basetype
))
2519 if (static_call_context
)
2521 cp_error ("cannot call signature member function `%T::%D' without signature pointer/reference",
2522 basetype
, save_name
);
2523 return error_mark_node
;
2525 return build_signature_method_call (function
, parms
);
2528 function
= DECL_MAIN_VARIANT (function
);
2529 mark_used (function
);
2531 fntype
= TREE_TYPE (function
);
2532 if (TREE_CODE (fntype
) == POINTER_TYPE
)
2533 fntype
= TREE_TYPE (fntype
);
2534 basetype
= DECL_CLASS_CONTEXT (function
);
2536 /* If we are referencing a virtual function from an object
2537 of effectively static type, then there is no need
2538 to go through the virtual function table. */
2539 if (need_vtbl
== maybe_needed
)
2541 int fixed_type
= resolves_to_fixed_type_p (instance
, 0);
2543 if (all_virtual
== 1
2544 && DECL_VINDEX (function
)
2545 && may_be_remote (basetype
))
2547 else if (DECL_VINDEX (function
))
2548 need_vtbl
= fixed_type
? unneeded
: needed
;
2550 need_vtbl
= not_needed
;
2553 if (TREE_CODE (fntype
) == METHOD_TYPE
&& static_call_context
2554 && !DECL_CONSTRUCTOR_P (function
))
2556 /* Let's be nasty to the user now, and give reasonable
2558 instance_ptr
= current_class_ptr
;
2561 if (basetype
!= current_class_type
)
2563 if (basetype
== error_mark_node
)
2564 return error_mark_node
;
2567 if (orig_basetype
!= NULL_TREE
)
2568 error_not_base_type (orig_basetype
, current_class_type
);
2570 error_not_base_type (function
, current_class_type
);
2571 return error_mark_node
;
2575 /* Only allow a static member function to call another static member
2577 else if (DECL_LANG_SPECIFIC (function
)
2578 && !DECL_STATIC_FUNCTION_P (function
))
2580 cp_error ("cannot call member function `%D' without object",
2582 return error_mark_node
;
2586 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2588 if (TYPE_SIZE (complete_type (value_type
)) == 0)
2590 if (flags
& LOOKUP_COMPLAIN
)
2591 incomplete_type_error (0, value_type
);
2592 return error_mark_node
;
2595 if (DECL_STATIC_FUNCTION_P (function
))
2596 parms
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2597 TREE_CHAIN (parms
), function
, LOOKUP_NORMAL
);
2598 else if (need_vtbl
== unneeded
)
2600 int sub_flags
= DECL_CONSTRUCTOR_P (function
) ? flags
: LOOKUP_NORMAL
;
2601 basetype
= TREE_TYPE (instance
);
2602 if (TYPE_METHOD_BASETYPE (TREE_TYPE (function
))
2603 != TYPE_MAIN_VARIANT (basetype
))
2605 basetype
= DECL_CLASS_CONTEXT (function
);
2606 instance_ptr
= convert_pointer_to (basetype
, instance_ptr
);
2607 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2609 parms
= expr_tree_cons (NULL_TREE
, instance_ptr
,
2610 convert_arguments (NULL_TREE
, TREE_CHAIN (TYPE_ARG_TYPES (fntype
)), TREE_CHAIN (parms
), function
, sub_flags
));
2614 if ((flags
& LOOKUP_NONVIRTUAL
) == 0)
2615 basetype
= DECL_CONTEXT (function
);
2617 /* First parm could be integer_zerop with casts like
2618 ((Object*)0)->Object::IsA() */
2619 if (!integer_zerop (TREE_VALUE (parms
)))
2621 /* Since we can't have inheritance with a union, doing get_binfo
2622 on it won't work. We do all the convert_pointer_to_real
2623 stuff to handle MI correctly...for unions, that's not
2624 an issue, so we must short-circuit that extra work here. */
2625 tree tmp
= TREE_TYPE (TREE_TYPE (TREE_VALUE (parms
)));
2626 if (tmp
!= NULL_TREE
&& TREE_CODE (tmp
) == UNION_TYPE
)
2627 instance_ptr
= TREE_VALUE (parms
);
2630 tree binfo
= get_binfo (basetype
,
2631 TREE_TYPE (TREE_TYPE (TREE_VALUE (parms
))),
2633 instance_ptr
= convert_pointer_to_real (binfo
, TREE_VALUE (parms
));
2636 = convert_pointer_to (build_type_variant (basetype
,
2640 if (TREE_CODE (instance_ptr
) == COND_EXPR
)
2642 instance_ptr
= save_expr (instance_ptr
);
2643 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2645 else if (TREE_CODE (instance_ptr
) == NOP_EXPR
2646 && TREE_CODE (TREE_OPERAND (instance_ptr
, 0)) == ADDR_EXPR
2647 && TREE_OPERAND (TREE_OPERAND (instance_ptr
, 0), 0) == instance
)
2649 /* The call to `convert_pointer_to' may return error_mark_node. */
2650 else if (instance_ptr
== error_mark_node
)
2651 return instance_ptr
;
2652 else if (instance
== NULL_TREE
2653 || TREE_CODE (instance
) != INDIRECT_REF
2654 || TREE_OPERAND (instance
, 0) != instance_ptr
)
2655 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2657 parms
= expr_tree_cons (NULL_TREE
, instance_ptr
,
2658 convert_arguments (NULL_TREE
, TREE_CHAIN (TYPE_ARG_TYPES (fntype
)), TREE_CHAIN (parms
), function
, LOOKUP_NORMAL
));
2661 if (parms
== error_mark_node
2662 || (parms
&& TREE_CHAIN (parms
) == error_mark_node
))
2663 return error_mark_node
;
2665 if (need_vtbl
== needed
)
2667 function
= build_vfn_ref (&TREE_VALUE (parms
), instance
,
2668 DECL_VINDEX (function
));
2669 TREE_TYPE (function
) = build_pointer_type (fntype
);
2672 if (TREE_CODE (function
) == FUNCTION_DECL
)
2673 GNU_xref_call (current_function_decl
,
2674 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function
)));
2676 result
= build_call (function
, value_type
, parms
);
2677 if (IS_AGGR_TYPE (value_type
))
2678 result
= build_cplus_new (value_type
, result
);
2679 result
= convert_from_reference (result
);
2683 /* Similar to `build_method_call', but for overloaded non-member functions.
2684 The name of this function comes through NAME. The name depends
2687 Note that this function must handle simple `C' promotions,
2688 as well as variable numbers of arguments (...), and
2689 default arguments to boot.
2691 If the overloading is successful, we return a tree node which
2692 contains the call to the function.
2694 If overloading produces candidates which are probable, but not definite,
2695 we hold these candidates. If FINAL_CP is non-zero, then we are free
2696 to assume that final_cp points to enough storage for all candidates that
2697 this function might generate. The `harshness' array is preallocated for
2698 the first candidate, but not for subsequent ones.
2700 Note that the DECL_RTL of FUNCTION must be made to agree with this
2701 function's new name. */
2704 build_overload_call_real (fnname
, parms
, flags
, final_cp
, require_complete
)
2707 struct candidate
*final_cp
;
2708 int require_complete
;
2710 /* must check for overloading here */
2711 tree functions
, function
;
2712 tree parmtypes
, last
;
2713 register tree outer
;
2715 int parmlength
= list_length (parms
);
2717 struct candidate
*candidates
, *cp
;
2721 final_cp
[0].h
.code
= 0;
2722 final_cp
[0].h
.distance
= 0;
2723 final_cp
[0].function
= 0;
2725 final_cp
[1].h
.code
= EVIL_CODE
;
2728 parmtypes
= default_parm_conversions (parms
, &last
);
2729 if (parmtypes
== error_mark_node
)
2732 final_cp
->h
.code
= EVIL_CODE
;
2733 return error_mark_node
;
2737 TREE_CHAIN (last
) = void_list_node
;
2739 parmtypes
= void_list_node
;
2741 if (is_overloaded_fn (fnname
))
2744 if (TREE_CODE (fnname
) == TREE_LIST
)
2745 fnname
= TREE_PURPOSE (functions
);
2746 else if (TREE_CODE (fnname
) == FUNCTION_DECL
)
2747 fnname
= DECL_NAME (functions
);
2750 functions
= lookup_name_nonclass (fnname
);
2752 if (functions
== NULL_TREE
)
2754 if (flags
& LOOKUP_SPECULATIVELY
)
2756 if (flags
& LOOKUP_COMPLAIN
)
2757 error ("only member functions apply");
2759 final_cp
->h
.code
= EVIL_CODE
;
2760 return error_mark_node
;
2763 if (TREE_CODE (functions
) == FUNCTION_DECL
&& ! IDENTIFIER_OPNAME_P (fnname
))
2765 functions
= DECL_MAIN_VARIANT (functions
);
2768 /* We are just curious whether this is a viable alternative or
2770 compute_conversion_costs (functions
, parms
, final_cp
, parmlength
);
2774 return build_function_call_real (functions
, parms
, 1, flags
);
2777 if (TREE_CODE (functions
) == TREE_LIST
2778 && TREE_VALUE (functions
) == NULL_TREE
)
2780 if (flags
& LOOKUP_SPECULATIVELY
)
2783 if (flags
& LOOKUP_COMPLAIN
)
2784 cp_error ("function `%D' declared overloaded, but no instances of that function declared",
2785 TREE_PURPOSE (functions
));
2787 final_cp
->h
.code
= EVIL_CODE
;
2788 return error_mark_node
;
2791 length
= count_functions (functions
);
2794 candidates
= final_cp
;
2798 = (struct candidate
*)alloca ((length
+1) * sizeof (struct candidate
));
2799 bzero ((char *) candidates
, (length
+ 1) * sizeof (struct candidate
));
2804 my_friendly_assert (is_overloaded_fn (functions
), 169);
2806 functions
= get_first_fn (functions
);
2808 /* OUTER is the list of FUNCTION_DECLS, in a TREE_LIST. */
2809 for (outer
= functions
; outer
; outer
= DECL_CHAIN (outer
))
2811 int template_cost
= 0;
2813 if (TREE_CODE (function
) != FUNCTION_DECL
2814 && ! (TREE_CODE (function
) == TEMPLATE_DECL
2815 && TREE_CODE (DECL_TEMPLATE_RESULT (function
)) == FUNCTION_DECL
))
2817 enum tree_code code
= TREE_CODE (function
);
2818 if (code
== TEMPLATE_DECL
)
2819 code
= TREE_CODE (DECL_TEMPLATE_RESULT (function
));
2820 if (code
== CONST_DECL
)
2822 ("enumeral value `%D' conflicts with function of same name",
2824 else if (code
== VAR_DECL
)
2826 if (TREE_STATIC (function
))
2828 ("variable `%D' conflicts with function of same name",
2832 ("constant field `%D' conflicts with function of same name",
2835 else if (code
== TYPE_DECL
)
2838 my_friendly_abort (2);
2839 error ("at this point in file");
2842 if (TREE_CODE (function
) == TEMPLATE_DECL
)
2844 int ntparms
= DECL_NTPARMS (function
);
2845 tree targs
= make_scratch_vec (ntparms
);
2848 i
= type_unification (DECL_INNERMOST_TEMPLATE_PARMS (function
),
2849 &TREE_VEC_ELT (targs
, 0),
2850 TYPE_ARG_TYPES (TREE_TYPE (function
)),
2851 parms
, NULL_TREE
, &template_cost
, 0, 0);
2854 function
= instantiate_template (function
, targs
);
2855 if (function
== error_mark_node
)
2860 if (TREE_CODE (function
) == TEMPLATE_DECL
)
2862 /* Unconverted template -- failed match. */
2863 cp
->function
= function
;
2865 cp
->h
.code
= EVIL_CODE
;
2869 struct candidate
*cp2
;
2871 /* Check that this decl is not the same as a function that's in
2872 the list due to some template instantiation. */
2875 if (cp2
->function
== function
)
2879 if (cp2
->function
== function
)
2882 function
= DECL_MAIN_VARIANT (function
);
2884 /* Can't use alloca here, since result might be
2885 passed to calling function. */
2886 cp
->h_len
= parmlength
;
2887 cp
->harshness
= (struct harshness_code
*)
2888 scratchalloc ((parmlength
+ 1) * sizeof (struct harshness_code
));
2890 compute_conversion_costs (function
, parms
, cp
, parmlength
);
2892 /* Make sure this is clear as well. */
2893 cp
->h
.int_penalty
+= template_cost
;
2895 if ((cp
[0].h
.code
& EVIL_CODE
) == 0)
2897 cp
[1].h
.code
= EVIL_CODE
;
2903 if (cp
- candidates
)
2905 tree rval
= error_mark_node
;
2908 cp
[0].h
.code
= EVIL_CODE
;
2909 if (cp
- candidates
> 1)
2911 struct candidate
*best_cp
2912 = ideal_candidate (candidates
, cp
- candidates
, parmlength
);
2913 if (best_cp
== (struct candidate
*)0)
2915 if (flags
& LOOKUP_COMPLAIN
)
2917 cp_error ("call of overloaded `%D' is ambiguous", fnname
);
2918 print_n_candidates (candidates
, cp
- candidates
);
2920 return error_mark_node
;
2923 rval
= best_cp
->function
;
2928 if (cp
->h
.code
& EVIL_CODE
)
2930 if (flags
& LOOKUP_COMPLAIN
)
2931 error ("type conversion ambiguous");
2934 rval
= cp
->function
;
2940 return build_function_call_real (rval
, parms
, require_complete
, flags
);
2943 if (flags
& LOOKUP_SPECULATIVELY
)
2946 if (flags
& LOOKUP_COMPLAIN
)
2947 report_type_mismatch (cp
, parms
, "function");
2949 return error_mark_node
;
2952 /* This requires a complete type on the result of the call. */
2955 build_overload_call (fnname
, parms
, flags
)
2959 return build_overload_call_real (fnname
, parms
, flags
, (struct candidate
*)0, 1);
2962 /* New overloading code. */
2964 struct z_candidate
{
2971 struct z_candidate
*next
;
2974 #define IDENTITY_RANK 0
2975 #define EXACT_RANK 1
2976 #define PROMO_RANK 2
2978 #define PBOOL_RANK 4
2980 #define ELLIPSIS_RANK 6
2983 #define ICS_RANK(NODE) \
2984 (ICS_BAD_FLAG (NODE) ? BAD_RANK \
2985 : ICS_ELLIPSIS_FLAG (NODE) ? ELLIPSIS_RANK \
2986 : ICS_USER_FLAG (NODE) ? USER_RANK \
2987 : ICS_STD_RANK (NODE))
2989 #define ICS_STD_RANK(NODE) TREE_COMPLEXITY (NODE)
2991 #define ICS_USER_FLAG(NODE) TREE_LANG_FLAG_0 (NODE)
2992 #define ICS_ELLIPSIS_FLAG(NODE) TREE_LANG_FLAG_1 (NODE)
2993 #define ICS_THIS_FLAG(NODE) TREE_LANG_FLAG_2 (NODE)
2994 #define ICS_BAD_FLAG(NODE) TREE_LANG_FLAG_3 (NODE)
2996 #define USER_CONV_FN(NODE) TREE_OPERAND (NODE, 1)
3003 || integer_zerop (t
) && TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
3009 build_conv (code
, type
, from
)
3010 enum tree_code code
;
3013 tree t
= build1 (code
, type
, from
);
3014 int rank
= ICS_STD_RANK (from
);
3021 if (rank
< STD_RANK
)
3026 if (rank
< EXACT_RANK
)
3032 ICS_STD_RANK (t
) = rank
;
3033 ICS_USER_FLAG (t
) = ICS_USER_FLAG (from
);
3034 ICS_BAD_FLAG (t
) = ICS_BAD_FLAG (from
);
3042 if (TREE_CODE (t
) == REFERENCE_TYPE
)
3051 if (TREE_CODE (t
) == ARRAY_TYPE
)
3053 return TYPE_MAIN_VARIANT (t
);
3056 /* Returns the standard conversion path (see [conv]) from type FROM to type
3057 TO, if any. For proper handling of null pointer constants, you must
3058 also pass the expression EXPR to convert from. */
3061 standard_conversion (to
, from
, expr
)
3062 tree to
, from
, expr
;
3064 enum tree_code fcode
, tcode
;
3068 if (TREE_CODE (to
) == REFERENCE_TYPE
)
3069 to
= TREE_TYPE (to
);
3070 if (TREE_CODE (from
) == REFERENCE_TYPE
)
3073 from
= TREE_TYPE (from
);
3075 to
= strip_top_quals (to
);
3076 from
= strip_top_quals (from
);
3078 fcode
= TREE_CODE (from
);
3079 tcode
= TREE_CODE (to
);
3081 conv
= build1 (IDENTITY_CONV
, from
, expr
);
3083 if (fcode
== FUNCTION_TYPE
)
3085 from
= build_pointer_type (from
);
3086 fcode
= TREE_CODE (from
);
3087 conv
= build_conv (LVALUE_CONV
, from
, conv
);
3089 else if (fcode
== ARRAY_TYPE
)
3091 from
= build_pointer_type (TREE_TYPE (from
));
3092 fcode
= TREE_CODE (from
);
3093 conv
= build_conv (LVALUE_CONV
, from
, conv
);
3095 else if (fromref
|| (expr
&& real_lvalue_p (expr
)))
3096 conv
= build_conv (RVALUE_CONV
, from
, conv
);
3101 if ((tcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (to
))
3102 && expr
&& null_ptr_cst_p (expr
))
3104 conv
= build_conv (STD_CONV
, to
, conv
);
3106 else if (tcode
== POINTER_TYPE
&& fcode
== POINTER_TYPE
)
3108 enum tree_code ufcode
= TREE_CODE (TREE_TYPE (from
));
3109 enum tree_code utcode
= TREE_CODE (TREE_TYPE (to
));
3110 tree nconv
= NULL_TREE
;
3112 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (from
)),
3113 TYPE_MAIN_VARIANT (TREE_TYPE (to
)), 1))
3115 else if (utcode
== VOID_TYPE
&& ufcode
!= OFFSET_TYPE
3116 && ufcode
!= FUNCTION_TYPE
)
3118 from
= build_pointer_type
3119 (cp_build_type_variant (void_type_node
,
3120 TYPE_READONLY (TREE_TYPE (from
)),
3121 TYPE_VOLATILE (TREE_TYPE (from
))));
3122 nconv
= build_conv (PTR_CONV
, from
, conv
);
3124 else if (ufcode
== OFFSET_TYPE
&& utcode
== OFFSET_TYPE
)
3126 tree fbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from
));
3127 tree tbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to
));
3129 if (DERIVED_FROM_P (fbase
, tbase
)
3130 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (from
))),
3131 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (to
))),
3134 from
= build_offset_type (tbase
, TREE_TYPE (TREE_TYPE (from
)));
3135 from
= build_pointer_type (from
);
3136 nconv
= build_conv (PMEM_CONV
, from
, conv
);
3139 else if (IS_AGGR_TYPE (TREE_TYPE (from
))
3140 && IS_AGGR_TYPE (TREE_TYPE (to
)))
3142 if (DERIVED_FROM_P (TREE_TYPE (to
), TREE_TYPE (from
)))
3144 from
= cp_build_type_variant (TREE_TYPE (to
),
3145 TYPE_READONLY (TREE_TYPE (from
)),
3146 TYPE_VOLATILE (TREE_TYPE (from
)));
3147 from
= build_pointer_type (from
);
3148 nconv
= build_conv (PTR_CONV
, from
, conv
);
3152 if (nconv
&& comptypes (from
, to
, 1))
3154 else if (nconv
&& comp_ptr_ttypes (TREE_TYPE (to
), TREE_TYPE (from
)))
3155 conv
= build_conv (QUAL_CONV
, to
, nconv
);
3156 else if (ptr_reasonably_similar (TREE_TYPE (to
), TREE_TYPE (from
)))
3158 conv
= build_conv (PTR_CONV
, to
, conv
);
3159 ICS_BAD_FLAG (conv
) = 1;
3166 else if (TYPE_PTRMEMFUNC_P (to
) && TYPE_PTRMEMFUNC_P (from
))
3168 tree fromfn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from
));
3169 tree tofn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to
));
3170 tree fbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn
)));
3171 tree tbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn
)));
3173 if (! DERIVED_FROM_P (fbase
, tbase
)
3174 || ! comptypes (TREE_TYPE (fromfn
), TREE_TYPE (tofn
), 1)
3175 || ! compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)),
3176 TREE_CHAIN (TYPE_ARG_TYPES (tofn
)), 1)
3177 || TYPE_READONLY (fbase
) != TYPE_READONLY (tbase
)
3178 || TYPE_VOLATILE (fbase
) != TYPE_VOLATILE (tbase
))
3181 from
= cp_build_type_variant (tbase
, TYPE_READONLY (fbase
),
3182 TYPE_VOLATILE (fbase
));
3183 from
= build_cplus_method_type (from
, TREE_TYPE (fromfn
),
3184 TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)));
3185 from
= build_ptrmemfunc_type (build_pointer_type (from
));
3186 conv
= build_conv (PMEM_CONV
, from
, conv
);
3188 else if (tcode
== BOOLEAN_TYPE
)
3190 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
3191 || fcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (from
)))
3194 conv
= build_conv (STD_CONV
, to
, conv
);
3195 if (fcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (from
)
3196 && ICS_STD_RANK (conv
) < PBOOL_RANK
)
3197 ICS_STD_RANK (conv
) = PBOOL_RANK
;
3199 /* We don't check for ENUMERAL_TYPE here because there are no standard
3200 conversions to enum type. */
3201 else if (tcode
== INTEGER_TYPE
|| tcode
== BOOLEAN_TYPE
3202 || tcode
== REAL_TYPE
)
3204 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
))
3206 conv
= build_conv (STD_CONV
, to
, conv
);
3208 /* Give this a better rank if it's a promotion. */
3209 if (to
== type_promotes_to (from
)
3210 && ICS_STD_RANK (TREE_OPERAND (conv
, 0)) <= PROMO_RANK
)
3211 ICS_STD_RANK (conv
) = PROMO_RANK
;
3213 else if (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
3214 && DERIVED_FROM_P (to
, from
))
3215 conv
= build_conv (BASE_CONV
, to
, conv
);
3222 /* Returns the conversion path from type FROM to reference type TO for
3223 purposes of reference binding. For lvalue binding, either pass a
3224 reference type to FROM or an lvalue expression to EXPR.
3226 Currently does not distinguish in the generated trees between binding to
3227 an lvalue and a temporary. Should it? */
3230 reference_binding (rto
, rfrom
, expr
, flags
)
3231 tree rto
, rfrom
, expr
;
3236 tree to
= TREE_TYPE (rto
);
3240 if (TREE_CODE (from
) == REFERENCE_TYPE
)
3241 from
= TREE_TYPE (from
);
3242 else if (! expr
|| ! real_lvalue_p (expr
))
3245 related
= (TYPE_MAIN_VARIANT (to
) == TYPE_MAIN_VARIANT (from
)
3246 || (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
3247 && DERIVED_FROM_P (to
, from
)));
3249 if (lvalue
&& related
3250 && TYPE_READONLY (to
) >= TYPE_READONLY (from
)
3251 && TYPE_VOLATILE (to
) >= TYPE_VOLATILE (from
))
3253 conv
= build1 (IDENTITY_CONV
, from
, expr
);
3255 if (TYPE_MAIN_VARIANT (to
) == TYPE_MAIN_VARIANT (from
))
3256 conv
= build_conv (REF_BIND
, rto
, conv
);
3259 conv
= build_conv (REF_BIND
, rto
, conv
);
3260 ICS_STD_RANK (conv
) = STD_RANK
;
3268 conv
= standard_conversion (to
, rfrom
, expr
);
3271 conv
= build_conv (REF_BIND
, rto
, conv
);
3273 /* Bind directly to a base subobject of a class rvalue. Do it
3274 after building the conversion for proper handling of ICS_RANK. */
3275 if (TREE_CODE (TREE_OPERAND (conv
, 0)) == BASE_CONV
)
3276 TREE_OPERAND (conv
, 0) = TREE_OPERAND (TREE_OPERAND (conv
, 0), 0);
3279 && ((! (TYPE_READONLY (to
) && ! TYPE_VOLATILE (to
)
3280 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0))
3281 /* If T1 is reference-related to T2, cv1 must be the same
3282 cv-qualification as, or greater cv-qualification than,
3283 cv2; otherwise, the program is ill-formed. */
3285 && (TYPE_READONLY (to
) < TYPE_READONLY (from
)
3286 || TYPE_VOLATILE (to
) < TYPE_VOLATILE (from
)))))
3287 ICS_BAD_FLAG (conv
) = 1;
3293 /* Returns the implicit conversion sequence (see [over.ics]) from type FROM
3294 to type TO. The optional expression EXPR may affect the conversion.
3295 FLAGS are the usual overloading flags. Only LOOKUP_NO_CONVERSION is
3299 implicit_conversion (to
, from
, expr
, flags
)
3300 tree to
, from
, expr
;
3304 struct z_candidate
*cand
;
3306 if (expr
&& type_unknown_p (expr
))
3308 expr
= instantiate_type (to
, expr
, 0);
3309 if (expr
== error_mark_node
)
3311 from
= TREE_TYPE (expr
);
3314 if (TREE_CODE (to
) == REFERENCE_TYPE
)
3315 conv
= reference_binding (to
, from
, expr
, flags
);
3317 conv
= standard_conversion (to
, from
, expr
);
3321 else if ((IS_AGGR_TYPE (non_reference (from
))
3322 || IS_AGGR_TYPE (non_reference (to
)))
3323 && (flags
& LOOKUP_NO_CONVERSION
) == 0)
3325 cand
= build_user_type_conversion_1
3326 (to
, expr
, LOOKUP_ONLYCONVERTING
);
3328 conv
= cand
->second_conv
;
3329 if ((! conv
|| ICS_BAD_FLAG (conv
))
3330 && TREE_CODE (to
) == REFERENCE_TYPE
3331 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0)
3333 cand
= build_user_type_conversion_1
3334 (TYPE_MAIN_VARIANT (TREE_TYPE (to
)), expr
, LOOKUP_ONLYCONVERTING
);
3337 if (! TYPE_READONLY (TREE_TYPE (to
))
3338 || TYPE_VOLATILE (TREE_TYPE (to
)))
3339 ICS_BAD_FLAG (cand
->second_conv
) = 1;
3340 if (!conv
|| (ICS_BAD_FLAG (conv
)
3341 > ICS_BAD_FLAG (cand
->second_conv
)))
3342 conv
= build_conv (REF_BIND
, to
, cand
->second_conv
);
3350 /* Create an overload candidate for the function or method FN called with
3351 the argument list ARGLIST and add it to CANDIDATES. FLAGS is passed on
3352 to implicit_conversion. */
3354 static struct z_candidate
*
3355 add_function_candidate (candidates
, fn
, arglist
, flags
)
3356 struct z_candidate
*candidates
;
3360 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
3363 tree parmnode
= parmlist
;
3364 tree argnode
= arglist
;
3366 struct z_candidate
*cand
;
3368 /* The `this' and `in_chrg' arguments to constructors are not considered
3369 in overload resolution. */
3370 if (DECL_CONSTRUCTOR_P (fn
))
3372 parmnode
= TREE_CHAIN (parmnode
);
3373 argnode
= TREE_CHAIN (argnode
);
3374 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3376 parmnode
= TREE_CHAIN (parmnode
);
3377 argnode
= TREE_CHAIN (argnode
);
3381 len
= list_length (argnode
);
3382 convs
= make_scratch_vec (len
);
3384 for (i
= 0; i
< len
; ++i
)
3386 tree arg
= TREE_VALUE (argnode
);
3387 tree argtype
= TREE_TYPE (arg
);
3390 argtype
= cp_build_type_variant
3391 (argtype
, TREE_READONLY (arg
), TREE_THIS_VOLATILE (arg
));
3393 if (parmnode
== void_list_node
)
3396 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
3399 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
3400 ICS_ELLIPSIS_FLAG (t
) = 1;
3403 if (i
== 0 && t
&& TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
3404 && ! DECL_CONSTRUCTOR_P (fn
))
3405 ICS_THIS_FLAG (t
) = 1;
3407 TREE_VEC_ELT (convs
, i
) = t
;
3411 if (ICS_BAD_FLAG (t
))
3415 parmnode
= TREE_CHAIN (parmnode
);
3416 argnode
= TREE_CHAIN (argnode
);
3422 /* Make sure there are default args for the rest of the parms. */
3423 for (; parmnode
&& parmnode
!= void_list_node
;
3424 parmnode
= TREE_CHAIN (parmnode
))
3425 if (! TREE_PURPOSE (parmnode
))
3431 cand
= (struct z_candidate
*) scratchalloc (sizeof (struct z_candidate
));
3434 cand
->convs
= convs
;
3435 cand
->second_conv
= NULL_TREE
;
3436 cand
->viable
= viable
;
3437 cand
->basetype_path
= NULL_TREE
;
3438 cand
->template = NULL_TREE
;
3439 cand
->next
= candidates
;
3444 /* Create an overload candidate for the conversion function FN which will
3445 be invoked for expression OBJ, producing a pointer-to-function which
3446 will in turn be called with the argument list ARGLIST, and add it to
3447 CANDIDATES. FLAGS is passed on to implicit_conversion. */
3449 static struct z_candidate
*
3450 add_conv_candidate (candidates
, fn
, obj
, arglist
)
3451 struct z_candidate
*candidates
;
3452 tree fn
, obj
, arglist
;
3454 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
3455 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (totype
));
3456 int i
, len
= list_length (arglist
) + 1;
3457 tree convs
= make_scratch_vec (len
);
3458 tree parmnode
= parmlist
;
3459 tree argnode
= arglist
;
3461 struct z_candidate
*cand
;
3462 int flags
= LOOKUP_NORMAL
;
3464 for (i
= 0; i
< len
; ++i
)
3466 tree arg
= i
== 0 ? obj
: TREE_VALUE (argnode
);
3467 tree argtype
= lvalue_type (arg
);
3471 t
= implicit_conversion (totype
, argtype
, arg
, flags
);
3472 else if (parmnode
== void_list_node
)
3475 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
3478 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
3479 ICS_ELLIPSIS_FLAG (t
) = 1;
3482 TREE_VEC_ELT (convs
, i
) = t
;
3486 if (ICS_BAD_FLAG (t
))
3493 parmnode
= TREE_CHAIN (parmnode
);
3494 argnode
= TREE_CHAIN (argnode
);
3500 for (; parmnode
&& parmnode
!= void_list_node
;
3501 parmnode
= TREE_CHAIN (parmnode
))
3502 if (! TREE_PURPOSE (parmnode
))
3508 cand
= (struct z_candidate
*) scratchalloc (sizeof (struct z_candidate
));
3511 cand
->convs
= convs
;
3512 cand
->second_conv
= NULL_TREE
;
3513 cand
->viable
= viable
;
3514 cand
->basetype_path
= NULL_TREE
;
3515 cand
->template = NULL_TREE
;
3516 cand
->next
= candidates
;
3521 static struct z_candidate
*
3522 build_builtin_candidate (candidates
, fnname
, type1
, type2
,
3523 args
, argtypes
, flags
)
3524 struct z_candidate
*candidates
;
3525 tree fnname
, type1
, type2
, *args
, *argtypes
;
3531 struct z_candidate
*cand
;
3537 convs
= make_scratch_vec (args
[2] ? 3 : (args
[1] ? 2 : 1));
3539 for (i
= 0; i
< 2; ++i
)
3544 t
= implicit_conversion (types
[i
], argtypes
[i
], args
[i
], flags
);
3548 /* We need something for printing the candidate. */
3549 t
= build1 (IDENTITY_CONV
, types
[i
], NULL_TREE
);
3551 else if (ICS_BAD_FLAG (t
))
3553 TREE_VEC_ELT (convs
, i
) = t
;
3556 /* For COND_EXPR we rearranged the arguments; undo that now. */
3559 TREE_VEC_ELT (convs
, 2) = TREE_VEC_ELT (convs
, 1);
3560 TREE_VEC_ELT (convs
, 1) = TREE_VEC_ELT (convs
, 0);
3561 t
= implicit_conversion (boolean_type_node
, argtypes
[2], args
[2], flags
);
3563 TREE_VEC_ELT (convs
, 0) = t
;
3568 cand
= (struct z_candidate
*) scratchalloc (sizeof (struct z_candidate
));
3571 cand
->convs
= convs
;
3572 cand
->second_conv
= NULL_TREE
;
3573 cand
->viable
= viable
;
3574 cand
->basetype_path
= NULL_TREE
;
3575 cand
->template = NULL_TREE
;
3576 cand
->next
= candidates
;
3585 return TYPE_SIZE (complete_type (t
)) != NULL_TREE
;
3588 /* Create any builtin operator overload candidates for the operator in
3589 question given the converted operand types TYPE1 and TYPE2. The other
3590 args are passed through from add_builtin_candidates to
3591 build_builtin_candidate. */
3593 static struct z_candidate
*
3594 add_builtin_candidate (candidates
, code
, code2
, fnname
, type1
, type2
,
3595 args
, argtypes
, flags
)
3596 struct z_candidate
*candidates
;
3597 enum tree_code code
, code2
;
3598 tree fnname
, type1
, type2
, *args
, *argtypes
;
3603 case POSTINCREMENT_EXPR
:
3604 case POSTDECREMENT_EXPR
:
3605 args
[1] = integer_zero_node
;
3606 type2
= integer_type_node
;
3612 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
3613 and VQ is either volatile or empty, there exist candidate operator
3614 functions of the form
3615 VQ T& operator++(VQ T&);
3616 T operator++(VQ T&, int);
3617 5 For every pair T, VQ), where T is an enumeration type or an arithmetic
3618 type other than bool, and VQ is either volatile or empty, there exist
3619 candidate operator functions of the form
3620 VQ T& operator--(VQ T&);
3621 T operator--(VQ T&, int);
3622 6 For every pair T, VQ), where T is a cv-qualified or cv-unqualified
3623 complete object type, and VQ is either volatile or empty, there exist
3624 candidate operator functions of the form
3625 T*VQ& operator++(T*VQ&);
3626 T*VQ& operator--(T*VQ&);
3627 T* operator++(T*VQ&, int);
3628 T* operator--(T*VQ&, int); */
3630 case POSTDECREMENT_EXPR
:
3631 case PREDECREMENT_EXPR
:
3632 if (TREE_CODE (type1
) == BOOLEAN_TYPE
)
3634 case POSTINCREMENT_EXPR
:
3635 case PREINCREMENT_EXPR
:
3636 if ((ARITHMETIC_TYPE_P (type1
) && TREE_CODE (type1
) != ENUMERAL_TYPE
)
3637 || TYPE_PTROB_P (type1
))
3639 type1
= build_reference_type (type1
);
3644 /* 7 For every cv-qualified or cv-unqualified complete object type T, there
3645 exist candidate operator functions of the form
3649 8 For every function type T, there exist candidate operator functions of
3651 T& operator*(T*); */
3654 if (TREE_CODE (type1
) == POINTER_TYPE
3655 && (TYPE_PTROB_P (type1
)
3656 || TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
))
3660 /* 9 For every type T, there exist candidate operator functions of the form
3663 10For every promoted arithmetic type T, there exist candidate operator
3664 functions of the form
3668 case CONVERT_EXPR
: /* unary + */
3669 if (TREE_CODE (type1
) == POINTER_TYPE
3670 && TREE_CODE (TREE_TYPE (type1
)) != OFFSET_TYPE
)
3673 if (ARITHMETIC_TYPE_P (type1
))
3677 /* 11For every promoted integral type T, there exist candidate operator
3678 functions of the form
3682 if (INTEGRAL_TYPE_P (type1
))
3686 /* 12For every quintuple C1, C2, T, CV1, CV2), where C2 is a class type, C1
3687 is the same type as C2 or is a derived class of C2, T is a complete
3688 object type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
3689 there exist candidate operator functions of the form
3690 CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
3691 where CV12 is the union of CV1 and CV2. */
3694 if (TREE_CODE (type1
) == POINTER_TYPE
3695 && (TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
)))
3697 tree c1
= TREE_TYPE (type1
);
3698 tree c2
= (TYPE_PTRMEMFUNC_P (type2
)
3699 ? TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type2
)))
3700 : TYPE_OFFSET_BASETYPE (TREE_TYPE (type2
)));
3702 if (IS_AGGR_TYPE (c1
) && DERIVED_FROM_P (c2
, c1
)
3703 && (TYPE_PTRMEMFUNC_P (type2
)
3704 || is_complete (TREE_TYPE (TREE_TYPE (type2
)))))
3709 /* 13For every pair of promoted arithmetic types L and R, there exist can-
3710 didate operator functions of the form
3715 bool operator<(L, R);
3716 bool operator>(L, R);
3717 bool operator<=(L, R);
3718 bool operator>=(L, R);
3719 bool operator==(L, R);
3720 bool operator!=(L, R);
3721 where LR is the result of the usual arithmetic conversions between
3724 14For every pair of types T and I, where T is a cv-qualified or cv-
3725 unqualified complete object type and I is a promoted integral type,
3726 there exist candidate operator functions of the form
3727 T* operator+(T*, I);
3728 T& operator[](T*, I);
3729 T* operator-(T*, I);
3730 T* operator+(I, T*);
3731 T& operator[](I, T*);
3733 15For every T, where T is a pointer to complete object type, there exist
3734 candidate operator functions of the form112)
3735 ptrdiff_t operator-(T, T);
3737 16For every pointer type T, there exist candidate operator functions of
3739 bool operator<(T, T);
3740 bool operator>(T, T);
3741 bool operator<=(T, T);
3742 bool operator>=(T, T);
3743 bool operator==(T, T);
3744 bool operator!=(T, T);
3746 17For every pointer to member type T, there exist candidate operator
3747 functions of the form
3748 bool operator==(T, T);
3749 bool operator!=(T, T); */
3752 if (TYPE_PTROB_P (type1
) && TYPE_PTROB_P (type2
))
3754 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
3756 type2
= ptrdiff_type_node
;
3760 case TRUNC_DIV_EXPR
:
3761 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3767 if (TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
)
3768 || TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
))
3770 if ((TYPE_PTRMEMFUNC_P (type1
) || TYPE_PTRMEM_P (type1
))
3771 && null_ptr_cst_p (args
[1]))
3776 if ((TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
))
3777 && null_ptr_cst_p (args
[0]))
3788 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
)
3789 || TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
3791 if (TYPE_PTR_P (type1
) && null_ptr_cst_p (args
[1]))
3796 if (null_ptr_cst_p (args
[0]) && TYPE_PTR_P (type2
))
3804 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3807 if (INTEGRAL_TYPE_P (type1
) && TYPE_PTROB_P (type2
))
3809 type1
= ptrdiff_type_node
;
3812 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
3814 type2
= ptrdiff_type_node
;
3819 /* 18For every pair of promoted integral types L and R, there exist candi-
3820 date operator functions of the form
3827 where LR is the result of the usual arithmetic conversions between
3830 case TRUNC_MOD_EXPR
:
3836 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
3840 /* 19For every triple L, VQ, R), where L is an arithmetic or enumeration
3841 type, VQ is either volatile or empty, and R is a promoted arithmetic
3842 type, there exist candidate operator functions of the form
3843 VQ L& operator=(VQ L&, R);
3844 VQ L& operator*=(VQ L&, R);
3845 VQ L& operator/=(VQ L&, R);
3846 VQ L& operator+=(VQ L&, R);
3847 VQ L& operator-=(VQ L&, R);
3849 20For every pair T, VQ), where T is any type and VQ is either volatile
3850 or empty, there exist candidate operator functions of the form
3851 T*VQ& operator=(T*VQ&, T*);
3853 21For every pair T, VQ), where T is a pointer to member type and VQ is
3854 either volatile or empty, there exist candidate operator functions of
3856 VQ T& operator=(VQ T&, T);
3858 22For every triple T, VQ, I), where T is a cv-qualified or cv-
3859 unqualified complete object type, VQ is either volatile or empty, and
3860 I is a promoted integral type, there exist candidate operator func-
3862 T*VQ& operator+=(T*VQ&, I);
3863 T*VQ& operator-=(T*VQ&, I);
3865 23For every triple L, VQ, R), where L is an integral or enumeration
3866 type, VQ is either volatile or empty, and R is a promoted integral
3867 type, there exist candidate operator functions of the form
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);
3873 VQ L& operator^=(VQ L&, R);
3874 VQ L& operator|=(VQ L&, R); */
3881 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
3883 type2
= ptrdiff_type_node
;
3887 case TRUNC_DIV_EXPR
:
3888 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3892 case TRUNC_MOD_EXPR
:
3898 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
3903 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3905 if ((TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
))
3906 || (TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
3907 || (TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
))
3908 || ((TYPE_PTRMEMFUNC_P (type1
)
3909 || TREE_CODE (type1
) == POINTER_TYPE
)
3910 && null_ptr_cst_p (args
[1])))
3918 my_friendly_abort (367);
3920 type1
= build_reference_type (type1
);
3924 /* Kludge around broken overloading rules whereby
3925 bool ? const char& : enum is ambiguous
3926 (between int and const char&). */
3927 flags
|= LOOKUP_NO_TEMP_BIND
;
3929 /* Extension: Support ?: of enumeral type. Hopefully this will not
3930 be an extension for long. */
3931 if (TREE_CODE (type1
) == ENUMERAL_TYPE
&& type1
== type2
)
3933 else if (TREE_CODE (type1
) == ENUMERAL_TYPE
3934 || TREE_CODE (type2
) == ENUMERAL_TYPE
)
3936 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3938 if (TREE_CODE (type1
) == TREE_CODE (type2
)
3939 && (TREE_CODE (type1
) == REFERENCE_TYPE
3940 || TREE_CODE (type1
) == POINTER_TYPE
3941 || TYPE_PTRMEMFUNC_P (type1
)
3942 || IS_AGGR_TYPE (type1
)))
3944 if (TREE_CODE (type1
) == REFERENCE_TYPE
3945 || TREE_CODE (type2
) == REFERENCE_TYPE
)
3947 if (((TYPE_PTRMEMFUNC_P (type1
) || TREE_CODE (type1
) == POINTER_TYPE
)
3948 && null_ptr_cst_p (args
[1]))
3949 || IS_AGGR_TYPE (type1
))
3954 if (((TYPE_PTRMEMFUNC_P (type2
) || TREE_CODE (type2
) == POINTER_TYPE
)
3955 && null_ptr_cst_p (args
[0]))
3956 || IS_AGGR_TYPE (type2
))
3964 my_friendly_abort (367);
3967 /* If we're dealing with two pointer types, we need candidates
3968 for both of them. */
3969 if (type2
&& type1
!= type2
3970 && TREE_CODE (type1
) == TREE_CODE (type2
)
3971 && (TREE_CODE (type1
) == REFERENCE_TYPE
3972 || (TREE_CODE (type1
) == POINTER_TYPE
3973 && TYPE_PTRMEM_P (type1
) == TYPE_PTRMEM_P (type2
))
3974 || TYPE_PTRMEMFUNC_P (type1
)
3975 || IS_AGGR_TYPE (type1
)))
3977 candidates
= build_builtin_candidate
3978 (candidates
, fnname
, type1
, type1
, args
, argtypes
, flags
);
3979 return build_builtin_candidate
3980 (candidates
, fnname
, type2
, type2
, args
, argtypes
, flags
);
3983 return build_builtin_candidate
3984 (candidates
, fnname
, type1
, type2
, args
, argtypes
, flags
);
3988 type_decays_to (type
)
3991 if (TREE_CODE (type
) == ARRAY_TYPE
)
3992 return build_pointer_type (TREE_TYPE (type
));
3993 if (TREE_CODE (type
) == FUNCTION_TYPE
)
3994 return build_pointer_type (type
);
3998 /* There are three conditions of builtin candidates:
4000 1) bool-taking candidates. These are the same regardless of the input.
4001 2) pointer-pair taking candidates. These are generated for each type
4002 one of the input types converts to.
4003 3) arithmetic candidates. According to the WP, we should generate
4004 all of these, but I'm trying not to... */
4006 static struct z_candidate
*
4007 add_builtin_candidates (candidates
, code
, code2
, fnname
, args
, flags
)
4008 struct z_candidate
*candidates
;
4009 enum tree_code code
, code2
;
4014 tree type
, argtypes
[3], types
[2];
4016 for (i
= 0; i
< 3; ++i
)
4019 argtypes
[i
] = lvalue_type (args
[i
]);
4021 argtypes
[i
] = NULL_TREE
;
4026 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
4027 and VQ is either volatile or empty, there exist candidate operator
4028 functions of the form
4029 VQ T& operator++(VQ T&); */
4031 case POSTINCREMENT_EXPR
:
4032 case PREINCREMENT_EXPR
:
4033 case POSTDECREMENT_EXPR
:
4034 case PREDECREMENT_EXPR
:
4039 /* 24There also exist candidate operator functions of the form
4040 bool operator!(bool);
4041 bool operator&&(bool, bool);
4042 bool operator||(bool, bool); */
4044 case TRUTH_NOT_EXPR
:
4045 return build_builtin_candidate
4046 (candidates
, fnname
, boolean_type_node
,
4047 NULL_TREE
, args
, argtypes
, flags
);
4049 case TRUTH_ORIF_EXPR
:
4050 case TRUTH_ANDIF_EXPR
:
4051 return build_builtin_candidate
4052 (candidates
, fnname
, boolean_type_node
,
4053 boolean_type_node
, args
, argtypes
, flags
);
4064 types
[0] = types
[1] = NULL_TREE
;
4066 for (i
= 0; i
< 2; ++i
)
4070 else if (IS_AGGR_TYPE (argtypes
[i
]))
4072 tree convs
= lookup_conversions (argtypes
[i
]);
4074 if (code
== COND_EXPR
)
4076 if (real_lvalue_p (args
[i
]))
4077 types
[i
] = scratch_tree_cons
4078 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
4080 types
[i
] = scratch_tree_cons
4081 (NULL_TREE
, TYPE_MAIN_VARIANT (argtypes
[i
]), types
[i
]);
4084 else if (! convs
|| (i
== 0 && code
== MODIFY_EXPR
4085 && code2
== NOP_EXPR
))
4088 for (; convs
; convs
= TREE_CHAIN (convs
))
4090 type
= TREE_TYPE (TREE_TYPE (TREE_VALUE (convs
)));
4093 && (TREE_CODE (type
) != REFERENCE_TYPE
4094 || TYPE_READONLY (TREE_TYPE (type
))))
4097 if (code
== COND_EXPR
&& TREE_CODE (type
) == REFERENCE_TYPE
)
4098 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
4100 type
= non_reference (type
);
4101 if (i
!= 0 || ! ref1
)
4103 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
4104 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
4105 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
4106 if (INTEGRAL_TYPE_P (type
))
4107 type
= type_promotes_to (type
);
4110 if (! value_member (type
, types
[i
]))
4111 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
4116 if (code
== COND_EXPR
&& real_lvalue_p (args
[i
]))
4117 types
[i
] = scratch_tree_cons
4118 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
4119 type
= non_reference (argtypes
[i
]);
4120 if (i
!= 0 || ! ref1
)
4122 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
4123 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
4124 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
4125 if (INTEGRAL_TYPE_P (type
))
4126 type
= type_promotes_to (type
);
4128 types
[i
] = scratch_tree_cons (NULL_TREE
, type
, types
[i
]);
4132 for (; types
[0]; types
[0] = TREE_CHAIN (types
[0]))
4135 for (type
= types
[1]; type
; type
= TREE_CHAIN (type
))
4136 candidates
= add_builtin_candidate
4137 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
4138 TREE_VALUE (type
), args
, argtypes
, flags
);
4140 candidates
= add_builtin_candidate
4141 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
4142 NULL_TREE
, args
, argtypes
, flags
);
4148 /* If TMPL can be successfully instantiated as indicated by
4149 EXPLICIT_TARGS and ARGLIST, adds the instantiation to CANDIDATES.
4151 TMPL is the template. EXPLICIT_TARGS are any explicit template arguments.
4152 ARGLIST is the arguments provided at the call-site. The RETURN_TYPE
4153 is the desired type for conversion operators. FLAGS are as for
4154 add_function_candidate. */
4156 static struct z_candidate
*
4157 add_template_candidate (candidates
, tmpl
, explicit_targs
,
4158 arglist
, return_type
, flags
)
4159 struct z_candidate
*candidates
;
4160 tree tmpl
, explicit_targs
, arglist
, return_type
;
4163 int ntparms
= DECL_NTPARMS (tmpl
);
4164 tree targs
= make_scratch_vec (ntparms
);
4165 struct z_candidate
*cand
;
4169 i
= fn_type_unification (tmpl
, explicit_targs
, targs
, arglist
,
4175 fn
= instantiate_template (tmpl
, targs
);
4176 if (fn
== error_mark_node
)
4179 cand
= add_function_candidate (candidates
, fn
, arglist
, flags
);
4180 cand
->template = DECL_TEMPLATE_INFO (fn
);
4185 static struct z_candidate
*
4186 add_template_conv_candidate (candidates
, tmpl
, obj
, arglist
, return_type
)
4187 struct z_candidate
*candidates
;
4188 tree tmpl
, obj
, arglist
, return_type
;
4190 int ntparms
= DECL_NTPARMS (tmpl
);
4191 tree targs
= make_scratch_vec (ntparms
);
4192 struct z_candidate
*cand
;
4196 i
= fn_type_unification (tmpl
, NULL_TREE
, targs
, arglist
, return_type
, 0);
4201 fn
= instantiate_template (tmpl
, targs
);
4202 if (fn
== error_mark_node
)
4205 cand
= add_conv_candidate (candidates
, fn
, obj
, arglist
);
4206 cand
->template = DECL_TEMPLATE_INFO (fn
);
4213 struct z_candidate
*cands
;
4215 for (; cands
; cands
= cands
->next
)
4216 if (pedantic
? cands
->viable
== 1 : cands
->viable
)
4221 static struct z_candidate
*
4222 splice_viable (cands
)
4223 struct z_candidate
*cands
;
4225 struct z_candidate
**p
= &cands
;
4229 if (pedantic
? (*p
)->viable
== 1 : (*p
)->viable
)
4242 /* Fix this to work on non-lvalues. */
4243 if (IS_SIGNATURE_POINTER (TREE_TYPE (obj
))
4244 || IS_SIGNATURE_REFERENCE (TREE_TYPE (obj
)))
4247 return build_unary_op (ADDR_EXPR
, obj
, 0);
4251 print_z_candidates (candidates
)
4252 struct z_candidate
*candidates
;
4254 char *str
= "candidates are:";
4255 for (; candidates
; candidates
= candidates
->next
)
4257 if (TREE_CODE (candidates
->fn
) == IDENTIFIER_NODE
)
4259 if (candidates
->fn
== ansi_opname
[COND_EXPR
])
4260 cp_error ("%s %D(%T, %T, %T) <builtin>", str
, candidates
->fn
,
4261 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
4262 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)),
4263 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 2)));
4264 else if (TREE_VEC_LENGTH (candidates
->convs
) == 2)
4265 cp_error ("%s %D(%T, %T) <builtin>", str
, candidates
->fn
,
4266 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
4267 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)));
4269 cp_error ("%s %D(%T) <builtin>", str
, candidates
->fn
,
4270 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)));
4273 cp_error_at ("%s %+D%s", str
, candidates
->fn
,
4274 candidates
->viable
== -1 ? " <near match>" : "");
4279 /* Returns the best overload candidate to perform the requested
4280 conversion. This function is used for three the overloading situations
4281 described in [over.match.copy], [over.match.conv], and [over.match.ref].
4282 If TOTYPE is a REFERENCE_TYPE, we're trying to find an lvalue binding as
4283 per [dcl.init.ref], so we ignore temporary bindings. */
4285 static struct z_candidate
*
4286 build_user_type_conversion_1 (totype
, expr
, flags
)
4290 struct z_candidate
*candidates
, *cand
;
4291 tree fromtype
= TREE_TYPE (expr
);
4292 tree ctors
= NULL_TREE
, convs
= NULL_TREE
, *p
;
4294 tree templates
= NULL_TREE
;
4296 if (IS_AGGR_TYPE (totype
))
4297 ctors
= lookup_fnfields (TYPE_BINFO (totype
), ctor_identifier
, 0);
4298 if (IS_AGGR_TYPE (fromtype
)
4299 && (! IS_AGGR_TYPE (totype
) || ! DERIVED_FROM_P (totype
, fromtype
)))
4300 convs
= lookup_conversions (fromtype
);
4303 flags
|= LOOKUP_NO_CONVERSION
;
4307 tree t
= build_int_2 (0, 0);
4308 TREE_TYPE (t
) = build_pointer_type (totype
);
4309 args
= build_scratch_list (NULL_TREE
, expr
);
4310 if (TYPE_USES_VIRTUAL_BASECLASSES (totype
))
4311 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
4312 args
= scratch_tree_cons (NULL_TREE
, t
, args
);
4314 ctors
= TREE_VALUE (ctors
);
4316 for (; ctors
; ctors
= DECL_CHAIN (ctors
))
4318 if (DECL_NONCONVERTING_P (ctors
))
4321 if (TREE_CODE (ctors
) == TEMPLATE_DECL
)
4323 templates
= scratch_tree_cons (NULL_TREE
, ctors
, templates
);
4325 add_template_candidate (candidates
, ctors
,
4326 NULL_TREE
, args
, NULL_TREE
, flags
);
4329 candidates
= add_function_candidate (candidates
, ctors
,
4334 candidates
->second_conv
= build1 (IDENTITY_CONV
, totype
, NULL_TREE
);
4335 candidates
->basetype_path
= TYPE_BINFO (totype
);
4340 args
= build_scratch_list (NULL_TREE
, build_this (expr
));
4342 for (; convs
; convs
= TREE_CHAIN (convs
))
4344 tree fn
= TREE_VALUE (convs
);
4345 int convflags
= LOOKUP_NO_CONVERSION
;
4348 /* If we are called to convert to a reference type, we are trying to
4349 find an lvalue binding, so don't even consider temporaries. If
4350 we don't find an lvalue binding, the caller will try again to
4351 look for a temporary binding. */
4352 if (TREE_CODE (totype
) == REFERENCE_TYPE
)
4353 convflags
|= LOOKUP_NO_TEMP_BIND
;
4355 ics
= implicit_conversion
4356 (totype
, TREE_TYPE (TREE_TYPE (fn
)), 0, convflags
);
4358 if (TREE_CODE (totype
) == REFERENCE_TYPE
&& ics
&& ICS_BAD_FLAG (ics
))
4359 /* ignore the near match. */;
4361 for (; fn
; fn
= DECL_CHAIN (fn
))
4363 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4365 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
4367 add_template_candidate (candidates
, fn
, NULL_TREE
,
4368 args
, totype
, flags
);
4371 candidates
= add_function_candidate (candidates
, fn
,
4376 candidates
->second_conv
= ics
;
4377 candidates
->basetype_path
= TREE_PURPOSE (convs
);
4378 if (candidates
->viable
== 1 && ICS_BAD_FLAG (ics
))
4379 candidates
->viable
= -1;
4384 if (! any_viable (candidates
))
4387 if (flags
& LOOKUP_COMPLAIN
)
4389 if (candidates
&& ! candidates
->next
)
4390 /* say why this one won't work or try to be loose */;
4392 cp_error ("no viable candidates");
4399 candidates
= splice_viable (candidates
);
4400 cand
= tourney (candidates
);
4404 if (flags
& LOOKUP_COMPLAIN
)
4406 cp_error ("conversion from `%T' to `%T' is ambiguous",
4408 print_z_candidates (candidates
);
4411 cand
= candidates
; /* any one will do */
4412 cand
->second_conv
= build1 (AMBIG_CONV
, totype
, expr
);
4413 ICS_USER_FLAG (cand
->second_conv
) = 1;
4414 ICS_BAD_FLAG (cand
->second_conv
) = 1;
4419 for (p
= &(cand
->second_conv
); TREE_CODE (*p
) != IDENTITY_CONV
; )
4420 p
= &(TREE_OPERAND (*p
, 0));
4422 /* Pedantically, normal function declarations are never considered
4423 to refer to template instantiations, so we only do this with
4425 if (flag_guiding_decls
&& templates
&& ! cand
->template
4426 && !DECL_INITIAL (cand
->fn
)
4427 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
4428 add_maybe_template (cand
->fn
, templates
);
4432 (DECL_CONSTRUCTOR_P (cand
->fn
)
4433 ? totype
: non_reference (TREE_TYPE (TREE_TYPE (cand
->fn
)))),
4434 expr
, cand
->fn
, cand
->convs
, cand
->basetype_path
);
4435 ICS_USER_FLAG (cand
->second_conv
) = 1;
4436 if (cand
->viable
== -1)
4437 ICS_BAD_FLAG (cand
->second_conv
) = 1;
4443 build_user_type_conversion (totype
, expr
, flags
)
4447 struct z_candidate
*cand
4448 = build_user_type_conversion_1 (totype
, expr
, flags
);
4452 if (TREE_CODE (cand
->second_conv
) == AMBIG_CONV
)
4453 return error_mark_node
;
4454 return convert_from_reference (convert_like (cand
->second_conv
, expr
));
4459 /* Do any initial processing on the arguments to a function call. */
4466 for (t
= args
; t
; t
= TREE_CHAIN (t
))
4468 if (TREE_VALUE (t
) == error_mark_node
)
4469 return error_mark_node
;
4470 else if (TREE_CODE (TREE_TYPE (TREE_VALUE (t
))) == VOID_TYPE
)
4472 error ("invalid use of void expression");
4473 return error_mark_node
;
4475 else if (TREE_CODE (TREE_VALUE (t
)) == OFFSET_REF
)
4476 TREE_VALUE (t
) = resolve_offset_ref (TREE_VALUE (t
));
4482 build_new_function_call (fn
, args
, obj
)
4485 struct z_candidate
*candidates
= 0, *cand
;
4486 tree explicit_targs
= NULL_TREE
;
4487 int template_only
= 0;
4489 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
4491 explicit_targs
= TREE_OPERAND (fn
, 1);
4492 fn
= TREE_OPERAND (fn
, 0);
4496 if (obj
== NULL_TREE
&& really_overloaded_fn (fn
))
4499 tree templates
= NULL_TREE
;
4501 args
= resolve_args (args
);
4503 if (args
== error_mark_node
)
4504 return error_mark_node
;
4506 for (t
= TREE_VALUE (fn
); t
; t
= DECL_CHAIN (t
))
4508 if (TREE_CODE (t
) == TEMPLATE_DECL
)
4510 templates
= scratch_tree_cons (NULL_TREE
, t
, templates
);
4511 candidates
= add_template_candidate
4512 (candidates
, t
, explicit_targs
, args
, NULL_TREE
,
4515 else if (! template_only
)
4516 candidates
= add_function_candidate
4517 (candidates
, t
, args
, LOOKUP_NORMAL
);
4520 if (! any_viable (candidates
))
4522 if (candidates
&& ! candidates
->next
)
4523 return build_function_call (candidates
->fn
, args
);
4524 cp_error ("no matching function for call to `%D (%A)'",
4525 TREE_PURPOSE (fn
), args
);
4527 print_z_candidates (candidates
);
4528 return error_mark_node
;
4530 candidates
= splice_viable (candidates
);
4531 cand
= tourney (candidates
);
4535 cp_error ("call of overloaded `%D (%A)' is ambiguous",
4536 TREE_PURPOSE (fn
), args
);
4537 print_z_candidates (candidates
);
4538 return error_mark_node
;
4541 /* Pedantically, normal function declarations are never considered
4542 to refer to template instantiations, so we only do this with
4544 if (flag_guiding_decls
&& templates
&& ! cand
->template
4545 && ! DECL_INITIAL (cand
->fn
))
4546 add_maybe_template (cand
->fn
, templates
);
4548 return build_over_call (cand
->fn
, cand
->convs
, args
, LOOKUP_NORMAL
);
4551 return build_function_call (fn
, args
);
4555 build_object_call (obj
, args
)
4558 struct z_candidate
*candidates
= 0, *cand
;
4559 tree fns
, convs
, mem_args
;
4560 tree type
= TREE_TYPE (obj
);
4561 tree templates
= NULL_TREE
;
4563 fns
= lookup_fnfields (TYPE_BINFO (type
), ansi_opname
[CALL_EXPR
], 0);
4565 args
= resolve_args (args
);
4567 if (args
== error_mark_node
)
4568 return error_mark_node
;
4572 tree fn
= TREE_VALUE (fns
);
4573 mem_args
= scratch_tree_cons (NULL_TREE
, build_this (obj
), args
);
4575 for (; fn
; fn
= DECL_CHAIN (fn
))
4577 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4579 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
4581 = add_template_candidate (candidates
, fn
, NULL_TREE
,
4582 mem_args
, NULL_TREE
,
4586 candidates
= add_function_candidate
4587 (candidates
, fn
, mem_args
, LOOKUP_NORMAL
);
4590 candidates
->basetype_path
= TREE_PURPOSE (fns
);
4594 convs
= lookup_conversions (type
);
4596 for (; convs
; convs
= TREE_CHAIN (convs
))
4598 tree fn
= TREE_VALUE (convs
);
4599 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
4601 if (TREE_CODE (totype
) == POINTER_TYPE
4602 && TREE_CODE (TREE_TYPE (totype
)) == FUNCTION_TYPE
)
4603 for (; fn
; fn
= DECL_CHAIN (fn
))
4605 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4607 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
4608 candidates
= add_template_conv_candidate (candidates
,
4615 candidates
= add_conv_candidate (candidates
, fn
, obj
, args
);
4618 candidates
->basetype_path
= TREE_PURPOSE (convs
);
4622 if (! any_viable (candidates
))
4624 cp_error ("no match for call to `(%T) (%A)'", TREE_TYPE (obj
), args
);
4625 print_z_candidates (candidates
);
4626 return error_mark_node
;
4629 candidates
= splice_viable (candidates
);
4630 cand
= tourney (candidates
);
4634 cp_error ("call of `(%T) (%A)' is ambiguous", TREE_TYPE (obj
), args
);
4635 print_z_candidates (candidates
);
4636 return error_mark_node
;
4639 if (DECL_NAME (cand
->fn
) == ansi_opname
[CALL_EXPR
])
4640 return build_over_call (cand
->fn
, cand
->convs
, mem_args
, LOOKUP_NORMAL
);
4642 obj
= convert_like (TREE_VEC_ELT (cand
->convs
, 0), obj
);
4645 return build_function_call (obj
, args
);
4649 op_error (code
, code2
, arg1
, arg2
, arg3
, problem
)
4650 enum tree_code code
, code2
;
4651 tree arg1
, arg2
, arg3
;
4655 = (code
== MODIFY_EXPR
? assignop_tab
[code2
] : opname_tab
[code
]);
4660 cp_error ("%s for `%T ? %T : %T'", problem
,
4661 error_type (arg1
), error_type (arg2
), error_type (arg3
));
4663 case POSTINCREMENT_EXPR
:
4664 case POSTDECREMENT_EXPR
:
4665 cp_error ("%s for `%T%s'", problem
, error_type (arg1
), opname
);
4668 cp_error ("%s for `%T[%T]'", problem
,
4669 error_type (arg1
), error_type (arg2
));
4673 cp_error ("%s for `%T %s %T'", problem
,
4674 error_type (arg1
), opname
, error_type (arg2
));
4676 cp_error ("%s for `%s%T'", problem
, opname
, error_type (arg1
));
4681 build_new_op (code
, flags
, arg1
, arg2
, arg3
)
4682 enum tree_code code
;
4684 tree arg1
, arg2
, arg3
;
4686 struct z_candidate
*candidates
= 0, *cand
;
4687 tree fns
, mem_arglist
, arglist
, fnname
;
4688 enum tree_code code2
= NOP_EXPR
;
4689 tree templates
= NULL_TREE
;
4692 if (arg1
== error_mark_node
4693 || arg2
== error_mark_node
4694 || arg3
== error_mark_node
)
4695 return error_mark_node
;
4697 /* This can happen if a template takes all non-type parameters, e.g.
4698 undeclared_template<1, 5, 72>a; */
4699 if (code
== LT_EXPR
&& TREE_CODE (arg1
) == TEMPLATE_DECL
)
4701 cp_error ("`%D' must be declared before use", arg1
);
4702 return error_mark_node
;
4705 if (code
== MODIFY_EXPR
)
4707 code2
= TREE_CODE (arg3
);
4709 fnname
= ansi_assopname
[code2
];
4712 fnname
= ansi_opname
[code
];
4721 arglist
= scratch_tree_cons (NULL_TREE
, arg2
, arg3
);
4722 if (flags
& LOOKUP_GLOBAL
)
4723 return build_new_function_call
4724 (lookup_name_nonclass (fnname
), arglist
, NULL_TREE
);
4727 rval
= build_method_call
4728 (build_indirect_ref (build1 (NOP_EXPR
, arg1
, error_mark_node
),
4730 fnname
, arglist
, NULL_TREE
, flags
);
4731 if (rval
== error_mark_node
)
4732 /* User might declare fancy operator new, but invoke it
4733 like standard one. */
4736 TREE_TYPE (rval
) = arg1
;
4737 TREE_CALLS_NEW (rval
) = 1;
4741 case VEC_DELETE_EXPR
:
4746 if (flags
& LOOKUP_GLOBAL
)
4747 return build_new_function_call
4748 (lookup_name_nonclass (fnname
),
4749 build_scratch_list (NULL_TREE
, arg1
), NULL_TREE
);
4751 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, build_scratch_list (NULL_TREE
, arg2
));
4753 arg1
= TREE_TYPE (arg1
);
4755 /* This handles the case where we're trying to delete
4760 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
4762 /* Strip off the pointer and the array. */
4763 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
4765 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
4766 arg1
= (TREE_TYPE (arg1
));
4768 arg1
= build_pointer_type (arg1
);
4772 rval
= build_method_call
4773 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
4776 fnname
, arglist
, NULL_TREE
, flags
);
4778 /* This can happen when operator delete is protected. */
4779 my_friendly_assert (rval
!= error_mark_node
, 250);
4780 TREE_TYPE (rval
) = void_type_node
;
4786 return build_object_call (arg1
, arg2
);
4789 /* The comma operator can have void args. */
4790 if (TREE_CODE (arg1
) == OFFSET_REF
)
4791 arg1
= resolve_offset_ref (arg1
);
4792 if (arg2
&& TREE_CODE (arg2
) == OFFSET_REF
)
4793 arg2
= resolve_offset_ref (arg2
);
4794 if (arg3
&& TREE_CODE (arg3
) == OFFSET_REF
)
4795 arg3
= resolve_offset_ref (arg3
);
4797 if (code
== COND_EXPR
)
4799 if (arg2
== NULL_TREE
4800 || TREE_CODE (TREE_TYPE (arg2
)) == VOID_TYPE
4801 || TREE_CODE (TREE_TYPE (arg3
)) == VOID_TYPE
4802 || (! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))
4803 && ! IS_OVERLOAD_TYPE (TREE_TYPE (arg3
))))
4806 else if (! IS_OVERLOAD_TYPE (TREE_TYPE (arg1
))
4807 && (! arg2
|| ! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))))
4810 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
4811 arg2
= integer_zero_node
;
4814 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, scratch_tree_cons
4815 (NULL_TREE
, arg2
, build_scratch_list (NULL_TREE
, arg3
)));
4817 arglist
= scratch_tree_cons (NULL_TREE
, arg1
, build_scratch_list (NULL_TREE
, arg2
));
4819 arglist
= build_scratch_list (NULL_TREE
, arg1
);
4821 fns
= lookup_name_nonclass (fnname
);
4822 /* + Koenig lookup */
4824 if (fns
&& TREE_CODE (fns
) == TREE_LIST
)
4825 fns
= TREE_VALUE (fns
);
4826 for (; fns
; fns
= DECL_CHAIN (fns
))
4828 if (TREE_CODE (fns
) == TEMPLATE_DECL
)
4830 templates
= scratch_tree_cons (NULL_TREE
, fns
, templates
);
4832 = add_template_candidate (candidates
, fns
, NULL_TREE
,
4833 arglist
, TREE_TYPE (fnname
),
4837 candidates
= add_function_candidate (candidates
, fns
, arglist
, flags
);
4840 if (IS_AGGR_TYPE (TREE_TYPE (arg1
)))
4841 fns
= lookup_fnfields (TYPE_BINFO (TREE_TYPE (arg1
)), fnname
, 0);
4847 tree fn
= TREE_VALUE (fns
);
4848 mem_arglist
= scratch_tree_cons (NULL_TREE
, build_this (arg1
), TREE_CHAIN (arglist
));
4849 for (; fn
; fn
= DECL_CHAIN (fn
))
4853 if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
4854 this_arglist
= mem_arglist
;
4856 this_arglist
= arglist
;
4858 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4860 /* A member template. */
4861 templates
= scratch_tree_cons (NULL_TREE
, fn
, templates
);
4863 = add_template_candidate (candidates
, fn
, NULL_TREE
,
4864 this_arglist
, TREE_TYPE
4865 (fnname
), LOOKUP_NORMAL
);
4868 candidates
= add_function_candidate
4869 (candidates
, fn
, this_arglist
, flags
);
4872 candidates
->basetype_path
= TREE_PURPOSE (fns
);
4879 /* Rearrange the arguments for ?: so that add_builtin_candidate only has
4880 to know about two args; a builtin candidate will always have a first
4881 parameter of type bool. We'll handle that in
4882 build_builtin_candidate. */
4883 if (code
== COND_EXPR
)
4893 args
[2] = NULL_TREE
;
4896 candidates
= add_builtin_candidates
4897 (candidates
, code
, code2
, fnname
, args
, flags
);
4900 if (! any_viable (candidates
))
4904 case POSTINCREMENT_EXPR
:
4905 case POSTDECREMENT_EXPR
:
4906 /* Look for an `operator++ (int)'. If they didn't have
4907 one, then we fall back to the old way of doing things. */
4908 if (flags
& LOOKUP_COMPLAIN
)
4909 cp_pedwarn ("no `%D (int)' declared for postfix `%s', trying prefix operator instead",
4910 fnname
, opname_tab
[code
]);
4911 if (code
== POSTINCREMENT_EXPR
)
4912 code
= PREINCREMENT_EXPR
;
4914 code
= PREDECREMENT_EXPR
;
4915 return build_new_op (code
, flags
, arg1
, NULL_TREE
, NULL_TREE
);
4917 /* The caller will deal with these. */
4923 if (flags
& LOOKUP_COMPLAIN
)
4925 op_error (code
, code2
, arg1
, arg2
, arg3
, "no match");
4926 print_z_candidates (candidates
);
4928 return error_mark_node
;
4930 candidates
= splice_viable (candidates
);
4931 cand
= tourney (candidates
);
4935 if (flags
& LOOKUP_COMPLAIN
)
4937 op_error (code
, code2
, arg1
, arg2
, arg3
, "ambiguous overload");
4938 print_z_candidates (candidates
);
4940 return error_mark_node
;
4943 if (TREE_CODE (cand
->fn
) == FUNCTION_DECL
)
4945 extern int warn_synth
;
4947 && fnname
== ansi_opname
[MODIFY_EXPR
]
4948 && DECL_ARTIFICIAL (cand
->fn
)
4950 && ! candidates
->next
->next
)
4952 cp_warning ("using synthesized `%#D' for copy assignment",
4954 cp_warning_at (" where cfront would use `%#D'",
4956 ? candidates
->next
->fn
4960 if (DECL_FUNCTION_MEMBER_P (cand
->fn
))
4961 enforce_access (cand
->basetype_path
, cand
->fn
);
4963 /* Pedantically, normal function declarations are never considered
4964 to refer to template instantiations, so we only do this with
4966 if (flag_guiding_decls
&& templates
&& ! cand
->template
4967 && ! DECL_INITIAL (cand
->fn
)
4968 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
4969 add_maybe_template (cand
->fn
, templates
);
4971 return build_over_call
4972 (cand
->fn
, cand
->convs
,
4973 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
4974 ? mem_arglist
: arglist
,
4978 /* Check for comparison of different enum types. */
4987 if (flag_int_enum_equivalence
== 0
4988 && TREE_CODE (TREE_TYPE (arg1
)) == ENUMERAL_TYPE
4989 && TREE_CODE (TREE_TYPE (arg2
)) == ENUMERAL_TYPE
4990 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg1
))
4991 != TYPE_MAIN_VARIANT (TREE_TYPE (arg2
))))
4993 cp_warning ("comparison between `%#T' and `%#T'",
4994 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
4998 /* We need to strip any leading REF_BIND so that bitfields don't cause
4999 errors. This should not remove any important conversions, because
5000 builtins don't apply to class objects directly. */
5001 conv
= TREE_VEC_ELT (cand
->convs
, 0);
5002 if (TREE_CODE (conv
) == REF_BIND
)
5003 conv
= TREE_OPERAND (conv
, 0);
5004 arg1
= convert_like (conv
, arg1
);
5006 arg2
= convert_like (TREE_VEC_ELT (cand
->convs
, 1), arg2
);
5008 arg3
= convert_like (TREE_VEC_ELT (cand
->convs
, 2), arg3
);
5014 return build_modify_expr (arg1
, code2
, arg2
);
5017 return build_indirect_ref (arg1
, "unary *");
5022 case TRUNC_DIV_EXPR
:
5033 case TRUNC_MOD_EXPR
:
5037 case TRUTH_ANDIF_EXPR
:
5038 case TRUTH_ORIF_EXPR
:
5039 return build_binary_op_nodefault (code
, arg1
, arg2
, code
);
5044 case TRUTH_NOT_EXPR
:
5045 case PREINCREMENT_EXPR
:
5046 case POSTINCREMENT_EXPR
:
5047 case PREDECREMENT_EXPR
:
5048 case POSTDECREMENT_EXPR
:
5051 return build_unary_op (code
, arg1
, candidates
!= 0);
5054 return build_array_ref (arg1
, arg2
);
5057 return build_conditional_expr (arg1
, arg2
, arg3
);
5060 return build_m_component_ref
5061 (build_indirect_ref (arg1
, NULL_PTR
), arg2
);
5063 /* The caller will deal with these. */
5070 my_friendly_abort (367);
5075 enforce_access (basetype_path
, function
)
5076 tree basetype_path
, function
;
5078 tree access
= compute_access (basetype_path
, function
);
5080 if (access
== access_private_node
)
5082 cp_error_at ("`%+#D' is %s", function
,
5083 TREE_PRIVATE (function
) ? "private"
5084 : "from private base class");
5085 error ("within this context");
5087 else if (access
== access_protected_node
)
5089 cp_error_at ("`%+#D' %s", function
,
5090 TREE_PROTECTED (function
) ? "is protected"
5091 : "has protected accessibility");
5092 error ("within this context");
5096 /* Perform the conversions in CONVS on the expression EXPR. */
5099 convert_like (convs
, expr
)
5102 if (ICS_BAD_FLAG (convs
)
5103 && TREE_CODE (convs
) != USER_CONV
5104 && TREE_CODE (convs
) != AMBIG_CONV
)
5107 for (; t
; t
= TREE_OPERAND (t
, 0))
5109 if (TREE_CODE (t
) == USER_CONV
)
5111 expr
= convert_like (t
, expr
);
5114 else if (TREE_CODE (t
) == AMBIG_CONV
)
5115 return convert_like (t
, expr
);
5116 else if (TREE_CODE (t
) == IDENTITY_CONV
)
5119 return convert_for_initialization
5120 (NULL_TREE
, TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
,
5121 "conversion", NULL_TREE
, 0);
5124 switch (TREE_CODE (convs
))
5128 tree fn
= TREE_OPERAND (convs
, 1);
5130 enforce_access (TREE_OPERAND (convs
, 3), fn
);
5132 if (DECL_CONSTRUCTOR_P (fn
))
5134 tree t
= build_int_2 (0, 0);
5135 TREE_TYPE (t
) = build_pointer_type (DECL_CONTEXT (fn
));
5137 args
= build_scratch_list (NULL_TREE
, expr
);
5138 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
5139 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
5140 args
= scratch_tree_cons (NULL_TREE
, t
, args
);
5143 args
= build_this (expr
);
5144 expr
= build_over_call
5145 (TREE_OPERAND (convs
, 1), TREE_OPERAND (convs
, 2),
5146 args
, LOOKUP_NORMAL
);
5148 /* If this is a constructor or a function returning an aggr type,
5149 we need to build up a TARGET_EXPR. */
5150 if (DECL_CONSTRUCTOR_P (fn
))
5151 expr
= build_cplus_new (TREE_TYPE (convs
), expr
);
5156 if (type_unknown_p (expr
))
5157 expr
= instantiate_type (TREE_TYPE (convs
), expr
, 1);
5158 if (TREE_READONLY_DECL_P (expr
))
5159 expr
= decl_constant_value (expr
);
5162 /* Call build_user_type_conversion again for the error. */
5163 return build_user_type_conversion
5164 (TREE_TYPE (convs
), TREE_OPERAND (convs
, 0), LOOKUP_NORMAL
);
5167 expr
= convert_like (TREE_OPERAND (convs
, 0), expr
);
5168 if (expr
== error_mark_node
)
5169 return error_mark_node
;
5171 switch (TREE_CODE (convs
))
5174 if (! IS_AGGR_TYPE (TREE_TYPE (convs
)))
5176 /* else fall through */
5178 return build_user_type_conversion
5179 (TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
);
5181 return convert_to_reference
5182 (TREE_TYPE (convs
), expr
,
5183 CONV_IMPLICIT
, LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
,
5186 return decay_conversion (expr
);
5188 return ocp_convert (TREE_TYPE (convs
), expr
, CONV_IMPLICIT
,
5189 LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
);
5193 convert_default_arg (type
, arg
)
5196 arg
= break_out_target_exprs (arg
);
5198 if (TREE_CODE (arg
) == CONSTRUCTOR
)
5200 arg
= digest_init (type
, arg
, 0);
5201 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
5202 "default argument", 0, 0);
5206 /* This could get clobbered by the following call. */
5207 if (TREE_HAS_CONSTRUCTOR (arg
))
5208 arg
= copy_node (arg
);
5210 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
5211 "default argument", 0, 0);
5212 #ifdef PROMOTE_PROTOTYPES
5213 if ((TREE_CODE (type
) == INTEGER_TYPE
5214 || TREE_CODE (type
) == ENUMERAL_TYPE
)
5215 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
5216 arg
= default_conversion (arg
);
5224 build_over_call (fn
, convs
, args
, flags
)
5225 tree fn
, convs
, args
;
5228 tree converted_args
= NULL_TREE
;
5229 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
5230 tree conv
, arg
, val
;
5234 if (args
&& TREE_CODE (args
) != TREE_LIST
)
5235 args
= build_scratch_list (NULL_TREE
, args
);
5238 /* The implicit parameters to a constructor are not considered by overload
5239 resolution, and must be of the proper type. */
5240 if (DECL_CONSTRUCTOR_P (fn
))
5242 converted_args
= expr_tree_cons (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
5243 arg
= TREE_CHAIN (arg
);
5244 parm
= TREE_CHAIN (parm
);
5245 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
5247 converted_args
= expr_tree_cons
5248 (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
5249 arg
= TREE_CHAIN (arg
);
5250 parm
= TREE_CHAIN (parm
);
5253 /* Bypass access control for 'this' parameter. */
5254 else if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
5256 tree parmtype
= TREE_VALUE (parm
);
5257 tree argtype
= TREE_TYPE (TREE_VALUE (arg
));
5258 if (ICS_BAD_FLAG (TREE_VEC_ELT (convs
, i
)))
5260 int dv
= (TYPE_VOLATILE (TREE_TYPE (parmtype
))
5261 < TYPE_VOLATILE (TREE_TYPE (argtype
)));
5262 int dc
= (TYPE_READONLY (TREE_TYPE (parmtype
))
5263 < TYPE_READONLY (TREE_TYPE (argtype
)));
5264 char *p
= (dv
&& dc
? "const and volatile"
5265 : dc
? "const" : dv
? "volatile" : "");
5267 cp_pedwarn ("passing `%T' as `this' argument of `%#D' discards %s",
5268 TREE_TYPE (argtype
), fn
, p
);
5270 converted_args
= expr_tree_cons
5271 (NULL_TREE
, convert_force (TREE_VALUE (parm
), TREE_VALUE (arg
), CONV_C_CAST
),
5273 parm
= TREE_CHAIN (parm
);
5274 arg
= TREE_CHAIN (arg
);
5280 parm
= TREE_CHAIN (parm
), arg
= TREE_CHAIN (arg
), ++i
)
5282 tree type
= TREE_VALUE (parm
);
5284 conv
= TREE_VEC_ELT (convs
, i
);
5285 if (ICS_BAD_FLAG (conv
))
5288 val
= TREE_VALUE (arg
);
5290 for (; t
; t
= TREE_OPERAND (t
, 0))
5292 if (TREE_CODE (t
) == USER_CONV
5293 || TREE_CODE (t
) == AMBIG_CONV
)
5295 val
= convert_like (t
, val
);
5298 else if (TREE_CODE (t
) == IDENTITY_CONV
)
5301 val
= convert_for_initialization
5302 (NULL_TREE
, type
, val
, LOOKUP_NORMAL
,
5303 "argument passing", fn
, i
- is_method
);
5306 val
= convert_like (conv
, TREE_VALUE (arg
));
5308 #ifdef PROMOTE_PROTOTYPES
5309 if ((TREE_CODE (type
) == INTEGER_TYPE
5310 || TREE_CODE (type
) == ENUMERAL_TYPE
)
5311 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
5312 val
= default_conversion (val
);
5314 converted_args
= expr_tree_cons (NULL_TREE
, val
, converted_args
);
5317 /* Default arguments */
5318 for (; parm
&& parm
!= void_list_node
; parm
= TREE_CHAIN (parm
))
5320 tree arg
= TREE_PURPOSE (parm
);
5322 if (DECL_TEMPLATE_INFO (fn
))
5323 /* This came from a template. Instantiate the default arg here,
5325 arg
= tsubst_expr (arg
, DECL_TI_ARGS (fn
),
5326 TREE_VEC_LENGTH (DECL_TI_ARGS (fn
)), NULL_TREE
);
5327 converted_args
= expr_tree_cons
5328 (NULL_TREE
, convert_default_arg (TREE_VALUE (parm
), arg
),
5333 for (; arg
; arg
= TREE_CHAIN (arg
))
5335 val
= TREE_VALUE (arg
);
5337 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
5338 && (TYPE_PRECISION (TREE_TYPE (val
))
5339 < TYPE_PRECISION (double_type_node
)))
5340 /* Convert `float' to `double'. */
5341 val
= cp_convert (double_type_node
, val
);
5342 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
5343 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
5344 cp_warning ("cannot pass objects of type `%T' through `...'",
5347 /* Convert `short' and `char' to full-size `int'. */
5348 val
= default_conversion (val
);
5350 converted_args
= expr_tree_cons (NULL_TREE
, val
, converted_args
);
5353 converted_args
= nreverse (converted_args
);
5355 /* Avoid actually calling copy constructors and copy assignment operators,
5357 if (DECL_CONSTRUCTOR_P (fn
)
5358 && TREE_VEC_LENGTH (convs
) == 1
5359 && copy_args_p (fn
))
5362 arg
= TREE_VALUE (TREE_CHAIN (converted_args
));
5364 /* Pull out the real argument, disregarding const-correctness. */
5366 while (TREE_CODE (targ
) == NOP_EXPR
5367 || TREE_CODE (targ
) == NON_LVALUE_EXPR
5368 || TREE_CODE (targ
) == CONVERT_EXPR
)
5369 targ
= TREE_OPERAND (targ
, 0);
5370 if (TREE_CODE (targ
) == ADDR_EXPR
)
5372 targ
= TREE_OPERAND (targ
, 0);
5373 if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg
))),
5374 TYPE_MAIN_VARIANT (TREE_TYPE (targ
)), 1))
5383 arg
= build_indirect_ref (arg
, 0);
5385 /* [class.copy]: the copy constructor is implicitly defined even if
5386 the implementation elided its use. */
5387 if (TYPE_HAS_COMPLEX_INIT_REF (DECL_CONTEXT (fn
)))
5390 /* If we're creating a temp and we already have one, don't create a
5391 new one. If we're not creating a temp but we get one, use
5392 INIT_EXPR to collapse the temp into our target. Otherwise, if the
5393 ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
5394 temp or an INIT_EXPR otherwise. */
5395 if (integer_zerop (TREE_VALUE (args
)))
5397 if (! real_lvalue_p (arg
))
5399 else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
5401 val
= build (VAR_DECL
, DECL_CONTEXT (fn
));
5402 layout_decl (val
, 0);
5403 val
= build (TARGET_EXPR
, DECL_CONTEXT (fn
), val
, arg
, 0, 0);
5404 TREE_SIDE_EFFECTS (val
) = 1;
5408 else if (! real_lvalue_p (arg
)
5409 || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
5411 tree to
= stabilize_reference
5412 (build_indirect_ref (TREE_VALUE (args
), 0));
5413 val
= build (INIT_EXPR
, DECL_CONTEXT (fn
), to
, arg
);
5414 TREE_SIDE_EFFECTS (val
) = 1;
5415 return build_unary_op (ADDR_EXPR
, val
, 0);
5418 else if (DECL_NAME (fn
) == ansi_opname
[MODIFY_EXPR
]
5420 && TYPE_HAS_TRIVIAL_ASSIGN_REF (DECL_CONTEXT (fn
)))
5422 tree to
= stabilize_reference
5423 (build_indirect_ref (TREE_VALUE (converted_args
), 0));
5424 arg
= build_indirect_ref (TREE_VALUE (TREE_CHAIN (converted_args
)), 0);
5425 val
= build (MODIFY_EXPR
, TREE_TYPE (to
), to
, arg
);
5426 TREE_SIDE_EFFECTS (val
) = 1;
5432 if (DECL_CONTEXT (fn
) && IS_SIGNATURE (DECL_CONTEXT (fn
)))
5433 return build_signature_method_call (fn
, converted_args
);
5434 else if (DECL_VINDEX (fn
) && (flags
& LOOKUP_NONVIRTUAL
) == 0)
5436 tree t
, *p
= &TREE_VALUE (converted_args
);
5437 tree binfo
= get_binfo
5438 (DECL_CONTEXT (fn
), TREE_TYPE (TREE_TYPE (*p
)), 0);
5439 *p
= convert_pointer_to_real (binfo
, *p
);
5440 if (TREE_SIDE_EFFECTS (*p
))
5441 *p
= save_expr (*p
);
5442 t
= build_pointer_type (TREE_TYPE (fn
));
5443 fn
= build_vfn_ref (p
, build_indirect_ref (*p
, 0), DECL_VINDEX (fn
));
5446 else if (DECL_INLINE (fn
))
5447 fn
= inline_conversion (fn
);
5449 fn
= build_addr_func (fn
);
5451 fn
= build_call (fn
, TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))), converted_args
);
5452 if (TREE_TYPE (fn
) == void_type_node
)
5454 fn
= require_complete_type (fn
);
5455 if (IS_AGGR_TYPE (TREE_TYPE (fn
)))
5456 fn
= build_cplus_new (TREE_TYPE (fn
), fn
);
5457 return convert_from_reference (fn
);
5461 build_new_method_call (instance
, name
, args
, basetype_path
, flags
)
5462 tree instance
, name
, args
, basetype_path
;
5465 struct z_candidate
*candidates
= 0, *cand
;
5466 tree explicit_targs
= NULL_TREE
;
5467 tree basetype
, mem_args
, fns
, instance_ptr
;
5469 tree user_args
= args
;
5470 tree templates
= NULL_TREE
;
5471 int template_only
= 0;
5473 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
5475 explicit_targs
= TREE_OPERAND (name
, 1);
5476 name
= TREE_OPERAND (name
, 0);
5477 if (TREE_CODE (name
) == TEMPLATE_DECL
)
5478 name
= DECL_NAME (name
);
5482 /* If there is an extra argument for controlling virtual bases,
5483 remove it for error reporting. */
5484 if (flags
& LOOKUP_HAS_IN_CHARGE
)
5485 user_args
= TREE_CHAIN (args
);
5487 args
= resolve_args (args
);
5489 if (args
== error_mark_node
)
5490 return error_mark_node
;
5492 if (instance
== NULL_TREE
)
5493 basetype
= BINFO_TYPE (basetype_path
);
5496 if (TREE_CODE (instance
) == OFFSET_REF
)
5497 instance
= resolve_offset_ref (instance
);
5498 if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
5499 instance
= convert_from_reference (instance
);
5500 basetype
= TREE_TYPE (instance
);
5502 /* XXX this should be handled before we get here. */
5503 if (! IS_AGGR_TYPE (basetype
)
5504 && ! (TYPE_LANG_SPECIFIC (basetype
)
5505 && (IS_SIGNATURE_POINTER (basetype
)
5506 || IS_SIGNATURE_REFERENCE (basetype
))))
5508 if ((flags
& LOOKUP_COMPLAIN
) && basetype
!= error_mark_node
)
5509 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
5510 name
, instance
, basetype
);
5512 return error_mark_node
;
5515 /* If `instance' is a signature pointer/reference and `name' is
5516 not a constructor, we are calling a signature member function.
5517 In that case set the `basetype' to the signature type. */
5518 if ((IS_SIGNATURE_POINTER (basetype
)
5519 || IS_SIGNATURE_REFERENCE (basetype
))
5520 && TYPE_IDENTIFIER (basetype
) != name
)
5521 basetype
= SIGNATURE_TYPE (basetype
);
5524 if (basetype_path
== NULL_TREE
)
5525 basetype_path
= TYPE_BINFO (basetype
);
5529 instance_ptr
= build_this (instance
);
5531 if (! template_only
)
5533 /* XXX this should be handled before we get here. */
5534 fns
= build_field_call (basetype_path
, instance_ptr
, name
, args
);
5541 instance_ptr
= build_int_2 (0, 0);
5542 TREE_TYPE (instance_ptr
) = build_pointer_type (basetype
);
5546 = (name
== ctor_identifier
? constructor_name (basetype
) : name
);
5548 fns
= lookup_fnfields (basetype_path
, name
, 1);
5550 if (fns
== error_mark_node
)
5551 return error_mark_node
;
5554 tree t
= TREE_VALUE (fns
);
5555 if (name
== ctor_identifier
&& TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
5556 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
5558 flags
|= LOOKUP_HAS_IN_CHARGE
;
5559 args
= scratch_tree_cons (NULL_TREE
, integer_one_node
, args
);
5561 mem_args
= scratch_tree_cons (NULL_TREE
, instance_ptr
, args
);
5562 for (; t
; t
= DECL_CHAIN (t
))
5566 /* We can end up here for copy-init of same or base class. */
5567 if (name
== ctor_identifier
5568 && (flags
& LOOKUP_ONLYCONVERTING
)
5569 && DECL_NONCONVERTING_P (t
))
5571 if (TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)
5572 this_arglist
= mem_args
;
5574 this_arglist
= args
;
5576 if (TREE_CODE (t
) == TEMPLATE_DECL
)
5578 /* A member template. */
5579 templates
= scratch_tree_cons (NULL_TREE
, t
, templates
);
5581 add_template_candidate (candidates
, t
, explicit_targs
,
5583 TREE_TYPE (name
), flags
);
5585 else if (! template_only
)
5586 candidates
= add_function_candidate (candidates
, t
,
5587 this_arglist
, flags
);
5590 candidates
->basetype_path
= TREE_PURPOSE (fns
);
5594 if (! any_viable (candidates
))
5596 /* XXX will LOOKUP_SPECULATIVELY be needed when this is done? */
5597 if (flags
& LOOKUP_SPECULATIVELY
)
5599 cp_error ("no matching function for call to `%T::%D (%A)%V'", basetype
,
5600 pretty_name
, user_args
, TREE_TYPE (TREE_TYPE (instance_ptr
)));
5601 print_z_candidates (candidates
);
5602 return error_mark_node
;
5604 candidates
= splice_viable (candidates
);
5605 cand
= tourney (candidates
);
5609 cp_error ("call of overloaded `%D(%A)' is ambiguous", pretty_name
,
5611 print_z_candidates (candidates
);
5612 return error_mark_node
;
5615 enforce_access (cand
->basetype_path
, cand
->fn
);
5616 if (DECL_ABSTRACT_VIRTUAL_P (cand
->fn
)
5617 && instance
== current_class_ref
5618 && DECL_CONSTRUCTOR_P (current_function_decl
)
5619 && ! (flags
& LOOKUP_NONVIRTUAL
)
5620 && value_member (cand
->fn
, get_abstract_virtuals (basetype
)))
5621 cp_error ("abstract virtual `%#D' called from constructor", cand
->fn
);
5622 if (TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
5623 && TREE_CODE (instance_ptr
) == NOP_EXPR
5624 && TREE_OPERAND (instance_ptr
, 0) == error_mark_node
)
5625 cp_error ("cannot call member function `%D' without object", cand
->fn
);
5627 if (DECL_VINDEX (cand
->fn
) && ! (flags
& LOOKUP_NONVIRTUAL
)
5628 && ((instance
== current_class_ref
&& (dtor_label
|| ctor_label
))
5629 || resolves_to_fixed_type_p (instance
, 0)))
5630 flags
|= LOOKUP_NONVIRTUAL
;
5632 /* Pedantically, normal function declarations are never considered
5633 to refer to template instantiations, so we only do this with
5635 if (flag_guiding_decls
&& templates
&& ! cand
->template
5636 && ! DECL_INITIAL (cand
->fn
))
5637 add_maybe_template (cand
->fn
, templates
);
5639 return build_over_call
5640 (cand
->fn
, cand
->convs
,
5641 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
? mem_args
: args
,
5645 /* Compare two implicit conversion sequences that differ only in their
5646 qualification conversion. Subroutine of compare_ics. */
5649 compare_qual (ics1
, ics2
)
5652 tree to1
= TREE_TYPE (ics1
);
5653 tree to2
= TREE_TYPE (ics2
);
5655 if (TYPE_PTRMEMFUNC_P (to1
))
5656 to1
= TYPE_PTRMEMFUNC_FN_TYPE (to1
);
5657 if (TYPE_PTRMEMFUNC_P (to2
))
5658 to2
= TYPE_PTRMEMFUNC_FN_TYPE (to2
);
5660 to1
= TREE_TYPE (to1
);
5661 to2
= TREE_TYPE (to2
);
5663 if (TREE_CODE (to1
) == OFFSET_TYPE
)
5665 to1
= TREE_TYPE (to1
);
5666 to2
= TREE_TYPE (to2
);
5669 if (TYPE_READONLY (to1
) >= TYPE_READONLY (to2
)
5670 && TYPE_VOLATILE (to1
) > TYPE_VOLATILE (to2
))
5672 else if (TYPE_READONLY (to1
) > TYPE_READONLY (to2
)
5673 && TYPE_VOLATILE (to1
) == TYPE_VOLATILE (to2
))
5675 else if (TYPE_READONLY (to1
) <= TYPE_READONLY (to2
)
5676 && TYPE_VOLATILE (to1
) < TYPE_VOLATILE (to2
))
5678 else if (TYPE_READONLY (to1
) < TYPE_READONLY (to2
)
5679 && TYPE_VOLATILE (to1
) == TYPE_VOLATILE (to2
))
5684 /* Determine whether standard conversion sequence ICS1 is a proper
5685 subsequence of ICS2. We assume that a conversion of the same code
5686 between the same types indicates a subsequence. */
5689 is_subseq (ics1
, ics2
)
5692 /* Do not consider lvalue transformations here. */
5693 if (TREE_CODE (ics2
) == RVALUE_CONV
5694 || TREE_CODE (ics2
) == LVALUE_CONV
)
5697 for (;; ics2
= TREE_OPERAND (ics2
, 0))
5699 if (TREE_CODE (ics2
) == TREE_CODE (ics1
)
5700 && comptypes (TREE_TYPE (ics2
), TREE_TYPE (ics1
), 1)
5701 && comptypes (TREE_TYPE (TREE_OPERAND (ics2
, 0)),
5702 TREE_TYPE (TREE_OPERAND (ics1
, 0)), 1))
5705 if (TREE_CODE (ics2
) == USER_CONV
5706 || TREE_CODE (ics2
) == AMBIG_CONV
5707 || TREE_CODE (ics2
) == IDENTITY_CONV
)
5712 /* Compare two implicit conversion sequences according to the rules set out in
5713 [over.ics.rank]. Return values:
5715 1: ics1 is better than ics2
5716 -1: ics2 is better than ics1
5717 0: ics1 and ics2 are indistinguishable */
5720 compare_ics (ics1
, ics2
)
5725 if (TREE_CODE (ics1
) == QUAL_CONV
)
5726 main1
= TREE_OPERAND (ics1
, 0);
5730 if (TREE_CODE (ics2
) == QUAL_CONV
)
5731 main2
= TREE_OPERAND (ics2
, 0);
5735 /* Conversions for `this' are PTR_CONVs, but we compare them as though
5736 they were REF_BINDs. */
5737 if (ICS_THIS_FLAG (ics1
))
5740 if (TREE_CODE (t
) == PTR_CONV
)
5741 t
= TREE_OPERAND (t
, 0);
5742 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
5743 t
= build_conv (REF_BIND
, TREE_TYPE (ics1
), t
);
5744 ICS_STD_RANK (t
) = ICS_STD_RANK (main1
);
5747 if (ICS_THIS_FLAG (ics2
))
5750 if (TREE_CODE (t
) == PTR_CONV
)
5751 t
= TREE_OPERAND (t
, 0);
5752 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
5753 t
= build_conv (REF_BIND
, TREE_TYPE (ics2
), t
);
5754 ICS_STD_RANK (t
) = ICS_STD_RANK (main2
);
5758 if (ICS_RANK (ics1
) > ICS_RANK (ics2
))
5760 else if (ICS_RANK (ics1
) < ICS_RANK (ics2
))
5763 if (ICS_RANK (ics1
) == BAD_RANK
)
5765 if (ICS_USER_FLAG (ics1
) > ICS_USER_FLAG (ics2
)
5766 || ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
5768 else if (ICS_USER_FLAG (ics1
) < ICS_USER_FLAG (ics2
)
5769 || ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
5772 /* else fall through */
5775 /* User-defined conversion sequence U1 is a better conversion sequence
5776 than another user-defined conversion sequence U2 if they contain the
5777 same user-defined conversion operator or constructor and if the sec-
5778 ond standard conversion sequence of U1 is better than the second
5779 standard conversion sequence of U2. */
5781 if (ICS_USER_FLAG (ics1
))
5785 for (t1
= ics1
; TREE_CODE (t1
) != USER_CONV
; t1
= TREE_OPERAND (t1
, 0))
5786 if (TREE_CODE (t1
) == AMBIG_CONV
)
5788 for (t2
= ics2
; TREE_CODE (t2
) != USER_CONV
; t2
= TREE_OPERAND (t2
, 0))
5789 if (TREE_CODE (t2
) == AMBIG_CONV
)
5792 if (USER_CONV_FN (t1
) != USER_CONV_FN (t2
))
5794 else if (ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
5796 else if (ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
5799 /* else fall through */
5802 #if 0 /* Handled by ranking */
5803 /* A conversion that is not a conversion of a pointer, or pointer to
5804 member, to bool is better than another conversion that is such a
5808 if (TREE_CODE (main1
) != TREE_CODE (main2
))
5810 /* ...if S1 is a proper subsequence of S2 */
5811 if (is_subseq (main1
, main2
))
5813 if (is_subseq (main2
, main1
))
5818 if (TREE_CODE (main1
) == PTR_CONV
|| TREE_CODE (main1
) == PMEM_CONV
5819 || TREE_CODE (main1
) == REF_BIND
|| TREE_CODE (main1
) == BASE_CONV
)
5821 tree to1
= TREE_TYPE (main1
);
5822 tree from1
= TREE_TYPE (TREE_OPERAND (main1
, 0));
5823 tree to2
= TREE_TYPE (main2
);
5824 tree from2
= TREE_TYPE (TREE_OPERAND (main2
, 0));
5827 /* Standard conversion sequence S1 is a better conversion sequence than
5828 standard conversion sequence S2 if...
5830 S1 and S2 differ only in their qualification conversion and they
5831 yield types identical except for cv-qualifiers and S2 adds all the
5832 qualifiers that S1 adds (and in the same places) and S2 adds yet
5833 more cv-qualifiers than S1, or the similar case with reference
5835 if (TREE_CODE (main1
) == REF_BIND
)
5837 if (TYPE_MAIN_VARIANT (TREE_TYPE (to1
))
5838 == TYPE_MAIN_VARIANT (TREE_TYPE (to2
)))
5839 return compare_qual (ics1
, ics2
);
5841 else if (TREE_CODE (main1
) != BASE_CONV
&& from1
== from2
&& to1
== to2
)
5842 return compare_qual (ics1
, ics2
);
5844 if (TYPE_PTRMEMFUNC_P (to1
))
5846 to1
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to1
)));
5847 from1
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from1
)));
5849 else if (TREE_CODE (main1
) != BASE_CONV
)
5851 to1
= TREE_TYPE (to1
);
5852 if (TREE_CODE (main1
) != REF_BIND
)
5853 from1
= TREE_TYPE (from1
);
5855 if (TREE_CODE (to1
) == OFFSET_TYPE
)
5857 to1
= TYPE_OFFSET_BASETYPE (to1
);
5858 from1
= TYPE_OFFSET_BASETYPE (from1
);
5862 if (TYPE_PTRMEMFUNC_P (to2
))
5864 to2
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to2
)));
5865 from2
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from2
)));
5867 else if (TREE_CODE (main1
) != BASE_CONV
)
5869 to2
= TREE_TYPE (to2
);
5870 if (TREE_CODE (main1
) != REF_BIND
)
5871 from2
= TREE_TYPE (from2
);
5873 if (TREE_CODE (to2
) == OFFSET_TYPE
)
5875 to2
= TYPE_OFFSET_BASETYPE (to2
);
5876 from2
= TYPE_OFFSET_BASETYPE (from2
);
5880 if (! (IS_AGGR_TYPE (from1
) && IS_AGGR_TYPE (from2
)))
5883 /* The sense of pmem conversions is reversed from that of the other
5885 if (TREE_CODE (main1
) == PMEM_CONV
)
5887 tree t
= from1
; from1
= from2
; from2
= t
;
5888 t
= to1
; to1
= to2
; to2
= t
;
5891 distf
= get_base_distance (from1
, from2
, 0, 0);
5894 distf
= -get_base_distance (from2
, from1
, 0, 0);
5899 /* If class B is derived directly or indirectly from class A,
5900 conver- sion of B* to A* is better than conversion of B* to
5901 void*, and conversion of A* to void* is better than
5902 conversion of B* to void*. */
5904 if (TREE_CODE (to1
) == VOID_TYPE
&& TREE_CODE (to2
) == VOID_TYPE
)
5911 else if (TREE_CODE (to2
) == VOID_TYPE
&& IS_AGGR_TYPE (to1
)
5912 && get_base_distance (to1
, from1
, 0, 0) != -1)
5914 else if (TREE_CODE (to1
) == VOID_TYPE
&& IS_AGGR_TYPE (to2
)
5915 && get_base_distance (to2
, from2
, 0, 0) != -1)
5918 if (! (IS_AGGR_TYPE (to1
) && IS_AGGR_TYPE (to2
)))
5921 /* If class B is derived directly or indirectly from class A and class
5922 C is derived directly or indirectly from B */
5924 distt
= get_base_distance (to1
, to2
, 0, 0);
5927 distt
= -get_base_distance (to2
, to1
, 0, 0);
5932 /* --conversion of C* to B* is better than conversion of C* to A*, */
5940 /* --conversion of B* to A* is better than conversion of C* to A*, */
5941 else if (distt
== 0)
5949 else if (TREE_CODE (TREE_TYPE (main1
)) == POINTER_TYPE
5950 || TYPE_PTRMEMFUNC_P (TREE_TYPE (main1
)))
5952 if (TREE_TYPE (main1
) == TREE_TYPE (main2
))
5953 return compare_qual (ics1
, ics2
);
5955 #if 0 /* This is now handled by making identity better than anything else. */
5956 /* existing practice, not WP-endorsed: const char * -> const char *
5957 is better than char * -> const char *. (jason 6/29/96) */
5958 if (TREE_TYPE (ics1
) == TREE_TYPE (ics2
))
5959 return -compare_qual (main1
, main2
);
5966 /* The source type for this standard conversion sequence. */
5972 for (;; t
= TREE_OPERAND (t
, 0))
5974 if (TREE_CODE (t
) == USER_CONV
5975 || TREE_CODE (t
) == AMBIG_CONV
5976 || TREE_CODE (t
) == IDENTITY_CONV
)
5977 return TREE_TYPE (t
);
5979 my_friendly_abort (1823);
5982 /* Compare two candidates for overloading as described in
5983 [over.match.best]. Return values:
5985 1: cand1 is better than cand2
5986 -1: cand2 is better than cand1
5987 0: cand1 and cand2 are indistinguishable */
5990 joust (cand1
, cand2
)
5991 struct z_candidate
*cand1
, *cand2
;
5994 int i
, off1
= 0, off2
= 0, len
;
5996 /* Candidates that involve bad conversions are always worse than those
5998 if (cand1
->viable
> cand2
->viable
)
6000 if (cand1
->viable
< cand2
->viable
)
6003 /* a viable function F1
6004 is defined to be a better function than another viable function F2 if
6005 for all arguments i, ICSi(F1) is not a worse conversion sequence than
6006 ICSi(F2), and then */
6008 /* for some argument j, ICSj(F1) is a better conversion sequence than
6011 /* For comparing static and non-static member functions, we ignore the
6012 implicit object parameter of the non-static function. The WP says to
6013 pretend that the static function has an object parm, but that won't
6014 work with operator overloading. */
6015 len
= TREE_VEC_LENGTH (cand1
->convs
);
6016 if (len
!= TREE_VEC_LENGTH (cand2
->convs
))
6018 if (DECL_STATIC_FUNCTION_P (cand1
->fn
)
6019 && ! DECL_STATIC_FUNCTION_P (cand2
->fn
))
6021 else if (! DECL_STATIC_FUNCTION_P (cand1
->fn
)
6022 && DECL_STATIC_FUNCTION_P (cand2
->fn
))
6028 my_friendly_abort (42);
6031 for (i
= 0; i
< len
; ++i
)
6033 tree t1
= TREE_VEC_ELT (cand1
->convs
, i
+off1
);
6034 tree t2
= TREE_VEC_ELT (cand2
->convs
, i
+off2
);
6035 int comp
= compare_ics (t1
, t2
);
6039 #if 0 /* move this warning to tourney. */
6041 && ICS_RANK (t1
) + ICS_RANK (t2
) == STD_RANK
+ PROMO_RANK
6042 && TREE_CODE (t1
) == STD_CONV
6043 && TREE_CODE (t2
) == STD_CONV
6044 && TREE_CODE (TREE_TYPE (t1
)) == INTEGER_TYPE
6045 && TREE_CODE (TREE_TYPE (t2
)) == INTEGER_TYPE
6046 && (TYPE_PRECISION (TREE_TYPE (t1
))
6047 == TYPE_PRECISION (TREE_TYPE (t2
)))
6048 && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (t1
, 0)))
6049 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (t1
, 0)))
6052 tree type
= TREE_TYPE (TREE_OPERAND (t1
, 0));
6055 type1
= TREE_TYPE (t1
), type2
= TREE_TYPE (t2
);
6057 type1
= TREE_TYPE (t2
), type2
= TREE_TYPE (t1
);
6059 cp_warning ("passing `%T' chooses `%T' over `%T'",
6060 type
, type1
, type2
);
6061 cp_warning (" in call to `%D'", DECL_NAME (cand1
->fn
));
6065 if (winner
&& comp
!= winner
)
6074 #if 0 /* move this warning to tourney. */
6075 /* warn about confusing overload resolution */
6076 if (winner
&& cand1
->second_conv
6077 && ! DECL_CONSTRUCTOR_P (cand1
->fn
)
6078 && ! DECL_CONSTRUCTOR_P (cand2
->fn
))
6080 int comp
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
6081 if (comp
&& comp
!= winner
)
6083 struct z_candidate
*w
, *l
;
6085 w
= cand1
, l
= cand2
;
6087 w
= cand2
, l
= cand1
;
6088 cp_warning ("choosing `%D' over `%D'", w
->fn
, l
->fn
);
6089 cp_warning (" for conversion from `%T' to `%T'",
6090 TREE_TYPE (source_type (TREE_VEC_ELT (w
->convs
, 0))),
6091 TREE_TYPE (w
->second_conv
));
6092 cp_warning (" because conversion sequence for `this' argument is better");
6101 F1 is a non-template function and F2 is a template function */
6103 if (! cand1
->template && cand2
->template)
6105 else if (cand1
->template && ! cand2
->template)
6107 else if (cand1
->template && cand2
->template)
6108 winner
= more_specialized
6109 (TI_TEMPLATE (cand1
->template), TI_TEMPLATE (cand2
->template));
6112 the context is an initialization by user-defined conversion (see
6113 _dcl.init_ and _over.match.user_) and the standard conversion
6114 sequence from the return type of F1 to the destination type (i.e.,
6115 the type of the entity being initialized) is a better conversion
6116 sequence than the standard conversion sequence from the return type
6117 of F2 to the destination type. */
6119 if (! winner
&& cand1
->second_conv
)
6120 winner
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
6122 /* If the built-in candidates are the same, arbitrarily pick one. */
6123 if (! winner
&& cand1
->fn
== cand2
->fn
6124 && TREE_CODE (cand1
->fn
) == IDENTIFIER_NODE
)
6126 for (i
= 0; i
< len
; ++i
)
6127 if (! comptypes (TREE_TYPE (TREE_VEC_ELT (cand1
->convs
, i
)),
6128 TREE_TYPE (TREE_VEC_ELT (cand2
->convs
, i
)), 1))
6130 if (i
== TREE_VEC_LENGTH (cand1
->convs
))
6133 /* Kludge around broken overloading rules whereby
6134 Integer a, b; test ? a : b; is ambiguous, since there's a builtin
6135 that takes references and another that takes values. */
6136 if (cand1
->fn
== ansi_opname
[COND_EXPR
])
6138 tree c1
= TREE_VEC_ELT (cand1
->convs
, 1);
6139 tree c2
= TREE_VEC_ELT (cand2
->convs
, 1);
6140 tree t1
= strip_top_quals (non_reference (TREE_TYPE (c1
)));
6141 tree t2
= strip_top_quals (non_reference (TREE_TYPE (c2
)));
6143 if (comptypes (t1
, t2
, 1))
6145 if (TREE_CODE (c1
) == REF_BIND
&& TREE_CODE (c2
) != REF_BIND
)
6147 if (TREE_CODE (c1
) != REF_BIND
&& TREE_CODE (c2
) == REF_BIND
)
6155 /* Extension: If the worst conversion for one candidate is worse than the
6156 worst conversion for the other, take the first. */
6157 if (! winner
&& ! pedantic
)
6159 int rank1
= IDENTITY_RANK
, rank2
= IDENTITY_RANK
;
6161 for (i
= 0; i
< len
; ++i
)
6163 if (ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
)) > rank1
)
6164 rank1
= ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
));
6165 if (ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
)) > rank2
)
6166 rank2
= ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
));
6178 /* Given a list of candidates for overloading, find the best one, if any.
6179 This algorithm has a worst case of O(2n) (winner is last), and a best
6180 case of O(n/2) (totally ambiguous); much better than a sorting
6183 static struct z_candidate
*
6184 tourney (candidates
)
6185 struct z_candidate
*candidates
;
6187 struct z_candidate
*champ
= candidates
, *challenger
;
6190 /* Walk through the list once, comparing each current champ to the next
6191 candidate, knocking out a candidate or two with each comparison. */
6193 for (challenger
= champ
->next
; challenger
; )
6195 fate
= joust (champ
, challenger
);
6197 challenger
= challenger
->next
;
6202 champ
= challenger
->next
;
6209 challenger
= champ
->next
;
6213 /* Make sure the champ is better than all the candidates it hasn't yet
6214 been compared to. This may do one more comparison than necessary. Oh
6217 for (challenger
= candidates
; challenger
!= champ
;
6218 challenger
= challenger
->next
)
6220 fate
= joust (champ
, challenger
);
6229 can_convert (to
, from
)
6232 if (flag_ansi_overloading
)
6234 tree t
= implicit_conversion (to
, from
, NULL_TREE
, LOOKUP_NORMAL
);
6235 return (t
&& ! ICS_BAD_FLAG (t
));
6239 struct harshness_code h
;
6240 h
= convert_harshness (to
, from
, NULL_TREE
);
6241 return (h
.code
< USER_CODE
) && (h
.distance
>= 0);
6246 can_convert_arg (to
, from
, arg
)
6249 if (flag_ansi_overloading
)
6251 tree t
= implicit_conversion (to
, from
, arg
, LOOKUP_NORMAL
);
6252 return (t
&& ! ICS_BAD_FLAG (t
));
6256 struct harshness_code h
;
6257 h
= convert_harshness (to
, from
, arg
);
6258 return (h
.code
< USER_CODE
) && (h
.distance
>= 0);