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
, 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
*));
106 #define EVIL_RETURN(ARG) ((ARG).code = EVIL_CODE, (ARG))
107 #define STD_RETURN(ARG) ((ARG).code = STD_CODE, (ARG))
108 #define QUAL_RETURN(ARG) ((ARG).code = QUAL_CODE, (ARG))
109 #define TRIVIAL_RETURN(ARG) ((ARG).code = TRIVIAL_CODE, (ARG))
110 #define ZERO_RETURN(ARG) ((ARG).code = 0, (ARG))
112 /* Ordering function for overload resolution. Compare two candidates
116 rank_for_overload (x
, y
)
117 struct candidate
*x
, *y
;
119 if (y
->h
.code
& (EVIL_CODE
|ELLIPSIS_CODE
|USER_CODE
))
120 return y
->h
.code
- x
->h
.code
;
121 if (x
->h
.code
& (EVIL_CODE
|ELLIPSIS_CODE
|USER_CODE
))
124 /* This is set by compute_conversion_costs, for calling a non-const
125 member function from a const member function. */
126 if ((y
->harshness
[0].code
& CONST_CODE
) ^ (x
->harshness
[0].code
& CONST_CODE
))
127 return y
->harshness
[0].code
- x
->harshness
[0].code
;
129 if (y
->h
.code
& STD_CODE
)
131 if (x
->h
.code
& STD_CODE
)
132 return y
->h
.distance
- x
->h
.distance
;
135 if (x
->h
.code
& STD_CODE
)
138 return y
->h
.code
- x
->h
.code
;
141 /* Compare two candidates, argument by argument. */
144 rank_for_ideal (x
, y
)
145 struct candidate
*x
, *y
;
149 if (x
->h_len
!= y
->h_len
)
152 for (i
= 0; i
< x
->h_len
; i
++)
154 if (y
->harshness
[i
].code
- x
->harshness
[i
].code
)
155 return y
->harshness
[i
].code
- x
->harshness
[i
].code
;
156 if ((y
->harshness
[i
].code
& STD_CODE
)
157 && (y
->harshness
[i
].distance
- x
->harshness
[i
].distance
))
158 return y
->harshness
[i
].distance
- x
->harshness
[i
].distance
;
160 /* They're both the same code. Now see if we're dealing with an
161 integral promotion that needs a finer grain of accuracy. */
162 if (y
->harshness
[0].code
& PROMO_CODE
163 && (y
->harshness
[i
].int_penalty
^ x
->harshness
[i
].int_penalty
))
164 return y
->harshness
[i
].int_penalty
- x
->harshness
[i
].int_penalty
;
169 /* TYPE is the type we wish to convert to. PARM is the parameter
170 we have to work with. We use a somewhat arbitrary cost function
171 to measure this conversion. */
173 static struct harshness_code
174 convert_harshness (type
, parmtype
, parm
)
175 register tree type
, parmtype
;
178 struct harshness_code h
;
179 register enum tree_code codel
;
180 register enum tree_code coder
;
187 #ifdef GATHER_STATISTICS
188 n_convert_harshness
++;
191 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
)
194 parm
= convert_from_reference (parm
);
195 parmtype
= TREE_TYPE (parmtype
);
199 lvalue
= lvalue_p (parm
);
203 if (TYPE_PTRMEMFUNC_P (type
))
204 type
= TYPE_PTRMEMFUNC_FN_TYPE (type
);
205 if (TYPE_PTRMEMFUNC_P (parmtype
))
206 parmtype
= TYPE_PTRMEMFUNC_FN_TYPE (parmtype
);
208 codel
= TREE_CODE (type
);
209 coder
= TREE_CODE (parmtype
);
211 if (TYPE_MAIN_VARIANT (parmtype
) == TYPE_MAIN_VARIANT (type
))
212 return ZERO_RETURN (h
);
214 if (coder
== ERROR_MARK
)
215 return EVIL_RETURN (h
);
217 if (codel
== REFERENCE_TYPE
)
220 int constp
= parm
? TREE_READONLY (parm
) : TYPE_READONLY (parmtype
);
221 int volatilep
= (parm
? TREE_THIS_VOLATILE (parm
)
222 : TYPE_VOLATILE (parmtype
));
223 register tree intype
= TYPE_MAIN_VARIANT (parmtype
);
224 register enum tree_code form
= TREE_CODE (intype
);
227 ttl
= TREE_TYPE (type
);
229 /* Only allow const reference binding if we were given a parm to deal
230 with, since it isn't really a conversion. This is a hack to
231 prevent build_type_conversion from finding this conversion, but
232 still allow overloading to find it. */
233 if (! lvalue
&& ! (parm
&& TYPE_READONLY (ttl
)))
234 return EVIL_RETURN (h
);
236 if ((TYPE_READONLY (ttl
) < constp
)
237 || (TYPE_VOLATILE (ttl
) < volatilep
))
238 return EVIL_RETURN (h
);
240 /* When passing a non-const argument into a const reference, dig it a
241 little, so a non-const reference is preferred over this one. */
242 penalty
= ((TYPE_READONLY (ttl
) > constp
)
243 + (TYPE_VOLATILE (ttl
) > volatilep
));
245 ttl
= TYPE_MAIN_VARIANT (ttl
);
247 if (form
== OFFSET_TYPE
)
249 intype
= TREE_TYPE (intype
);
250 form
= TREE_CODE (intype
);
255 if (TREE_CODE (ttl
) == ARRAY_TYPE
&& TREE_CODE (ttr
) == ARRAY_TYPE
)
257 if (comptypes (ttl
, ttr
, 1))
258 return ZERO_RETURN (h
);
259 return EVIL_RETURN (h
);
262 h
= convert_harshness (ttl
, ttr
, NULL_TREE
);
263 if (penalty
&& h
.code
== 0)
266 h
.int_penalty
= penalty
;
271 if (codel
== POINTER_TYPE
&& fntype_p (parmtype
))
274 struct harshness_code h1
, h2
;
276 /* Get to the METHOD_TYPE or FUNCTION_TYPE that this might be. */
277 type
= TREE_TYPE (type
);
279 if (coder
== POINTER_TYPE
)
281 parmtype
= TREE_TYPE (parmtype
);
282 coder
= TREE_CODE (parmtype
);
285 if (coder
!= TREE_CODE (type
))
286 return EVIL_RETURN (h
);
288 if (type
!= parmtype
&& coder
== METHOD_TYPE
)
290 tree ttl
= TYPE_METHOD_BASETYPE (type
);
291 tree ttr
= TYPE_METHOD_BASETYPE (parmtype
);
293 int b_or_d
= get_base_distance (ttr
, ttl
, 0, (tree
*)0);
296 b_or_d
= get_base_distance (ttl
, ttr
, 0, (tree
*)0);
298 return EVIL_RETURN (h
);
299 h
.distance
= -b_or_d
;
305 type
= build_function_type
306 (TREE_TYPE (type
), TREE_CHAIN (TYPE_ARG_TYPES (type
)));
307 parmtype
= build_function_type
308 (TREE_TYPE (parmtype
), TREE_CHAIN (TYPE_ARG_TYPES (parmtype
)));
311 /* We allow the default conversion between function type
312 and pointer-to-function type for free. */
313 if (comptypes (type
, parmtype
, 1))
317 return EVIL_RETURN (h
);
319 /* Compare return types. */
320 p1
= TREE_TYPE (type
);
321 p2
= TREE_TYPE (parmtype
);
322 h2
= convert_harshness (p1
, p2
, NULL_TREE
);
323 if (h2
.code
& EVIL_CODE
)
326 h1
.code
= TRIVIAL_CODE
;
329 if (h2
.distance
!= 0)
333 /* This only works for pointers. */
334 if (TREE_CODE (p1
) != POINTER_TYPE
335 && TREE_CODE (p1
) != REFERENCE_TYPE
)
336 return EVIL_RETURN (h
);
340 /* Don't die if we happen to be dealing with void*. */
341 if (!IS_AGGR_TYPE (p1
) || !IS_AGGR_TYPE (p2
))
342 return EVIL_RETURN (h
);
344 binfo
= get_binfo (p2
, p1
, 0);
346 binfo
= get_binfo (p1
, p2
, 0);
348 if (! BINFO_OFFSET_ZEROP (binfo
))
351 static int explained
= 0;
353 message_2_types (sorry
, "cannot cast `%s' to `%s' at function call site", p2
, p1
);
355 message_2_types (sorry
, "cannot cast `%s' to `%s' at function call site", p1
, p2
);
358 sorry ("(because pointer values change during conversion)");
360 return EVIL_RETURN (h
);
365 if (h2
.distance
> h1
.distance
)
366 h1
.distance
= h2
.distance
;
368 p1
= TYPE_ARG_TYPES (type
);
369 p2
= TYPE_ARG_TYPES (parmtype
);
370 while (p1
&& TREE_VALUE (p1
) != void_type_node
371 && p2
&& TREE_VALUE (p2
) != void_type_node
)
373 h2
= convert_harshness (TREE_VALUE (p1
), TREE_VALUE (p2
),
375 if (h2
.code
& EVIL_CODE
)
380 /* This only works for pointers and references. */
381 if (TREE_CODE (TREE_VALUE (p1
)) != POINTER_TYPE
382 && TREE_CODE (TREE_VALUE (p1
)) != REFERENCE_TYPE
)
383 return EVIL_RETURN (h
);
384 h2
.distance
= - h2
.distance
;
388 if (h2
.distance
> h1
.distance
)
389 h1
.distance
= h2
.distance
;
390 p1
= TREE_CHAIN (p1
);
391 p2
= TREE_CHAIN (p2
);
398 return EVIL_RETURN (h
);
399 h1
.code
|= ELLIPSIS_CODE
;
404 if (TREE_PURPOSE (p1
) == NULL_TREE
)
405 h1
.code
|= EVIL_CODE
;
409 else if (codel
== POINTER_TYPE
&& coder
== OFFSET_TYPE
)
413 /* Get to the OFFSET_TYPE that this might be. */
414 type
= TREE_TYPE (type
);
416 if (coder
!= TREE_CODE (type
))
417 return EVIL_RETURN (h
);
419 ttl
= TYPE_OFFSET_BASETYPE (type
);
420 ttr
= TYPE_OFFSET_BASETYPE (parmtype
);
426 int b_or_d
= get_base_distance (ttr
, ttl
, 0, (tree
*)0);
429 b_or_d
= get_base_distance (ttl
, ttr
, 0, (tree
*)0);
431 return EVIL_RETURN (h
);
432 h
.distance
= -b_or_d
;
439 /* Now test the OFFSET_TYPE's target compatibility. */
440 type
= TREE_TYPE (type
);
441 parmtype
= TREE_TYPE (parmtype
);
444 if (coder
== UNKNOWN_TYPE
)
446 if (codel
== FUNCTION_TYPE
447 || codel
== METHOD_TYPE
448 || (codel
== POINTER_TYPE
449 && (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
450 || TREE_CODE (TREE_TYPE (type
)) == METHOD_TYPE
)))
451 return TRIVIAL_RETURN (h
);
452 return EVIL_RETURN (h
);
455 if (coder
== VOID_TYPE
)
456 return EVIL_RETURN (h
);
458 if (codel
== BOOLEAN_TYPE
)
460 if (INTEGRAL_CODE_P (coder
) || coder
== REAL_TYPE
)
461 return STD_RETURN (h
);
462 else if (coder
== POINTER_TYPE
|| coder
== OFFSET_TYPE
)
464 /* Make this worse than any conversion to another pointer.
465 FIXME this is how I think the language should work, but it may not
466 end up being how the language is standardized (jason 1/30/95). */
468 return STD_RETURN (h
);
470 return EVIL_RETURN (h
);
473 if (INTEGRAL_CODE_P (codel
))
475 /* Control equivalence of ints an enums. */
477 if (codel
== ENUMERAL_TYPE
478 && flag_int_enum_equivalence
== 0)
480 /* Enums can be converted to ints, but not vice-versa. */
481 if (coder
!= ENUMERAL_TYPE
482 || TYPE_MAIN_VARIANT (type
) != TYPE_MAIN_VARIANT (parmtype
))
483 return EVIL_RETURN (h
);
486 /* else enums and ints (almost) freely interconvert. */
488 if (INTEGRAL_CODE_P (coder
))
490 if (TYPE_MAIN_VARIANT (type
)
491 == TYPE_MAIN_VARIANT (type_promotes_to (parmtype
)))
500 else if (coder
== REAL_TYPE
)
508 if (codel
== REAL_TYPE
)
510 if (coder
== REAL_TYPE
)
512 if (TYPE_MAIN_VARIANT (type
)
513 == TYPE_MAIN_VARIANT (type_promotes_to (parmtype
)))
520 else if (INTEGRAL_CODE_P (coder
))
528 /* Convert arrays which have not previously been converted. */
529 if (coder
== ARRAY_TYPE
)
531 coder
= POINTER_TYPE
;
534 parm
= decay_conversion (parm
);
535 parmtype
= TREE_TYPE (parm
);
538 parmtype
= build_pointer_type (TREE_TYPE (parmtype
));
541 /* Conversions among pointers */
542 if (codel
== POINTER_TYPE
&& coder
== POINTER_TYPE
)
544 register tree ttl
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
545 register tree ttr
= TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
));
546 int penalty
= 4 * (ttl
!= ttr
);
548 /* Anything converts to void *. Since this may be `const void *'
549 (etc.) use VOID_TYPE instead of void_type_node. Otherwise, the
550 targets must be the same, except that we do allow (at some cost)
551 conversion between signed and unsigned pointer types. */
553 if ((TREE_CODE (ttl
) == METHOD_TYPE
554 || TREE_CODE (ttl
) == FUNCTION_TYPE
)
555 && TREE_CODE (ttl
) == TREE_CODE (ttr
))
557 if (comptypes (ttl
, ttr
, -1))
559 h
.code
= penalty
? STD_CODE
: 0;
568 if (TREE_CODE (ttl
) != VOID_TYPE
569 && (TREE_CODE (ttr
) != VOID_TYPE
|| !parm
|| !null_ptr_cst_p (parm
)))
571 if (comp_target_types (type
, parmtype
, 1) <= 0)
572 return EVIL_RETURN (h
);
575 if (!(TREE_CODE (ttl
) == VOID_TYPE
576 || TREE_CODE (ttr
) == VOID_TYPE
577 || (TREE_UNSIGNED (ttl
) ^ TREE_UNSIGNED (ttr
)
578 && (ttl
= unsigned_type (ttl
),
579 ttr
= unsigned_type (ttr
),
581 || (comp_target_types (ttl
, ttr
, 0) > 0)))
582 return EVIL_RETURN (h
);
587 tree tmp1
= TREE_TYPE (type
), tmp2
= TREE_TYPE (parmtype
);
590 /* Note conversion from `T*' to `const T*',
591 or `T*' to `volatile T*'. */
592 if ((TYPE_READONLY (tmp1
) < TREE_READONLY (tmp2
))
593 || (TYPE_VOLATILE (tmp1
) < TYPE_VOLATILE (tmp2
)))
595 else if ((TYPE_READONLY (tmp1
) != TREE_READONLY (tmp2
))
596 || (TYPE_VOLATILE (tmp1
) != TYPE_VOLATILE (tmp2
)))
604 if (TREE_CODE (ttl
) == RECORD_TYPE
&& TREE_CODE (ttr
) == RECORD_TYPE
)
606 int b_or_d
= get_base_distance (ttl
, ttr
, 0, (tree
*)0);
609 b_or_d
= get_base_distance (ttr
, ttl
, 0, (tree
*)0);
611 return EVIL_RETURN (h
);
612 h
.distance
= -b_or_d
;
620 /* If converting from a `class*' to a `void*', make it
621 less favorable than any inheritance relationship. */
622 if (TREE_CODE (ttl
) == VOID_TYPE
&& IS_AGGR_TYPE (ttr
))
625 h
.distance
= CLASSTYPE_MAX_DEPTH (ttr
)+1;
629 h
.code
= penalty
? STD_CODE
: PROMO_CODE
;
630 /* Catch things like `const char *' -> `const void *'
631 vs `const char *' -> `void *'. */
634 tree tmp1
= TREE_TYPE (type
), tmp2
= TREE_TYPE (parmtype
);
635 if ((TYPE_READONLY (tmp1
) < TREE_READONLY (tmp2
))
636 || (TYPE_VOLATILE (tmp1
) < TYPE_VOLATILE (tmp2
)))
638 else if ((TYPE_READONLY (tmp1
) > TREE_READONLY (tmp2
))
639 || (TYPE_VOLATILE (tmp1
) > TYPE_VOLATILE (tmp2
)))
645 if (codel
== POINTER_TYPE
&& coder
== INTEGER_TYPE
)
647 /* This is not a bad match, but don't let it beat
648 integer-enum combinations. */
649 if (parm
&& integer_zerop (parm
))
657 /* C++: Since the `this' parameter of a signature member function
658 is represented as a signature pointer to handle default implementations
659 correctly, we can have the case that `type' is a signature pointer
660 while `parmtype' is a pointer to a signature table. We don't really
661 do any conversions in this case, so just return 0. */
663 if (codel
== RECORD_TYPE
&& coder
== POINTER_TYPE
664 && IS_SIGNATURE_POINTER (type
) && IS_SIGNATURE (TREE_TYPE (parmtype
)))
665 return ZERO_RETURN (h
);
667 if (codel
== RECORD_TYPE
&& coder
== RECORD_TYPE
)
669 int b_or_d
= get_base_distance (type
, parmtype
, 0, (tree
*)0);
672 b_or_d
= get_base_distance (parmtype
, type
, 0, (tree
*)0);
674 return EVIL_RETURN (h
);
675 h
.distance
= -b_or_d
;
682 return EVIL_RETURN (h
);
685 /* A clone of build_type_conversion for checking user-defined conversions in
686 overload resolution. */
689 user_harshness (type
, parmtype
)
690 register tree type
, parmtype
;
693 tree winner
= NULL_TREE
;
697 tree typename
= build_typename_overload (type
);
698 if (lookup_fnfields (TYPE_BINFO (parmtype
), typename
, 0))
702 for (conv
= lookup_conversions (parmtype
); conv
; conv
= TREE_CHAIN (conv
))
704 struct harshness_code tmp
;
705 tree cand
= TREE_VALUE (conv
);
707 if (winner
&& winner
== cand
)
710 tmp
= convert_harshness (type
, TREE_TYPE (TREE_TYPE (cand
)), NULL_TREE
);
711 if ((tmp
.code
< USER_CODE
) && (tmp
.distance
>= 0))
729 #ifdef DEBUG_MATCHING
732 struct harshness_code
*h
;
734 static char buf
[1024];
737 bzero (buf
, 1024 * sizeof (char));
738 strcat (buf
, "codes=[");
739 if (h
->code
& EVIL_CODE
)
740 strcat (buf
, "EVIL");
741 if (h
->code
& CONST_CODE
)
742 strcat (buf
, " CONST");
743 if (h
->code
& ELLIPSIS_CODE
)
744 strcat (buf
, " ELLIPSIS");
745 if (h
->code
& USER_CODE
)
746 strcat (buf
, " USER");
747 if (h
->code
& STD_CODE
)
748 strcat (buf
, " STD");
749 if (h
->code
& PROMO_CODE
)
750 strcat (buf
, " PROMO");
751 if (h
->code
& QUAL_CODE
)
752 strcat (buf
, " QUAL");
753 if (h
->code
& TRIVIAL_CODE
)
754 strcat (buf
, " TRIVIAL");
758 sprintf (tmp
, "] distance=%d int_penalty=%d", h
->distance
, h
->int_penalty
);
766 /* Algorithm: For each argument, calculate how difficult it is to
767 make FUNCTION accept that argument. If we can easily tell that
768 FUNCTION won't be acceptable to one of the arguments, then we
769 don't need to compute the ease of converting the other arguments,
770 since it will never show up in the intersection of all arguments'
773 Conversions between builtin and user-defined types are allowed, but
774 no function involving such a conversion is preferred to one which
775 does not require such a conversion. Furthermore, such conversions
779 compute_conversion_costs (function
, tta_in
, cp
, arglen
)
782 struct candidate
*cp
;
785 tree ttf_in
= TYPE_ARG_TYPES (TREE_TYPE (function
));
789 /* Start out with no strikes against. */
790 int evil_strikes
= 0;
791 int ellipsis_strikes
= 0;
792 int user_strikes
= 0;
793 int b_or_d_strikes
= 0;
794 int easy_strikes
= 0;
796 int strike_index
= 0, win
;
797 struct harshness_code lose
;
798 extern int cp_silent
;
800 #ifdef GATHER_STATISTICS
801 n_compute_conversion_costs
++;
804 #ifndef DEBUG_MATCHING
805 /* We don't emit any warnings or errors while trying out each candidate. */
809 cp
->function
= function
;
810 cp
->arg
= tta
? TREE_VALUE (tta
) : NULL_TREE
;
811 cp
->u
.bad_arg
= 0; /* optimistic! */
815 cp
->h
.int_penalty
= 0;
816 bzero ((char *) cp
->harshness
,
817 (cp
->h_len
+ 1) * sizeof (struct harshness_code
));
821 struct harshness_code h
;
823 if (ttf
== void_list_node
)
826 if (type_unknown_p (TREE_VALUE (tta
)))
828 /* Must perform some instantiation here. */
829 tree rhs
= TREE_VALUE (tta
);
830 tree lhstype
= TREE_VALUE (ttf
);
832 /* Keep quiet about possible contravariance violations. */
833 int old_inhibit_warnings
= inhibit_warnings
;
834 inhibit_warnings
= 1;
836 /* @@ This is to undo what `grokdeclarator' does to
837 parameter types. It really should go through
838 something more general. */
840 TREE_TYPE (tta
) = unknown_type_node
;
841 rhs
= instantiate_type (lhstype
, rhs
, 0);
842 inhibit_warnings
= old_inhibit_warnings
;
844 if (TREE_CODE (rhs
) == ERROR_MARK
)
847 h
= convert_harshness (lhstype
, TREE_TYPE (rhs
), rhs
);
851 #ifdef DEBUG_MATCHING
852 static tree old_function
= NULL_TREE
;
854 if (!old_function
|| function
!= old_function
)
856 cp_error ("trying %D", function
);
857 old_function
= function
;
860 cp_error (" doing (%T) %E against arg %T",
861 TREE_TYPE (TREE_VALUE (tta
)), TREE_VALUE (tta
),
865 h
= convert_harshness (TREE_VALUE (ttf
),
866 TREE_TYPE (TREE_VALUE (tta
)),
869 #ifdef DEBUG_MATCHING
870 cp_error (" evaluated %s", print_harshness (&h
));
874 cp
->harshness
[strike_index
] = h
;
875 if ((h
.code
& EVIL_CODE
)
876 || ((h
.code
& STD_CODE
) && h
.distance
< 0))
878 cp
->u
.bad_arg
= strike_index
;
881 else if (h
.code
& ELLIPSIS_CODE
)
882 ellipsis_strikes
+= 1;
884 /* This is never set by `convert_harshness'. */
885 else if (h
.code
& USER_CODE
)
892 if ((h
.code
& STD_CODE
) && h
.distance
)
894 if (h
.distance
> b_or_d_strikes
)
895 b_or_d_strikes
= h
.distance
;
898 easy_strikes
+= (h
.code
& (STD_CODE
|PROMO_CODE
|TRIVIAL_CODE
));
899 cp
->h
.code
|= h
.code
;
900 /* Make sure we communicate this. */
901 cp
->h
.int_penalty
+= h
.int_penalty
;
904 ttf
= TREE_CHAIN (ttf
);
905 tta
= TREE_CHAIN (tta
);
911 /* ran out of formals, and parmlist is fixed size. */
912 if (ttf
/* == void_type_node */)
914 cp
->h
.code
= EVIL_CODE
;
921 struct harshness_code h
;
922 int l
= list_length (tta
);
923 ellipsis_strikes
+= l
;
924 h
.code
= ELLIPSIS_CODE
;
928 cp
->harshness
[strike_index
++] = h
;
931 else if (ttf
&& ttf
!= void_list_node
)
933 /* ran out of actuals, and no defaults. */
934 if (TREE_PURPOSE (ttf
) == NULL_TREE
)
936 cp
->h
.code
= EVIL_CODE
;
941 /* Store index of first default. */
942 cp
->harshness
[arglen
].distance
= strike_index
+1;
945 cp
->harshness
[arglen
].distance
= 0;
947 /* Argument list lengths work out, so don't need to check them again. */
950 /* We do not check for derived->base conversions here, since in
951 no case would they give evil strike counts, unless such conversions
952 are somehow ambiguous. */
954 /* See if any user-defined conversions apply.
955 But make sure that we do not loop. */
956 static int dont_convert_types
= 0;
958 if (dont_convert_types
)
960 cp
->h
.code
= EVIL_CODE
;
965 win
= 0; /* Only get one chance to win. */
966 ttf
= TYPE_ARG_TYPES (TREE_TYPE (function
));
973 if (ttf
== void_list_node
)
976 lose
= cp
->harshness
[strike_index
];
977 if ((lose
.code
& EVIL_CODE
)
978 || ((lose
.code
& STD_CODE
) && lose
.distance
< 0))
980 tree actual_type
= TREE_TYPE (TREE_VALUE (tta
));
981 tree formal_type
= TREE_VALUE (ttf
);
982 int extra_conversions
= 0;
984 dont_convert_types
= 1;
986 if (TREE_CODE (formal_type
) == REFERENCE_TYPE
)
987 formal_type
= TREE_TYPE (formal_type
);
988 if (TREE_CODE (actual_type
) == REFERENCE_TYPE
)
989 actual_type
= TREE_TYPE (actual_type
);
991 if (formal_type
!= error_mark_node
992 && actual_type
!= error_mark_node
)
994 formal_type
= complete_type (TYPE_MAIN_VARIANT (formal_type
));
995 actual_type
= complete_type (TYPE_MAIN_VARIANT (actual_type
));
997 if (TYPE_HAS_CONSTRUCTOR (formal_type
))
999 /* If it has a constructor for this type,
1001 /* @@ There is no way to save this result yet, so
1002 success is a NULL_TREE for now. */
1003 if (convert_to_aggr (formal_type
, TREE_VALUE (tta
), 0, 1)
1007 if (TYPE_LANG_SPECIFIC (actual_type
)
1008 && TYPE_HAS_CONVERSION (actual_type
))
1010 int extra
= user_harshness (formal_type
, actual_type
);
1012 if (extra
== EVIL_CODE
)
1014 else if (extra
>= 0)
1017 extra_conversions
= extra
;
1021 dont_convert_types
= 0;
1026 cp
->harshness
[strike_index
].code
1027 = USER_CODE
| (extra_conversions
? STD_CODE
: 0);
1032 if (cp
->u
.bad_arg
> strike_index
)
1033 cp
->u
.bad_arg
= strike_index
;
1035 evil_strikes
= win
? 2 : 1;
1040 ttf
= TREE_CHAIN (ttf
);
1041 tta
= TREE_CHAIN (tta
);
1046 /* Const member functions get a small penalty because defaulting
1047 to const is less useful than defaulting to non-const. */
1048 /* This is bogus, it does not correspond to anything in the ARM.
1049 This code will be fixed when this entire section is rewritten
1050 to conform to the ARM. (mrs) */
1051 if (TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
1053 tree this_parm
= TREE_VALUE (ttf_in
);
1055 if (TREE_CODE (this_parm
) == RECORD_TYPE
/* Is `this' a sig ptr? */
1056 ? TYPE_READONLY (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (this_parm
))))
1057 : TYPE_READONLY (TREE_TYPE (this_parm
)))
1059 cp
->harshness
[0].code
|= TRIVIAL_CODE
;
1064 /* Calling a non-const member function from a const member function
1065 is probably invalid, but for now we let it only draw a warning.
1066 We indicate that such a mismatch has occurred by setting the
1067 harshness to a maximum value. */
1068 if (TREE_CODE (TREE_TYPE (TREE_VALUE (tta_in
))) == POINTER_TYPE
1069 && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (TREE_VALUE (tta_in
))))))
1070 cp
->harshness
[0].code
|= CONST_CODE
;
1075 cp
->h
.code
= EVIL_CODE
;
1076 if (ellipsis_strikes
)
1077 cp
->h
.code
|= ELLIPSIS_CODE
;
1079 cp
->h
.code
|= USER_CODE
;
1081 #ifdef DEBUG_MATCHING
1082 cp_error ("final eval %s", print_harshness (&cp
->h
));
1086 /* Subroutine of ideal_candidate. See if X or Y is a better match
1090 strictly_better (x
, y
)
1099 if (xor >= x
|| xor >= y
)
1104 /* When one of several possible overloaded functions and/or methods
1105 can be called, choose the best candidate for overloading.
1107 BASETYPE is the context from which we start method resolution
1108 or NULL if we are comparing overloaded functions.
1109 CANDIDATES is the array of candidates we have to choose from.
1110 N_CANDIDATES is the length of CANDIDATES.
1111 PARMS is a TREE_LIST of parameters to the function we'll ultimately
1112 choose. It is modified in place when resolving methods. It is not
1113 modified in place when resolving overloaded functions.
1114 LEN is the length of the parameter list. */
1116 static struct candidate
*
1117 ideal_candidate (candidates
, n_candidates
, len
)
1118 struct candidate
*candidates
;
1122 struct candidate
*cp
= candidates
+n_candidates
;
1123 int i
, j
= -1, best_code
;
1125 /* For each argument, sort the functions from best to worst for the arg.
1126 For each function that's not best for this arg, set its overall
1127 harshness to EVIL so that other args won't like it. The candidate
1128 list for the last argument is the intersection of all the best-liked
1131 qsort (candidates
, n_candidates
, sizeof (struct candidate
),
1132 (int (*) PROTO((const void *, const void *))) rank_for_overload
);
1133 best_code
= cp
[-1].h
.code
;
1135 /* If they're at least as good as each other, do an arg-by-arg check. */
1136 if (! strictly_better (cp
[-1].h
.code
, cp
[-2].h
.code
))
1141 for (j
= 0; j
< n_candidates
; j
++)
1142 if (! strictly_better (candidates
[j
].h
.code
, best_code
))
1145 qsort (candidates
+j
, n_candidates
-j
, sizeof (struct candidate
),
1146 (int (*) PROTO((const void *, const void *))) rank_for_ideal
);
1147 for (i
= 0; i
< len
; i
++)
1149 if (cp
[-1].harshness
[i
].code
< cp
[-2].harshness
[i
].code
)
1151 else if (cp
[-1].harshness
[i
].code
> cp
[-2].harshness
[i
].code
)
1153 else if (cp
[-1].harshness
[i
].code
& STD_CODE
)
1155 /* If it involves a standard conversion, let the
1156 inheritance lattice be the final arbiter. */
1157 if (cp
[-1].harshness
[i
].distance
> cp
[-2].harshness
[i
].distance
)
1159 else if (cp
[-1].harshness
[i
].distance
< cp
[-2].harshness
[i
].distance
)
1162 else if (cp
[-1].harshness
[i
].code
& PROMO_CODE
)
1164 /* For integral promotions, take into account a finer
1165 granularity for determining which types should be favored
1166 over others in such promotions. */
1167 if (cp
[-1].harshness
[i
].int_penalty
> cp
[-2].harshness
[i
].int_penalty
)
1169 else if (cp
[-1].harshness
[i
].int_penalty
< cp
[-2].harshness
[i
].int_penalty
)
1174 if (! better
|| worse
)
1180 /* Assume that if the class referred to is not in the
1181 current class hierarchy, that it may be remote.
1182 PARENT is assumed to be of aggregate type here. */
1185 may_be_remote (parent
)
1188 if (TYPE_OVERLOADS_METHOD_CALL_EXPR (parent
) == 0)
1191 if (current_class_type
== NULL_TREE
)
1194 if (parent
== current_class_type
)
1197 if (UNIQUELY_DERIVED_FROM_P (parent
, current_class_type
))
1203 build_vfield_ref (datum
, type
)
1207 int old_assume_nonnull_objects
= flag_assume_nonnull_objects
;
1209 if (datum
== error_mark_node
)
1210 return error_mark_node
;
1212 /* Vtable references are always made from non-null objects. */
1213 flag_assume_nonnull_objects
= 1;
1214 if (TREE_CODE (TREE_TYPE (datum
)) == REFERENCE_TYPE
)
1215 datum
= convert_from_reference (datum
);
1217 if (! TYPE_USES_COMPLEX_INHERITANCE (type
))
1218 rval
= build (COMPONENT_REF
, TREE_TYPE (CLASSTYPE_VFIELD (type
)),
1219 datum
, CLASSTYPE_VFIELD (type
));
1221 rval
= build_component_ref (datum
, DECL_NAME (CLASSTYPE_VFIELD (type
)), NULL_TREE
, 0);
1222 flag_assume_nonnull_objects
= old_assume_nonnull_objects
;
1227 /* Build a call to a member of an object. I.e., one that overloads
1228 operator ()(), or is a pointer-to-function or pointer-to-method. */
1231 build_field_call (basetype_path
, instance_ptr
, name
, parms
)
1232 tree basetype_path
, instance_ptr
, name
, parms
;
1234 tree field
, instance
;
1236 if (name
== ctor_identifier
|| name
== dtor_identifier
)
1239 if (instance_ptr
== current_class_ptr
)
1241 /* Check to see if we really have a reference to an instance variable
1242 with `operator()()' overloaded. */
1243 field
= IDENTIFIER_CLASS_VALUE (name
);
1245 if (field
== NULL_TREE
)
1247 cp_error ("`this' has no member named `%D'", name
);
1248 return error_mark_node
;
1251 if (TREE_CODE (field
) == FIELD_DECL
)
1253 /* If it's a field, try overloading operator (),
1254 or calling if the field is a pointer-to-function. */
1255 instance
= build_component_ref_1 (current_class_ref
, field
, 0);
1256 if (instance
== error_mark_node
)
1257 return error_mark_node
;
1259 if (TYPE_LANG_SPECIFIC (TREE_TYPE (instance
))
1260 && (TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (instance
))
1261 || flag_ansi_overloading
))
1262 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
, instance
, parms
, NULL_TREE
);
1264 if (TREE_CODE (TREE_TYPE (instance
)) == POINTER_TYPE
)
1266 if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == FUNCTION_TYPE
)
1267 return build_function_call (instance
, parms
);
1268 else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance
))) == METHOD_TYPE
)
1269 return build_function_call (instance
, tree_cons (NULL_TREE
, current_class_ptr
, parms
));
1275 /* Check to see if this is not really a reference to an instance variable
1276 with `operator()()' overloaded. */
1277 field
= lookup_field (basetype_path
, name
, 1, 0);
1279 /* This can happen if the reference was ambiguous or for access
1281 if (field
== error_mark_node
)
1282 return error_mark_node
;
1287 tree ftype
= TREE_TYPE (field
);
1289 if (TREE_CODE (ftype
) == REFERENCE_TYPE
)
1290 ftype
= TREE_TYPE (ftype
);
1292 if (TYPE_LANG_SPECIFIC (ftype
)
1293 && (TYPE_OVERLOADS_CALL_EXPR (ftype
) || flag_ansi_overloading
))
1295 /* Make the next search for this field very short. */
1296 basetype
= DECL_FIELD_CONTEXT (field
);
1297 instance_ptr
= convert_pointer_to (basetype
, instance_ptr
);
1299 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
1300 return build_opfncall (CALL_EXPR
, LOOKUP_NORMAL
,
1301 build_component_ref_1 (instance
, field
, 0),
1304 if (TREE_CODE (ftype
) == POINTER_TYPE
)
1306 if (TREE_CODE (TREE_TYPE (ftype
)) == FUNCTION_TYPE
1307 || TREE_CODE (TREE_TYPE (ftype
)) == METHOD_TYPE
)
1309 /* This is a member which is a pointer to function. */
1311 = build_component_ref_1 (build_indirect_ref (instance_ptr
,
1313 field
, LOOKUP_COMPLAIN
);
1314 if (ref
== error_mark_node
)
1315 return error_mark_node
;
1316 return build_function_call (ref
, parms
);
1319 else if (TREE_CODE (ftype
) == METHOD_TYPE
)
1321 error ("invalid call via pointer-to-member function");
1322 return error_mark_node
;
1331 find_scoped_type (type
, inner_name
, inner_types
)
1332 tree type
, inner_name
, inner_types
;
1334 tree tags
= CLASSTYPE_TAGS (type
);
1338 /* The TREE_PURPOSE of an enum tag (which becomes a member of the
1339 enclosing class) is set to the name for the enum type. So, if
1340 inner_name is `bar', and we strike `baz' for `enum bar { baz }',
1341 then this test will be true. */
1342 if (TREE_PURPOSE (tags
) == inner_name
)
1344 if (inner_types
== NULL_TREE
)
1345 return TYPE_MAIN_DECL (TREE_VALUE (tags
));
1346 return resolve_scope_to_name (TREE_VALUE (tags
), inner_types
);
1348 tags
= TREE_CHAIN (tags
);
1351 /* Look for a TYPE_DECL. */
1352 for (tags
= TYPE_FIELDS (type
); tags
; tags
= TREE_CHAIN (tags
))
1353 if (TREE_CODE (tags
) == TYPE_DECL
&& DECL_NAME (tags
) == inner_name
)
1355 /* Code by raeburn. */
1356 if (inner_types
== NULL_TREE
)
1358 return resolve_scope_to_name (TREE_TYPE (tags
), inner_types
);
1364 /* Resolve an expression NAME1::NAME2::...::NAMEn to
1365 the name that names the above nested type. INNER_TYPES
1366 is a chain of nested type names (held together by SCOPE_REFs);
1367 OUTER_TYPE is the type we know to enclose INNER_TYPES.
1368 Returns NULL_TREE if there is an error. */
1371 resolve_scope_to_name (outer_type
, inner_stuff
)
1372 tree outer_type
, inner_stuff
;
1375 tree inner_name
, inner_type
;
1377 if (outer_type
== NULL_TREE
&& current_class_type
!= NULL_TREE
)
1379 /* We first try to look for a nesting in our current class context,
1380 then try any enclosing classes. */
1381 tree type
= current_class_type
;
1383 while (type
&& (TREE_CODE (type
) == RECORD_TYPE
1384 || TREE_CODE (type
) == UNION_TYPE
))
1386 tree rval
= resolve_scope_to_name (type
, inner_stuff
);
1388 if (rval
!= NULL_TREE
)
1390 type
= DECL_CONTEXT (TYPE_MAIN_DECL (type
));
1394 if (TREE_CODE (inner_stuff
) == SCOPE_REF
)
1396 inner_name
= TREE_OPERAND (inner_stuff
, 0);
1397 inner_type
= TREE_OPERAND (inner_stuff
, 1);
1401 inner_name
= inner_stuff
;
1402 inner_type
= NULL_TREE
;
1405 if (outer_type
== NULL_TREE
)
1408 /* If we have something that's already a type by itself,
1410 if (IDENTIFIER_HAS_TYPE_VALUE (inner_name
))
1413 return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name
),
1418 x
= lookup_name (inner_name
, 0);
1420 if (x
&& TREE_CODE (x
) == NAMESPACE_DECL
)
1422 x
= lookup_namespace_name (x
, inner_type
);
1428 if (! IS_AGGR_TYPE (outer_type
))
1431 /* Look for member classes or enums. */
1432 tmp
= find_scoped_type (outer_type
, inner_name
, inner_type
);
1434 /* If it's not a type in this class, then go down into the
1435 base classes and search there. */
1436 if (! tmp
&& TYPE_BINFO (outer_type
))
1438 tree binfos
= TYPE_BINFO_BASETYPES (outer_type
);
1439 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1441 for (i
= 0; i
< n_baselinks
; i
++)
1443 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1444 tmp
= resolve_scope_to_name (BINFO_TYPE (base_binfo
), inner_stuff
);
1454 /* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'.
1455 This is how virtual function calls are avoided. */
1458 build_scoped_method_call (exp
, basetype
, name
, parms
)
1459 tree exp
, basetype
, name
, parms
;
1461 /* Because this syntactic form does not allow
1462 a pointer to a base class to be `stolen',
1463 we need not protect the derived->base conversion
1466 @@ But we do have to check access privileges later. */
1468 tree type
= TREE_TYPE (exp
);
1470 if (type
== error_mark_node
1471 || basetype
== error_mark_node
)
1472 return error_mark_node
;
1474 if (processing_template_decl
)
1476 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1478 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 1);
1479 name
= build_min_nt (BIT_NOT_EXPR
, type
);
1481 name
= build_min_nt (SCOPE_REF
, basetype
, name
);
1482 return build_min_nt (METHOD_CALL_EXPR
, name
, exp
, parms
, NULL_TREE
);
1485 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1486 type
= TREE_TYPE (type
);
1488 if (TREE_CODE (basetype
) == TREE_VEC
)
1491 basetype
= BINFO_TYPE (binfo
);
1496 /* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
1497 that explicit ~int is caught in the parser; this deals with typedefs
1498 and template parms. */
1499 if (TREE_CODE (name
) == BIT_NOT_EXPR
&& ! IS_AGGR_TYPE (basetype
))
1501 if (type
!= basetype
)
1502 cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
1503 exp
, basetype
, type
);
1504 name
= TREE_OPERAND (name
, 0);
1505 if (basetype
!= name
&& basetype
!= get_type_value (name
))
1506 cp_error ("qualified type `%T' does not match destructor name `~%T'",
1508 return cp_convert (void_type_node
, exp
);
1511 if (! is_aggr_type (basetype
, 1))
1512 return error_mark_node
;
1514 if (! IS_AGGR_TYPE (type
))
1516 cp_error ("base object `%E' of scoped method call is of non-aggregate type `%T'",
1518 return error_mark_node
;
1523 binfo
= get_binfo (basetype
, type
, 1);
1524 if (binfo
== error_mark_node
)
1525 return error_mark_node
;
1527 error_not_base_type (basetype
, type
);
1532 if (TREE_CODE (exp
) == INDIRECT_REF
)
1533 decl
= build_indirect_ref
1534 (convert_pointer_to_real
1535 (binfo
, build_unary_op (ADDR_EXPR
, exp
, 0)), NULL_PTR
);
1537 decl
= build_scoped_ref (exp
, basetype
);
1539 /* Call to a destructor. */
1540 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1542 /* Explicit call to destructor. */
1543 name
= TREE_OPERAND (name
, 0);
1544 if (! (name
== TYPE_MAIN_VARIANT (TREE_TYPE (decl
))
1545 || name
== constructor_name (TREE_TYPE (decl
))
1546 || TREE_TYPE (decl
) == get_type_value (name
)))
1549 ("qualified type `%T' does not match destructor name `~%T'",
1550 TREE_TYPE (decl
), name
);
1551 return error_mark_node
;
1553 if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl
)))
1554 return cp_convert (void_type_node
, exp
);
1556 return build_delete (TREE_TYPE (decl
), decl
, integer_two_node
,
1557 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
,
1561 /* Call to a method. */
1562 return build_method_call (decl
, name
, parms
, binfo
,
1563 LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
);
1565 return error_mark_node
;
1569 print_candidates (candidates
)
1572 cp_error_at ("candidates are: %D", TREE_VALUE (candidates
));
1573 candidates
= TREE_CHAIN (candidates
);
1577 cp_error_at (" %D", TREE_VALUE (candidates
));
1578 candidates
= TREE_CHAIN (candidates
);
1583 print_n_candidates (candidates
, n
)
1584 struct candidate
*candidates
;
1589 cp_error_at ("candidates are: %D", candidates
[0].function
);
1590 for (i
= 1; i
< n
; i
++)
1591 cp_error_at (" %D", candidates
[i
].function
);
1594 /* We want the address of a function or method. We avoid creating a
1595 pointer-to-member function. */
1598 build_addr_func (function
)
1601 tree type
= TREE_TYPE (function
);
1603 /* We have to do these by hand to avoid real pointer to member
1605 if (TREE_CODE (type
) == METHOD_TYPE
)
1609 type
= build_pointer_type (type
);
1611 if (mark_addressable (function
) == 0)
1612 return error_mark_node
;
1614 addr
= build1 (ADDR_EXPR
, type
, function
);
1616 /* Address of a static or external variable or function counts
1618 if (staticp (function
))
1619 TREE_CONSTANT (addr
) = 1;
1624 function
= default_conversion (function
);
1629 /* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
1630 POINTER_TYPE to those. Note, pointer to member function types
1631 (TYPE_PTRMEMFUNC_P) must be handled by our callers. */
1634 build_call (function
, result_type
, parms
)
1635 tree function
, result_type
, parms
;
1637 int is_constructor
= 0;
1639 function
= build_addr_func (function
);
1641 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function
)))
1643 sorry ("unable to call pointer to member function here");
1644 return error_mark_node
;
1647 if (TREE_CODE (function
) == ADDR_EXPR
1648 && TREE_CODE (TREE_OPERAND (function
, 0)) == FUNCTION_DECL
1649 && DECL_CONSTRUCTOR_P (TREE_OPERAND (function
, 0)))
1652 function
= build_nt (CALL_EXPR
, function
, parms
, NULL_TREE
);
1653 TREE_HAS_CONSTRUCTOR (function
) = is_constructor
;
1654 TREE_TYPE (function
) = result_type
;
1655 TREE_SIDE_EFFECTS (function
) = 1;
1661 default_parm_conversions (parms
, last
)
1664 tree parm
, parmtypes
= NULL_TREE
;
1668 for (parm
= parms
; parm
; parm
= TREE_CHAIN (parm
))
1670 tree t
= TREE_TYPE (TREE_VALUE (parm
));
1672 if (TREE_CODE (t
) == OFFSET_TYPE
1673 || TREE_CODE (t
) == METHOD_TYPE
1674 || TREE_CODE (t
) == FUNCTION_TYPE
)
1676 TREE_VALUE (parm
) = default_conversion (TREE_VALUE (parm
));
1677 t
= TREE_TYPE (TREE_VALUE (parm
));
1680 if (t
== error_mark_node
)
1681 return error_mark_node
;
1683 *last
= build_tree_list (NULL_TREE
, t
);
1684 parmtypes
= chainon (parmtypes
, *last
);
1691 /* Build something of the form ptr->method (args)
1692 or object.method (args). This can also build
1693 calls to constructors, and find friends.
1695 Member functions always take their class variable
1698 INSTANCE is a class instance.
1700 NAME is the name of the method desired, usually an IDENTIFIER_NODE.
1702 PARMS help to figure out what that NAME really refers to.
1704 BASETYPE_PATH, if non-NULL, contains a chain from the type of INSTANCE
1705 down to the real instance type to use for access checking. We need this
1706 information to get protected accesses correct. This parameter is used
1707 by build_member_call.
1709 FLAGS is the logical disjunction of zero or more LOOKUP_
1710 flags. See cp-tree.h for more info.
1712 If this is all OK, calls build_function_call with the resolved
1715 This function must also handle being called to perform
1716 initialization, promotion/coercion of arguments, and
1717 instantiation of default parameters.
1719 Note that NAME may refer to an instance variable name. If
1720 `operator()()' is defined for the type of that field, then we return
1724 build_method_call (instance
, name
, parms
, basetype_path
, flags
)
1725 tree instance
, name
, parms
, basetype_path
;
1728 register tree function
, fntype
, value_type
;
1729 register tree basetype
, save_basetype
;
1730 register tree baselink
, result
, parmtypes
;
1733 tree access
= access_public_node
;
1734 tree orig_basetype
= basetype_path
? BINFO_TYPE (basetype_path
) : NULL_TREE
;
1736 /* Range of cases for vtable optimization. */
1737 enum vtable_needs
{ not_needed
, maybe_needed
, unneeded
, needed
};
1738 enum vtable_needs need_vtbl
= not_needed
;
1741 tree save_name
= name
;
1743 tree instance_ptr
= NULL_TREE
;
1744 int all_virtual
= flag_all_virtual
;
1745 int static_call_context
= 0;
1746 tree found_fns
= NULL_TREE
;
1748 /* Keep track of `const' and `volatile' objects. */
1749 int constp
, volatilep
;
1751 #ifdef GATHER_STATISTICS
1752 n_build_method_call
++;
1755 if (instance
== error_mark_node
1756 || name
== error_mark_node
1757 || parms
== error_mark_node
1758 || (instance
!= NULL_TREE
&& TREE_TYPE (instance
) == error_mark_node
))
1759 return error_mark_node
;
1761 if (processing_template_decl
)
1763 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1765 tree type
= get_aggr_from_typedef (TREE_OPERAND (name
, 0), 1);
1766 name
= build_min_nt (BIT_NOT_EXPR
, type
);
1769 return build_min_nt (METHOD_CALL_EXPR
, name
, instance
, parms
, NULL_TREE
);
1772 /* This is the logic that magically deletes the second argument to
1773 operator delete, if it is not needed. */
1774 if (name
== ansi_opname
[(int) DELETE_EXPR
] && list_length (parms
)==2)
1776 tree save_last
= TREE_CHAIN (parms
);
1778 /* get rid of unneeded argument */
1779 TREE_CHAIN (parms
) = NULL_TREE
;
1780 result
= build_method_call (instance
, name
, parms
, basetype_path
,
1781 (LOOKUP_SPECULATIVELY
|flags
)
1783 /* If it finds a match, return it. */
1785 return build_method_call (instance
, name
, parms
, basetype_path
, flags
);
1786 /* If it doesn't work, two argument delete must work */
1787 TREE_CHAIN (parms
) = save_last
;
1789 /* We already know whether it's needed or not for vec delete. */
1790 else if (name
== ansi_opname
[(int) VEC_DELETE_EXPR
]
1791 && TYPE_LANG_SPECIFIC (TREE_TYPE (instance
))
1792 && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance
)))
1793 TREE_CHAIN (parms
) = NULL_TREE
;
1795 if (TREE_CODE (name
) == BIT_NOT_EXPR
)
1797 flags
|= LOOKUP_DESTRUCTOR
;
1798 name
= TREE_OPERAND (name
, 0);
1800 error ("destructors take no parameters");
1801 basetype
= TREE_TYPE (instance
);
1802 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
1803 basetype
= TREE_TYPE (basetype
);
1804 if (! (name
== basetype
1805 || (IS_AGGR_TYPE (basetype
)
1806 && name
== constructor_name (basetype
))
1807 || basetype
== get_type_value (name
)))
1809 cp_error ("destructor name `~%D' does not match type `%T' of expression",
1811 return cp_convert (void_type_node
, instance
);
1814 if (! TYPE_HAS_DESTRUCTOR (basetype
))
1815 return cp_convert (void_type_node
, instance
);
1816 instance
= default_conversion (instance
);
1817 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
1818 return build_delete (build_pointer_type (basetype
),
1819 instance_ptr
, integer_two_node
,
1820 LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
, 0);
1823 if (flag_ansi_overloading
)
1824 return build_new_method_call (instance
, name
, parms
, basetype_path
, flags
);
1829 /* Initialize name for error reporting. */
1830 if (IDENTIFIER_OPNAME_P (name
) && ! IDENTIFIER_TYPENAME_P (name
))
1832 char *p
= operator_name_string (name
);
1833 xref_name
= (char *)alloca (strlen (p
) + 10);
1834 sprintf (xref_name
, "operator %s", p
);
1836 else if (TREE_CODE (name
) == SCOPE_REF
)
1837 xref_name
= IDENTIFIER_POINTER (TREE_OPERAND (name
, 1));
1839 xref_name
= IDENTIFIER_POINTER (name
);
1841 GNU_xref_call (current_function_decl
, xref_name
);
1844 if (instance
== NULL_TREE
)
1846 basetype
= NULL_TREE
;
1847 /* Check cases where this is really a call to raise
1849 if (current_class_type
&& TREE_CODE (name
) == IDENTIFIER_NODE
)
1851 basetype
= purpose_member (name
, CLASSTYPE_TAGS (current_class_type
));
1853 basetype
= TREE_VALUE (basetype
);
1855 else if (TREE_CODE (name
) == SCOPE_REF
1856 && TREE_CODE (TREE_OPERAND (name
, 0)) == IDENTIFIER_NODE
)
1858 if (! is_aggr_typedef (TREE_OPERAND (name
, 0), 1))
1859 return error_mark_node
;
1860 basetype
= purpose_member (TREE_OPERAND (name
, 1),
1861 CLASSTYPE_TAGS (IDENTIFIER_TYPE_VALUE (TREE_OPERAND (name
, 0))));
1863 basetype
= TREE_VALUE (basetype
);
1866 if (basetype
!= NULL_TREE
)
1868 /* call to a constructor... */
1869 else if (basetype_path
)
1871 basetype
= BINFO_TYPE (basetype_path
);
1872 if (name
== TYPE_IDENTIFIER (basetype
))
1873 name
= ctor_identifier
;
1875 else if (IDENTIFIER_HAS_TYPE_VALUE (name
))
1877 basetype
= IDENTIFIER_TYPE_VALUE (name
);
1878 name
= ctor_identifier
;
1882 tree typedef_name
= lookup_name (name
, 1);
1883 if (typedef_name
&& TREE_CODE (typedef_name
) == TYPE_DECL
)
1885 /* Canonicalize the typedef name. */
1886 basetype
= TREE_TYPE (typedef_name
);
1887 name
= ctor_identifier
;
1891 cp_error ("no constructor named `%T' in scope",
1893 return error_mark_node
;
1897 if (! IS_AGGR_TYPE (basetype
))
1900 if ((flags
& LOOKUP_COMPLAIN
) && basetype
!= error_mark_node
)
1901 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
1902 name
, instance
, basetype
);
1904 return error_mark_node
;
1907 else if (instance
== current_class_ref
|| instance
== current_class_ptr
)
1909 /* When doing initialization, we side-effect the TREE_TYPE of
1910 current_class_ref, hence we cannot set up BASETYPE from CURRENT_CLASS_TYPE. */
1911 basetype
= TREE_TYPE (current_class_ref
);
1913 /* Anything manifestly `this' in constructors and destructors
1914 has a known type, so virtual function tables are not needed. */
1915 if (TYPE_VIRTUAL_P (basetype
)
1916 && !(flags
& LOOKUP_NONVIRTUAL
))
1917 need_vtbl
= (dtor_label
|| ctor_label
)
1918 ? unneeded
: maybe_needed
;
1920 /* If `this' is a signature pointer and `name' is not a constructor,
1921 we are calling a signature member function. In that case, set the
1922 `basetype' to the signature type and dereference the `optr' field. */
1923 if (IS_SIGNATURE_POINTER (basetype
)
1924 && TYPE_IDENTIFIER (basetype
) != name
)
1926 basetype
= SIGNATURE_TYPE (basetype
);
1927 instance_ptr
= instance
;
1928 basetype_path
= TYPE_BINFO (basetype
);
1932 instance
= current_class_ref
;
1933 instance_ptr
= current_class_ptr
;
1934 basetype_path
= TYPE_BINFO (current_class_type
);
1936 result
= build_field_call (basetype_path
, instance_ptr
, name
, parms
);
1941 else if (TREE_CODE (instance
) == RESULT_DECL
)
1943 basetype
= TREE_TYPE (instance
);
1944 /* Should we ever have to make a virtual function reference
1945 from a RESULT_DECL, know that it must be of fixed type
1946 within the scope of this function. */
1947 if (!(flags
& LOOKUP_NONVIRTUAL
) && TYPE_VIRTUAL_P (basetype
))
1948 need_vtbl
= maybe_needed
;
1949 instance_ptr
= build1 (ADDR_EXPR
, build_pointer_type (basetype
), instance
);
1953 /* The MAIN_VARIANT of the type that `instance_ptr' winds up being. */
1954 tree inst_ptr_basetype
;
1957 = (TREE_CODE (instance
) == INDIRECT_REF
1958 && TREE_CODE (TREE_OPERAND (instance
, 0)) == NOP_EXPR
1959 && TREE_OPERAND (TREE_OPERAND (instance
, 0), 0) == error_mark_node
);
1961 if (TREE_CODE (instance
) == OFFSET_REF
)
1962 instance
= resolve_offset_ref (instance
);
1964 /* the base type of an instance variable is pointer to class */
1965 basetype
= TREE_TYPE (instance
);
1967 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
1969 basetype
= TREE_TYPE (basetype
);
1970 if (! IS_AGGR_TYPE (basetype
))
1971 goto non_aggr_error
;
1972 /* Call to convert not needed because we are remaining
1973 within the same type. */
1974 instance_ptr
= build1 (NOP_EXPR
, build_pointer_type (basetype
),
1976 inst_ptr_basetype
= TYPE_MAIN_VARIANT (basetype
);
1980 if (! IS_AGGR_TYPE (basetype
)
1981 && ! (TYPE_LANG_SPECIFIC (basetype
)
1982 && (IS_SIGNATURE_POINTER (basetype
)
1983 || IS_SIGNATURE_REFERENCE (basetype
))))
1984 goto non_aggr_error
;
1986 /* If `instance' is a signature pointer/reference and `name' is
1987 not a constructor, we are calling a signature member function.
1988 In that case set the `basetype' to the signature type. */
1989 if ((IS_SIGNATURE_POINTER (basetype
)
1990 || IS_SIGNATURE_REFERENCE (basetype
))
1991 && TYPE_IDENTIFIER (basetype
) != name
)
1992 basetype
= SIGNATURE_TYPE (basetype
);
1994 basetype
= complete_type (basetype
);
1996 if ((IS_SIGNATURE (basetype
)
1997 && (instance_ptr
= instance
))
1998 || (lvalue_p (instance
)
1999 && (instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0)))
2000 || (instance_ptr
= unary_complex_lvalue (ADDR_EXPR
, instance
)))
2002 if (instance_ptr
== error_mark_node
)
2003 return error_mark_node
;
2005 else if (TREE_CODE (instance
) == NOP_EXPR
2006 || TREE_CODE (instance
) == CONSTRUCTOR
)
2008 /* A cast is not an lvalue. Initialize a fresh temp
2009 with the value we are casting from, and proceed with
2010 that temporary. We can't cast to a reference type,
2011 so that simplifies the initialization to something
2013 tree temp
= get_temp_name (TREE_TYPE (instance
), 0);
2014 if (IS_AGGR_TYPE (TREE_TYPE (instance
)))
2015 expand_aggr_init (temp
, instance
, 0, flags
);
2018 store_init_value (temp
, instance
);
2019 expand_decl_init (temp
);
2022 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
2026 if (TREE_CODE (instance
) != CALL_EXPR
)
2027 my_friendly_abort (125);
2028 if (TYPE_NEEDS_CONSTRUCTING (basetype
))
2029 instance
= build_cplus_new (basetype
, instance
);
2032 instance
= get_temp_name (basetype
, 0);
2033 TREE_ADDRESSABLE (instance
) = 1;
2035 instance_ptr
= build_unary_op (ADDR_EXPR
, instance
, 0);
2037 /* @@ Should we call comp_target_types here? */
2038 if (IS_SIGNATURE (basetype
))
2039 inst_ptr_basetype
= basetype
;
2041 inst_ptr_basetype
= TREE_TYPE (TREE_TYPE (instance_ptr
));
2042 if (TYPE_MAIN_VARIANT (basetype
) == TYPE_MAIN_VARIANT (inst_ptr_basetype
))
2043 basetype
= inst_ptr_basetype
;
2046 instance_ptr
= cp_convert (build_pointer_type (basetype
), instance_ptr
);
2047 if (instance_ptr
== error_mark_node
)
2048 return error_mark_node
;
2052 /* After converting `instance_ptr' above, `inst_ptr_basetype' was
2053 not updated, so we use `basetype' instead. */
2054 if (basetype_path
== NULL_TREE
2055 && IS_SIGNATURE (basetype
))
2056 basetype_path
= TYPE_BINFO (basetype
);
2057 else if (basetype_path
== NULL_TREE
2058 || (BINFO_TYPE (basetype_path
)
2059 != TYPE_MAIN_VARIANT (inst_ptr_basetype
)))
2060 basetype_path
= TYPE_BINFO (inst_ptr_basetype
);
2062 result
= build_field_call (basetype_path
, instance_ptr
, name
, parms
);
2066 if (!(flags
& LOOKUP_NONVIRTUAL
) && TYPE_VIRTUAL_P (basetype
))
2068 if (TREE_SIDE_EFFECTS (instance_ptr
))
2070 /* This action is needed because the instance is needed
2071 for providing the base of the virtual function table.
2072 Without using a SAVE_EXPR, the function we are building
2073 may be called twice, or side effects on the instance
2074 variable (such as a post-increment), may happen twice. */
2075 instance_ptr
= save_expr (instance_ptr
);
2076 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2078 else if (TREE_CODE (TREE_TYPE (instance
)) == POINTER_TYPE
)
2080 /* This happens when called for operator new (). */
2081 instance
= build_indirect_ref (instance
, NULL_PTR
);
2084 need_vtbl
= maybe_needed
;
2088 if (save_name
== ctor_identifier
)
2089 save_name
= TYPE_IDENTIFIER (basetype
);
2091 if (TYPE_SIZE (complete_type (basetype
)) == 0)
2093 /* This is worth complaining about, I think. */
2094 cp_error ("cannot lookup method in incomplete type `%T'", basetype
);
2095 return error_mark_node
;
2098 save_basetype
= TYPE_MAIN_VARIANT (basetype
);
2100 parmtypes
= default_parm_conversions (parms
, &last
);
2101 if (parmtypes
== error_mark_node
)
2103 return error_mark_node
;
2106 if (instance
&& IS_SIGNATURE (basetype
))
2108 /* @@ Should this be the constp/volatilep flags for the optr field
2109 of the signature pointer? */
2110 constp
= TYPE_READONLY (basetype
);
2111 volatilep
= TYPE_VOLATILE (basetype
);
2112 parms
= tree_cons (NULL_TREE
, instance_ptr
, parms
);
2116 /* TREE_READONLY (instance) fails for references. */
2117 constp
= TYPE_READONLY (TREE_TYPE (TREE_TYPE (instance_ptr
)));
2118 volatilep
= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (instance_ptr
)));
2119 parms
= tree_cons (NULL_TREE
, instance_ptr
, parms
);
2123 /* Raw constructors are always in charge. */
2124 if (TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
2125 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
2127 flags
|= LOOKUP_HAS_IN_CHARGE
;
2128 parms
= tree_cons (NULL_TREE
, integer_one_node
, parms
);
2129 parmtypes
= tree_cons (NULL_TREE
, integer_type_node
, parmtypes
);
2134 instance_ptr
= build_int_2 (0, 0);
2135 TREE_TYPE (instance_ptr
) = build_pointer_type (basetype
);
2136 parms
= tree_cons (NULL_TREE
, instance_ptr
, parms
);
2139 parmtypes
= tree_cons (NULL_TREE
, TREE_TYPE (instance_ptr
), parmtypes
);
2141 if (last
== NULL_TREE
)
2144 /* Look up function name in the structure type definition. */
2146 /* FIXME Axe most of this now? */
2147 if ((IDENTIFIER_HAS_TYPE_VALUE (name
)
2148 && ! IDENTIFIER_OPNAME_P (name
)
2149 && IS_AGGR_TYPE (IDENTIFIER_TYPE_VALUE (name
)))
2150 || name
== constructor_name (basetype
)
2151 || name
== ctor_identifier
)
2153 tree tmp
= NULL_TREE
;
2154 if (IDENTIFIER_TYPE_VALUE (name
) == basetype
2155 || name
== constructor_name (basetype
)
2156 || name
== ctor_identifier
)
2157 tmp
= TYPE_BINFO (basetype
);
2159 tmp
= get_binfo (IDENTIFIER_TYPE_VALUE (name
), basetype
, 0);
2161 if (tmp
!= NULL_TREE
)
2163 name_kind
= "constructor";
2165 if (TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
2166 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
2168 /* Constructors called for initialization
2169 only are never in charge. */
2172 flags
|= LOOKUP_HAS_IN_CHARGE
;
2173 tmplist
= tree_cons (NULL_TREE
, integer_zero_node
,
2174 TREE_CHAIN (parms
));
2175 TREE_CHAIN (parms
) = tmplist
;
2176 tmplist
= tree_cons (NULL_TREE
, integer_type_node
, TREE_CHAIN (parmtypes
));
2177 TREE_CHAIN (parmtypes
) = tmplist
;
2179 basetype
= BINFO_TYPE (tmp
);
2182 name_kind
= "method";
2185 name_kind
= "method";
2187 if (basetype_path
== NULL_TREE
2188 || BINFO_TYPE (basetype_path
) != TYPE_MAIN_VARIANT (basetype
))
2189 basetype_path
= TYPE_BINFO (basetype
);
2190 result
= lookup_fnfields (basetype_path
, name
,
2191 (flags
& LOOKUP_COMPLAIN
));
2192 if (result
== error_mark_node
)
2193 return error_mark_node
;
2195 for (pass
= 0; pass
< 2; pass
++)
2197 struct candidate
*candidates
;
2198 struct candidate
*cp
;
2207 = (struct candidate
*) alloca ((ever_seen
+1)
2208 * sizeof (struct candidate
));
2209 bzero ((char *) candidates
, (ever_seen
+ 1) * sizeof (struct candidate
));
2211 len
= list_length (parms
);
2214 /* First see if a global function has a shot at it. */
2215 if (flags
& LOOKUP_GLOBAL
)
2218 tree parm
= instance_ptr
;
2220 if (TREE_CODE (TREE_TYPE (parm
)) == REFERENCE_TYPE
)
2221 parm
= convert_from_reference (parm
);
2222 else if (TREE_CODE (TREE_TYPE (parm
)) == POINTER_TYPE
)
2223 parm
= build_indirect_ref (parm
, "friendifying parms (compiler error)");
2225 my_friendly_abort (167);
2227 friend_parms
= tree_cons (NULL_TREE
, parm
, TREE_CHAIN (parms
));
2230 cp
->harshness
= (struct harshness_code
*)
2231 alloca ((len
+ 1) * sizeof (struct harshness_code
));
2233 result
= build_overload_call_real (name
, friend_parms
, 0, cp
, 1);
2235 /* If it turns out to be the one we were actually looking for
2236 (it was probably a friend function), the return the
2238 if (TREE_CODE (result
) == CALL_EXPR
)
2241 while ((cp
->h
.code
& EVIL_CODE
) == 0)
2243 /* non-standard uses: set the field to 0 to indicate
2244 we are using a non-member function. */
2246 if (cp
->harshness
[len
].distance
== 0
2247 && cp
->h
.code
< best
)
2256 /* We have a hit (of sorts). If the parameter list is
2257 "error_mark_node", or some variant thereof, it won't
2258 match any methods. Since we have verified that the is
2259 some method vaguely matching this one (in name at least),
2262 Don't stop for friends, however. */
2263 basetype_path
= TREE_PURPOSE (baselink
);
2265 function
= TREE_VALUE (baselink
);
2266 if (TREE_CODE (basetype_path
) == TREE_LIST
)
2267 basetype_path
= TREE_VALUE (basetype_path
);
2268 basetype
= BINFO_TYPE (basetype_path
);
2270 for (; function
; function
= DECL_CHAIN (function
))
2272 #ifdef GATHER_STATISTICS
2273 n_inner_fields_searched
++;
2277 found_fns
= tree_cons (NULL_TREE
, function
, found_fns
);
2279 /* Not looking for friends here. */
2280 if (TREE_CODE (TREE_TYPE (function
)) == FUNCTION_TYPE
2281 && ! DECL_STATIC_FUNCTION_P (function
))
2286 tree these_parms
= parms
;
2288 #ifdef GATHER_STATISTICS
2289 n_inner_fields_searched
++;
2292 cp
->harshness
= (struct harshness_code
*)
2293 alloca ((len
+ 1) * sizeof (struct harshness_code
));
2295 if (DECL_STATIC_FUNCTION_P (function
))
2296 these_parms
= TREE_CHAIN (these_parms
);
2297 compute_conversion_costs (function
, these_parms
, cp
, len
);
2299 if ((cp
->h
.code
& EVIL_CODE
) == 0)
2301 cp
->u
.field
= function
;
2302 cp
->function
= function
;
2303 cp
->basetypes
= basetype_path
;
2305 /* Don't allow non-converting constructors to convert. */
2306 if (flags
& LOOKUP_ONLYCONVERTING
2307 && DECL_LANG_SPECIFIC (function
)
2308 && DECL_NONCONVERTING_P (function
))
2311 /* No "two-level" conversions. */
2312 if (flags
& LOOKUP_NO_CONVERSION
2313 && (cp
->h
.code
& USER_CODE
))
2324 tree igv
= lookup_name_nonclass (name
);
2326 /* No exact match could be found. Now try to find match
2327 using default conversions. */
2328 if ((flags
& LOOKUP_GLOBAL
) && igv
)
2330 if (TREE_CODE (igv
) == FUNCTION_DECL
)
2332 else if (TREE_CODE (igv
) == TREE_LIST
)
2333 ever_seen
+= count_functions (igv
);
2338 if ((flags
& (LOOKUP_SPECULATIVELY
|LOOKUP_COMPLAIN
))
2339 == LOOKUP_SPECULATIVELY
)
2342 TREE_CHAIN (last
) = void_list_node
;
2343 if (flags
& LOOKUP_GLOBAL
)
2344 cp_error ("no global or member function `%D(%A)' defined",
2345 save_name
, parmtypes
);
2347 cp_error ("no member function `%T::%D(%A)' defined",
2348 save_basetype
, save_name
, TREE_CHAIN (parmtypes
));
2349 return error_mark_node
;
2354 if (cp
- candidates
!= 0)
2356 /* Rank from worst to best. Then cp will point to best one.
2357 Private fields have their bits flipped. For unsigned
2358 numbers, this should make them look very large.
2359 If the best alternate has a (signed) negative value,
2360 then all we ever saw were private members. */
2361 if (cp
- candidates
> 1)
2363 int n_candidates
= cp
- candidates
;
2364 extern int warn_synth
;
2365 TREE_VALUE (parms
) = instance_ptr
;
2366 cp
= ideal_candidate (candidates
, n_candidates
, len
);
2367 if (cp
== (struct candidate
*)0)
2369 if (flags
& LOOKUP_COMPLAIN
)
2371 TREE_CHAIN (last
) = void_list_node
;
2372 cp_error ("call of overloaded %s `%D(%A)' is ambiguous",
2373 name_kind
, save_name
, TREE_CHAIN (parmtypes
));
2374 print_n_candidates (candidates
, n_candidates
);
2376 return error_mark_node
;
2378 if (cp
->h
.code
& EVIL_CODE
)
2379 return error_mark_node
;
2381 && DECL_NAME (cp
->function
) == ansi_opname
[MODIFY_EXPR
]
2382 && DECL_ARTIFICIAL (cp
->function
)
2383 && n_candidates
== 2)
2385 cp_warning ("using synthesized `%#D' for copy assignment",
2387 cp_warning_at (" where cfront would use `%#D'",
2388 candidates
->function
);
2391 else if (cp
[-1].h
.code
& EVIL_CODE
)
2393 if (flags
& LOOKUP_COMPLAIN
)
2394 cp_error ("ambiguous type conversion requested for %s `%D'",
2395 name_kind
, save_name
);
2396 return error_mark_node
;
2401 /* The global function was the best, so use it. */
2402 if (cp
->u
.field
== 0)
2404 /* We must convert the instance pointer into a reference type.
2405 Global overloaded functions can only either take
2406 aggregate objects (which come for free from references)
2407 or reference data types anyway. */
2408 TREE_VALUE (parms
) = copy_node (instance_ptr
);
2409 TREE_TYPE (TREE_VALUE (parms
)) = build_reference_type (TREE_TYPE (TREE_TYPE (instance_ptr
)));
2410 return build_function_call (cp
->function
, parms
);
2413 function
= cp
->function
;
2414 basetype_path
= cp
->basetypes
;
2415 if (! DECL_STATIC_FUNCTION_P (function
))
2416 TREE_VALUE (parms
) = cp
->arg
;
2417 goto found_and_maybe_warn
;
2420 if (flags
& (LOOKUP_COMPLAIN
|LOOKUP_SPECULATIVELY
))
2422 if ((flags
& (LOOKUP_SPECULATIVELY
|LOOKUP_COMPLAIN
))
2423 == LOOKUP_SPECULATIVELY
)
2426 if (DECL_STATIC_FUNCTION_P (cp
->function
))
2427 parms
= TREE_CHAIN (parms
);
2430 if (flags
& LOOKUP_SPECULATIVELY
)
2432 if (static_call_context
2433 && TREE_CODE (TREE_TYPE (cp
->function
)) == METHOD_TYPE
)
2434 cp_error ("object missing in call to `%D'", cp
->function
);
2435 else if (ever_seen
> 1)
2437 TREE_CHAIN (last
) = void_list_node
;
2438 cp_error ("no matching function for call to `%T::%D (%A)%V'",
2439 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (instance_ptr
))),
2440 save_name
, TREE_CHAIN (parmtypes
),
2441 TREE_TYPE (TREE_TYPE (instance_ptr
)));
2442 TREE_CHAIN (last
) = NULL_TREE
;
2443 print_candidates (found_fns
);
2446 report_type_mismatch (cp
, parms
, name_kind
);
2447 return error_mark_node
;
2450 if ((flags
& (LOOKUP_SPECULATIVELY
|LOOKUP_COMPLAIN
))
2453 cp_error ("%T has no method named %D", save_basetype
, save_name
);
2454 return error_mark_node
;
2460 found_and_maybe_warn
:
2461 if ((cp
->harshness
[0].code
& CONST_CODE
)
2462 /* 12.1p2: Constructors can be called for const objects. */
2463 && ! DECL_CONSTRUCTOR_P (cp
->function
))
2465 if (flags
& LOOKUP_COMPLAIN
)
2467 cp_error_at ("non-const member function `%D'", cp
->function
);
2468 error ("called for const object at this point in file");
2470 /* Not good enough for a match. */
2472 return error_mark_node
;
2476 /* Silently return error_mark_node. */
2477 return error_mark_node
;
2480 if (flags
& LOOKUP_PROTECT
)
2481 access
= compute_access (basetype_path
, function
);
2483 if (access
== access_private_node
)
2485 if (flags
& LOOKUP_COMPLAIN
)
2487 cp_error_at ("%s `%+#D' is %s", name_kind
, function
,
2488 TREE_PRIVATE (function
) ? "private"
2489 : "from private base class");
2490 error ("within this context");
2492 return error_mark_node
;
2494 else if (access
== access_protected_node
)
2496 if (flags
& LOOKUP_COMPLAIN
)
2498 cp_error_at ("%s `%+#D' %s", name_kind
, function
,
2499 TREE_PROTECTED (function
) ? "is protected"
2500 : "has protected accessibility");
2501 error ("within this context");
2503 return error_mark_node
;
2506 /* From here on down, BASETYPE is the type that INSTANCE_PTR's
2507 type (if it exists) is a pointer to. */
2509 if (DECL_ABSTRACT_VIRTUAL_P (function
)
2510 && instance
== current_class_ref
2511 && DECL_CONSTRUCTOR_P (current_function_decl
)
2512 && ! (flags
& LOOKUP_NONVIRTUAL
)
2513 && value_member (function
, get_abstract_virtuals (basetype
)))
2514 cp_error ("abstract virtual `%#D' called from constructor", function
);
2516 if (IS_SIGNATURE (basetype
))
2518 if (static_call_context
)
2520 cp_error ("cannot call signature member function `%T::%D' without signature pointer/reference",
2521 basetype
, save_name
);
2522 return error_mark_node
;
2524 return build_signature_method_call (function
, parms
);
2527 function
= DECL_MAIN_VARIANT (function
);
2528 mark_used (function
);
2530 fntype
= TREE_TYPE (function
);
2531 if (TREE_CODE (fntype
) == POINTER_TYPE
)
2532 fntype
= TREE_TYPE (fntype
);
2533 basetype
= DECL_CLASS_CONTEXT (function
);
2535 /* If we are referencing a virtual function from an object
2536 of effectively static type, then there is no need
2537 to go through the virtual function table. */
2538 if (need_vtbl
== maybe_needed
)
2540 int fixed_type
= resolves_to_fixed_type_p (instance
, 0);
2542 if (all_virtual
== 1
2543 && DECL_VINDEX (function
)
2544 && may_be_remote (basetype
))
2546 else if (DECL_VINDEX (function
))
2547 need_vtbl
= fixed_type
? unneeded
: needed
;
2549 need_vtbl
= not_needed
;
2552 if (TREE_CODE (fntype
) == METHOD_TYPE
&& static_call_context
2553 && !DECL_CONSTRUCTOR_P (function
))
2555 /* Let's be nasty to the user now, and give reasonable
2557 instance_ptr
= current_class_ptr
;
2560 if (basetype
!= current_class_type
)
2562 if (basetype
== error_mark_node
)
2563 return error_mark_node
;
2566 if (orig_basetype
!= NULL_TREE
)
2567 error_not_base_type (orig_basetype
, current_class_type
);
2569 error_not_base_type (function
, current_class_type
);
2570 return error_mark_node
;
2574 /* Only allow a static member function to call another static member
2576 else if (DECL_LANG_SPECIFIC (function
)
2577 && !DECL_STATIC_FUNCTION_P (function
))
2579 cp_error ("cannot call member function `%D' without object",
2581 return error_mark_node
;
2585 value_type
= TREE_TYPE (fntype
) ? TREE_TYPE (fntype
) : void_type_node
;
2587 if (TYPE_SIZE (complete_type (value_type
)) == 0)
2589 if (flags
& LOOKUP_COMPLAIN
)
2590 incomplete_type_error (0, value_type
);
2591 return error_mark_node
;
2594 if (DECL_STATIC_FUNCTION_P (function
))
2595 parms
= convert_arguments (NULL_TREE
, TYPE_ARG_TYPES (fntype
),
2596 TREE_CHAIN (parms
), function
, LOOKUP_NORMAL
);
2597 else if (need_vtbl
== unneeded
)
2599 int sub_flags
= DECL_CONSTRUCTOR_P (function
) ? flags
: LOOKUP_NORMAL
;
2600 basetype
= TREE_TYPE (instance
);
2601 if (TYPE_METHOD_BASETYPE (TREE_TYPE (function
))
2602 != TYPE_MAIN_VARIANT (basetype
))
2604 basetype
= DECL_CLASS_CONTEXT (function
);
2605 instance_ptr
= convert_pointer_to (basetype
, instance_ptr
);
2606 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2608 parms
= tree_cons (NULL_TREE
, instance_ptr
,
2609 convert_arguments (NULL_TREE
, TREE_CHAIN (TYPE_ARG_TYPES (fntype
)), TREE_CHAIN (parms
), function
, sub_flags
));
2613 if ((flags
& LOOKUP_NONVIRTUAL
) == 0)
2614 basetype
= DECL_CONTEXT (function
);
2616 /* First parm could be integer_zerop with casts like
2617 ((Object*)0)->Object::IsA() */
2618 if (!integer_zerop (TREE_VALUE (parms
)))
2620 /* Since we can't have inheritance with a union, doing get_binfo
2621 on it won't work. We do all the convert_pointer_to_real
2622 stuff to handle MI correctly...for unions, that's not
2623 an issue, so we must short-circuit that extra work here. */
2624 tree tmp
= TREE_TYPE (TREE_TYPE (TREE_VALUE (parms
)));
2625 if (tmp
!= NULL_TREE
&& TREE_CODE (tmp
) == UNION_TYPE
)
2626 instance_ptr
= TREE_VALUE (parms
);
2629 tree binfo
= get_binfo (basetype
,
2630 TREE_TYPE (TREE_TYPE (TREE_VALUE (parms
))),
2632 instance_ptr
= convert_pointer_to_real (binfo
, TREE_VALUE (parms
));
2635 = convert_pointer_to (build_type_variant (basetype
,
2639 if (TREE_CODE (instance_ptr
) == COND_EXPR
)
2641 instance_ptr
= save_expr (instance_ptr
);
2642 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2644 else if (TREE_CODE (instance_ptr
) == NOP_EXPR
2645 && TREE_CODE (TREE_OPERAND (instance_ptr
, 0)) == ADDR_EXPR
2646 && TREE_OPERAND (TREE_OPERAND (instance_ptr
, 0), 0) == instance
)
2648 /* The call to `convert_pointer_to' may return error_mark_node. */
2649 else if (instance_ptr
== error_mark_node
)
2650 return instance_ptr
;
2651 else if (instance
== NULL_TREE
2652 || TREE_CODE (instance
) != INDIRECT_REF
2653 || TREE_OPERAND (instance
, 0) != instance_ptr
)
2654 instance
= build_indirect_ref (instance_ptr
, NULL_PTR
);
2656 parms
= tree_cons (NULL_TREE
, instance_ptr
,
2657 convert_arguments (NULL_TREE
, TREE_CHAIN (TYPE_ARG_TYPES (fntype
)), TREE_CHAIN (parms
), function
, LOOKUP_NORMAL
));
2660 if (parms
== error_mark_node
2661 || (parms
&& TREE_CHAIN (parms
) == error_mark_node
))
2662 return error_mark_node
;
2664 if (need_vtbl
== needed
)
2666 function
= build_vfn_ref (&TREE_VALUE (parms
), instance
,
2667 DECL_VINDEX (function
));
2668 TREE_TYPE (function
) = build_pointer_type (fntype
);
2671 if (TREE_CODE (function
) == FUNCTION_DECL
)
2672 GNU_xref_call (current_function_decl
,
2673 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function
)));
2675 result
= build_call (function
, value_type
, parms
);
2676 if (IS_AGGR_TYPE (value_type
))
2677 result
= build_cplus_new (value_type
, result
);
2678 result
= convert_from_reference (result
);
2682 /* Similar to `build_method_call', but for overloaded non-member functions.
2683 The name of this function comes through NAME. The name depends
2686 Note that this function must handle simple `C' promotions,
2687 as well as variable numbers of arguments (...), and
2688 default arguments to boot.
2690 If the overloading is successful, we return a tree node which
2691 contains the call to the function.
2693 If overloading produces candidates which are probable, but not definite,
2694 we hold these candidates. If FINAL_CP is non-zero, then we are free
2695 to assume that final_cp points to enough storage for all candidates that
2696 this function might generate. The `harshness' array is preallocated for
2697 the first candidate, but not for subsequent ones.
2699 Note that the DECL_RTL of FUNCTION must be made to agree with this
2700 function's new name. */
2703 build_overload_call_real (fnname
, parms
, flags
, final_cp
, require_complete
)
2706 struct candidate
*final_cp
;
2707 int require_complete
;
2709 /* must check for overloading here */
2710 tree functions
, function
;
2711 tree parmtypes
, last
;
2712 register tree outer
;
2714 int parmlength
= list_length (parms
);
2716 struct candidate
*candidates
, *cp
;
2720 final_cp
[0].h
.code
= 0;
2721 final_cp
[0].h
.distance
= 0;
2722 final_cp
[0].function
= 0;
2724 final_cp
[1].h
.code
= EVIL_CODE
;
2727 parmtypes
= default_parm_conversions (parms
, &last
);
2728 if (parmtypes
== error_mark_node
)
2731 final_cp
->h
.code
= EVIL_CODE
;
2732 return error_mark_node
;
2736 TREE_CHAIN (last
) = void_list_node
;
2738 parmtypes
= void_list_node
;
2740 if (is_overloaded_fn (fnname
))
2743 if (TREE_CODE (fnname
) == TREE_LIST
)
2744 fnname
= TREE_PURPOSE (functions
);
2745 else if (TREE_CODE (fnname
) == FUNCTION_DECL
)
2746 fnname
= DECL_NAME (functions
);
2749 functions
= lookup_name_nonclass (fnname
);
2751 if (functions
== NULL_TREE
)
2753 if (flags
& LOOKUP_SPECULATIVELY
)
2755 if (flags
& LOOKUP_COMPLAIN
)
2756 error ("only member functions apply");
2758 final_cp
->h
.code
= EVIL_CODE
;
2759 return error_mark_node
;
2762 if (TREE_CODE (functions
) == FUNCTION_DECL
&& ! IDENTIFIER_OPNAME_P (fnname
))
2764 functions
= DECL_MAIN_VARIANT (functions
);
2767 /* We are just curious whether this is a viable alternative or
2769 compute_conversion_costs (functions
, parms
, final_cp
, parmlength
);
2773 return build_function_call_real (functions
, parms
, 1, flags
);
2776 if (TREE_CODE (functions
) == TREE_LIST
2777 && TREE_VALUE (functions
) == NULL_TREE
)
2779 if (flags
& LOOKUP_SPECULATIVELY
)
2782 if (flags
& LOOKUP_COMPLAIN
)
2783 cp_error ("function `%D' declared overloaded, but no instances of that function declared",
2784 TREE_PURPOSE (functions
));
2786 final_cp
->h
.code
= EVIL_CODE
;
2787 return error_mark_node
;
2790 length
= count_functions (functions
);
2793 candidates
= final_cp
;
2797 = (struct candidate
*)alloca ((length
+1) * sizeof (struct candidate
));
2798 bzero ((char *) candidates
, (length
+ 1) * sizeof (struct candidate
));
2803 my_friendly_assert (is_overloaded_fn (functions
), 169);
2805 functions
= get_first_fn (functions
);
2807 /* OUTER is the list of FUNCTION_DECLS, in a TREE_LIST. */
2808 for (outer
= functions
; outer
; outer
= DECL_CHAIN (outer
))
2810 int template_cost
= 0;
2812 if (TREE_CODE (function
) != FUNCTION_DECL
2813 && ! (TREE_CODE (function
) == TEMPLATE_DECL
2814 && TREE_CODE (DECL_TEMPLATE_RESULT (function
)) == FUNCTION_DECL
))
2816 enum tree_code code
= TREE_CODE (function
);
2817 if (code
== TEMPLATE_DECL
)
2818 code
= TREE_CODE (DECL_TEMPLATE_RESULT (function
));
2819 if (code
== CONST_DECL
)
2821 ("enumeral value `%D' conflicts with function of same name",
2823 else if (code
== VAR_DECL
)
2825 if (TREE_STATIC (function
))
2827 ("variable `%D' conflicts with function of same name",
2831 ("constant field `%D' conflicts with function of same name",
2834 else if (code
== TYPE_DECL
)
2837 my_friendly_abort (2);
2838 error ("at this point in file");
2841 if (TREE_CODE (function
) == TEMPLATE_DECL
)
2843 int ntparms
= DECL_NTPARMS (function
);
2844 tree targs
= make_tree_vec (ntparms
);
2847 i
= type_unification (DECL_INNERMOST_TEMPLATE_PARMS (function
),
2848 &TREE_VEC_ELT (targs
, 0),
2849 TYPE_ARG_TYPES (TREE_TYPE (function
)),
2850 parms
, &template_cost
, 0, 0);
2853 function
= instantiate_template (function
, targs
);
2854 if (function
== error_mark_node
)
2859 if (TREE_CODE (function
) == TEMPLATE_DECL
)
2861 /* Unconverted template -- failed match. */
2862 cp
->function
= function
;
2864 cp
->h
.code
= EVIL_CODE
;
2868 struct candidate
*cp2
;
2870 /* Check that this decl is not the same as a function that's in
2871 the list due to some template instantiation. */
2874 if (cp2
->function
== function
)
2878 if (cp2
->function
== function
)
2881 function
= DECL_MAIN_VARIANT (function
);
2883 /* Can't use alloca here, since result might be
2884 passed to calling function. */
2885 cp
->h_len
= parmlength
;
2886 cp
->harshness
= (struct harshness_code
*)
2887 oballoc ((parmlength
+ 1) * sizeof (struct harshness_code
));
2889 compute_conversion_costs (function
, parms
, cp
, parmlength
);
2891 /* Make sure this is clear as well. */
2892 cp
->h
.int_penalty
+= template_cost
;
2894 if ((cp
[0].h
.code
& EVIL_CODE
) == 0)
2896 cp
[1].h
.code
= EVIL_CODE
;
2902 if (cp
- candidates
)
2904 tree rval
= error_mark_node
;
2907 cp
[0].h
.code
= EVIL_CODE
;
2908 if (cp
- candidates
> 1)
2910 struct candidate
*best_cp
2911 = ideal_candidate (candidates
, cp
- candidates
, parmlength
);
2912 if (best_cp
== (struct candidate
*)0)
2914 if (flags
& LOOKUP_COMPLAIN
)
2916 cp_error ("call of overloaded `%D' is ambiguous", fnname
);
2917 print_n_candidates (candidates
, cp
- candidates
);
2919 return error_mark_node
;
2922 rval
= best_cp
->function
;
2927 if (cp
->h
.code
& EVIL_CODE
)
2929 if (flags
& LOOKUP_COMPLAIN
)
2930 error ("type conversion ambiguous");
2933 rval
= cp
->function
;
2939 return build_function_call_real (rval
, parms
, require_complete
, flags
);
2942 if (flags
& LOOKUP_SPECULATIVELY
)
2945 if (flags
& LOOKUP_COMPLAIN
)
2946 report_type_mismatch (cp
, parms
, "function");
2948 return error_mark_node
;
2951 /* This requires a complete type on the result of the call. */
2954 build_overload_call (fnname
, parms
, flags
)
2958 return build_overload_call_real (fnname
, parms
, flags
, (struct candidate
*)0, 1);
2961 /* New overloading code. */
2963 struct z_candidate
{
2970 struct z_candidate
*next
;
2973 #define IDENTITY_RANK 0
2974 #define EXACT_RANK 1
2975 #define PROMO_RANK 2
2977 #define PBOOL_RANK 4
2979 #define ELLIPSIS_RANK 6
2982 #define ICS_RANK(NODE) \
2983 (ICS_BAD_FLAG (NODE) ? BAD_RANK \
2984 : ICS_ELLIPSIS_FLAG (NODE) ? ELLIPSIS_RANK \
2985 : ICS_USER_FLAG (NODE) ? USER_RANK \
2986 : ICS_STD_RANK (NODE))
2988 #define ICS_STD_RANK(NODE) TREE_COMPLEXITY (NODE)
2990 #define ICS_USER_FLAG(NODE) TREE_LANG_FLAG_0 (NODE)
2991 #define ICS_ELLIPSIS_FLAG(NODE) TREE_LANG_FLAG_1 (NODE)
2992 #define ICS_THIS_FLAG(NODE) TREE_LANG_FLAG_2 (NODE)
2993 #define ICS_BAD_FLAG(NODE) TREE_LANG_FLAG_3 (NODE)
2995 #define USER_CONV_FN(NODE) TREE_OPERAND (NODE, 1)
3002 || integer_zerop (t
) && INTEGRAL_TYPE_P (TREE_TYPE (t
)))
3008 build_conv (code
, type
, from
)
3009 enum tree_code code
;
3012 tree t
= build1 (code
, type
, from
);
3013 int rank
= ICS_STD_RANK (from
);
3020 if (rank
< STD_RANK
)
3027 if (rank
< EXACT_RANK
)
3033 ICS_STD_RANK (t
) = rank
;
3034 ICS_USER_FLAG (t
) = ICS_USER_FLAG (from
);
3035 ICS_BAD_FLAG (t
) = ICS_BAD_FLAG (from
);
3043 if (TREE_CODE (t
) == REFERENCE_TYPE
)
3052 if (TREE_CODE (t
) == ARRAY_TYPE
)
3054 return TYPE_MAIN_VARIANT (t
);
3057 /* Returns the standard conversion path (see [conv]) from type FROM to type
3058 TO, if any. For proper handling of null pointer constants, you must
3059 also pass the expression EXPR to convert from. */
3062 standard_conversion (to
, from
, expr
)
3063 tree to
, from
, expr
;
3065 enum tree_code fcode
, tcode
;
3069 if (TREE_CODE (to
) == REFERENCE_TYPE
)
3070 to
= TREE_TYPE (to
);
3071 if (TREE_CODE (from
) == REFERENCE_TYPE
)
3074 from
= TREE_TYPE (from
);
3076 to
= strip_top_quals (to
);
3077 from
= strip_top_quals (from
);
3079 fcode
= TREE_CODE (from
);
3080 tcode
= TREE_CODE (to
);
3082 conv
= build1 (IDENTITY_CONV
, from
, expr
);
3084 if (fcode
== FUNCTION_TYPE
)
3086 from
= build_pointer_type (from
);
3087 fcode
= TREE_CODE (from
);
3088 conv
= build_conv (LVALUE_CONV
, from
, conv
);
3090 else if (fcode
== ARRAY_TYPE
)
3092 from
= build_pointer_type (TREE_TYPE (from
));
3093 fcode
= TREE_CODE (from
);
3094 conv
= build_conv (LVALUE_CONV
, from
, conv
);
3096 else if (fromref
|| (expr
&& real_lvalue_p (expr
)))
3097 conv
= build_conv (RVALUE_CONV
, from
, conv
);
3102 if ((tcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (to
))
3103 && expr
&& null_ptr_cst_p (expr
))
3105 conv
= build_conv (STD_CONV
, to
, conv
);
3107 else if (tcode
== POINTER_TYPE
&& fcode
== POINTER_TYPE
)
3109 enum tree_code ufcode
= TREE_CODE (TREE_TYPE (from
));
3110 enum tree_code utcode
= TREE_CODE (TREE_TYPE (to
));
3111 tree nconv
= NULL_TREE
;
3113 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (from
)),
3114 TYPE_MAIN_VARIANT (TREE_TYPE (to
)), 1))
3116 else if (utcode
== VOID_TYPE
&& ufcode
!= OFFSET_TYPE
3117 && ufcode
!= FUNCTION_TYPE
)
3119 from
= build_pointer_type
3120 (cp_build_type_variant (void_type_node
,
3121 TYPE_READONLY (TREE_TYPE (from
)),
3122 TYPE_VOLATILE (TREE_TYPE (from
))));
3123 nconv
= build_conv (PTR_CONV
, from
, conv
);
3125 else if (ufcode
== OFFSET_TYPE
&& utcode
== OFFSET_TYPE
)
3127 tree fbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (from
));
3128 tree tbase
= TYPE_OFFSET_BASETYPE (TREE_TYPE (to
));
3130 if (DERIVED_FROM_P (fbase
, tbase
)
3131 && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (from
))),
3132 TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (to
))),
3135 from
= build_offset_type (tbase
, TREE_TYPE (TREE_TYPE (from
)));
3136 from
= build_pointer_type (from
);
3137 nconv
= build_conv (PMEM_CONV
, from
, conv
);
3140 else if (IS_AGGR_TYPE (TREE_TYPE (from
))
3141 && IS_AGGR_TYPE (TREE_TYPE (to
)))
3143 if (DERIVED_FROM_P (TREE_TYPE (to
), TREE_TYPE (from
)))
3145 from
= cp_build_type_variant (TREE_TYPE (to
),
3146 TYPE_READONLY (TREE_TYPE (from
)),
3147 TYPE_VOLATILE (TREE_TYPE (from
)));
3148 from
= build_pointer_type (from
);
3149 nconv
= build_conv (PTR_CONV
, from
, conv
);
3153 if (nconv
&& comptypes (from
, to
, 1))
3155 else if (nconv
&& comp_ptr_ttypes (TREE_TYPE (to
), TREE_TYPE (from
)))
3156 conv
= build_conv (QUAL_CONV
, to
, nconv
);
3157 else if (ptr_reasonably_similar (TREE_TYPE (to
), TREE_TYPE (from
)))
3159 conv
= build_conv (PTR_CONV
, to
, conv
);
3160 ICS_BAD_FLAG (conv
) = 1;
3167 else if (TYPE_PTRMEMFUNC_P (to
) && TYPE_PTRMEMFUNC_P (from
))
3169 tree fromfn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from
));
3170 tree tofn
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to
));
3171 tree fbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn
)));
3172 tree tbase
= TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn
)));
3174 if (! DERIVED_FROM_P (fbase
, tbase
)
3175 || ! comptypes (TREE_TYPE (fromfn
), TREE_TYPE (tofn
), 1)
3176 || ! compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)),
3177 TREE_CHAIN (TYPE_ARG_TYPES (tofn
)), 1)
3178 || TYPE_READONLY (fbase
) != TYPE_READONLY (tbase
)
3179 || TYPE_VOLATILE (fbase
) != TYPE_VOLATILE (tbase
))
3182 from
= cp_build_type_variant (tbase
, TYPE_READONLY (fbase
),
3183 TYPE_VOLATILE (fbase
));
3184 from
= build_cplus_method_type (from
, TREE_TYPE (fromfn
),
3185 TREE_CHAIN (TYPE_ARG_TYPES (fromfn
)));
3186 from
= build_ptrmemfunc_type (build_pointer_type (from
));
3187 conv
= build_conv (PMEM_CONV
, from
, conv
);
3189 else if (tcode
== BOOLEAN_TYPE
)
3191 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
3192 || fcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (from
)))
3195 conv
= build_conv (STD_CONV
, to
, conv
);
3196 if (fcode
== POINTER_TYPE
|| TYPE_PTRMEMFUNC_P (from
)
3197 && ICS_STD_RANK (conv
) < PBOOL_RANK
)
3198 ICS_STD_RANK (conv
) = PBOOL_RANK
;
3200 /* We don't check for ENUMERAL_TYPE here because there are no standard
3201 conversions to enum type. */
3202 else if (tcode
== INTEGER_TYPE
|| tcode
== BOOLEAN_TYPE
3203 || tcode
== REAL_TYPE
)
3205 if (! (INTEGRAL_CODE_P (fcode
) || fcode
== REAL_TYPE
))
3207 conv
= build_conv (STD_CONV
, to
, conv
);
3209 /* Give this a better rank if it's a promotion. */
3210 if (to
== type_promotes_to (from
)
3211 && ICS_STD_RANK (TREE_OPERAND (conv
, 0)) <= PROMO_RANK
)
3212 ICS_STD_RANK (conv
) = PROMO_RANK
;
3214 else if (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
3215 && DERIVED_FROM_P (to
, from
))
3216 conv
= build_conv (BASE_CONV
, to
, conv
);
3223 /* Returns the conversion path from type FROM to reference type TO for
3224 purposes of reference binding. For lvalue binding, either pass a
3225 reference type to FROM or an lvalue expression to EXPR.
3227 Currently does not distinguish in the generated trees between binding to
3228 an lvalue and a temporary. Should it? */
3231 reference_binding (rto
, rfrom
, expr
, flags
)
3232 tree rto
, rfrom
, expr
;
3237 tree to
= TREE_TYPE (rto
);
3241 if (TREE_CODE (from
) == REFERENCE_TYPE
)
3242 from
= TREE_TYPE (from
);
3243 else if (! expr
|| ! real_lvalue_p (expr
))
3246 related
= (TYPE_MAIN_VARIANT (to
) == TYPE_MAIN_VARIANT (from
)
3247 || (IS_AGGR_TYPE (to
) && IS_AGGR_TYPE (from
)
3248 && DERIVED_FROM_P (to
, from
)));
3250 if (lvalue
&& related
3251 && TYPE_READONLY (to
) >= TYPE_READONLY (from
)
3252 && TYPE_VOLATILE (to
) >= TYPE_VOLATILE (from
))
3254 conv
= build1 (IDENTITY_CONV
, from
, expr
);
3256 if (TYPE_MAIN_VARIANT (to
) == TYPE_MAIN_VARIANT (from
))
3257 conv
= build_conv (REF_BIND
, rto
, conv
);
3260 conv
= build_conv (REF_BIND
, rto
, conv
);
3261 ICS_STD_RANK (conv
) = STD_RANK
;
3269 conv
= standard_conversion (to
, rfrom
, expr
);
3272 conv
= build_conv (REF_BIND
, rto
, conv
);
3274 /* Bind directly to a base subobject of a class rvalue. Do it
3275 after building the conversion for proper handling of ICS_RANK. */
3276 if (TREE_CODE (TREE_OPERAND (conv
, 0)) == BASE_CONV
)
3277 TREE_OPERAND (conv
, 0) = TREE_OPERAND (TREE_OPERAND (conv
, 0), 0);
3280 && ((! (TYPE_READONLY (to
) && ! TYPE_VOLATILE (to
)
3281 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0))
3282 /* If T1 is reference-related to T2, cv1 must be the same
3283 cv-qualification as, or greater cv-qualification than,
3284 cv2; otherwise, the program is ill-formed. */
3286 && (TYPE_READONLY (to
) < TYPE_READONLY (from
)
3287 || TYPE_VOLATILE (to
) < TYPE_VOLATILE (from
)))))
3288 ICS_BAD_FLAG (conv
) = 1;
3294 /* Returns the implicit conversion sequence (see [over.ics]) from type FROM
3295 to type TO. The optional expression EXPR may affect the conversion.
3296 FLAGS are the usual overloading flags. Only LOOKUP_NO_CONVERSION is
3300 implicit_conversion (to
, from
, expr
, flags
)
3301 tree to
, from
, expr
;
3305 struct z_candidate
*cand
;
3307 if (expr
&& type_unknown_p (expr
))
3309 expr
= instantiate_type (to
, expr
, 0);
3310 if (expr
== error_mark_node
)
3312 from
= TREE_TYPE (expr
);
3315 if (TREE_CODE (to
) == REFERENCE_TYPE
)
3316 conv
= reference_binding (to
, from
, expr
, flags
);
3318 conv
= standard_conversion (to
, from
, expr
);
3322 else if ((IS_AGGR_TYPE (non_reference (from
))
3323 || IS_AGGR_TYPE (non_reference (to
)))
3324 && (flags
& LOOKUP_NO_CONVERSION
) == 0)
3326 cand
= build_user_type_conversion_1
3327 (to
, expr
, LOOKUP_ONLYCONVERTING
);
3329 conv
= cand
->second_conv
;
3330 if ((! conv
|| ICS_BAD_FLAG (conv
))
3331 && TREE_CODE (to
) == REFERENCE_TYPE
3332 && (flags
& LOOKUP_NO_TEMP_BIND
) == 0)
3334 cand
= build_user_type_conversion_1
3335 (TYPE_MAIN_VARIANT (TREE_TYPE (to
)), expr
, LOOKUP_ONLYCONVERTING
);
3338 if (! TYPE_READONLY (TREE_TYPE (to
))
3339 || TYPE_VOLATILE (TREE_TYPE (to
)))
3340 ICS_BAD_FLAG (cand
->second_conv
) = 1;
3341 if (!conv
|| (ICS_BAD_FLAG (conv
)
3342 > ICS_BAD_FLAG (cand
->second_conv
)))
3343 conv
= build_conv (REF_BIND
, to
, cand
->second_conv
);
3351 /* Create an overload candidate for the function or method FN called with
3352 the argument list ARGLIST and add it to CANDIDATES. FLAGS is passed on
3353 to implicit_conversion. */
3355 static struct z_candidate
*
3356 add_function_candidate (candidates
, fn
, arglist
, flags
)
3357 struct z_candidate
*candidates
;
3361 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
3364 tree parmnode
= parmlist
;
3365 tree argnode
= arglist
;
3367 struct z_candidate
*cand
;
3369 /* The `this' and `in_chrg' arguments to constructors are not considered
3370 in overload resolution. */
3371 if (DECL_CONSTRUCTOR_P (fn
))
3373 parmnode
= TREE_CHAIN (parmnode
);
3374 argnode
= TREE_CHAIN (argnode
);
3375 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
3377 parmnode
= TREE_CHAIN (parmnode
);
3378 argnode
= TREE_CHAIN (argnode
);
3382 len
= list_length (argnode
);
3383 convs
= make_tree_vec (len
);
3385 for (i
= 0; i
< len
; ++i
)
3387 tree arg
= TREE_VALUE (argnode
);
3388 tree argtype
= TREE_TYPE (arg
);
3391 argtype
= cp_build_type_variant
3392 (argtype
, TREE_READONLY (arg
), TREE_THIS_VOLATILE (arg
));
3394 if (parmnode
== void_list_node
)
3397 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
3400 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
3401 ICS_ELLIPSIS_FLAG (t
) = 1;
3404 if (i
== 0 && t
&& TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
3405 && ! DECL_CONSTRUCTOR_P (fn
))
3406 ICS_THIS_FLAG (t
) = 1;
3408 TREE_VEC_ELT (convs
, i
) = t
;
3412 if (ICS_BAD_FLAG (t
))
3416 parmnode
= TREE_CHAIN (parmnode
);
3417 argnode
= TREE_CHAIN (argnode
);
3423 /* Make sure there are default args for the rest of the parms. */
3424 for (; parmnode
&& parmnode
!= void_list_node
;
3425 parmnode
= TREE_CHAIN (parmnode
))
3426 if (! TREE_PURPOSE (parmnode
))
3432 cand
= (struct z_candidate
*) oballoc (sizeof (struct z_candidate
));
3435 cand
->convs
= convs
;
3436 cand
->second_conv
= NULL_TREE
;
3437 cand
->viable
= viable
;
3438 cand
->basetype_path
= NULL_TREE
;
3439 cand
->template = NULL_TREE
;
3440 cand
->next
= candidates
;
3445 /* Create an overload candidate for the conversion function FN which will
3446 be invoked for expression OBJ, producing a pointer-to-function which
3447 will in turn be called with the argument list ARGLIST, and add it to
3448 CANDIDATES. FLAGS is passed on to implicit_conversion. */
3450 static struct z_candidate
*
3451 add_conv_candidate (candidates
, fn
, obj
, arglist
)
3452 struct z_candidate
*candidates
;
3453 tree fn
, obj
, arglist
;
3455 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
3456 tree parmlist
= TYPE_ARG_TYPES (TREE_TYPE (totype
));
3457 int i
, len
= list_length (arglist
) + 1;
3458 tree convs
= make_tree_vec (len
);
3459 tree parmnode
= parmlist
;
3460 tree argnode
= arglist
;
3462 struct z_candidate
*cand
;
3463 int flags
= LOOKUP_NORMAL
;
3465 for (i
= 0; i
< len
; ++i
)
3467 tree arg
= i
== 0 ? obj
: TREE_VALUE (argnode
);
3468 tree argtype
= lvalue_type (arg
);
3472 t
= implicit_conversion (totype
, argtype
, arg
, flags
);
3473 else if (parmnode
== void_list_node
)
3476 t
= implicit_conversion (TREE_VALUE (parmnode
), argtype
, arg
, flags
);
3479 t
= build1 (IDENTITY_CONV
, argtype
, arg
);
3480 ICS_ELLIPSIS_FLAG (t
) = 1;
3483 TREE_VEC_ELT (convs
, i
) = t
;
3487 if (ICS_BAD_FLAG (t
))
3494 parmnode
= TREE_CHAIN (parmnode
);
3495 argnode
= TREE_CHAIN (argnode
);
3501 for (; parmnode
&& parmnode
!= void_list_node
;
3502 parmnode
= TREE_CHAIN (parmnode
))
3503 if (! TREE_PURPOSE (parmnode
))
3509 cand
= (struct z_candidate
*) oballoc (sizeof (struct z_candidate
));
3512 cand
->convs
= convs
;
3513 cand
->second_conv
= NULL_TREE
;
3514 cand
->viable
= viable
;
3515 cand
->basetype_path
= NULL_TREE
;
3516 cand
->template = NULL_TREE
;
3517 cand
->next
= candidates
;
3522 static struct z_candidate
*
3523 build_builtin_candidate (candidates
, fnname
, type1
, type2
,
3524 args
, argtypes
, flags
)
3525 struct z_candidate
*candidates
;
3526 tree fnname
, type1
, type2
, *args
, *argtypes
;
3532 struct z_candidate
*cand
;
3538 convs
= make_tree_vec (args
[2] ? 3 : (args
[1] ? 2 : 1));
3540 for (i
= 0; i
< 2; ++i
)
3545 t
= implicit_conversion (types
[i
], argtypes
[i
], args
[i
], flags
);
3549 /* We need something for printing the candidate. */
3550 t
= build1 (IDENTITY_CONV
, types
[i
], NULL_TREE
);
3552 else if (ICS_BAD_FLAG (t
))
3554 TREE_VEC_ELT (convs
, i
) = t
;
3557 /* For COND_EXPR we rearranged the arguments; undo that now. */
3560 TREE_VEC_ELT (convs
, 2) = TREE_VEC_ELT (convs
, 1);
3561 TREE_VEC_ELT (convs
, 1) = TREE_VEC_ELT (convs
, 0);
3562 t
= implicit_conversion (boolean_type_node
, argtypes
[2], args
[2], flags
);
3564 TREE_VEC_ELT (convs
, 0) = t
;
3569 cand
= (struct z_candidate
*) oballoc (sizeof (struct z_candidate
));
3572 cand
->convs
= convs
;
3573 cand
->second_conv
= NULL_TREE
;
3574 cand
->viable
= viable
;
3575 cand
->basetype_path
= NULL_TREE
;
3576 cand
->template = NULL_TREE
;
3577 cand
->next
= candidates
;
3586 return TYPE_SIZE (complete_type (t
)) != NULL_TREE
;
3589 /* Create any builtin operator overload candidates for the operator in
3590 question given the converted operand types TYPE1 and TYPE2. The other
3591 args are passed through from add_builtin_candidates to
3592 build_builtin_candidate. */
3594 static struct z_candidate
*
3595 add_builtin_candidate (candidates
, code
, code2
, fnname
, type1
, type2
,
3596 args
, argtypes
, flags
)
3597 struct z_candidate
*candidates
;
3598 enum tree_code code
, code2
;
3599 tree fnname
, type1
, type2
, *args
, *argtypes
;
3604 case POSTINCREMENT_EXPR
:
3605 case POSTDECREMENT_EXPR
:
3606 args
[1] = integer_zero_node
;
3607 type2
= integer_type_node
;
3613 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
3614 and VQ is either volatile or empty, there exist candidate operator
3615 functions of the form
3616 VQ T& operator++(VQ T&);
3617 T operator++(VQ T&, int);
3618 5 For every pair T, VQ), where T is an enumeration type or an arithmetic
3619 type other than bool, and VQ is either volatile or empty, there exist
3620 candidate operator functions of the form
3621 VQ T& operator--(VQ T&);
3622 T operator--(VQ T&, int);
3623 6 For every pair T, VQ), where T is a cv-qualified or cv-unqualified
3624 complete object type, and VQ is either volatile or empty, there exist
3625 candidate operator functions of the form
3626 T*VQ& operator++(T*VQ&);
3627 T*VQ& operator--(T*VQ&);
3628 T* operator++(T*VQ&, int);
3629 T* operator--(T*VQ&, int); */
3631 case POSTDECREMENT_EXPR
:
3632 case PREDECREMENT_EXPR
:
3633 if (TREE_CODE (type1
) == BOOLEAN_TYPE
)
3635 case POSTINCREMENT_EXPR
:
3636 case PREINCREMENT_EXPR
:
3637 if ((ARITHMETIC_TYPE_P (type1
) && TREE_CODE (type1
) != ENUMERAL_TYPE
)
3638 || TYPE_PTROB_P (type1
))
3640 type1
= build_reference_type (type1
);
3645 /* 7 For every cv-qualified or cv-unqualified complete object type T, there
3646 exist candidate operator functions of the form
3650 8 For every function type T, there exist candidate operator functions of
3652 T& operator*(T*); */
3655 if (TREE_CODE (type1
) == POINTER_TYPE
3656 && (TYPE_PTROB_P (type1
)
3657 || TREE_CODE (TREE_TYPE (type1
)) == FUNCTION_TYPE
))
3661 /* 9 For every type T, there exist candidate operator functions of the form
3664 10For every promoted arithmetic type T, there exist candidate operator
3665 functions of the form
3669 case CONVERT_EXPR
: /* unary + */
3670 if (TREE_CODE (type1
) == POINTER_TYPE
3671 && TREE_CODE (TREE_TYPE (type1
)) != OFFSET_TYPE
)
3674 if (ARITHMETIC_TYPE_P (type1
))
3678 /* 11For every promoted integral type T, there exist candidate operator
3679 functions of the form
3683 if (INTEGRAL_TYPE_P (type1
))
3687 /* 12For every quintuple C1, C2, T, CV1, CV2), where C2 is a class type, C1
3688 is the same type as C2 or is a derived class of C2, T is a complete
3689 object type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
3690 there exist candidate operator functions of the form
3691 CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
3692 where CV12 is the union of CV1 and CV2. */
3695 if (TREE_CODE (type1
) == POINTER_TYPE
3696 && (TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
)))
3698 tree c1
= TREE_TYPE (type1
);
3699 tree c2
= (TYPE_PTRMEMFUNC_P (type2
)
3700 ? TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type2
)))
3701 : TYPE_OFFSET_BASETYPE (TREE_TYPE (type2
)));
3703 if (IS_AGGR_TYPE (c1
) && DERIVED_FROM_P (c2
, c1
)
3704 && (TYPE_PTRMEMFUNC_P (type2
)
3705 || is_complete (TREE_TYPE (TREE_TYPE (type2
)))))
3710 /* 13For every pair of promoted arithmetic types L and R, there exist can-
3711 didate operator functions of the form
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 bool operator!=(L, R);
3722 where LR is the result of the usual arithmetic conversions between
3725 14For every pair of types T and I, where T is a cv-qualified or cv-
3726 unqualified complete object type and I is a promoted integral type,
3727 there exist candidate operator functions of the form
3728 T* operator+(T*, I);
3729 T& operator[](T*, I);
3730 T* operator-(T*, I);
3731 T* operator+(I, T*);
3732 T& operator[](I, T*);
3734 15For every T, where T is a pointer to complete object type, there exist
3735 candidate operator functions of the form112)
3736 ptrdiff_t operator-(T, T);
3738 16For every pointer type T, there exist candidate operator functions of
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);
3745 bool operator!=(T, T);
3747 17For every pointer to member type T, there exist candidate operator
3748 functions of the form
3749 bool operator==(T, T);
3750 bool operator!=(T, T); */
3753 if (TYPE_PTROB_P (type1
) && TYPE_PTROB_P (type2
))
3755 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
3757 type2
= ptrdiff_type_node
;
3761 case TRUNC_DIV_EXPR
:
3762 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3768 if (TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
)
3769 || TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
))
3771 if ((TYPE_PTRMEMFUNC_P (type1
) || TYPE_PTRMEM_P (type1
))
3772 && null_ptr_cst_p (args
[1]))
3777 if ((TYPE_PTRMEMFUNC_P (type2
) || TYPE_PTRMEM_P (type2
))
3778 && null_ptr_cst_p (args
[0]))
3789 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
)
3790 || TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
3792 if (TYPE_PTR_P (type1
) && null_ptr_cst_p (args
[1]))
3797 if (null_ptr_cst_p (args
[0]) && TYPE_PTR_P (type2
))
3805 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3808 if (INTEGRAL_TYPE_P (type1
) && TYPE_PTROB_P (type2
))
3810 type1
= ptrdiff_type_node
;
3813 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
3815 type2
= ptrdiff_type_node
;
3820 /* 18For every pair of promoted integral types L and R, there exist candi-
3821 date operator functions of the form
3828 where LR is the result of the usual arithmetic conversions between
3831 case TRUNC_MOD_EXPR
:
3837 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
3841 /* 19For every triple L, VQ, R), where L is an arithmetic or enumeration
3842 type, VQ is either volatile or empty, and R is a promoted arithmetic
3843 type, there exist candidate operator functions of the form
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);
3848 VQ L& operator-=(VQ L&, R);
3850 20For every pair T, VQ), where T is any type and VQ is either volatile
3851 or empty, there exist candidate operator functions of the form
3852 T*VQ& operator=(T*VQ&, T*);
3854 21For every pair T, VQ), where T is a pointer to member type and VQ is
3855 either volatile or empty, there exist candidate operator functions of
3857 VQ T& operator=(VQ T&, T);
3859 22For every triple T, VQ, I), where T is a cv-qualified or cv-
3860 unqualified complete object type, VQ is either volatile or empty, and
3861 I is a promoted integral type, there exist candidate operator func-
3863 T*VQ& operator+=(T*VQ&, I);
3864 T*VQ& operator-=(T*VQ&, I);
3866 23For every triple L, VQ, R), where L is an integral or enumeration
3867 type, VQ is either volatile or empty, and R is a promoted integral
3868 type, there exist candidate operator functions of the form
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);
3875 VQ L& operator|=(VQ L&, R); */
3882 if (TYPE_PTROB_P (type1
) && INTEGRAL_TYPE_P (type2
))
3884 type2
= ptrdiff_type_node
;
3888 case TRUNC_DIV_EXPR
:
3889 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3893 case TRUNC_MOD_EXPR
:
3899 if (INTEGRAL_TYPE_P (type1
) && INTEGRAL_TYPE_P (type2
))
3904 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3906 if ((TYPE_PTRMEMFUNC_P (type1
) && TYPE_PTRMEMFUNC_P (type2
))
3907 || (TYPE_PTR_P (type1
) && TYPE_PTR_P (type2
))
3908 || (TYPE_PTRMEM_P (type1
) && TYPE_PTRMEM_P (type2
))
3909 || ((TYPE_PTRMEMFUNC_P (type1
)
3910 || TREE_CODE (type1
) == POINTER_TYPE
)
3911 && null_ptr_cst_p (args
[1])))
3919 my_friendly_abort (367);
3921 type1
= build_reference_type (type1
);
3925 /* Kludge around broken overloading rules whereby
3926 bool ? const char& : enum is ambiguous
3927 (between int and const char&). */
3928 flags
|= LOOKUP_NO_TEMP_BIND
;
3930 /* Extension: Support ?: of enumeral type. Hopefully this will not
3931 be an extension for long. */
3932 if (TREE_CODE (type1
) == ENUMERAL_TYPE
&& type1
== type2
)
3934 else if (TREE_CODE (type1
) == ENUMERAL_TYPE
3935 || TREE_CODE (type2
) == ENUMERAL_TYPE
)
3937 if (ARITHMETIC_TYPE_P (type1
) && ARITHMETIC_TYPE_P (type2
))
3939 if (TREE_CODE (type1
) == TREE_CODE (type2
)
3940 && (TREE_CODE (type1
) == REFERENCE_TYPE
3941 || TREE_CODE (type1
) == POINTER_TYPE
3942 || TYPE_PTRMEMFUNC_P (type1
)
3943 || IS_AGGR_TYPE (type1
)))
3945 if (TREE_CODE (type1
) == REFERENCE_TYPE
3946 || TREE_CODE (type2
) == REFERENCE_TYPE
)
3948 if (((TYPE_PTRMEMFUNC_P (type1
) || TREE_CODE (type1
) == POINTER_TYPE
)
3949 && null_ptr_cst_p (args
[1]))
3950 || IS_AGGR_TYPE (type1
))
3955 if (((TYPE_PTRMEMFUNC_P (type2
) || TREE_CODE (type2
) == POINTER_TYPE
)
3956 && null_ptr_cst_p (args
[0]))
3957 || IS_AGGR_TYPE (type2
))
3965 my_friendly_abort (367);
3968 /* If we're dealing with two pointer types, we need candidates
3969 for both of them. */
3970 if (type2
&& type1
!= type2
3971 && TREE_CODE (type1
) == TREE_CODE (type2
)
3972 && (TREE_CODE (type1
) == REFERENCE_TYPE
3973 || (TREE_CODE (type1
) == POINTER_TYPE
3974 && TYPE_PTRMEM_P (type1
) == TYPE_PTRMEM_P (type2
))
3975 || TYPE_PTRMEMFUNC_P (type1
)
3976 || IS_AGGR_TYPE (type1
)))
3978 candidates
= build_builtin_candidate
3979 (candidates
, fnname
, type1
, type1
, args
, argtypes
, flags
);
3980 return build_builtin_candidate
3981 (candidates
, fnname
, type2
, type2
, args
, argtypes
, flags
);
3984 return build_builtin_candidate
3985 (candidates
, fnname
, type1
, type2
, args
, argtypes
, flags
);
3989 type_decays_to (type
)
3992 if (TREE_CODE (type
) == ARRAY_TYPE
)
3993 return build_pointer_type (TREE_TYPE (type
));
3994 if (TREE_CODE (type
) == FUNCTION_TYPE
)
3995 return build_pointer_type (type
);
3999 /* There are three conditions of builtin candidates:
4001 1) bool-taking candidates. These are the same regardless of the input.
4002 2) pointer-pair taking candidates. These are generated for each type
4003 one of the input types converts to.
4004 3) arithmetic candidates. According to the WP, we should generate
4005 all of these, but I'm trying not to... */
4007 static struct z_candidate
*
4008 add_builtin_candidates (candidates
, code
, code2
, fnname
, args
, flags
)
4009 struct z_candidate
*candidates
;
4010 enum tree_code code
, code2
;
4015 tree type
, argtypes
[3], types
[2];
4017 for (i
= 0; i
< 3; ++i
)
4020 argtypes
[i
] = lvalue_type (args
[i
]);
4022 argtypes
[i
] = NULL_TREE
;
4027 /* 4 For every pair T, VQ), where T is an arithmetic or enumeration type,
4028 and VQ is either volatile or empty, there exist candidate operator
4029 functions of the form
4030 VQ T& operator++(VQ T&); */
4032 case POSTINCREMENT_EXPR
:
4033 case PREINCREMENT_EXPR
:
4034 case POSTDECREMENT_EXPR
:
4035 case PREDECREMENT_EXPR
:
4040 /* 24There also exist candidate operator functions of the form
4041 bool operator!(bool);
4042 bool operator&&(bool, bool);
4043 bool operator||(bool, bool); */
4045 case TRUTH_NOT_EXPR
:
4046 return build_builtin_candidate
4047 (candidates
, fnname
, boolean_type_node
,
4048 NULL_TREE
, args
, argtypes
, flags
);
4050 case TRUTH_ORIF_EXPR
:
4051 case TRUTH_ANDIF_EXPR
:
4052 return build_builtin_candidate
4053 (candidates
, fnname
, boolean_type_node
,
4054 boolean_type_node
, args
, argtypes
, flags
);
4065 types
[0] = types
[1] = NULL_TREE
;
4067 for (i
= 0; i
< 2; ++i
)
4071 else if (IS_AGGR_TYPE (argtypes
[i
]))
4073 tree convs
= lookup_conversions (argtypes
[i
]);
4075 if (code
== COND_EXPR
)
4077 if (real_lvalue_p (args
[i
]))
4078 types
[i
] = tree_cons
4079 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
4081 types
[i
] = tree_cons
4082 (NULL_TREE
, TYPE_MAIN_VARIANT (argtypes
[i
]), types
[i
]);
4085 else if (! convs
|| (i
== 0 && code
== MODIFY_EXPR
4086 && code2
== NOP_EXPR
))
4089 for (; convs
; convs
= TREE_CHAIN (convs
))
4091 type
= TREE_TYPE (TREE_TYPE (TREE_VALUE (convs
)));
4094 && (TREE_CODE (type
) != REFERENCE_TYPE
4095 || TYPE_READONLY (TREE_TYPE (type
))))
4098 if (code
== COND_EXPR
&& TREE_CODE (type
) == REFERENCE_TYPE
)
4099 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4101 type
= non_reference (type
);
4102 if (i
!= 0 || ! ref1
)
4104 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
4105 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
4106 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4107 if (INTEGRAL_TYPE_P (type
))
4108 type
= type_promotes_to (type
);
4111 if (! value_member (type
, types
[i
]))
4112 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4117 if (code
== COND_EXPR
&& real_lvalue_p (args
[i
]))
4118 types
[i
] = tree_cons
4119 (NULL_TREE
, build_reference_type (argtypes
[i
]), types
[i
]);
4120 type
= non_reference (argtypes
[i
]);
4121 if (i
!= 0 || ! ref1
)
4123 type
= TYPE_MAIN_VARIANT (type_decays_to (type
));
4124 if (code
== COND_EXPR
&& TREE_CODE (type
) == ENUMERAL_TYPE
)
4125 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4126 if (INTEGRAL_TYPE_P (type
))
4127 type
= type_promotes_to (type
);
4129 types
[i
] = tree_cons (NULL_TREE
, type
, types
[i
]);
4133 for (; types
[0]; types
[0] = TREE_CHAIN (types
[0]))
4136 for (type
= types
[1]; type
; type
= TREE_CHAIN (type
))
4137 candidates
= add_builtin_candidate
4138 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
4139 TREE_VALUE (type
), args
, argtypes
, flags
);
4141 candidates
= add_builtin_candidate
4142 (candidates
, code
, code2
, fnname
, TREE_VALUE (types
[0]),
4143 NULL_TREE
, args
, argtypes
, flags
);
4149 static struct z_candidate
*
4150 add_template_candidate (candidates
, tmpl
, arglist
, return_type
, flags
)
4151 struct z_candidate
*candidates
;
4152 tree tmpl
, arglist
, return_type
;
4155 int ntparms
= DECL_NTPARMS (tmpl
);
4156 tree targs
= make_tree_vec (ntparms
);
4157 struct z_candidate
*cand
;
4161 i
= fn_type_unification (tmpl
, targs
, arglist
, return_type
, 0);
4166 fn
= instantiate_template (tmpl
, targs
);
4167 if (fn
== error_mark_node
)
4170 cand
= add_function_candidate (candidates
, fn
, arglist
, flags
);
4171 cand
->template = DECL_TEMPLATE_INFO (fn
);
4176 static struct z_candidate
*
4177 add_template_conv_candidate (candidates
, tmpl
, obj
, arglist
, return_type
)
4178 struct z_candidate
*candidates
;
4179 tree tmpl
, obj
, arglist
, return_type
;
4181 int ntparms
= DECL_NTPARMS (tmpl
);
4182 tree targs
= make_tree_vec (ntparms
);
4183 struct z_candidate
*cand
;
4187 i
= fn_type_unification (tmpl
, targs
, arglist
, return_type
, 0);
4192 fn
= instantiate_template (tmpl
, targs
);
4193 if (fn
== error_mark_node
)
4196 cand
= add_conv_candidate (candidates
, fn
, obj
, arglist
);
4197 cand
->template = DECL_TEMPLATE_INFO (fn
);
4204 struct z_candidate
*cands
;
4206 for (; cands
; cands
= cands
->next
)
4207 if (pedantic
? cands
->viable
== 1 : cands
->viable
)
4212 static struct z_candidate
*
4213 splice_viable (cands
)
4214 struct z_candidate
*cands
;
4216 struct z_candidate
**p
= &cands
;
4220 if (pedantic
? (*p
)->viable
== 1 : (*p
)->viable
)
4233 /* Fix this to work on non-lvalues. */
4234 if (IS_SIGNATURE_POINTER (TREE_TYPE (obj
))
4235 || IS_SIGNATURE_REFERENCE (TREE_TYPE (obj
)))
4238 return build_unary_op (ADDR_EXPR
, obj
, 0);
4242 print_z_candidates (candidates
)
4243 struct z_candidate
*candidates
;
4245 char *str
= "candidates are:";
4246 for (; candidates
; candidates
= candidates
->next
)
4248 if (TREE_CODE (candidates
->fn
) == IDENTIFIER_NODE
)
4250 if (candidates
->fn
== ansi_opname
[COND_EXPR
])
4251 cp_error ("%s %D(%T, %T, %T) <builtin>", str
, candidates
->fn
,
4252 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
4253 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)),
4254 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 2)));
4255 else if (TREE_VEC_LENGTH (candidates
->convs
) == 2)
4256 cp_error ("%s %D(%T, %T) <builtin>", str
, candidates
->fn
,
4257 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)),
4258 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 1)));
4260 cp_error ("%s %D(%T) <builtin>", str
, candidates
->fn
,
4261 TREE_TYPE (TREE_VEC_ELT (candidates
->convs
, 0)));
4264 cp_error_at ("%s %+D%s", str
, candidates
->fn
,
4265 candidates
->viable
== -1 ? " <near match>" : "");
4270 /* Returns the best overload candidate to perform the requested
4271 conversion. This function is used for three the overloading situations
4272 described in [over.match.copy], [over.match.conv], and [over.match.ref].
4273 If TOTYPE is a REFERENCE_TYPE, we're trying to find an lvalue binding as
4274 per [dcl.init.ref], so we ignore temporary bindings. */
4276 static struct z_candidate
*
4277 build_user_type_conversion_1 (totype
, expr
, flags
)
4281 struct z_candidate
*candidates
, *cand
;
4282 tree fromtype
= TREE_TYPE (expr
);
4283 tree ctors
= NULL_TREE
, convs
= NULL_TREE
, *p
;
4285 tree templates
= NULL_TREE
;
4287 if (IS_AGGR_TYPE (totype
))
4288 ctors
= lookup_fnfields (TYPE_BINFO (totype
), ctor_identifier
, 0);
4289 if (IS_AGGR_TYPE (fromtype
)
4290 && (! IS_AGGR_TYPE (totype
) || ! DERIVED_FROM_P (totype
, fromtype
)))
4291 convs
= lookup_conversions (fromtype
);
4294 flags
|= LOOKUP_NO_CONVERSION
;
4298 tree t
= build_int_2 (0, 0);
4299 TREE_TYPE (t
) = build_pointer_type (totype
);
4300 args
= build_tree_list (NULL_TREE
, expr
);
4301 if (TYPE_USES_VIRTUAL_BASECLASSES (totype
))
4302 args
= tree_cons (NULL_TREE
, integer_one_node
, args
);
4303 args
= tree_cons (NULL_TREE
, t
, args
);
4305 ctors
= TREE_VALUE (ctors
);
4307 for (; ctors
; ctors
= DECL_CHAIN (ctors
))
4309 if (DECL_NONCONVERTING_P (ctors
))
4312 if (TREE_CODE (ctors
) == TEMPLATE_DECL
)
4314 templates
= decl_tree_cons (NULL_TREE
, ctors
, templates
);
4316 add_template_candidate (candidates
, ctors
,
4317 args
, NULL_TREE
, flags
);
4320 candidates
= add_function_candidate (candidates
, ctors
,
4325 candidates
->second_conv
= build1 (IDENTITY_CONV
, totype
, NULL_TREE
);
4326 candidates
->basetype_path
= TYPE_BINFO (totype
);
4331 args
= build_tree_list (NULL_TREE
, build_this (expr
));
4333 for (; convs
; convs
= TREE_CHAIN (convs
))
4335 tree fn
= TREE_VALUE (convs
);
4336 int convflags
= LOOKUP_NO_CONVERSION
;
4339 /* If we are called to convert to a reference type, we are trying to
4340 find an lvalue binding, so don't even consider temporaries. If
4341 we don't find an lvalue binding, the caller will try again to
4342 look for a temporary binding. */
4343 if (TREE_CODE (totype
) == REFERENCE_TYPE
)
4344 convflags
|= LOOKUP_NO_TEMP_BIND
;
4346 ics
= implicit_conversion
4347 (totype
, TREE_TYPE (TREE_TYPE (fn
)), 0, convflags
);
4349 if (TREE_CODE (totype
) == REFERENCE_TYPE
&& ics
&& ICS_BAD_FLAG (ics
))
4350 /* ignore the near match. */;
4352 for (; fn
; fn
= DECL_CHAIN (fn
))
4354 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4356 templates
= decl_tree_cons (NULL_TREE
, fn
, templates
);
4358 add_template_candidate (candidates
, fn
, args
,
4362 candidates
= add_function_candidate (candidates
, fn
,
4367 candidates
->second_conv
= ics
;
4368 candidates
->basetype_path
= TREE_PURPOSE (convs
);
4369 if (candidates
->viable
== 1 && ICS_BAD_FLAG (ics
))
4370 candidates
->viable
= -1;
4375 if (! any_viable (candidates
))
4378 if (flags
& LOOKUP_COMPLAIN
)
4380 if (candidates
&& ! candidates
->next
)
4381 /* say why this one won't work or try to be loose */;
4383 cp_error ("no viable candidates");
4390 candidates
= splice_viable (candidates
);
4391 cand
= tourney (candidates
);
4395 if (flags
& LOOKUP_COMPLAIN
)
4397 cp_error ("conversion from `%T' to `%T' is ambiguous",
4399 print_z_candidates (candidates
);
4402 cand
= candidates
; /* any one will do */
4403 cand
->second_conv
= build1 (AMBIG_CONV
, totype
, expr
);
4404 ICS_USER_FLAG (cand
->second_conv
) = 1;
4405 ICS_BAD_FLAG (cand
->second_conv
) = 1;
4410 for (p
= &(cand
->second_conv
); TREE_CODE (*p
) != IDENTITY_CONV
; )
4411 p
= &(TREE_OPERAND (*p
, 0));
4413 /* Pedantically, normal function declarations are never considered
4414 to refer to template instantiations, but we won't implement that
4415 until we implement full template instantiation syntax. */
4416 if (templates
&& ! cand
->template && ! DECL_INITIAL (cand
->fn
)
4417 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
4418 add_maybe_template (cand
->fn
, templates
);
4422 (DECL_CONSTRUCTOR_P (cand
->fn
)
4423 ? totype
: non_reference (TREE_TYPE (TREE_TYPE (cand
->fn
)))),
4424 NULL_TREE
, cand
->fn
, cand
->convs
, cand
->basetype_path
);
4425 ICS_USER_FLAG (cand
->second_conv
) = 1;
4426 if (cand
->viable
== -1)
4427 ICS_BAD_FLAG (cand
->second_conv
) = 1;
4433 build_user_type_conversion (totype
, expr
, flags
)
4437 struct z_candidate
*cand
4438 = build_user_type_conversion_1 (totype
, expr
, flags
);
4442 if (TREE_CODE (cand
->second_conv
) == AMBIG_CONV
)
4443 return error_mark_node
;
4444 return convert_from_reference (convert_like (cand
->second_conv
, expr
));
4449 /* Do any initial processing on the arguments to a function call. */
4456 for (t
= args
; t
; t
= TREE_CHAIN (t
))
4458 if (TREE_VALUE (t
) == error_mark_node
)
4459 return error_mark_node
;
4460 else if (TREE_CODE (TREE_TYPE (TREE_VALUE (t
))) == VOID_TYPE
)
4462 error ("invalid use of void expression");
4463 return error_mark_node
;
4465 else if (TREE_CODE (TREE_VALUE (t
)) == OFFSET_REF
)
4466 TREE_VALUE (t
) = resolve_offset_ref (TREE_VALUE (t
));
4472 build_new_function_call (fn
, args
, obj
)
4475 struct z_candidate
*candidates
= 0, *cand
;
4477 if (obj
== NULL_TREE
&& TREE_CODE (fn
) == TREE_LIST
)
4480 tree templates
= NULL_TREE
;
4482 args
= resolve_args (args
);
4484 if (args
== error_mark_node
)
4485 return error_mark_node
;
4487 for (t
= TREE_VALUE (fn
); t
; t
= DECL_CHAIN (t
))
4489 if (TREE_CODE (t
) == TEMPLATE_DECL
)
4491 templates
= decl_tree_cons (NULL_TREE
, t
, templates
);
4492 candidates
= add_template_candidate
4493 (candidates
, t
, args
, NULL_TREE
, LOOKUP_NORMAL
);
4496 candidates
= add_function_candidate
4497 (candidates
, t
, args
, LOOKUP_NORMAL
);
4500 if (! any_viable (candidates
))
4502 if (candidates
&& ! candidates
->next
)
4503 return build_function_call (candidates
->fn
, args
);
4504 cp_error ("no matching function for call to `%D (%A)'",
4505 TREE_PURPOSE (fn
), args
);
4507 print_z_candidates (candidates
);
4508 return error_mark_node
;
4510 candidates
= splice_viable (candidates
);
4511 cand
= tourney (candidates
);
4515 cp_error ("call of overloaded `%D (%A)' is ambiguous",
4516 TREE_PURPOSE (fn
), args
);
4517 print_z_candidates (candidates
);
4518 return error_mark_node
;
4521 /* Pedantically, normal function declarations are never considered
4522 to refer to template instantiations, but we won't implement that
4523 until we implement full template instantiation syntax. */
4524 if (templates
&& ! cand
->template && ! DECL_INITIAL (cand
->fn
))
4525 add_maybe_template (cand
->fn
, templates
);
4527 return build_over_call (cand
->fn
, cand
->convs
, args
, LOOKUP_NORMAL
);
4530 return build_function_call (fn
, args
);
4534 build_object_call (obj
, args
)
4537 struct z_candidate
*candidates
= 0, *cand
;
4538 tree fns
, convs
, mem_args
;
4539 tree type
= TREE_TYPE (obj
);
4540 tree templates
= NULL_TREE
;
4542 fns
= lookup_fnfields (TYPE_BINFO (type
), ansi_opname
[CALL_EXPR
], 0);
4544 args
= resolve_args (args
);
4546 if (args
== error_mark_node
)
4547 return error_mark_node
;
4551 tree fn
= TREE_VALUE (fns
);
4552 mem_args
= tree_cons (NULL_TREE
, build_this (obj
), args
);
4554 for (; fn
; fn
= DECL_CHAIN (fn
))
4556 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4558 templates
= decl_tree_cons (NULL_TREE
, fn
, templates
);
4559 candidates
= add_template_candidate (candidates
, fn
,
4560 mem_args
, NULL_TREE
,
4564 candidates
= add_function_candidate
4565 (candidates
, fn
, mem_args
, LOOKUP_NORMAL
);
4568 candidates
->basetype_path
= TREE_PURPOSE (fns
);
4572 convs
= lookup_conversions (type
);
4574 for (; convs
; convs
= TREE_CHAIN (convs
))
4576 tree fn
= TREE_VALUE (convs
);
4577 tree totype
= TREE_TYPE (TREE_TYPE (fn
));
4579 if (TREE_CODE (totype
) == POINTER_TYPE
4580 && TREE_CODE (TREE_TYPE (totype
)) == FUNCTION_TYPE
)
4581 for (; fn
; fn
= DECL_CHAIN (fn
))
4583 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4585 templates
= decl_tree_cons (NULL_TREE
, fn
, templates
);
4586 candidates
= add_template_conv_candidate (candidates
,
4593 candidates
= add_conv_candidate (candidates
, fn
, obj
, args
);
4596 candidates
->basetype_path
= TREE_PURPOSE (convs
);
4600 if (! any_viable (candidates
))
4602 cp_error ("no match for call to `(%T) (%A)'", TREE_TYPE (obj
), args
);
4603 print_z_candidates (candidates
);
4604 return error_mark_node
;
4607 candidates
= splice_viable (candidates
);
4608 cand
= tourney (candidates
);
4612 cp_error ("call of `(%T) (%A)' is ambiguous", TREE_TYPE (obj
), args
);
4613 print_z_candidates (candidates
);
4614 return error_mark_node
;
4617 if (DECL_NAME (cand
->fn
) == ansi_opname
[CALL_EXPR
])
4618 return build_over_call (cand
->fn
, cand
->convs
, mem_args
, LOOKUP_NORMAL
);
4620 obj
= convert_like (TREE_VEC_ELT (cand
->convs
, 0), obj
);
4623 return build_function_call (obj
, args
);
4627 op_error (code
, code2
, arg1
, arg2
, arg3
, problem
)
4628 enum tree_code code
, code2
;
4629 tree arg1
, arg2
, arg3
;
4633 = (code
== MODIFY_EXPR
? assignop_tab
[code2
] : opname_tab
[code
]);
4638 cp_error ("%s for `%T ? %T : %T'", problem
,
4639 error_type (arg1
), error_type (arg2
), error_type (arg3
));
4641 case POSTINCREMENT_EXPR
:
4642 case POSTDECREMENT_EXPR
:
4643 cp_error ("%s for `%T%s'", problem
, error_type (arg1
), opname
);
4646 cp_error ("%s for `%T[%T]'", problem
,
4647 error_type (arg1
), error_type (arg2
));
4651 cp_error ("%s for `%T %s %T'", problem
,
4652 error_type (arg1
), opname
, error_type (arg2
));
4654 cp_error ("%s for `%s%T'", problem
, opname
, error_type (arg1
));
4659 build_new_op (code
, flags
, arg1
, arg2
, arg3
)
4660 enum tree_code code
;
4662 tree arg1
, arg2
, arg3
;
4664 struct z_candidate
*candidates
= 0, *cand
;
4665 tree fns
, mem_arglist
, arglist
, fnname
;
4666 enum tree_code code2
= NOP_EXPR
;
4667 tree templates
= NULL_TREE
;
4670 if (arg1
== error_mark_node
4671 || arg2
== error_mark_node
4672 || arg3
== error_mark_node
)
4673 return error_mark_node
;
4675 if (code
== MODIFY_EXPR
)
4677 code2
= TREE_CODE (arg3
);
4679 fnname
= ansi_assopname
[code2
];
4682 fnname
= ansi_opname
[code
];
4691 arglist
= tree_cons (NULL_TREE
, arg2
, arg3
);
4692 if (flags
& LOOKUP_GLOBAL
)
4693 return build_new_function_call
4694 (lookup_name_nonclass (fnname
), arglist
, NULL_TREE
);
4697 rval
= build_method_call
4698 (build_indirect_ref (build1 (NOP_EXPR
, arg1
, error_mark_node
),
4700 fnname
, arglist
, NULL_TREE
, flags
);
4701 if (rval
== error_mark_node
)
4702 /* User might declare fancy operator new, but invoke it
4703 like standard one. */
4706 TREE_TYPE (rval
) = arg1
;
4707 TREE_CALLS_NEW (rval
) = 1;
4711 case VEC_DELETE_EXPR
:
4716 if (flags
& LOOKUP_GLOBAL
)
4717 return build_new_function_call
4718 (lookup_name_nonclass (fnname
),
4719 build_tree_list (NULL_TREE
, arg1
), NULL_TREE
);
4721 arglist
= tree_cons (NULL_TREE
, arg1
, build_tree_list (NULL_TREE
, arg2
));
4723 arg1
= TREE_TYPE (arg1
);
4725 /* This handles the case where we're trying to delete
4730 if (TREE_CODE (TREE_TYPE (arg1
)) == ARRAY_TYPE
)
4732 /* Strip off the pointer and the array. */
4733 arg1
= TREE_TYPE (TREE_TYPE (arg1
));
4735 while (TREE_CODE (arg1
) == ARRAY_TYPE
)
4736 arg1
= (TREE_TYPE (arg1
));
4738 arg1
= build_pointer_type (arg1
);
4742 rval
= build_method_call
4743 (build_indirect_ref (build1 (NOP_EXPR
, arg1
,
4746 fnname
, arglist
, NULL_TREE
, flags
);
4748 /* This can happen when operator delete is protected. */
4749 my_friendly_assert (rval
!= error_mark_node
, 250);
4750 TREE_TYPE (rval
) = void_type_node
;
4756 return build_object_call (arg1
, arg2
);
4759 /* The comma operator can have void args. */
4760 if (TREE_CODE (arg1
) == OFFSET_REF
)
4761 arg1
= resolve_offset_ref (arg1
);
4762 if (arg2
&& TREE_CODE (arg2
) == OFFSET_REF
)
4763 arg2
= resolve_offset_ref (arg2
);
4764 if (arg3
&& TREE_CODE (arg3
) == OFFSET_REF
)
4765 arg3
= resolve_offset_ref (arg3
);
4767 if (code
== COND_EXPR
)
4769 if (arg2
== NULL_TREE
4770 || TREE_CODE (TREE_TYPE (arg2
)) == VOID_TYPE
4771 || TREE_CODE (TREE_TYPE (arg3
)) == VOID_TYPE
4772 || (! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))
4773 && ! IS_OVERLOAD_TYPE (TREE_TYPE (arg3
))))
4776 else if (! IS_OVERLOAD_TYPE (TREE_TYPE (arg1
))
4777 && (! arg2
|| ! IS_OVERLOAD_TYPE (TREE_TYPE (arg2
))))
4780 if (code
== POSTINCREMENT_EXPR
|| code
== POSTDECREMENT_EXPR
)
4781 arg2
= integer_zero_node
;
4783 fns
= lookup_name_nonclass (fnname
);
4784 /* + Koenig lookup */
4787 arglist
= tree_cons (NULL_TREE
, arg1
, tree_cons
4788 (NULL_TREE
, arg2
, build_tree_list (NULL_TREE
, arg3
)));
4790 arglist
= tree_cons (NULL_TREE
, arg1
, build_tree_list (NULL_TREE
, arg2
));
4792 arglist
= build_tree_list (NULL_TREE
, arg1
);
4794 if (fns
&& TREE_CODE (fns
) == TREE_LIST
)
4795 fns
= TREE_VALUE (fns
);
4796 for (; fns
; fns
= DECL_CHAIN (fns
))
4798 if (TREE_CODE (fns
) == TEMPLATE_DECL
)
4800 templates
= decl_tree_cons (NULL_TREE
, fns
, templates
);
4801 candidates
= add_template_candidate
4802 (candidates
, fns
, arglist
, TREE_TYPE (fnname
), flags
);
4805 candidates
= add_function_candidate (candidates
, fns
, arglist
, flags
);
4808 if (IS_AGGR_TYPE (TREE_TYPE (arg1
)))
4809 fns
= lookup_fnfields (TYPE_BINFO (TREE_TYPE (arg1
)), fnname
, 0);
4815 tree fn
= TREE_VALUE (fns
);
4816 mem_arglist
= tree_cons (NULL_TREE
, build_this (arg1
), TREE_CHAIN (arglist
));
4817 for (; fn
; fn
= DECL_CHAIN (fn
))
4821 if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
4822 this_arglist
= mem_arglist
;
4824 this_arglist
= arglist
;
4826 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4828 /* A member template. */
4829 templates
= decl_tree_cons (NULL_TREE
, fn
, templates
);
4830 candidates
= add_template_candidate
4831 (candidates
, fn
, this_arglist
,
4832 TREE_TYPE (fnname
), LOOKUP_NORMAL
);
4835 candidates
= add_function_candidate
4836 (candidates
, fn
, this_arglist
, flags
);
4839 candidates
->basetype_path
= TREE_PURPOSE (fns
);
4846 /* Rearrange the arguments for ?: so that add_builtin_candidate only has
4847 to know about two args; a builtin candidate will always have a first
4848 parameter of type bool. We'll handle that in
4849 build_builtin_candidate. */
4850 if (code
== COND_EXPR
)
4860 args
[2] = NULL_TREE
;
4863 candidates
= add_builtin_candidates
4864 (candidates
, code
, code2
, fnname
, args
, flags
);
4867 if (! any_viable (candidates
))
4871 case POSTINCREMENT_EXPR
:
4872 case POSTDECREMENT_EXPR
:
4873 /* Look for an `operator++ (int)'. If they didn't have
4874 one, then we fall back to the old way of doing things. */
4875 if (flags
& LOOKUP_COMPLAIN
)
4876 cp_pedwarn ("no `%D (int)' declared for postfix `%s', trying prefix operator instead",
4877 fnname
, opname_tab
[code
]);
4878 if (code
== POSTINCREMENT_EXPR
)
4879 code
= PREINCREMENT_EXPR
;
4881 code
= PREDECREMENT_EXPR
;
4882 return build_new_op (code
, flags
, arg1
, NULL_TREE
, NULL_TREE
);
4884 /* The caller will deal with these. */
4890 if (flags
& LOOKUP_COMPLAIN
)
4892 op_error (code
, code2
, arg1
, arg2
, arg3
, "no match");
4893 print_z_candidates (candidates
);
4895 return error_mark_node
;
4897 candidates
= splice_viable (candidates
);
4898 cand
= tourney (candidates
);
4902 if (flags
& LOOKUP_COMPLAIN
)
4904 op_error (code
, code2
, arg1
, arg2
, arg3
, "ambiguous overload");
4905 print_z_candidates (candidates
);
4907 return error_mark_node
;
4910 if (TREE_CODE (cand
->fn
) == FUNCTION_DECL
)
4912 extern int warn_synth
;
4914 && fnname
== ansi_opname
[MODIFY_EXPR
]
4915 && DECL_ARTIFICIAL (cand
->fn
)
4917 && ! candidates
->next
->next
)
4919 cp_warning ("using synthesized `%#D' for copy assignment",
4921 cp_warning_at (" where cfront would use `%#D'",
4923 ? candidates
->next
->fn
4927 if (DECL_FUNCTION_MEMBER_P (cand
->fn
))
4928 enforce_access (cand
->basetype_path
, cand
->fn
);
4930 /* Pedantically, normal function declarations are never considered
4931 to refer to template instantiations, but we won't implement that
4932 until we implement full template instantiation syntax. */
4933 if (templates
&& ! cand
->template && ! DECL_INITIAL (cand
->fn
)
4934 && TREE_CODE (TREE_TYPE (cand
->fn
)) != METHOD_TYPE
)
4935 add_maybe_template (cand
->fn
, templates
);
4937 return build_over_call
4938 (cand
->fn
, cand
->convs
,
4939 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
4940 ? mem_arglist
: arglist
,
4944 /* Check for comparison of different enum types. */
4953 if (flag_int_enum_equivalence
== 0
4954 && TREE_CODE (TREE_TYPE (arg1
)) == ENUMERAL_TYPE
4955 && TREE_CODE (TREE_TYPE (arg2
)) == ENUMERAL_TYPE
4956 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg1
))
4957 != TYPE_MAIN_VARIANT (TREE_TYPE (arg2
))))
4959 cp_warning ("comparison between `%#T' and `%#T'",
4960 TREE_TYPE (arg1
), TREE_TYPE (arg2
));
4964 /* We need to strip any leading REF_BIND so that bitfields don't cause
4965 errors. This should not remove any important conversions, because
4966 builtins don't apply to class objects directly. */
4967 conv
= TREE_VEC_ELT (cand
->convs
, 0);
4968 if (TREE_CODE (conv
) == REF_BIND
)
4969 conv
= TREE_OPERAND (conv
, 0);
4970 arg1
= convert_like (conv
, arg1
);
4972 arg2
= convert_like (TREE_VEC_ELT (cand
->convs
, 1), arg2
);
4974 arg3
= convert_like (TREE_VEC_ELT (cand
->convs
, 2), arg3
);
4980 return build_modify_expr (arg1
, code2
, arg2
);
4983 return build_indirect_ref (arg1
, "unary *");
4988 case TRUNC_DIV_EXPR
:
4999 case TRUNC_MOD_EXPR
:
5003 case TRUTH_ANDIF_EXPR
:
5004 case TRUTH_ORIF_EXPR
:
5005 return build_binary_op_nodefault (code
, arg1
, arg2
, code
);
5010 case TRUTH_NOT_EXPR
:
5011 case PREINCREMENT_EXPR
:
5012 case POSTINCREMENT_EXPR
:
5013 case PREDECREMENT_EXPR
:
5014 case POSTDECREMENT_EXPR
:
5017 return build_unary_op (code
, arg1
, candidates
!= 0);
5020 return build_array_ref (arg1
, arg2
);
5023 return build_conditional_expr (arg1
, arg2
, arg3
);
5026 return build_m_component_ref
5027 (build_indirect_ref (arg1
, NULL_PTR
), arg2
);
5029 /* The caller will deal with these. */
5036 my_friendly_abort (367);
5041 enforce_access (basetype_path
, function
)
5042 tree basetype_path
, function
;
5044 tree access
= compute_access (basetype_path
, function
);
5046 if (access
== access_private_node
)
5048 cp_error_at ("`%+#D' is %s", function
,
5049 TREE_PRIVATE (function
) ? "private"
5050 : "from private base class");
5051 error ("within this context");
5053 else if (access
== access_protected_node
)
5055 cp_error_at ("`%+#D' %s", function
,
5056 TREE_PROTECTED (function
) ? "is protected"
5057 : "has protected accessibility");
5058 error ("within this context");
5062 /* Perform the conversions in CONVS on the expression EXPR. */
5065 convert_like (convs
, expr
)
5068 if (ICS_BAD_FLAG (convs
)
5069 && TREE_CODE (convs
) != USER_CONV
5070 && TREE_CODE (convs
) != AMBIG_CONV
)
5073 for (; t
; t
= TREE_OPERAND (t
, 0))
5075 if (TREE_CODE (t
) == USER_CONV
)
5077 expr
= convert_like (t
, expr
);
5080 else if (TREE_CODE (t
) == AMBIG_CONV
)
5081 return convert_like (t
, expr
);
5082 else if (TREE_CODE (t
) == IDENTITY_CONV
)
5085 return convert_for_initialization
5086 (NULL_TREE
, TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
,
5087 "conversion", NULL_TREE
, 0);
5090 switch (TREE_CODE (convs
))
5094 tree fn
= TREE_OPERAND (convs
, 1);
5096 enforce_access (TREE_OPERAND (convs
, 3), fn
);
5098 if (DECL_CONSTRUCTOR_P (fn
))
5100 tree t
= build_int_2 (0, 0);
5101 TREE_TYPE (t
) = build_pointer_type (DECL_CONTEXT (fn
));
5103 args
= build_tree_list (NULL_TREE
, expr
);
5104 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
5105 args
= tree_cons (NULL_TREE
, integer_one_node
, args
);
5106 args
= tree_cons (NULL_TREE
, t
, args
);
5109 args
= build_this (expr
);
5110 expr
= build_over_call
5111 (TREE_OPERAND (convs
, 1), TREE_OPERAND (convs
, 2),
5112 args
, LOOKUP_NORMAL
);
5114 /* If this is a constructor or a function returning an aggr type,
5115 we need to build up a TARGET_EXPR. */
5116 if (DECL_CONSTRUCTOR_P (fn
))
5117 expr
= build_cplus_new (TREE_TYPE (convs
), expr
);
5122 if (type_unknown_p (expr
))
5123 expr
= instantiate_type (TREE_TYPE (convs
), expr
, 1);
5124 if (TREE_READONLY_DECL_P (expr
))
5125 expr
= decl_constant_value (expr
);
5128 /* Call build_user_type_conversion again for the error. */
5129 return build_user_type_conversion
5130 (TREE_TYPE (convs
), TREE_OPERAND (convs
, 0), LOOKUP_NORMAL
);
5133 expr
= convert_like (TREE_OPERAND (convs
, 0), expr
);
5134 if (expr
== error_mark_node
)
5135 return error_mark_node
;
5137 switch (TREE_CODE (convs
))
5140 if (! IS_AGGR_TYPE (TREE_TYPE (convs
)))
5142 /* else fall through */
5144 return build_user_type_conversion
5145 (TREE_TYPE (convs
), expr
, LOOKUP_NORMAL
);
5147 return convert_to_reference
5148 (TREE_TYPE (convs
), expr
,
5149 CONV_IMPLICIT
, LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
,
5152 return decay_conversion (expr
);
5154 return ocp_convert (TREE_TYPE (convs
), expr
, CONV_IMPLICIT
,
5155 LOOKUP_NORMAL
|LOOKUP_NO_CONVERSION
);
5159 convert_default_arg (type
, arg
)
5162 arg
= break_out_target_exprs (arg
);
5164 if (TREE_CODE (arg
) == CONSTRUCTOR
)
5166 arg
= digest_init (type
, arg
, 0);
5167 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
5168 "default argument", 0, 0);
5172 /* This could get clobbered by the following call. */
5173 if (TREE_HAS_CONSTRUCTOR (arg
))
5174 arg
= copy_node (arg
);
5176 arg
= convert_for_initialization (0, type
, arg
, LOOKUP_NORMAL
,
5177 "default argument", 0, 0);
5178 #ifdef PROMOTE_PROTOTYPES
5179 if ((TREE_CODE (type
) == INTEGER_TYPE
5180 || TREE_CODE (type
) == ENUMERAL_TYPE
)
5181 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
5182 arg
= default_conversion (arg
);
5190 build_over_call (fn
, convs
, args
, flags
)
5191 tree fn
, convs
, args
;
5194 tree converted_args
= NULL_TREE
;
5195 tree parm
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
5196 tree conv
, arg
, val
;
5200 if (args
&& TREE_CODE (args
) != TREE_LIST
)
5201 args
= build_tree_list (NULL_TREE
, args
);
5204 /* The implicit parameters to a constructor are not considered by overload
5205 resolution, and must be of the proper type. */
5206 if (DECL_CONSTRUCTOR_P (fn
))
5208 converted_args
= tree_cons (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
5209 arg
= TREE_CHAIN (arg
);
5210 parm
= TREE_CHAIN (parm
);
5211 if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn
)))
5213 converted_args
= tree_cons
5214 (NULL_TREE
, TREE_VALUE (arg
), converted_args
);
5215 arg
= TREE_CHAIN (arg
);
5216 parm
= TREE_CHAIN (parm
);
5219 /* Bypass access control for 'this' parameter. */
5220 else if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
5222 tree parmtype
= TREE_VALUE (parm
);
5223 tree argtype
= TREE_TYPE (TREE_VALUE (arg
));
5224 if (ICS_BAD_FLAG (TREE_VEC_ELT (convs
, i
)))
5226 int dv
= (TYPE_VOLATILE (TREE_TYPE (parmtype
))
5227 < TYPE_VOLATILE (TREE_TYPE (argtype
)));
5228 int dc
= (TYPE_READONLY (TREE_TYPE (parmtype
))
5229 < TYPE_READONLY (TREE_TYPE (argtype
)));
5230 char *p
= (dv
&& dc
? "const and volatile"
5231 : dc
? "const" : dv
? "volatile" : "");
5233 cp_pedwarn ("passing `%T' as `this' argument of `%#D' discards %s",
5234 TREE_TYPE (argtype
), fn
, p
);
5236 converted_args
= tree_cons
5237 (NULL_TREE
, convert_force (TREE_VALUE (parm
), TREE_VALUE (arg
), CONV_C_CAST
),
5239 parm
= TREE_CHAIN (parm
);
5240 arg
= TREE_CHAIN (arg
);
5246 parm
= TREE_CHAIN (parm
), arg
= TREE_CHAIN (arg
), ++i
)
5248 tree type
= TREE_VALUE (parm
);
5250 conv
= TREE_VEC_ELT (convs
, i
);
5251 if (ICS_BAD_FLAG (conv
))
5254 val
= TREE_VALUE (arg
);
5256 for (; t
; t
= TREE_OPERAND (t
, 0))
5258 if (TREE_CODE (t
) == USER_CONV
5259 || TREE_CODE (t
) == AMBIG_CONV
)
5261 val
= convert_like (t
, val
);
5264 else if (TREE_CODE (t
) == IDENTITY_CONV
)
5267 val
= convert_for_initialization
5268 (NULL_TREE
, type
, val
, LOOKUP_NORMAL
,
5269 "argument passing", fn
, i
- is_method
);
5272 val
= convert_like (conv
, TREE_VALUE (arg
));
5274 #ifdef PROMOTE_PROTOTYPES
5275 if ((TREE_CODE (type
) == INTEGER_TYPE
5276 || TREE_CODE (type
) == ENUMERAL_TYPE
)
5277 && (TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
)))
5278 val
= default_conversion (val
);
5280 converted_args
= tree_cons (NULL_TREE
, val
, converted_args
);
5283 /* Default arguments */
5284 for (; parm
&& parm
!= void_list_node
; parm
= TREE_CHAIN (parm
))
5286 tree arg
= TREE_PURPOSE (parm
);
5288 if (DECL_TEMPLATE_INFO (fn
))
5289 /* This came from a template. Instantiate the default arg here,
5291 arg
= tsubst_expr (arg
, DECL_TI_ARGS (fn
),
5292 TREE_VEC_LENGTH (DECL_TI_ARGS (fn
)), NULL_TREE
);
5293 converted_args
= tree_cons
5294 (NULL_TREE
, convert_default_arg (TREE_VALUE (parm
), arg
),
5299 for (; arg
; arg
= TREE_CHAIN (arg
))
5301 val
= TREE_VALUE (arg
);
5303 if (TREE_CODE (TREE_TYPE (val
)) == REAL_TYPE
5304 && (TYPE_PRECISION (TREE_TYPE (val
))
5305 < TYPE_PRECISION (double_type_node
)))
5306 /* Convert `float' to `double'. */
5307 val
= cp_convert (double_type_node
, val
);
5308 else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val
))
5309 && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val
)))
5310 cp_warning ("cannot pass objects of type `%T' through `...'",
5313 /* Convert `short' and `char' to full-size `int'. */
5314 val
= default_conversion (val
);
5316 converted_args
= tree_cons (NULL_TREE
, val
, converted_args
);
5319 converted_args
= nreverse (converted_args
);
5321 /* Avoid actually calling copy constructors and copy assignment operators,
5323 if (DECL_CONSTRUCTOR_P (fn
)
5324 && TREE_VEC_LENGTH (convs
) == 1
5325 && copy_args_p (fn
))
5328 arg
= TREE_VALUE (TREE_CHAIN (converted_args
));
5330 /* Pull out the real argument, disregarding const-correctness. */
5332 while (TREE_CODE (targ
) == NOP_EXPR
5333 || TREE_CODE (targ
) == NON_LVALUE_EXPR
5334 || TREE_CODE (targ
) == CONVERT_EXPR
)
5335 targ
= TREE_OPERAND (targ
, 0);
5336 if (TREE_CODE (targ
) == ADDR_EXPR
)
5338 targ
= TREE_OPERAND (targ
, 0);
5339 if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg
))),
5340 TYPE_MAIN_VARIANT (TREE_TYPE (targ
)), 1))
5349 arg
= build_indirect_ref (arg
, 0);
5351 /* [class.copy]: the copy constructor is implicitly defined even if
5352 the implementation elided its use. */
5353 if (TYPE_HAS_COMPLEX_INIT_REF (DECL_CONTEXT (fn
)))
5356 /* If we're creating a temp and we already have one, don't create a
5357 new one. If we're not creating a temp but we get one, use
5358 INIT_EXPR to collapse the temp into our target. Otherwise, if the
5359 ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
5360 temp or an INIT_EXPR otherwise. */
5361 if (integer_zerop (TREE_VALUE (args
)))
5363 if (! real_lvalue_p (arg
))
5365 else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
5367 val
= build (VAR_DECL
, DECL_CONTEXT (fn
));
5368 layout_decl (val
, 0);
5369 val
= build (TARGET_EXPR
, DECL_CONTEXT (fn
), val
, arg
, 0, 0);
5370 TREE_SIDE_EFFECTS (val
) = 1;
5374 else if (! real_lvalue_p (arg
)
5375 || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn
)))
5377 tree to
= stabilize_reference
5378 (build_indirect_ref (TREE_VALUE (args
), 0));
5379 val
= build (INIT_EXPR
, DECL_CONTEXT (fn
), to
, arg
);
5380 TREE_SIDE_EFFECTS (val
) = 1;
5381 return build_unary_op (ADDR_EXPR
, val
, 0);
5384 else if (DECL_NAME (fn
) == ansi_opname
[MODIFY_EXPR
]
5386 && TYPE_HAS_TRIVIAL_ASSIGN_REF (DECL_CONTEXT (fn
)))
5388 tree to
= stabilize_reference
5389 (build_indirect_ref (TREE_VALUE (converted_args
), 0));
5390 arg
= build_indirect_ref (TREE_VALUE (TREE_CHAIN (converted_args
)), 0);
5391 val
= build (MODIFY_EXPR
, TREE_TYPE (to
), to
, arg
);
5392 TREE_SIDE_EFFECTS (val
) = 1;
5398 if (DECL_CONTEXT (fn
) && IS_SIGNATURE (DECL_CONTEXT (fn
)))
5399 return build_signature_method_call (fn
, converted_args
);
5400 else if (DECL_VINDEX (fn
) && (flags
& LOOKUP_NONVIRTUAL
) == 0)
5402 tree t
, *p
= &TREE_VALUE (converted_args
);
5403 tree binfo
= get_binfo
5404 (DECL_CONTEXT (fn
), TREE_TYPE (TREE_TYPE (*p
)), 0);
5405 *p
= convert_pointer_to_real (binfo
, *p
);
5406 if (TREE_SIDE_EFFECTS (*p
))
5407 *p
= save_expr (*p
);
5408 t
= build_pointer_type (TREE_TYPE (fn
));
5409 fn
= build_vfn_ref (p
, build_indirect_ref (*p
, 0), DECL_VINDEX (fn
));
5412 else if (DECL_INLINE (fn
))
5413 fn
= inline_conversion (fn
);
5415 fn
= build_addr_func (fn
);
5417 fn
= build_call (fn
, TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))), converted_args
);
5418 if (TREE_TYPE (fn
) == void_type_node
)
5420 if (IS_AGGR_TYPE (TREE_TYPE (fn
)))
5421 fn
= build_cplus_new (TREE_TYPE (fn
), fn
);
5422 return convert_from_reference (require_complete_type (fn
));
5426 build_new_method_call (instance
, name
, args
, basetype_path
, flags
)
5427 tree instance
, name
, args
, basetype_path
;
5430 struct z_candidate
*candidates
= 0, *cand
;
5431 tree basetype
, mem_args
, fns
, instance_ptr
;
5433 tree user_args
= args
;
5434 tree templates
= NULL_TREE
;
5436 /* If there is an extra argument for controlling virtual bases,
5437 remove it for error reporting. */
5438 if (flags
& LOOKUP_HAS_IN_CHARGE
)
5439 user_args
= TREE_CHAIN (args
);
5441 args
= resolve_args (args
);
5443 if (args
== error_mark_node
)
5444 return error_mark_node
;
5446 if (instance
== NULL_TREE
)
5447 basetype
= BINFO_TYPE (basetype_path
);
5450 if (TREE_CODE (instance
) == OFFSET_REF
)
5451 instance
= resolve_offset_ref (instance
);
5452 if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
5453 instance
= convert_from_reference (instance
);
5454 basetype
= TREE_TYPE (instance
);
5456 /* XXX this should be handled before we get here. */
5457 if (! IS_AGGR_TYPE (basetype
)
5458 && ! (TYPE_LANG_SPECIFIC (basetype
)
5459 && (IS_SIGNATURE_POINTER (basetype
)
5460 || IS_SIGNATURE_REFERENCE (basetype
))))
5462 if ((flags
& LOOKUP_COMPLAIN
) && basetype
!= error_mark_node
)
5463 cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
5464 name
, instance
, basetype
);
5466 return error_mark_node
;
5469 /* If `instance' is a signature pointer/reference and `name' is
5470 not a constructor, we are calling a signature member function.
5471 In that case set the `basetype' to the signature type. */
5472 if ((IS_SIGNATURE_POINTER (basetype
)
5473 || IS_SIGNATURE_REFERENCE (basetype
))
5474 && TYPE_IDENTIFIER (basetype
) != name
)
5475 basetype
= SIGNATURE_TYPE (basetype
);
5478 if (basetype_path
== NULL_TREE
)
5479 basetype_path
= TYPE_BINFO (basetype
);
5483 instance_ptr
= build_this (instance
);
5485 /* XXX this should be handled before we get here. */
5486 fns
= build_field_call (basetype_path
, instance_ptr
, name
, args
);
5492 instance_ptr
= build_int_2 (0, 0);
5493 TREE_TYPE (instance_ptr
) = build_pointer_type (basetype
);
5497 = (name
== ctor_identifier
? constructor_name_full (basetype
) : name
);
5499 fns
= lookup_fnfields (basetype_path
, name
, 1);
5501 if (fns
== error_mark_node
)
5502 return error_mark_node
;
5505 tree t
= TREE_VALUE (fns
);
5506 if (name
== ctor_identifier
&& TYPE_USES_VIRTUAL_BASECLASSES (basetype
)
5507 && ! (flags
& LOOKUP_HAS_IN_CHARGE
))
5509 flags
|= LOOKUP_HAS_IN_CHARGE
;
5510 args
= tree_cons (NULL_TREE
, integer_one_node
, args
);
5512 mem_args
= tree_cons (NULL_TREE
, instance_ptr
, args
);
5513 for (; t
; t
= DECL_CHAIN (t
))
5517 /* We can end up here for copy-init of same or base class. */
5518 if (name
== ctor_identifier
5519 && (flags
& LOOKUP_ONLYCONVERTING
)
5520 && DECL_NONCONVERTING_P (t
))
5522 if (TREE_CODE (TREE_TYPE (t
)) == METHOD_TYPE
)
5523 this_arglist
= mem_args
;
5525 this_arglist
= args
;
5527 if (TREE_CODE (t
) == TEMPLATE_DECL
)
5529 /* A member template. */
5530 templates
= decl_tree_cons (NULL_TREE
, t
, templates
);
5532 add_template_candidate (candidates
, t
,
5538 candidates
= add_function_candidate (candidates
, t
,
5539 this_arglist
, flags
);
5542 candidates
->basetype_path
= TREE_PURPOSE (fns
);
5546 if (! any_viable (candidates
))
5548 /* XXX will LOOKUP_SPECULATIVELY be needed when this is done? */
5549 if (flags
& LOOKUP_SPECULATIVELY
)
5551 cp_error ("no matching function for call to `%T::%D (%A)%V'", basetype
,
5552 pretty_name
, user_args
, TREE_TYPE (TREE_TYPE (instance_ptr
)));
5553 print_z_candidates (candidates
);
5554 return error_mark_node
;
5556 candidates
= splice_viable (candidates
);
5557 cand
= tourney (candidates
);
5561 cp_error ("call of overloaded `%D(%A)' is ambiguous", pretty_name
,
5563 print_z_candidates (candidates
);
5564 return error_mark_node
;
5567 enforce_access (cand
->basetype_path
, cand
->fn
);
5568 if (DECL_ABSTRACT_VIRTUAL_P (cand
->fn
)
5569 && instance
== current_class_ref
5570 && DECL_CONSTRUCTOR_P (current_function_decl
)
5571 && ! (flags
& LOOKUP_NONVIRTUAL
)
5572 && value_member (cand
->fn
, get_abstract_virtuals (basetype
)))
5573 cp_error ("abstract virtual `%#D' called from constructor", cand
->fn
);
5574 if (TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
5575 && TREE_CODE (instance_ptr
) == NOP_EXPR
5576 && TREE_OPERAND (instance_ptr
, 0) == error_mark_node
)
5577 cp_error ("cannot call member function `%D' without object", cand
->fn
);
5579 if (DECL_VINDEX (cand
->fn
) && ! (flags
& LOOKUP_NONVIRTUAL
)
5580 && ((instance
== current_class_ref
&& (dtor_label
|| ctor_label
))
5581 || resolves_to_fixed_type_p (instance
, 0)))
5582 flags
|= LOOKUP_NONVIRTUAL
;
5584 /* Pedantically, normal function declarations are never considered
5585 to refer to template instantiations, but we won't implement that
5586 until we implement full template instantiation syntax. */
5587 if (templates
&& ! cand
->template && ! DECL_INITIAL (cand
->fn
))
5588 add_maybe_template (cand
->fn
, templates
);
5590 return build_over_call
5591 (cand
->fn
, cand
->convs
,
5592 TREE_CODE (TREE_TYPE (cand
->fn
)) == METHOD_TYPE
? mem_args
: args
,
5596 /* Compare two implicit conversion sequences that differ only in their
5597 qualification conversion. Subroutine of compare_ics. */
5600 compare_qual (ics1
, ics2
)
5603 tree to1
= TREE_TYPE (ics1
);
5604 tree to2
= TREE_TYPE (ics2
);
5606 to1
= TREE_TYPE (to1
);
5607 to2
= TREE_TYPE (to2
);
5609 if (TREE_CODE (to1
) == OFFSET_TYPE
)
5611 to1
= TREE_TYPE (to1
);
5612 to2
= TREE_TYPE (to2
);
5615 if (TYPE_READONLY (to1
) >= TYPE_READONLY (to2
)
5616 && TYPE_VOLATILE (to1
) > TYPE_VOLATILE (to2
))
5618 else if (TYPE_READONLY (to1
) > TYPE_READONLY (to2
)
5619 && TYPE_VOLATILE (to1
) == TYPE_VOLATILE (to2
))
5621 else if (TYPE_READONLY (to1
) <= TYPE_READONLY (to2
)
5622 && TYPE_VOLATILE (to1
) < TYPE_VOLATILE (to2
))
5624 else if (TYPE_READONLY (to1
) < TYPE_READONLY (to2
)
5625 && TYPE_VOLATILE (to1
) == TYPE_VOLATILE (to2
))
5630 /* Determine whether standard conversion sequence ICS1 is a proper
5631 subsequence of ICS2. We assume that a conversion of the same code
5632 between the same types indicates a subsequence. */
5635 is_subseq (ics1
, ics2
)
5638 for (;; ics2
= TREE_OPERAND (ics2
, 0))
5640 if (TREE_CODE (ics2
) == TREE_CODE (ics1
)
5641 && comptypes (TREE_TYPE (ics2
), TREE_TYPE (ics1
), 1)
5642 && comptypes (TREE_TYPE (TREE_OPERAND (ics2
, 0)),
5643 TREE_TYPE (TREE_OPERAND (ics1
, 0)), 1))
5646 if (TREE_CODE (ics2
) == USER_CONV
5647 || TREE_CODE (ics2
) == AMBIG_CONV
5648 || TREE_CODE (ics2
) == IDENTITY_CONV
)
5653 /* Compare two implicit conversion sequences according to the rules set out in
5654 [over.ics.rank]. Return values:
5656 1: ics1 is better than ics2
5657 -1: ics2 is better than ics1
5658 0: ics1 and ics2 are indistinguishable */
5661 compare_ics (ics1
, ics2
)
5666 if (TREE_CODE (ics1
) == QUAL_CONV
)
5667 main1
= TREE_OPERAND (ics1
, 0);
5671 if (TREE_CODE (ics2
) == QUAL_CONV
)
5672 main2
= TREE_OPERAND (ics2
, 0);
5676 /* Conversions for `this' are PTR_CONVs, but we compare them as though
5677 they were REF_BINDs. */
5678 if (ICS_THIS_FLAG (ics1
))
5681 if (TREE_CODE (t
) == PTR_CONV
)
5682 t
= TREE_OPERAND (t
, 0);
5683 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
5684 t
= build_conv (REF_BIND
, TREE_TYPE (ics1
), t
);
5685 ICS_STD_RANK (t
) = ICS_STD_RANK (main1
);
5688 if (ICS_THIS_FLAG (ics2
))
5691 if (TREE_CODE (t
) == PTR_CONV
)
5692 t
= TREE_OPERAND (t
, 0);
5693 t
= build1 (IDENTITY_CONV
, TREE_TYPE (TREE_TYPE (t
)), NULL_TREE
);
5694 t
= build_conv (REF_BIND
, TREE_TYPE (ics2
), t
);
5695 ICS_STD_RANK (t
) = ICS_STD_RANK (main2
);
5699 if (ICS_RANK (ics1
) > ICS_RANK (ics2
))
5701 else if (ICS_RANK (ics1
) < ICS_RANK (ics2
))
5704 if (ICS_RANK (ics1
) == BAD_RANK
)
5706 if (ICS_USER_FLAG (ics1
) > ICS_USER_FLAG (ics2
)
5707 || ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
5709 else if (ICS_USER_FLAG (ics1
) < ICS_USER_FLAG (ics2
)
5710 || ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
5713 /* else fall through */
5716 /* User-defined conversion sequence U1 is a better conversion sequence
5717 than another user-defined conversion sequence U2 if they contain the
5718 same user-defined conversion operator or constructor and if the sec-
5719 ond standard conversion sequence of U1 is better than the second
5720 standard conversion sequence of U2. */
5722 if (ICS_USER_FLAG (ics1
))
5726 for (t1
= ics1
; TREE_CODE (t1
) != USER_CONV
; t1
= TREE_OPERAND (t1
, 0))
5727 if (TREE_CODE (t1
) == AMBIG_CONV
)
5729 for (t2
= ics2
; TREE_CODE (t2
) != USER_CONV
; t2
= TREE_OPERAND (t2
, 0))
5730 if (TREE_CODE (t2
) == AMBIG_CONV
)
5733 if (USER_CONV_FN (t1
) != USER_CONV_FN (t2
))
5735 else if (ICS_STD_RANK (ics1
) > ICS_STD_RANK (ics2
))
5737 else if (ICS_STD_RANK (ics1
) < ICS_STD_RANK (ics2
))
5740 /* else fall through */
5743 #if 0 /* Handled by ranking */
5744 /* A conversion that is not a conversion of a pointer, or pointer to
5745 member, to bool is better than another conversion that is such a
5749 if (TREE_CODE (main1
) != TREE_CODE (main2
))
5751 /* ...if S1 is a proper subsequence of S2 */
5752 if (is_subseq (main1
, main2
))
5754 if (is_subseq (main2
, main1
))
5759 if (TREE_CODE (main1
) == PTR_CONV
|| TREE_CODE (main1
) == PMEM_CONV
5760 || TREE_CODE (main1
) == REF_BIND
|| TREE_CODE (main1
) == BASE_CONV
)
5762 tree to1
= TREE_TYPE (main1
);
5763 tree from1
= TREE_TYPE (TREE_OPERAND (main1
, 0));
5764 tree to2
= TREE_TYPE (main2
);
5765 tree from2
= TREE_TYPE (TREE_OPERAND (main2
, 0));
5768 /* Standard conversion sequence S1 is a better conversion sequence than
5769 standard conversion sequence S2 if...
5771 S1 and S2 differ only in their qualification conversion and they
5772 yield types identical except for cv-qualifiers and S2 adds all the
5773 qualifiers that S1 adds (and in the same places) and S2 adds yet
5774 more cv-qualifiers than S1, or the similar case with reference
5776 if (TREE_CODE (main1
) == REF_BIND
)
5778 if (TYPE_MAIN_VARIANT (TREE_TYPE (to1
))
5779 == TYPE_MAIN_VARIANT (TREE_TYPE (to2
)))
5780 return compare_qual (ics1
, ics2
);
5782 else if (TREE_CODE (main1
) != BASE_CONV
&& from1
== from2
&& to1
== to2
)
5783 return compare_qual (ics1
, ics2
);
5785 if (TYPE_PTRMEMFUNC_P (to1
))
5787 to1
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to1
)));
5788 from1
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from1
)));
5790 else if (TREE_CODE (main1
) != BASE_CONV
)
5792 to1
= TREE_TYPE (to1
);
5793 if (TREE_CODE (main1
) != REF_BIND
)
5794 from1
= TREE_TYPE (from1
);
5796 if (TREE_CODE (to1
) == OFFSET_TYPE
)
5798 to1
= TYPE_OFFSET_BASETYPE (to1
);
5799 from1
= TYPE_OFFSET_BASETYPE (from1
);
5803 if (TYPE_PTRMEMFUNC_P (to2
))
5805 to2
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to2
)));
5806 from2
= TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from2
)));
5808 else if (TREE_CODE (main1
) != BASE_CONV
)
5810 to2
= TREE_TYPE (to2
);
5811 if (TREE_CODE (main1
) != REF_BIND
)
5812 from2
= TREE_TYPE (from2
);
5814 if (TREE_CODE (to2
) == OFFSET_TYPE
)
5816 to2
= TYPE_OFFSET_BASETYPE (to2
);
5817 from2
= TYPE_OFFSET_BASETYPE (from2
);
5821 if (! (IS_AGGR_TYPE (from1
) && IS_AGGR_TYPE (from2
)))
5824 /* The sense of pmem conversions is reversed from that of the other
5826 if (TREE_CODE (main1
) == PMEM_CONV
)
5828 tree t
= from1
; from1
= from2
; from2
= t
;
5829 t
= to1
; to1
= to2
; to2
= t
;
5832 distf
= get_base_distance (from1
, from2
, 0, 0);
5835 distf
= -get_base_distance (from2
, from1
, 0, 0);
5840 /* If class B is derived directly or indirectly from class A,
5841 conver- sion of B* to A* is better than conversion of B* to
5842 void*, and conversion of A* to void* is better than
5843 conversion of B* to void*. */
5845 if (TREE_CODE (to1
) == VOID_TYPE
&& TREE_CODE (to2
) == VOID_TYPE
)
5852 else if (TREE_CODE (to2
) == VOID_TYPE
&& IS_AGGR_TYPE (to1
)
5853 && get_base_distance (to1
, from1
, 0, 0) != -1)
5855 else if (TREE_CODE (to1
) == VOID_TYPE
&& IS_AGGR_TYPE (to2
)
5856 && get_base_distance (to2
, from2
, 0, 0) != -1)
5859 if (! (IS_AGGR_TYPE (to1
) && IS_AGGR_TYPE (to2
)))
5862 /* If class B is derived directly or indirectly from class A and class
5863 C is derived directly or indirectly from B */
5865 distt
= get_base_distance (to1
, to2
, 0, 0);
5868 distt
= -get_base_distance (to2
, to1
, 0, 0);
5873 /* --conversion of C* to B* is better than conversion of C* to A*, */
5881 /* --conversion of B* to A* is better than conversion of C* to A*, */
5882 else if (distt
== 0)
5890 else if (TREE_CODE (TREE_TYPE (main1
)) == POINTER_TYPE
5891 || TYPE_PTRMEMFUNC_P (TREE_TYPE (main1
)))
5893 if (TREE_TYPE (main1
) == TREE_TYPE (main2
))
5894 return compare_qual (ics1
, ics2
);
5896 #if 0 /* This is now handled by making identity better than anything else. */
5897 /* existing practice, not WP-endorsed: const char * -> const char *
5898 is better than char * -> const char *. (jason 6/29/96) */
5899 if (TREE_TYPE (ics1
) == TREE_TYPE (ics2
))
5900 return -compare_qual (main1
, main2
);
5907 /* The source type for this standard conversion sequence. */
5913 for (;; t
= TREE_OPERAND (t
, 0))
5915 if (TREE_CODE (t
) == USER_CONV
5916 || TREE_CODE (t
) == AMBIG_CONV
5917 || TREE_CODE (t
) == IDENTITY_CONV
)
5918 return TREE_TYPE (t
);
5920 my_friendly_abort (1823);
5923 /* Compare two candidates for overloading as described in
5924 [over.match.best]. Return values:
5926 1: cand1 is better than cand2
5927 -1: cand2 is better than cand1
5928 0: cand1 and cand2 are indistinguishable */
5931 joust (cand1
, cand2
)
5932 struct z_candidate
*cand1
, *cand2
;
5935 int i
, off1
= 0, off2
= 0, len
;
5937 /* Candidates that involve bad conversions are always worse than those
5939 if (cand1
->viable
> cand2
->viable
)
5941 if (cand1
->viable
< cand2
->viable
)
5944 /* a viable function F1
5945 is defined to be a better function than another viable function F2 if
5946 for all arguments i, ICSi(F1) is not a worse conversion sequence than
5947 ICSi(F2), and then */
5949 /* for some argument j, ICSj(F1) is a better conversion sequence than
5952 /* For comparing static and non-static member functions, we ignore the
5953 implicit object parameter of the non-static function. The WP says to
5954 pretend that the static function has an object parm, but that won't
5955 work with operator overloading. */
5956 len
= TREE_VEC_LENGTH (cand1
->convs
);
5957 if (len
!= TREE_VEC_LENGTH (cand2
->convs
))
5959 if (DECL_STATIC_FUNCTION_P (cand1
->fn
)
5960 && ! DECL_STATIC_FUNCTION_P (cand2
->fn
))
5962 else if (! DECL_STATIC_FUNCTION_P (cand1
->fn
)
5963 && DECL_STATIC_FUNCTION_P (cand2
->fn
))
5969 my_friendly_abort (42);
5972 for (i
= 0; i
< len
; ++i
)
5974 tree t1
= TREE_VEC_ELT (cand1
->convs
, i
+off1
);
5975 tree t2
= TREE_VEC_ELT (cand2
->convs
, i
+off2
);
5976 int comp
= compare_ics (t1
, t2
);
5980 #if 0 /* move this warning to tourney. */
5982 && ICS_RANK (t1
) + ICS_RANK (t2
) == STD_RANK
+ PROMO_RANK
5983 && TREE_CODE (t1
) == STD_CONV
5984 && TREE_CODE (t2
) == STD_CONV
5985 && TREE_CODE (TREE_TYPE (t1
)) == INTEGER_TYPE
5986 && TREE_CODE (TREE_TYPE (t2
)) == INTEGER_TYPE
5987 && (TYPE_PRECISION (TREE_TYPE (t1
))
5988 == TYPE_PRECISION (TREE_TYPE (t2
)))
5989 && (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (t1
, 0)))
5990 || (TREE_CODE (TREE_TYPE (TREE_OPERAND (t1
, 0)))
5993 tree type
= TREE_TYPE (TREE_OPERAND (t1
, 0));
5996 type1
= TREE_TYPE (t1
), type2
= TREE_TYPE (t2
);
5998 type1
= TREE_TYPE (t2
), type2
= TREE_TYPE (t1
);
6000 cp_warning ("passing `%T' chooses `%T' over `%T'",
6001 type
, type1
, type2
);
6002 cp_warning (" in call to `%D'", DECL_NAME (cand1
->fn
));
6006 if (winner
&& comp
!= winner
)
6015 #if 0 /* move this warning to tourney. */
6016 /* warn about confusing overload resolution */
6017 if (winner
&& cand1
->second_conv
6018 && ! DECL_CONSTRUCTOR_P (cand1
->fn
)
6019 && ! DECL_CONSTRUCTOR_P (cand2
->fn
))
6021 int comp
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
6022 if (comp
&& comp
!= winner
)
6024 struct z_candidate
*w
, *l
;
6026 w
= cand1
, l
= cand2
;
6028 w
= cand2
, l
= cand1
;
6029 cp_warning ("choosing `%D' over `%D'", w
->fn
, l
->fn
);
6030 cp_warning (" for conversion from `%T' to `%T'",
6031 TREE_TYPE (source_type (TREE_VEC_ELT (w
->convs
, 0))),
6032 TREE_TYPE (w
->second_conv
));
6033 cp_warning (" because conversion sequence for `this' argument is better");
6042 F1 is a non-template function and F2 is a template function */
6044 if (! cand1
->template && cand2
->template)
6046 else if (cand1
->template && ! cand2
->template)
6048 else if (cand1
->template && cand2
->template)
6049 winner
= more_specialized
6050 (TI_TEMPLATE (cand1
->template), TI_TEMPLATE (cand2
->template));
6053 the context is an initialization by user-defined conversion (see
6054 _dcl.init_ and _over.match.user_) and the standard conversion
6055 sequence from the return type of F1 to the destination type (i.e.,
6056 the type of the entity being initialized) is a better conversion
6057 sequence than the standard conversion sequence from the return type
6058 of F2 to the destination type. */
6060 if (! winner
&& cand1
->second_conv
)
6061 winner
= compare_ics (cand1
->second_conv
, cand2
->second_conv
);
6063 /* If the built-in candidates are the same, arbitrarily pick one. */
6064 if (! winner
&& cand1
->fn
== cand2
->fn
6065 && TREE_CODE (cand1
->fn
) == IDENTIFIER_NODE
)
6067 for (i
= 0; i
< len
; ++i
)
6068 if (! comptypes (TREE_TYPE (TREE_VEC_ELT (cand1
->convs
, i
)),
6069 TREE_TYPE (TREE_VEC_ELT (cand2
->convs
, i
)), 1))
6071 if (i
== TREE_VEC_LENGTH (cand1
->convs
))
6074 /* Kludge around broken overloading rules whereby
6075 bool ? void *const & : void *const & is ambiguous. */
6076 /* Huh? Explain the problem better. */
6077 if (cand1
->fn
== ansi_opname
[COND_EXPR
])
6079 tree c1
= TREE_VEC_ELT (cand1
->convs
, 1);
6080 tree c2
= TREE_VEC_ELT (cand2
->convs
, 1);
6081 tree t1
= strip_top_quals (non_reference (TREE_TYPE (c1
)));
6082 tree t2
= strip_top_quals (non_reference (TREE_TYPE (c2
)));
6084 if (comptypes (t1
, t2
, 1))
6086 if (TREE_CODE (c1
) == REF_BIND
&& TREE_CODE (c2
) != REF_BIND
)
6088 if (TREE_CODE (c1
) != REF_BIND
&& TREE_CODE (c2
) == REF_BIND
)
6097 /* Extension: If the worst conversion for one candidate is worse than the
6098 worst conversion for the other, take the first. */
6099 if (! winner
&& ! pedantic
)
6101 int rank1
= IDENTITY_RANK
, rank2
= IDENTITY_RANK
;
6103 for (i
= 0; i
< len
; ++i
)
6105 if (ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
)) > rank1
)
6106 rank1
= ICS_RANK (TREE_VEC_ELT (cand1
->convs
, i
+off1
));
6107 if (ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
)) > rank2
)
6108 rank2
= ICS_RANK (TREE_VEC_ELT (cand2
->convs
, i
+off2
));
6120 /* Given a list of candidates for overloading, find the best one, if any.
6121 This algorithm has a worst case of O(2n) (winner is last), and a best
6122 case of O(n/2) (totally ambiguous); much better than a sorting
6125 static struct z_candidate
*
6126 tourney (candidates
)
6127 struct z_candidate
*candidates
;
6129 struct z_candidate
*champ
= candidates
, *challenger
;
6132 /* Walk through the list once, comparing each current champ to the next
6133 candidate, knocking out a candidate or two with each comparison. */
6135 for (challenger
= champ
->next
; challenger
; )
6137 fate
= joust (champ
, challenger
);
6139 challenger
= challenger
->next
;
6144 champ
= challenger
->next
;
6151 challenger
= champ
->next
;
6155 /* Make sure the champ is better than all the candidates it hasn't yet
6156 been compared to. This may do one more comparison than necessary. Oh
6159 for (challenger
= candidates
; challenger
!= champ
;
6160 challenger
= challenger
->next
)
6162 fate
= joust (champ
, challenger
);
6171 can_convert (to
, from
)
6174 if (flag_ansi_overloading
)
6176 tree t
= implicit_conversion (to
, from
, NULL_TREE
, LOOKUP_NORMAL
);
6177 return (t
&& ! ICS_BAD_FLAG (t
));
6181 struct harshness_code h
;
6182 h
= convert_harshness (to
, from
, NULL_TREE
);
6183 return (h
.code
< USER_CODE
) && (h
.distance
>= 0);
6188 can_convert_arg (to
, from
, arg
)
6191 if (flag_ansi_overloading
)
6193 tree t
= implicit_conversion (to
, from
, arg
, LOOKUP_NORMAL
);
6194 return (t
&& ! ICS_BAD_FLAG (t
));
6198 struct harshness_code h
;
6199 h
= convert_harshness (to
, from
, arg
);
6200 return (h
.code
< USER_CODE
) && (h
.distance
>= 0);