00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "config.h"
00028 #include "system.h"
00029 #include "coretypes.h"
00030 #include "tm.h"
00031 #include "tree.h"
00032 #include "cp-tree.h"
00033 #include "output.h"
00034 #include "flags.h"
00035 #include "rtl.h"
00036 #include "toplev.h"
00037 #include "expr.h"
00038 #include "diagnostic.h"
00039 #include "intl.h"
00040 #include "target.h"
00041 #include "convert.h"
00042
00043
00044
00045 typedef enum conversion_kind {
00046 ck_identity,
00047 ck_lvalue,
00048 ck_qual,
00049 ck_std,
00050 ck_ptr,
00051 ck_pmem,
00052 ck_base,
00053 ck_ref_bind,
00054 ck_user,
00055 ck_ambig,
00056 ck_rvalue
00057 } conversion_kind;
00058
00059
00060
00061
00062 typedef enum conversion_rank {
00063 cr_identity,
00064 cr_exact,
00065 cr_promotion,
00066 cr_std,
00067 cr_pbool,
00068 cr_user,
00069 cr_ellipsis,
00070 cr_bad
00071 } conversion_rank;
00072
00073
00074
00075
00076
00077 typedef struct conversion conversion;
00078 struct conversion {
00079
00080 conversion_kind kind;
00081
00082 conversion_rank rank;
00083 BOOL_BITFIELD user_conv_p : 1;
00084 BOOL_BITFIELD ellipsis_p : 1;
00085 BOOL_BITFIELD this_p : 1;
00086 BOOL_BITFIELD bad_p : 1;
00087
00088
00089
00090 BOOL_BITFIELD need_temporary_p : 1;
00091
00092
00093
00094 BOOL_BITFIELD check_copy_constructor_p : 1;
00095
00096
00097 BOOL_BITFIELD base_p : 1;
00098
00099 tree type;
00100 union {
00101
00102
00103
00104
00105 conversion *next;
00106
00107
00108 tree expr;
00109 } u;
00110
00111
00112 struct z_candidate *cand;
00113 };
00114
00115 #define CONVERSION_RANK(NODE) \
00116 ((NODE)->bad_p ? cr_bad \
00117 : (NODE)->ellipsis_p ? cr_ellipsis \
00118 : (NODE)->user_conv_p ? cr_user \
00119 : (NODE)->rank)
00120
00121 static struct obstack conversion_obstack;
00122 static bool conversion_obstack_initialized;
00123
00124 static struct z_candidate * tourney (struct z_candidate *);
00125 static int equal_functions (tree, tree);
00126 static int joust (struct z_candidate *, struct z_candidate *, bool);
00127 static int compare_ics (conversion *, conversion *);
00128 static tree build_over_call (struct z_candidate *, int);
00129 static tree build_java_interface_fn_ref (tree, tree);
00130 #define convert_like(CONV, EXPR) \
00131 convert_like_real ((CONV), (EXPR), NULL_TREE, 0, 0, \
00132 true, \
00133 false)
00134 #define convert_like_with_context(CONV, EXPR, FN, ARGNO) \
00135 convert_like_real ((CONV), (EXPR), (FN), (ARGNO), 0, \
00136 true, \
00137 false)
00138 static tree convert_like_real (conversion *, tree, tree, int, int, bool,
00139 bool);
00140 static void op_error (enum tree_code, enum tree_code, tree, tree,
00141 tree, const char *);
00142 static tree build_object_call (tree, tree);
00143 static tree resolve_args (tree);
00144 static struct z_candidate *build_user_type_conversion_1 (tree, tree, int);
00145 static void print_z_candidate (const char *, struct z_candidate *);
00146 static void print_z_candidates (struct z_candidate *);
00147 static tree build_this (tree);
00148 static struct z_candidate *splice_viable (struct z_candidate *, bool, bool *);
00149 static bool any_strictly_viable (struct z_candidate *);
00150 static struct z_candidate *add_template_candidate
00151 (struct z_candidate **, tree, tree, tree, tree, tree,
00152 tree, tree, int, unification_kind_t);
00153 static struct z_candidate *add_template_candidate_real
00154 (struct z_candidate **, tree, tree, tree, tree, tree,
00155 tree, tree, int, tree, unification_kind_t);
00156 static struct z_candidate *add_template_conv_candidate
00157 (struct z_candidate **, tree, tree, tree, tree, tree, tree);
00158 static void add_builtin_candidates
00159 (struct z_candidate **, enum tree_code, enum tree_code,
00160 tree, tree *, int);
00161 static void add_builtin_candidate
00162 (struct z_candidate **, enum tree_code, enum tree_code,
00163 tree, tree, tree, tree *, tree *, int);
00164 static bool is_complete (tree);
00165 static void build_builtin_candidate
00166 (struct z_candidate **, tree, tree, tree, tree *, tree *,
00167 int);
00168 static struct z_candidate *add_conv_candidate
00169 (struct z_candidate **, tree, tree, tree, tree, tree);
00170 static struct z_candidate *add_function_candidate
00171 (struct z_candidate **, tree, tree, tree, tree, tree, int);
00172 static conversion *implicit_conversion (tree, tree, tree, bool, int);
00173 static conversion *standard_conversion (tree, tree, tree, bool, int);
00174 static conversion *reference_binding (tree, tree, tree, bool, int);
00175 static conversion *build_conv (conversion_kind, tree, conversion *);
00176 static bool is_subseq (conversion *, conversion *);
00177 static tree maybe_handle_ref_bind (conversion **);
00178 static void maybe_handle_implicit_object (conversion **);
00179 static struct z_candidate *add_candidate
00180 (struct z_candidate **, tree, tree, size_t,
00181 conversion **, tree, tree, int);
00182 static tree source_type (conversion *);
00183 static void add_warning (struct z_candidate *, struct z_candidate *);
00184 static bool reference_related_p (tree, tree);
00185 static bool reference_compatible_p (tree, tree);
00186 static conversion *convert_class_to_reference (tree, tree, tree);
00187 static conversion *direct_reference_binding (tree, conversion *);
00188 static bool promoted_arithmetic_type_p (tree);
00189 static conversion *conditional_conversion (tree, tree);
00190 static char *name_as_c_string (tree, tree, bool *);
00191 static tree call_builtin_trap (void);
00192 static tree prep_operand (tree);
00193 static void add_candidates (tree, tree, tree, bool, tree, tree,
00194 int, struct z_candidate **);
00195 static conversion *merge_conversion_sequences (conversion *, conversion *);
00196 static bool magic_varargs_p (tree);
00197 typedef void (*diagnostic_fn_t) (const char *, ...) ATTRIBUTE_GCC_CXXDIAG(1,2);
00198 static tree build_temp (tree, tree, int, diagnostic_fn_t *);
00199 static void check_constructor_callable (tree, tree);
00200
00201
00202
00203
00204 bool
00205 check_dtor_name (tree basetype, tree name)
00206 {
00207
00208 if (name == error_mark_node)
00209 return true;
00210
00211 if (TREE_CODE (name) == TYPE_DECL)
00212 name = TREE_TYPE (name);
00213 else if (TYPE_P (name))
00214 ;
00215 else if (TREE_CODE (name) == IDENTIFIER_NODE)
00216 {
00217 if ((IS_AGGR_TYPE (basetype) && name == constructor_name (basetype))
00218 || (TREE_CODE (basetype) == ENUMERAL_TYPE
00219 && name == TYPE_IDENTIFIER (basetype)))
00220 return true;
00221 else
00222 name = get_type_value (name);
00223 }
00224 else
00225 {
00226
00227
00228
00229
00230
00231
00232
00233 gcc_assert (DECL_CLASS_TEMPLATE_P (name));
00234 return false;
00235 }
00236
00237 if (!name)
00238 return false;
00239 return same_type_p (TYPE_MAIN_VARIANT (basetype), TYPE_MAIN_VARIANT (name));
00240 }
00241
00242
00243
00244
00245 tree
00246 build_addr_func (tree function)
00247 {
00248 tree type = TREE_TYPE (function);
00249
00250
00251
00252 if (TREE_CODE (type) == METHOD_TYPE)
00253 {
00254 if (TREE_CODE (function) == OFFSET_REF)
00255 {
00256 tree object = build_address (TREE_OPERAND (function, 0));
00257 return get_member_function_from_ptrfunc (&object,
00258 TREE_OPERAND (function, 1));
00259 }
00260 function = build_address (function);
00261 }
00262 else
00263 function = decay_conversion (function);
00264
00265 return function;
00266 }
00267
00268
00269
00270
00271
00272 tree
00273 build_call (tree function, tree parms)
00274 {
00275 int is_constructor = 0;
00276 int nothrow;
00277 tree tmp;
00278 tree decl;
00279 tree result_type;
00280 tree fntype;
00281
00282 function = build_addr_func (function);
00283
00284 gcc_assert (TYPE_PTR_P (TREE_TYPE (function)));
00285 fntype = TREE_TYPE (TREE_TYPE (function));
00286 gcc_assert (TREE_CODE (fntype) == FUNCTION_TYPE
00287 || TREE_CODE (fntype) == METHOD_TYPE);
00288 result_type = TREE_TYPE (fntype);
00289
00290 if (TREE_CODE (function) == ADDR_EXPR
00291 && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
00292 {
00293 decl = TREE_OPERAND (function, 0);
00294 if (!TREE_USED (decl))
00295 {
00296
00297
00298
00299
00300 gcc_assert (DECL_ARTIFICIAL (decl)
00301 || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
00302 "__", 2));
00303 mark_used (decl);
00304 }
00305 }
00306 else
00307 decl = NULL_TREE;
00308
00309
00310
00311 nothrow = ((decl && TREE_NOTHROW (decl))
00312 || TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (function))));
00313
00314 if (decl && TREE_THIS_VOLATILE (decl) && cfun)
00315 current_function_returns_abnormally = 1;
00316
00317 if (decl && TREE_DEPRECATED (decl))
00318 warn_deprecated_use (decl);
00319 require_complete_eh_spec_types (fntype, decl);
00320
00321 if (decl && DECL_CONSTRUCTOR_P (decl))
00322 is_constructor = 1;
00323
00324
00325
00326
00327 if (! decl || ! DECL_BUILT_IN (decl))
00328 for (tmp = parms; tmp; tmp = TREE_CHAIN (tmp))
00329 if (is_empty_class (TREE_TYPE (TREE_VALUE (tmp)))
00330 && ! TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (tmp))))
00331 {
00332 tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (TREE_VALUE (tmp)));
00333 TREE_VALUE (tmp) = build2 (COMPOUND_EXPR, TREE_TYPE (t),
00334 TREE_VALUE (tmp), t);
00335 }
00336
00337 function = build3 (CALL_EXPR, result_type, function, parms, NULL_TREE);
00338 TREE_HAS_CONSTRUCTOR (function) = is_constructor;
00339 TREE_NOTHROW (function) = nothrow;
00340
00341 return function;
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 typedef struct z_candidate z_candidate;
00378
00379 typedef struct candidate_warning candidate_warning;
00380 struct candidate_warning {
00381 z_candidate *loser;
00382 candidate_warning *next;
00383 };
00384
00385 struct z_candidate {
00386
00387
00388 tree fn;
00389
00390 tree args;
00391
00392
00393 conversion **convs;
00394
00395 size_t num_convs;
00396
00397
00398
00399 conversion *second_conv;
00400 int viable;
00401
00402
00403
00404
00405
00406 tree access_path;
00407
00408
00409
00410
00411
00412 tree conversion_path;
00413 tree template_decl;
00414 candidate_warning *warnings;
00415 z_candidate *next;
00416 };
00417
00418
00419
00420
00421 bool
00422 null_ptr_cst_p (tree t)
00423 {
00424
00425
00426
00427
00428 t = integral_constant_value (t);
00429 if (t == null_node)
00430 return true;
00431 if (CP_INTEGRAL_TYPE_P (TREE_TYPE (t)) && integer_zerop (t))
00432 {
00433 STRIP_NOPS (t);
00434 if (!TREE_CONSTANT_OVERFLOW (t))
00435 return true;
00436 }
00437 return false;
00438 }
00439
00440
00441
00442
00443 bool
00444 sufficient_parms_p (tree parmlist)
00445 {
00446 for (; parmlist && parmlist != void_list_node;
00447 parmlist = TREE_CHAIN (parmlist))
00448 if (!TREE_PURPOSE (parmlist))
00449 return false;
00450 return true;
00451 }
00452
00453
00454
00455
00456 static void *
00457 conversion_obstack_alloc (size_t n)
00458 {
00459 void *p;
00460 if (!conversion_obstack_initialized)
00461 {
00462 gcc_obstack_init (&conversion_obstack);
00463 conversion_obstack_initialized = true;
00464 }
00465 p = obstack_alloc (&conversion_obstack, n);
00466 memset (p, 0, n);
00467 return p;
00468 }
00469
00470
00471
00472 static conversion *
00473 alloc_conversion (conversion_kind kind)
00474 {
00475 conversion *c;
00476 c = (conversion *) conversion_obstack_alloc (sizeof (conversion));
00477 c->kind = kind;
00478 return c;
00479 }
00480
00481 #ifdef ENABLE_CHECKING
00482
00483
00484
00485
00486 void
00487 validate_conversion_obstack (void)
00488 {
00489 if (conversion_obstack_initialized)
00490 gcc_assert ((obstack_next_free (&conversion_obstack)
00491 == obstack_base (&conversion_obstack)));
00492 }
00493
00494 #endif
00495
00496
00497
00498 static conversion **
00499 alloc_conversions (size_t n)
00500 {
00501 return (conversion **) conversion_obstack_alloc (n * sizeof (conversion *));
00502 }
00503
00504 static conversion *
00505 build_conv (conversion_kind code, tree type, conversion *from)
00506 {
00507 conversion *t;
00508 conversion_rank rank = CONVERSION_RANK (from);
00509
00510
00511
00512
00513 t = alloc_conversion (code);
00514 t->type = type;
00515 t->u.next = from;
00516
00517 switch (code)
00518 {
00519 case ck_ptr:
00520 case ck_pmem:
00521 case ck_base:
00522 case ck_std:
00523 if (rank < cr_std)
00524 rank = cr_std;
00525 break;
00526
00527 case ck_qual:
00528 if (rank < cr_exact)
00529 rank = cr_exact;
00530 break;
00531
00532 default:
00533 break;
00534 }
00535 t->rank = rank;
00536 t->user_conv_p = (code == ck_user || from->user_conv_p);
00537 t->bad_p = from->bad_p;
00538 t->base_p = false;
00539 return t;
00540 }
00541
00542
00543
00544
00545 static conversion *
00546 build_identity_conv (tree type, tree expr)
00547 {
00548 conversion *c;
00549
00550 c = alloc_conversion (ck_identity);
00551 c->type = type;
00552 c->u.expr = expr;
00553
00554 return c;
00555 }
00556
00557
00558
00559
00560
00561 static conversion *
00562 build_ambiguous_conv (tree type, tree expr)
00563 {
00564 conversion *c;
00565
00566 c = alloc_conversion (ck_ambig);
00567 c->type = type;
00568 c->u.expr = expr;
00569
00570 return c;
00571 }
00572
00573 tree
00574 strip_top_quals (tree t)
00575 {
00576 if (TREE_CODE (t) == ARRAY_TYPE)
00577 return t;
00578 return cp_build_qualified_type (t, 0);
00579 }
00580
00581
00582
00583
00584
00585
00586 static conversion *
00587 standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
00588 int flags)
00589 {
00590 enum tree_code fcode, tcode;
00591 conversion *conv;
00592 bool fromref = false;
00593
00594 to = non_reference (to);
00595 if (TREE_CODE (from) == REFERENCE_TYPE)
00596 {
00597 fromref = true;
00598 from = TREE_TYPE (from);
00599 }
00600 to = strip_top_quals (to);
00601 from = strip_top_quals (from);
00602
00603 if ((TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
00604 && expr && type_unknown_p (expr))
00605 {
00606 expr = instantiate_type (to, expr, tf_conv);
00607 if (expr == error_mark_node)
00608 return NULL;
00609 from = TREE_TYPE (expr);
00610 }
00611
00612 fcode = TREE_CODE (from);
00613 tcode = TREE_CODE (to);
00614
00615 conv = build_identity_conv (from, expr);
00616 if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE)
00617 {
00618 from = type_decays_to (from);
00619 fcode = TREE_CODE (from);
00620 conv = build_conv (ck_lvalue, from, conv);
00621 }
00622 else if (fromref || (expr && lvalue_p (expr)))
00623 {
00624 if (expr)
00625 {
00626 tree bitfield_type;
00627 bitfield_type = is_bitfield_expr_with_lowered_type (expr);
00628 if (bitfield_type)
00629 {
00630 from = strip_top_quals (bitfield_type);
00631 fcode = TREE_CODE (from);
00632 }
00633 }
00634 conv = build_conv (ck_rvalue, from, conv);
00635 }
00636
00637
00638 if (tcode == COMPLEX_TYPE && fcode == COMPLEX_TYPE)
00639 {
00640
00641
00642
00643 conversion *part_conv = standard_conversion
00644 (TREE_TYPE (to), TREE_TYPE (from), NULL_TREE, c_cast_p, flags);
00645
00646 if (part_conv)
00647 {
00648 conv = build_conv (part_conv->kind, to, conv);
00649 conv->rank = part_conv->rank;
00650 }
00651 else
00652 conv = NULL;
00653
00654 return conv;
00655 }
00656
00657 if (same_type_p (from, to))
00658 return conv;
00659
00660 if ((tcode == POINTER_TYPE || TYPE_PTR_TO_MEMBER_P (to))
00661 && expr && null_ptr_cst_p (expr))
00662 conv = build_conv (ck_std, to, conv);
00663 else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
00664 || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
00665 {
00666
00667
00668 conv = build_conv (ck_std, to, conv);
00669 conv->bad_p = true;
00670 }
00671 else if (tcode == ENUMERAL_TYPE && fcode == INTEGER_TYPE)
00672 {
00673
00674
00675 conv = build_conv (ck_std, to, conv);
00676 conv->bad_p = true;
00677 }
00678 else if ((tcode == POINTER_TYPE && fcode == POINTER_TYPE)
00679 || (TYPE_PTRMEM_P (to) && TYPE_PTRMEM_P (from)))
00680 {
00681 tree to_pointee;
00682 tree from_pointee;
00683
00684 if (tcode == POINTER_TYPE
00685 && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (from),
00686 TREE_TYPE (to)))
00687 ;
00688 else if (VOID_TYPE_P (TREE_TYPE (to))
00689 && !TYPE_PTRMEM_P (from)
00690 && TREE_CODE (TREE_TYPE (from)) != FUNCTION_TYPE)
00691 {
00692 from = build_pointer_type
00693 (cp_build_qualified_type (void_type_node,
00694 cp_type_quals (TREE_TYPE (from))));
00695 conv = build_conv (ck_ptr, from, conv);
00696 }
00697 else if (TYPE_PTRMEM_P (from))
00698 {
00699 tree fbase = TYPE_PTRMEM_CLASS_TYPE (from);
00700 tree tbase = TYPE_PTRMEM_CLASS_TYPE (to);
00701
00702 if (DERIVED_FROM_P (fbase, tbase)
00703 && (same_type_ignoring_top_level_qualifiers_p
00704 (TYPE_PTRMEM_POINTED_TO_TYPE (from),
00705 TYPE_PTRMEM_POINTED_TO_TYPE (to))))
00706 {
00707 from = build_ptrmem_type (tbase,
00708 TYPE_PTRMEM_POINTED_TO_TYPE (from));
00709 conv = build_conv (ck_pmem, from, conv);
00710 }
00711 else if (!same_type_p (fbase, tbase))
00712 return NULL;
00713 }
00714 else if (IS_AGGR_TYPE (TREE_TYPE (from))
00715 && IS_AGGR_TYPE (TREE_TYPE (to))
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727 && DERIVED_FROM_P (TREE_TYPE (to), TREE_TYPE (from))
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739 && COMPLETE_TYPE_P (TREE_TYPE (from)))
00740 {
00741 from =
00742 cp_build_qualified_type (TREE_TYPE (to),
00743 cp_type_quals (TREE_TYPE (from)));
00744 from = build_pointer_type (from);
00745 conv = build_conv (ck_ptr, from, conv);
00746 conv->base_p = true;
00747 }
00748
00749 if (tcode == POINTER_TYPE)
00750 {
00751 to_pointee = TREE_TYPE (to);
00752 from_pointee = TREE_TYPE (from);
00753 }
00754 else
00755 {
00756 to_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (to);
00757 from_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (from);
00758 }
00759
00760 if (same_type_p (from, to))
00761 ;
00762 else if (c_cast_p && comp_ptr_ttypes_const (to, from))
00763
00764
00765
00766 conv = build_conv (ck_qual, to, conv);
00767 else if (!c_cast_p && comp_ptr_ttypes (to_pointee, from_pointee))
00768 conv = build_conv (ck_qual, to, conv);
00769 else if (expr && string_conv_p (to, expr, 0))
00770
00771 conv = build_conv (ck_qual, to, conv);
00772 else if (ptr_reasonably_similar (to_pointee, from_pointee))
00773 {
00774 conv = build_conv (ck_ptr, to, conv);
00775 conv->bad_p = true;
00776 }
00777 else
00778 return NULL;
00779
00780 from = to;
00781 }
00782 else if (TYPE_PTRMEMFUNC_P (to) && TYPE_PTRMEMFUNC_P (from))
00783 {
00784 tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
00785 tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
00786 tree fbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn)));
00787 tree tbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn)));
00788
00789 if (!DERIVED_FROM_P (fbase, tbase)
00790 || !same_type_p (TREE_TYPE (fromfn), TREE_TYPE (tofn))
00791 || !compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn)),
00792 TREE_CHAIN (TYPE_ARG_TYPES (tofn)))
00793 || cp_type_quals (fbase) != cp_type_quals (tbase))
00794 return NULL;
00795
00796 from = cp_build_qualified_type (tbase, cp_type_quals (fbase));
00797 from = build_method_type_directly (from,
00798 TREE_TYPE (fromfn),
00799 TREE_CHAIN (TYPE_ARG_TYPES (fromfn)));
00800 from = build_ptrmemfunc_type (build_pointer_type (from));
00801 conv = build_conv (ck_pmem, from, conv);
00802 conv->base_p = true;
00803 }
00804 else if (tcode == BOOLEAN_TYPE)
00805 {
00806
00807
00808
00809
00810 if (ARITHMETIC_TYPE_P (from)
00811 || fcode == ENUMERAL_TYPE
00812 || fcode == POINTER_TYPE
00813 || TYPE_PTR_TO_MEMBER_P (from))
00814 {
00815 conv = build_conv (ck_std, to, conv);
00816 if (fcode == POINTER_TYPE
00817 || TYPE_PTRMEM_P (from)
00818 || (TYPE_PTRMEMFUNC_P (from)
00819 && conv->rank < cr_pbool))
00820 conv->rank = cr_pbool;
00821 return conv;
00822 }
00823
00824 return NULL;
00825 }
00826
00827
00828 else if (tcode == INTEGER_TYPE || tcode == BOOLEAN_TYPE
00829 || tcode == REAL_TYPE)
00830 {
00831 if (! (INTEGRAL_CODE_P (fcode) || fcode == REAL_TYPE))
00832 return NULL;
00833 conv = build_conv (ck_std, to, conv);
00834
00835
00836 if (same_type_p (to, type_promotes_to (from))
00837 && conv->u.next->rank <= cr_promotion)
00838 conv->rank = cr_promotion;
00839 }
00840 else if (fcode == VECTOR_TYPE && tcode == VECTOR_TYPE
00841 && vector_types_convertible_p (from, to))
00842 return build_conv (ck_std, to, conv);
00843 else if (!(flags & LOOKUP_CONSTRUCTOR_CALLABLE)
00844 && IS_AGGR_TYPE (to) && IS_AGGR_TYPE (from)
00845 && is_properly_derived_from (from, to))
00846 {
00847 if (conv->kind == ck_rvalue)
00848 conv = conv->u.next;
00849 conv = build_conv (ck_base, to, conv);
00850
00851
00852
00853
00854 conv->need_temporary_p = true;
00855 }
00856 else
00857 return NULL;
00858
00859 return conv;
00860 }
00861
00862
00863
00864 static bool
00865 reference_related_p (tree t1, tree t2)
00866 {
00867 t1 = TYPE_MAIN_VARIANT (t1);
00868 t2 = TYPE_MAIN_VARIANT (t2);
00869
00870
00871
00872
00873
00874
00875 return (same_type_p (t1, t2)
00876 || (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
00877 && DERIVED_FROM_P (t1, t2)));
00878 }
00879
00880
00881
00882 static bool
00883 reference_compatible_p (tree t1, tree t2)
00884 {
00885
00886
00887
00888
00889
00890 return (reference_related_p (t1, t2)
00891 && at_least_as_qualified_p (t1, t2));
00892 }
00893
00894
00895
00896
00897 static conversion *
00898 convert_class_to_reference (tree t, tree s, tree expr)
00899 {
00900 tree conversions;
00901 tree arglist;
00902 conversion *conv;
00903 tree reference_type;
00904 struct z_candidate *candidates;
00905 struct z_candidate *cand;
00906 bool any_viable_p;
00907
00908 conversions = lookup_conversions (s);
00909 if (!conversions)
00910 return NULL;
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927 candidates = 0;
00928
00929
00930
00931
00932
00933
00934 arglist = build_int_cst (build_pointer_type (s), 0);
00935 arglist = build_tree_list (NULL_TREE, arglist);
00936
00937 reference_type = build_reference_type (t);
00938
00939 while (conversions)
00940 {
00941 tree fns = TREE_VALUE (conversions);
00942
00943 for (; fns; fns = OVL_NEXT (fns))
00944 {
00945 tree f = OVL_CURRENT (fns);
00946 tree t2 = TREE_TYPE (TREE_TYPE (f));
00947
00948 cand = NULL;
00949
00950
00951
00952 if (TREE_CODE (f) == TEMPLATE_DECL)
00953 {
00954 cand = add_template_candidate (&candidates,
00955 f, s,
00956 NULL_TREE,
00957 arglist,
00958 reference_type,
00959 TYPE_BINFO (s),
00960 TREE_PURPOSE (conversions),
00961 LOOKUP_NORMAL,
00962 DEDUCE_CONV);
00963
00964 if (cand)
00965 {
00966
00967
00968
00969
00970 f = cand->fn;
00971 t2 = TREE_TYPE (TREE_TYPE (f));
00972 if (TREE_CODE (t2) != REFERENCE_TYPE
00973 || !reference_compatible_p (t, TREE_TYPE (t2)))
00974 {
00975 candidates = candidates->next;
00976 cand = NULL;
00977 }
00978 }
00979 }
00980 else if (TREE_CODE (t2) == REFERENCE_TYPE
00981 && reference_compatible_p (t, TREE_TYPE (t2)))
00982 cand = add_function_candidate (&candidates, f, s, arglist,
00983 TYPE_BINFO (s),
00984 TREE_PURPOSE (conversions),
00985 LOOKUP_NORMAL);
00986
00987 if (cand)
00988 {
00989 conversion *identity_conv;
00990
00991
00992
00993 identity_conv
00994 = build_identity_conv (TREE_TYPE (TREE_TYPE
00995 (TREE_TYPE (cand->fn))),
00996 NULL_TREE);
00997 cand->second_conv
00998 = (direct_reference_binding
00999 (reference_type, identity_conv));
01000 cand->second_conv->bad_p |= cand->convs[0]->bad_p;
01001 }
01002 }
01003 conversions = TREE_CHAIN (conversions);
01004 }
01005
01006 candidates = splice_viable (candidates, pedantic, &any_viable_p);
01007
01008
01009 if (!any_viable_p)
01010 return NULL;
01011
01012 cand = tourney (candidates);
01013 if (!cand)
01014 return NULL;
01015
01016
01017
01018 cand->args = tree_cons (NULL_TREE,
01019 build_this (expr),
01020 TREE_CHAIN (cand->args));
01021
01022
01023
01024 conv = build_conv (ck_user,
01025 TREE_TYPE (TREE_TYPE (cand->fn)),
01026 build_identity_conv (TREE_TYPE (expr), expr));
01027 conv->cand = cand;
01028
01029
01030
01031 cand->second_conv = merge_conversion_sequences (conv, cand->second_conv);
01032
01033 if (cand->viable == -1)
01034 conv->bad_p = true;
01035
01036 return cand->second_conv;
01037 }
01038
01039
01040
01041
01042
01043 static conversion *
01044 direct_reference_binding (tree type, conversion *conv)
01045 {
01046 tree t;
01047
01048 gcc_assert (TREE_CODE (type) == REFERENCE_TYPE);
01049 gcc_assert (TREE_CODE (conv->type) != REFERENCE_TYPE);
01050
01051 t = TREE_TYPE (type);
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069 if (!same_type_ignoring_top_level_qualifiers_p (t, conv->type))
01070 {
01071
01072 conv = build_conv (ck_base, t, conv);
01073
01074
01075
01076 conv->need_temporary_p = false;
01077 }
01078 return build_conv (ck_ref_bind, type, conv);
01079 }
01080
01081
01082
01083
01084
01085
01086
01087
01088 static conversion *
01089 reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags)
01090 {
01091 conversion *conv = NULL;
01092 tree to = TREE_TYPE (rto);
01093 tree from = rfrom;
01094 bool related_p;
01095 bool compatible_p;
01096 cp_lvalue_kind lvalue_p = clk_none;
01097
01098 if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
01099 {
01100 expr = instantiate_type (to, expr, tf_none);
01101 if (expr == error_mark_node)
01102 return NULL;
01103 from = TREE_TYPE (expr);
01104 }
01105
01106 if (TREE_CODE (from) == REFERENCE_TYPE)
01107 {
01108
01109 lvalue_p = clk_ordinary;
01110 from = TREE_TYPE (from);
01111 }
01112 else if (expr)
01113 lvalue_p = real_lvalue_p (expr);
01114
01115
01116
01117
01118 related_p = reference_related_p (to, from);
01119
01120
01121 if (related_p && c_cast_p
01122 && !at_least_as_qualified_p (to, from))
01123 to = build_qualified_type (to, cp_type_quals (from));
01124 compatible_p = reference_compatible_p (to, from);
01125
01126 if (lvalue_p && compatible_p)
01127 {
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137 conv = build_identity_conv (from, expr);
01138 conv = direct_reference_binding (rto, conv);
01139 if ((lvalue_p & clk_bitfield) != 0
01140 || ((lvalue_p & clk_packed) != 0 && !TYPE_PACKED (to)))
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152 conv->need_temporary_p = true;
01153
01154 return conv;
01155 }
01156 else if (CLASS_TYPE_P (from) && !(flags & LOOKUP_NO_CONVERSION))
01157 {
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171 conv = convert_class_to_reference (to, from, expr);
01172 if (conv)
01173 return conv;
01174 }
01175
01176
01177
01178 if (flags & LOOKUP_NO_TEMP_BIND)
01179 return NULL;
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195 if (!CP_TYPE_CONST_NON_VOLATILE_P (to))
01196 return NULL;
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214 if (CLASS_TYPE_P (from) && compatible_p)
01215 {
01216 conv = build_identity_conv (from, expr);
01217 conv = direct_reference_binding (rto, conv);
01218 if (!(flags & LOOKUP_CONSTRUCTOR_CALLABLE))
01219 conv->u.next->check_copy_constructor_p = true;
01220 return conv;
01221 }
01222
01223
01224
01225
01226
01227
01228
01229
01230 if (related_p && !at_least_as_qualified_p (to, from))
01231 return NULL;
01232
01233 conv = implicit_conversion (to, from, expr, c_cast_p,
01234 flags);
01235 if (!conv)
01236 return NULL;
01237
01238 conv = build_conv (ck_ref_bind, rto, conv);
01239
01240
01241 conv->need_temporary_p = true;
01242
01243 return conv;
01244 }
01245
01246
01247
01248
01249
01250
01251
01252 static conversion *
01253 implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
01254 int flags)
01255 {
01256 conversion *conv;
01257
01258 if (from == error_mark_node || to == error_mark_node
01259 || expr == error_mark_node)
01260 return NULL;
01261
01262 if (TREE_CODE (to) == REFERENCE_TYPE)
01263 conv = reference_binding (to, from, expr, c_cast_p, flags);
01264 else
01265 conv = standard_conversion (to, from, expr, c_cast_p, flags);
01266
01267 if (conv)
01268 return conv;
01269
01270 if (expr != NULL_TREE
01271 && (IS_AGGR_TYPE (from)
01272 || IS_AGGR_TYPE (to))
01273 && (flags & LOOKUP_NO_CONVERSION) == 0)
01274 {
01275 struct z_candidate *cand;
01276
01277 cand = build_user_type_conversion_1
01278 (to, expr, LOOKUP_ONLYCONVERTING);
01279 if (cand)
01280 conv = cand->second_conv;
01281
01282
01283
01284
01285 return conv;
01286 }
01287
01288 return NULL;
01289 }
01290
01291
01292
01293
01294 static struct z_candidate *
01295 add_candidate (struct z_candidate **candidates,
01296 tree fn, tree args,
01297 size_t num_convs, conversion **convs,
01298 tree access_path, tree conversion_path,
01299 int viable)
01300 {
01301 struct z_candidate *cand = (struct z_candidate *)
01302 conversion_obstack_alloc (sizeof (struct z_candidate));
01303
01304 cand->fn = fn;
01305 cand->args = args;
01306 cand->convs = convs;
01307 cand->num_convs = num_convs;
01308 cand->access_path = access_path;
01309 cand->conversion_path = conversion_path;
01310 cand->viable = viable;
01311 cand->next = *candidates;
01312 *candidates = cand;
01313
01314 return cand;
01315 }
01316
01317
01318
01319
01320
01321
01322
01323
01324 static struct z_candidate *
01325 add_function_candidate (struct z_candidate **candidates,
01326 tree fn, tree ctype, tree arglist,
01327 tree access_path, tree conversion_path,
01328 int flags)
01329 {
01330 tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
01331 int i, len;
01332 conversion **convs;
01333 tree parmnode, argnode;
01334 tree orig_arglist;
01335 int viable = 1;
01336
01337
01338
01339
01340 gcc_assert (!DECL_ANTICIPATED (fn) || DECL_HIDDEN_FRIEND_P (fn));
01341
01342
01343
01344 if (DECL_CONSTRUCTOR_P (fn))
01345 {
01346 parmlist = skip_artificial_parms_for (fn, parmlist);
01347 orig_arglist = arglist;
01348 arglist = skip_artificial_parms_for (fn, arglist);
01349 }
01350 else
01351 orig_arglist = arglist;
01352
01353 len = list_length (arglist);
01354 convs = alloc_conversions (len);
01355
01356
01357
01358
01359
01360
01361
01362
01363 parmnode = parmlist;
01364 for (i = 0; i < len; ++i)
01365 {
01366 if (parmnode == NULL_TREE || parmnode == void_list_node)
01367 break;
01368 parmnode = TREE_CHAIN (parmnode);
01369 }
01370
01371 if (i < len && parmnode)
01372 viable = 0;
01373
01374
01375 else if (!sufficient_parms_p (parmnode))
01376 viable = 0;
01377
01378 if (! viable)
01379 goto out;
01380
01381
01382
01383
01384
01385 parmnode = parmlist;
01386 argnode = arglist;
01387
01388 for (i = 0; i < len; ++i)
01389 {
01390 tree arg = TREE_VALUE (argnode);
01391 tree argtype = lvalue_type (arg);
01392 conversion *t;
01393 int is_this;
01394
01395 if (parmnode == void_list_node)
01396 break;
01397
01398 is_this = (i == 0 && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
01399 && ! DECL_CONSTRUCTOR_P (fn));
01400
01401 if (parmnode)
01402 {
01403 tree parmtype = TREE_VALUE (parmnode);
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414 if (ctype && is_this)
01415 {
01416 parmtype
01417 = build_qualified_type (ctype,
01418 TYPE_QUALS (TREE_TYPE (parmtype)));
01419 parmtype = build_pointer_type (parmtype);
01420 }
01421
01422 t = implicit_conversion (parmtype, argtype, arg,
01423 false, flags);
01424 }
01425 else
01426 {
01427 t = build_identity_conv (argtype, arg);
01428 t->ellipsis_p = true;
01429 }
01430
01431 if (t && is_this)
01432 t->this_p = true;
01433
01434 convs[i] = t;
01435 if (! t)
01436 {
01437 viable = 0;
01438 break;
01439 }
01440
01441 if (t->bad_p)
01442 viable = -1;
01443
01444 if (parmnode)
01445 parmnode = TREE_CHAIN (parmnode);
01446 argnode = TREE_CHAIN (argnode);
01447 }
01448
01449 out:
01450 return add_candidate (candidates, fn, orig_arglist, len, convs,
01451 access_path, conversion_path, viable);
01452 }
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465 static struct z_candidate *
01466 add_conv_candidate (struct z_candidate **candidates, tree fn, tree obj,
01467 tree arglist, tree access_path, tree conversion_path)
01468 {
01469 tree totype = TREE_TYPE (TREE_TYPE (fn));
01470 int i, len, viable, flags;
01471 tree parmlist, parmnode, argnode;
01472 conversion **convs;
01473
01474 for (parmlist = totype; TREE_CODE (parmlist) != FUNCTION_TYPE; )
01475 parmlist = TREE_TYPE (parmlist);
01476 parmlist = TYPE_ARG_TYPES (parmlist);
01477
01478 len = list_length (arglist) + 1;
01479 convs = alloc_conversions (len);
01480 parmnode = parmlist;
01481 argnode = arglist;
01482 viable = 1;
01483 flags = LOOKUP_NORMAL;
01484
01485
01486 if (*candidates && (*candidates)->fn == totype)
01487 return NULL;
01488
01489 for (i = 0; i < len; ++i)
01490 {
01491 tree arg = i == 0 ? obj : TREE_VALUE (argnode);
01492 tree argtype = lvalue_type (arg);
01493 conversion *t;
01494
01495 if (i == 0)
01496 t = implicit_conversion (totype, argtype, arg, false,
01497 flags);
01498 else if (parmnode == void_list_node)
01499 break;
01500 else if (parmnode)
01501 t = implicit_conversion (TREE_VALUE (parmnode), argtype, arg,
01502 false, flags);
01503 else
01504 {
01505 t = build_identity_conv (argtype, arg);
01506 t->ellipsis_p = true;
01507 }
01508
01509 convs[i] = t;
01510 if (! t)
01511 break;
01512
01513 if (t->bad_p)
01514 viable = -1;
01515
01516 if (i == 0)
01517 continue;
01518
01519 if (parmnode)
01520 parmnode = TREE_CHAIN (parmnode);
01521 argnode = TREE_CHAIN (argnode);
01522 }
01523
01524 if (i < len)
01525 viable = 0;
01526
01527 if (!sufficient_parms_p (parmnode))
01528 viable = 0;
01529
01530 return add_candidate (candidates, totype, arglist, len, convs,
01531 access_path, conversion_path, viable);
01532 }
01533
01534 static void
01535 build_builtin_candidate (struct z_candidate **candidates, tree fnname,
01536 tree type1, tree type2, tree *args, tree *argtypes,
01537 int flags)
01538 {
01539 conversion *t;
01540 conversion **convs;
01541 size_t num_convs;
01542 int viable = 1, i;
01543 tree types[2];
01544
01545 types[0] = type1;
01546 types[1] = type2;
01547
01548 num_convs = args[2] ? 3 : (args[1] ? 2 : 1);
01549 convs = alloc_conversions (num_convs);
01550
01551 for (i = 0; i < 2; ++i)
01552 {
01553 if (! args[i])
01554 break;
01555
01556 t = implicit_conversion (types[i], argtypes[i], args[i],
01557 false, flags);
01558 if (! t)
01559 {
01560 viable = 0;
01561
01562 t = build_identity_conv (types[i], NULL_TREE);
01563 }
01564 else if (t->bad_p)
01565 viable = 0;
01566 convs[i] = t;
01567 }
01568
01569
01570 if (args[2])
01571 {
01572 convs[2] = convs[1];
01573 convs[1] = convs[0];
01574 t = implicit_conversion (boolean_type_node, argtypes[2], args[2],
01575 false, flags);
01576 if (t)
01577 convs[0] = t;
01578 else
01579 viable = 0;
01580 }
01581
01582 add_candidate (candidates, fnname, NULL_TREE,
01583 num_convs, convs,
01584 NULL_TREE,
01585 NULL_TREE,
01586 viable);
01587 }
01588
01589 static bool
01590 is_complete (tree t)
01591 {
01592 return COMPLETE_TYPE_P (complete_type (t));
01593 }
01594
01595
01596
01597 static bool
01598 promoted_arithmetic_type_p (tree type)
01599 {
01600
01601
01602
01603
01604
01605
01606
01607 return ((INTEGRAL_TYPE_P (type)
01608 && same_type_p (type_promotes_to (type), type))
01609 || TREE_CODE (type) == REAL_TYPE);
01610 }
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622 static void
01623 add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
01624 enum tree_code code2, tree fnname, tree type1,
01625 tree type2, tree *args, tree *argtypes, int flags)
01626 {
01627 switch (code)
01628 {
01629 case POSTINCREMENT_EXPR:
01630 case POSTDECREMENT_EXPR:
01631 args[1] = integer_zero_node;
01632 type2 = integer_type_node;
01633 break;
01634 default:
01635 break;
01636 }
01637
01638 switch (code)
01639 {
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659 case POSTDECREMENT_EXPR:
01660 case PREDECREMENT_EXPR:
01661 if (TREE_CODE (type1) == BOOLEAN_TYPE)
01662 return;
01663 case POSTINCREMENT_EXPR:
01664 case PREINCREMENT_EXPR:
01665 if (ARITHMETIC_TYPE_P (type1) || TYPE_PTROB_P (type1))
01666 {
01667 type1 = build_reference_type (type1);
01668 break;
01669 }
01670 return;
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681 case INDIRECT_REF:
01682 if (TREE_CODE (type1) == POINTER_TYPE
01683 && (TYPE_PTROB_P (type1)
01684 || TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE))
01685 break;
01686 return;
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696 case UNARY_PLUS_EXPR:
01697 if (TREE_CODE (type1) == POINTER_TYPE)
01698 break;
01699 case NEGATE_EXPR:
01700 if (ARITHMETIC_TYPE_P (type1))
01701 break;
01702 return;
01703
01704
01705
01706
01707
01708 case BIT_NOT_EXPR:
01709 if (INTEGRAL_TYPE_P (type1))
01710 break;
01711 return;
01712
01713
01714
01715
01716
01717
01718
01719
01720 case MEMBER_REF:
01721 if (TREE_CODE (type1) == POINTER_TYPE
01722 && TYPE_PTR_TO_MEMBER_P (type2))
01723 {
01724 tree c1 = TREE_TYPE (type1);
01725 tree c2 = TYPE_PTRMEM_CLASS_TYPE (type2);
01726
01727 if (IS_AGGR_TYPE (c1) && DERIVED_FROM_P (c2, c1)
01728 && (TYPE_PTRMEMFUNC_P (type2)
01729 || is_complete (TYPE_PTRMEM_POINTED_TO_TYPE (type2))))
01730 break;
01731 }
01732 return;
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776 case MINUS_EXPR:
01777 if (TYPE_PTROB_P (type1) && TYPE_PTROB_P (type2))
01778 break;
01779 if (TYPE_PTROB_P (type1) && INTEGRAL_TYPE_P (type2))
01780 {
01781 type2 = ptrdiff_type_node;
01782 break;
01783 }
01784 case MULT_EXPR:
01785 case TRUNC_DIV_EXPR:
01786 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
01787 break;
01788 return;
01789
01790 case EQ_EXPR:
01791 case NE_EXPR:
01792 if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
01793 || (TYPE_PTRMEM_P (type1) && TYPE_PTRMEM_P (type2)))
01794 break;
01795 if (TYPE_PTR_TO_MEMBER_P (type1) && null_ptr_cst_p (args[1]))
01796 {
01797 type2 = type1;
01798 break;
01799 }
01800 if (TYPE_PTR_TO_MEMBER_P (type2) && null_ptr_cst_p (args[0]))
01801 {
01802 type1 = type2;
01803 break;
01804 }
01805
01806 case LT_EXPR:
01807 case GT_EXPR:
01808 case LE_EXPR:
01809 case GE_EXPR:
01810 case MAX_EXPR:
01811 case MIN_EXPR:
01812 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
01813 break;
01814 if (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
01815 break;
01816 if (TREE_CODE (type1) == ENUMERAL_TYPE
01817 && TREE_CODE (type2) == ENUMERAL_TYPE)
01818 break;
01819 if (TYPE_PTR_P (type1)
01820 && null_ptr_cst_p (args[1])
01821 && !uses_template_parms (type1))
01822 {
01823 type2 = type1;
01824 break;
01825 }
01826 if (null_ptr_cst_p (args[0])
01827 && TYPE_PTR_P (type2)
01828 && !uses_template_parms (type2))
01829 {
01830 type1 = type2;
01831 break;
01832 }
01833 return;
01834
01835 case PLUS_EXPR:
01836 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
01837 break;
01838 case ARRAY_REF:
01839 if (INTEGRAL_TYPE_P (type1) && TYPE_PTROB_P (type2))
01840 {
01841 type1 = ptrdiff_type_node;
01842 break;
01843 }
01844 if (TYPE_PTROB_P (type1) && INTEGRAL_TYPE_P (type2))
01845 {
01846 type2 = ptrdiff_type_node;
01847 break;
01848 }
01849 return;
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862 case TRUNC_MOD_EXPR:
01863 case BIT_AND_EXPR:
01864 case BIT_IOR_EXPR:
01865 case BIT_XOR_EXPR:
01866 case LSHIFT_EXPR:
01867 case RSHIFT_EXPR:
01868 if (INTEGRAL_TYPE_P (type1) && INTEGRAL_TYPE_P (type2))
01869 break;
01870 return;
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908 case MODIFY_EXPR:
01909 switch (code2)
01910 {
01911 case PLUS_EXPR:
01912 case MINUS_EXPR:
01913 if (TYPE_PTROB_P (type1) && INTEGRAL_TYPE_P (type2))
01914 {
01915 type2 = ptrdiff_type_node;
01916 break;
01917 }
01918 case MULT_EXPR:
01919 case TRUNC_DIV_EXPR:
01920 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
01921 break;
01922 return;
01923
01924 case TRUNC_MOD_EXPR:
01925 case BIT_AND_EXPR:
01926 case BIT_IOR_EXPR:
01927 case BIT_XOR_EXPR:
01928 case LSHIFT_EXPR:
01929 case RSHIFT_EXPR:
01930 if (INTEGRAL_TYPE_P (type1) && INTEGRAL_TYPE_P (type2))
01931 break;
01932 return;
01933
01934 case NOP_EXPR:
01935 if (ARITHMETIC_TYPE_P (type1) && ARITHMETIC_TYPE_P (type2))
01936 break;
01937 if ((TYPE_PTRMEMFUNC_P (type1) && TYPE_PTRMEMFUNC_P (type2))
01938 || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
01939 || (TYPE_PTRMEM_P (type1) && TYPE_PTRMEM_P (type2))
01940 || ((TYPE_PTRMEMFUNC_P (type1)
01941 || TREE_CODE (type1) == POINTER_TYPE)
01942 && null_ptr_cst_p (args[1])))
01943 {
01944 type2 = type1;
01945 break;
01946 }
01947 return;
01948
01949 default:
01950 gcc_unreachable ();
01951 }
01952 type1 = build_reference_type (type1);
01953 break;
01954
01955 case COND_EXPR:
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970 if (promoted_arithmetic_type_p (type1)
01971 && promoted_arithmetic_type_p (type2))
01972
01973 break;
01974
01975
01976 if (!(TYPE_PTR_P (type1) || TYPE_PTR_TO_MEMBER_P (type1))
01977 || !(TYPE_PTR_P (type2) || TYPE_PTR_TO_MEMBER_P (type2)))
01978 return;
01979
01980
01981
01982
01983
01984 break;
01985
01986 default:
01987 gcc_unreachable ();
01988 }
01989
01990
01991
01992 if (type2 && !same_type_p (type1, type2)
01993 && TREE_CODE (type1) == TREE_CODE (type2)
01994 && (TREE_CODE (type1) == REFERENCE_TYPE
01995 || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
01996 || (TYPE_PTRMEM_P (type1) && TYPE_PTRMEM_P (type2))
01997 || TYPE_PTRMEMFUNC_P (type1)
01998 || IS_AGGR_TYPE (type1)
01999 || TREE_CODE (type1) == ENUMERAL_TYPE))
02000 {
02001 build_builtin_candidate
02002 (candidates, fnname, type1, type1, args, argtypes, flags);
02003 build_builtin_candidate
02004 (candidates, fnname, type2, type2, args, argtypes, flags);
02005 return;
02006 }
02007
02008 build_builtin_candidate
02009 (candidates, fnname, type1, type2, args, argtypes, flags);
02010 }
02011
02012 tree
02013 type_decays_to (tree type)
02014 {
02015 if (TREE_CODE (type) == ARRAY_TYPE)
02016 return build_pointer_type (TREE_TYPE (type));
02017 if (TREE_CODE (type) == FUNCTION_TYPE)
02018 return build_pointer_type (type);
02019 return type;
02020 }
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035 static void
02036 add_builtin_candidates (struct z_candidate **candidates, enum tree_code code,
02037 enum tree_code code2, tree fnname, tree *args,
02038 int flags)
02039 {
02040 int ref1, i;
02041 int enum_p = 0;
02042 tree type, argtypes[3];
02043
02044
02045
02046
02047 tree types[2];
02048
02049 for (i = 0; i < 3; ++i)
02050 {
02051 if (args[i])
02052 argtypes[i] = lvalue_type (args[i]);
02053 else
02054 argtypes[i] = NULL_TREE;
02055 }
02056
02057 switch (code)
02058 {
02059
02060
02061
02062
02063
02064 case POSTINCREMENT_EXPR:
02065 case PREINCREMENT_EXPR:
02066 case POSTDECREMENT_EXPR:
02067 case PREDECREMENT_EXPR:
02068 case MODIFY_EXPR:
02069 ref1 = 1;
02070 break;
02071
02072
02073
02074
02075
02076
02077 case TRUTH_NOT_EXPR:
02078 build_builtin_candidate
02079 (candidates, fnname, boolean_type_node,
02080 NULL_TREE, args, argtypes, flags);
02081 return;
02082
02083 case TRUTH_ORIF_EXPR:
02084 case TRUTH_ANDIF_EXPR:
02085 build_builtin_candidate
02086 (candidates, fnname, boolean_type_node,
02087 boolean_type_node, args, argtypes, flags);
02088 return;
02089
02090 case ADDR_EXPR:
02091 case COMPOUND_EXPR:
02092 case COMPONENT_REF:
02093 return;
02094
02095 case COND_EXPR:
02096 case EQ_EXPR:
02097 case NE_EXPR:
02098 case LT_EXPR:
02099 case LE_EXPR:
02100 case GT_EXPR:
02101 case GE_EXPR:
02102 enum_p = 1;
02103
02104
02105 default:
02106 ref1 = 0;
02107 }
02108
02109 types[0] = types[1] = NULL_TREE;
02110
02111 for (i = 0; i < 2; ++i)
02112 {
02113 if (! args[i])
02114 ;
02115 else if (IS_AGGR_TYPE (argtypes[i]))
02116 {
02117 tree convs;
02118
02119 if (i == 0 && code == MODIFY_EXPR && code2 == NOP_EXPR)
02120 return;
02121
02122 convs = lookup_conversions (argtypes[i]);
02123
02124 if (code == COND_EXPR)
02125 {
02126 if (real_lvalue_p (args[i]))
02127 types[i] = tree_cons
02128 (NULL_TREE, build_reference_type (argtypes[i]), types[i]);
02129
02130 types[i] = tree_cons
02131 (NULL_TREE, TYPE_MAIN_VARIANT (argtypes[i]), types[i]);
02132 }
02133
02134 else if (! convs)
02135 return;
02136
02137 for (; convs; convs = TREE_CHAIN (convs))
02138 {
02139 type = TREE_TYPE (TREE_TYPE (OVL_CURRENT (TREE_VALUE (convs))));
02140
02141 if (i == 0 && ref1
02142 && (TREE_CODE (type) != REFERENCE_TYPE
02143 || CP_TYPE_CONST_P (TREE_TYPE (type))))
02144 continue;
02145
02146 if (code == COND_EXPR && TREE_CODE (type) == REFERENCE_TYPE)
02147 types[i] = tree_cons (NULL_TREE, type, types[i]);
02148
02149 type = non_reference (type);
02150 if (i != 0 || ! ref1)
02151 {
02152 type = TYPE_MAIN_VARIANT (type_decays_to (type));
02153 if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE)
02154 types[i] = tree_cons (NULL_TREE, type, types[i]);
02155 if (INTEGRAL_TYPE_P (type))
02156 type = type_promotes_to (type);
02157 }
02158
02159 if (! value_member (type, types[i]))
02160 types[i] = tree_cons (NULL_TREE, type, types[i]);
02161 }
02162 }
02163 else
02164 {
02165 if (code == COND_EXPR && real_lvalue_p (args[i]))
02166 types[i] = tree_cons
02167 (NULL_TREE, build_reference_type (argtypes[i]), types[i]);
02168 type = non_reference (argtypes[i]);
02169 if (i != 0 || ! ref1)
02170 {
02171 type = TYPE_MAIN_VARIANT (type_decays_to (type));
02172 if (enum_p && TREE_CODE (type) == ENUMERAL_TYPE)
02173 types[i] = tree_cons (NULL_TREE, type, types[i]);
02174 if (INTEGRAL_TYPE_P (type))
02175 type = type_promotes_to (type);
02176 }
02177 types[i] = tree_cons (NULL_TREE, type, types[i]);
02178 }
02179 }
02180
02181
02182
02183 for (; types[0]; types[0] = TREE_CHAIN (types[0]))
02184 {
02185 if (types[1])
02186 for (type = types[1]; type; type = TREE_CHAIN (type))
02187 add_builtin_candidate
02188 (candidates, code, code2, fnname, TREE_VALUE (types[0]),
02189 TREE_VALUE (type), args, argtypes, flags);
02190 else
02191 add_builtin_candidate
02192 (candidates, code, code2, fnname, TREE_VALUE (types[0]),
02193 NULL_TREE, args, argtypes, flags);
02194 }
02195 }
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208 static struct z_candidate*
02209 add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
02210 tree ctype, tree explicit_targs, tree arglist,
02211 tree return_type, tree access_path,
02212 tree conversion_path, int flags, tree obj,
02213 unification_kind_t strict)
02214 {
02215 int ntparms = DECL_NTPARMS (tmpl);
02216 tree targs = make_tree_vec (ntparms);
02217 tree args_without_in_chrg = arglist;
02218 struct z_candidate *cand;
02219 int i;
02220 tree fn;
02221
02222
02223
02224 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (tmpl))
02225 args_without_in_chrg = TREE_CHAIN (args_without_in_chrg);
02226
02227 if ((DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (tmpl)
02228 || DECL_BASE_CONSTRUCTOR_P (tmpl))
02229 && CLASSTYPE_VBASECLASSES (DECL_CONTEXT (tmpl)))
02230 args_without_in_chrg = TREE_CHAIN (args_without_in_chrg);
02231
02232 i = fn_type_unification (tmpl, explicit_targs, targs,
02233 args_without_in_chrg,
02234 return_type, strict, flags);
02235
02236 if (i != 0)
02237 return NULL;
02238
02239 fn = instantiate_template (tmpl, targs, tf_none);
02240 if (fn == error_mark_node)
02241 return NULL;
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265 if (DECL_CONSTRUCTOR_P (fn) && list_length (arglist) == 2)
02266 {
02267 tree arg_types = FUNCTION_FIRST_USER_PARMTYPE (fn);
02268 if (arg_types && same_type_p (TYPE_MAIN_VARIANT (TREE_VALUE (arg_types)),
02269 ctype))
02270 return NULL;
02271 }
02272
02273 if (obj != NULL_TREE)
02274
02275 cand = add_conv_candidate (candidates, fn, obj, access_path,
02276 conversion_path, arglist);
02277 else
02278 cand = add_function_candidate (candidates, fn, ctype,
02279 arglist, access_path,
02280 conversion_path, flags);
02281 if (DECL_TI_TEMPLATE (fn) != tmpl)
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299 cand->template_decl = tree_cons (tmpl, targs, NULL_TREE);
02300 else
02301 cand->template_decl = DECL_TEMPLATE_INFO (fn);
02302
02303 return cand;
02304 }
02305
02306
02307 static struct z_candidate *
02308 add_template_candidate (struct z_candidate **candidates, tree tmpl, tree ctype,
02309 tree explicit_targs, tree arglist, tree return_type,
02310 tree access_path, tree conversion_path, int flags,
02311 unification_kind_t strict)
02312 {
02313 return
02314 add_template_candidate_real (candidates, tmpl, ctype,
02315 explicit_targs, arglist, return_type,
02316 access_path, conversion_path,
02317 flags, NULL_TREE, strict);
02318 }
02319
02320
02321 static struct z_candidate *
02322 add_template_conv_candidate (struct z_candidate **candidates, tree tmpl,
02323 tree obj, tree arglist, tree return_type,
02324 tree access_path, tree conversion_path)
02325 {
02326 return
02327 add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE,
02328 arglist, return_type, access_path,
02329 conversion_path, 0, obj, DEDUCE_CONV);
02330 }
02331
02332
02333
02334
02335
02336
02337
02338 static struct z_candidate*
02339 splice_viable (struct z_candidate *cands,
02340 bool strict_p,
02341 bool *any_viable_p)
02342 {
02343 struct z_candidate *viable;
02344 struct z_candidate **last_viable;
02345 struct z_candidate **cand;
02346
02347 viable = NULL;
02348 last_viable = &viable;
02349 *any_viable_p = false;
02350
02351 cand = &cands;
02352 while (*cand)
02353 {
02354 struct z_candidate *c = *cand;
02355 if (strict_p ? c->viable == 1 : c->viable)
02356 {
02357 *last_viable = c;
02358 *cand = c->next;
02359 c->next = NULL;
02360 last_viable = &c->next;
02361 *any_viable_p = true;
02362 }
02363 else
02364 cand = &c->next;
02365 }
02366
02367 return viable ? viable : cands;
02368 }
02369
02370 static bool
02371 any_strictly_viable (struct z_candidate *cands)
02372 {
02373 for (; cands; cands = cands->next)
02374 if (cands->viable == 1)
02375 return true;
02376 return false;
02377 }
02378
02379
02380
02381
02382
02383 static tree
02384 build_this (tree obj)
02385 {
02386
02387
02388 if (processing_template_decl)
02389 return build_address (obj);
02390
02391 return build_unary_op (ADDR_EXPR, obj, 0);
02392 }
02393
02394
02395
02396
02397
02398 static inline int
02399 equal_functions (tree fn1, tree fn2)
02400 {
02401 if (DECL_LOCAL_FUNCTION_P (fn1) || DECL_LOCAL_FUNCTION_P (fn2)
02402 || DECL_EXTERN_C_FUNCTION_P (fn1))
02403 return decls_match (fn1, fn2);
02404 return fn1 == fn2;
02405 }
02406
02407
02408
02409
02410
02411
02412
02413
02414 static void
02415 print_z_candidate (const char *msgstr, struct z_candidate *candidate)
02416 {
02417 if (TREE_CODE (candidate->fn) == IDENTIFIER_NODE)
02418 {
02419 if (candidate->num_convs == 3)
02420 inform ("%s %D(%T, %T, %T) <built-in>", msgstr, candidate->fn,
02421 candidate->convs[0]->type,
02422 candidate->convs[1]->type,
02423 candidate->convs[2]->type);
02424 else if (candidate->num_convs == 2)
02425 inform ("%s %D(%T, %T) <built-in>", msgstr, candidate->fn,
02426 candidate->convs[0]->type,
02427 candidate->convs[1]->type);
02428 else
02429 inform ("%s %D(%T) <built-in>", msgstr, candidate->fn,
02430 candidate->convs[0]->type);
02431 }
02432 else if (TYPE_P (candidate->fn))
02433 inform ("%s %T <conversion>", msgstr, candidate->fn);
02434 else if (candidate->viable == -1)
02435 inform ("%s %+#D <near match>", msgstr, candidate->fn);
02436 else
02437 inform ("%s %+#D", msgstr, candidate->fn);
02438 }
02439
02440 static void
02441 print_z_candidates (struct z_candidate *candidates)
02442 {
02443 const char *str;
02444 struct z_candidate *cand1;
02445 struct z_candidate **cand2;
02446
02447
02448
02449
02450
02451
02452 for (cand1 = candidates; cand1; cand1 = cand1->next)
02453 {
02454 tree fn = cand1->fn;
02455
02456 if (TREE_CODE (fn) != FUNCTION_DECL)
02457 continue;
02458 cand2 = &cand1->next;
02459 while (*cand2)
02460 {
02461 if (TREE_CODE ((*cand2)->fn) == FUNCTION_DECL
02462 && equal_functions (fn, (*cand2)->fn))
02463 *cand2 = (*cand2)->next;
02464 else
02465 cand2 = &(*cand2)->next;
02466 }
02467 }
02468
02469 if (!candidates)
02470 return;
02471
02472 str = _("candidates are:");
02473 print_z_candidate (str, candidates);
02474 if (candidates->next)
02475 {
02476
02477
02478 size_t len = gcc_gettext_width (str) + 1;
02479 char *spaces = (char *) alloca (len);
02480 memset (spaces, ' ', len-1);
02481 spaces[len - 1] = '\0';
02482
02483 candidates = candidates->next;
02484 do
02485 {
02486 print_z_candidate (spaces, candidates);
02487 candidates = candidates->next;
02488 }
02489 while (candidates);
02490 }
02491 }
02492
02493
02494
02495
02496
02497
02498
02499 static conversion *
02500 merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
02501 {
02502 conversion **t;
02503
02504 gcc_assert (user_seq->kind == ck_user);
02505
02506
02507 t = &(std_seq);
02508 while ((*t)->kind != ck_identity)
02509 t = &((*t)->u.next);
02510
02511
02512
02513 *t = user_seq;
02514
02515
02516 std_seq->user_conv_p = true;
02517
02518 return std_seq;
02519 }
02520
02521
02522
02523
02524
02525
02526
02527 static struct z_candidate *
02528 build_user_type_conversion_1 (tree totype, tree expr, int flags)
02529 {
02530 struct z_candidate *candidates, *cand;
02531 tree fromtype = TREE_TYPE (expr);
02532 tree ctors = NULL_TREE;
02533 tree conv_fns = NULL_TREE;
02534 conversion *conv = NULL;
02535 tree args = NULL_TREE;
02536 bool any_viable_p;
02537
02538
02539
02540
02541 gcc_assert (!IS_AGGR_TYPE (fromtype) || !IS_AGGR_TYPE (totype)
02542 || !DERIVED_FROM_P (totype, fromtype));
02543
02544 if (IS_AGGR_TYPE (totype))
02545 ctors = lookup_fnfields (totype, complete_ctor_identifier, 0);
02546
02547 if (IS_AGGR_TYPE (fromtype))
02548 conv_fns = lookup_conversions (fromtype);
02549
02550 candidates = 0;
02551 flags |= LOOKUP_NO_CONVERSION;
02552
02553 if (ctors)
02554 {
02555 tree t;
02556
02557 ctors = BASELINK_FUNCTIONS (ctors);
02558
02559 t = build_int_cst (build_pointer_type (totype), 0);
02560 args = build_tree_list (NULL_TREE, expr);
02561
02562
02563 gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (OVL_CURRENT (ctors))
02564 && !DECL_HAS_VTT_PARM_P (OVL_CURRENT (ctors)));
02565 args = tree_cons (NULL_TREE, t, args);
02566 }
02567 for (; ctors; ctors = OVL_NEXT (ctors))
02568 {
02569 tree ctor = OVL_CURRENT (ctors);
02570 if (DECL_NONCONVERTING_P (ctor))
02571 continue;
02572
02573 if (TREE_CODE (ctor) == TEMPLATE_DECL)
02574 cand = add_template_candidate (&candidates, ctor, totype,
02575 NULL_TREE, args, NULL_TREE,
02576 TYPE_BINFO (totype),
02577 TYPE_BINFO (totype),
02578 flags,
02579 DEDUCE_CALL);
02580 else
02581 cand = add_function_candidate (&candidates, ctor, totype,
02582 args, TYPE_BINFO (totype),
02583 TYPE_BINFO (totype),
02584 flags);
02585
02586 if (cand)
02587 cand->second_conv = build_identity_conv (totype, NULL_TREE);
02588 }
02589
02590 if (conv_fns)
02591 args = build_tree_list (NULL_TREE, build_this (expr));
02592
02593 for (; conv_fns; conv_fns = TREE_CHAIN (conv_fns))
02594 {
02595 tree fns;
02596 tree conversion_path = TREE_PURPOSE (conv_fns);
02597 int convflags = LOOKUP_NO_CONVERSION;
02598
02599
02600
02601
02602
02603 if (TREE_CODE (totype) == REFERENCE_TYPE)
02604 convflags |= LOOKUP_NO_TEMP_BIND;
02605
02606 for (fns = TREE_VALUE (conv_fns); fns; fns = OVL_NEXT (fns))
02607 {
02608 tree fn = OVL_CURRENT (fns);
02609
02610
02611
02612
02613
02614
02615
02616
02617 if (TREE_CODE (fn) == TEMPLATE_DECL)
02618 cand = add_template_candidate (&candidates, fn, fromtype,
02619 NULL_TREE,
02620 args, totype,
02621 TYPE_BINFO (fromtype),
02622 conversion_path,
02623 flags,
02624 DEDUCE_CONV);
02625 else
02626 cand = add_function_candidate (&candidates, fn, fromtype,
02627 args,
02628 TYPE_BINFO (fromtype),
02629 conversion_path,
02630 flags);
02631
02632 if (cand)
02633 {
02634 conversion *ics
02635 = implicit_conversion (totype,
02636 TREE_TYPE (TREE_TYPE (cand->fn)),
02637 0,
02638 false, convflags);
02639
02640 cand->second_conv = ics;
02641
02642 if (!ics)
02643 cand->viable = 0;
02644 else if (candidates->viable == 1 && ics->bad_p)
02645 cand->viable = -1;
02646 }
02647 }
02648 }
02649
02650 candidates = splice_viable (candidates, pedantic, &any_viable_p);
02651 if (!any_viable_p)
02652 return NULL;
02653
02654 cand = tourney (candidates);
02655 if (cand == 0)
02656 {
02657 if (flags & LOOKUP_COMPLAIN)
02658 {
02659 error ("conversion from %qT to %qT is ambiguous",
02660 fromtype, totype);
02661 print_z_candidates (candidates);
02662 }
02663
02664 cand = candidates;
02665 cand->second_conv = build_ambiguous_conv (totype, expr);
02666 cand->second_conv->user_conv_p = true;
02667 if (!any_strictly_viable (candidates))
02668 cand->second_conv->bad_p = true;
02669
02670
02671
02672
02673 return cand;
02674 }
02675
02676
02677 conv = build_conv
02678 (ck_user,
02679 (DECL_CONSTRUCTOR_P (cand->fn)
02680 ? totype : non_reference (TREE_TYPE (TREE_TYPE (cand->fn)))),
02681 build_identity_conv (TREE_TYPE (expr), expr));
02682 conv->cand = cand;
02683
02684
02685 cand->second_conv = merge_conversion_sequences (conv,
02686 cand->second_conv);
02687
02688 if (cand->viable == -1)
02689 cand->second_conv->bad_p = true;
02690
02691 return cand;
02692 }
02693
02694 tree
02695 build_user_type_conversion (tree totype, tree expr, int flags)
02696 {
02697 struct z_candidate *cand
02698 = build_user_type_conversion_1 (totype, expr, flags);
02699
02700 if (cand)
02701 {
02702 if (cand->second_conv->kind == ck_ambig)
02703 return error_mark_node;
02704 expr = convert_like (cand->second_conv, expr);
02705 return convert_from_reference (expr);
02706 }
02707 return NULL_TREE;
02708 }
02709
02710
02711
02712 static tree
02713 resolve_args (tree args)
02714 {
02715 tree t;
02716 for (t = args; t; t = TREE_CHAIN (t))
02717 {
02718 tree arg = TREE_VALUE (t);
02719
02720 if (error_operand_p (arg))
02721 return error_mark_node;
02722 else if (VOID_TYPE_P (TREE_TYPE (arg)))
02723 {
02724 error ("invalid use of void expression");
02725 return error_mark_node;
02726 }
02727 else if (invalid_nonstatic_memfn_p (arg))
02728 return error_mark_node;
02729 }
02730 return args;
02731 }
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745 static struct z_candidate *
02746 perform_overload_resolution (tree fn,
02747 tree args,
02748 struct z_candidate **candidates,
02749 bool *any_viable_p)
02750 {
02751 struct z_candidate *cand;
02752 tree explicit_targs = NULL_TREE;
02753 int template_only = 0;
02754
02755 *candidates = NULL;
02756 *any_viable_p = true;
02757
02758
02759 gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
02760 || TREE_CODE (fn) == TEMPLATE_DECL
02761 || TREE_CODE (fn) == OVERLOAD
02762 || TREE_CODE (fn) == TEMPLATE_ID_EXPR);
02763 gcc_assert (!args || TREE_CODE (args) == TREE_LIST);
02764
02765 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
02766 {
02767 explicit_targs = TREE_OPERAND (fn, 1);
02768 fn = TREE_OPERAND (fn, 0);
02769 template_only = 1;
02770 }
02771
02772
02773 add_candidates (fn, args, explicit_targs, template_only,
02774 NULL_TREE,
02775 NULL_TREE,
02776 LOOKUP_NORMAL,
02777 candidates);
02778
02779 *candidates = splice_viable (*candidates, pedantic, any_viable_p);
02780 if (!*any_viable_p)
02781 return NULL;
02782
02783 cand = tourney (*candidates);
02784 return cand;
02785 }
02786
02787
02788
02789
02790 tree
02791 build_new_function_call (tree fn, tree args, bool koenig_p)
02792 {
02793 struct z_candidate *candidates, *cand;
02794 bool any_viable_p;
02795 void *p;
02796 tree result;
02797
02798 args = resolve_args (args);
02799 if (args == error_mark_node)
02800 return error_mark_node;
02801
02802
02803
02804
02805 if (!koenig_p)
02806 {
02807 tree orig_fn = fn;
02808
02809 fn = remove_hidden_names (fn);
02810 if (!fn)
02811 {
02812 error ("no matching function for call to %<%D(%A)%>",
02813 DECL_NAME (OVL_CURRENT (orig_fn)), args);
02814 return error_mark_node;
02815 }
02816 }
02817
02818
02819 p = conversion_obstack_alloc (0);
02820
02821 cand = perform_overload_resolution (fn, args, &candidates, &any_viable_p);
02822
02823 if (!cand)
02824 {
02825 if (!any_viable_p && candidates && ! candidates->next)
02826 return build_function_call (candidates->fn, args);
02827 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
02828 fn = TREE_OPERAND (fn, 0);
02829 if (!any_viable_p)
02830 error ("no matching function for call to %<%D(%A)%>",
02831 DECL_NAME (OVL_CURRENT (fn)), args);
02832 else
02833 error ("call of overloaded %<%D(%A)%> is ambiguous",
02834 DECL_NAME (OVL_CURRENT (fn)), args);
02835 if (candidates)
02836 print_z_candidates (candidates);
02837 result = error_mark_node;
02838 }
02839 else
02840 result = build_over_call (cand, LOOKUP_NORMAL);
02841
02842
02843 obstack_free (&conversion_obstack, p);
02844
02845 return result;
02846 }
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856
02857 tree
02858 build_operator_new_call (tree fnname, tree args,
02859 tree *size, tree *cookie_size,
02860 tree *fn)
02861 {
02862 tree fns;
02863 struct z_candidate *candidates;
02864 struct z_candidate *cand;
02865 bool any_viable_p;
02866
02867 if (fn)
02868 *fn = NULL_TREE;
02869 args = tree_cons (NULL_TREE, *size, args);
02870 args = resolve_args (args);
02871 if (args == error_mark_node)
02872 return args;
02873
02874
02875
02876
02877
02878
02879
02880
02881
02882
02883 fns = lookup_function_nonclass (fnname, args, false);
02884
02885
02886 cand = perform_overload_resolution (fns, args, &candidates, &any_viable_p);
02887
02888
02889
02890 if (!cand)
02891 {
02892 if (!any_viable_p)
02893 error ("no matching function for call to %<%D(%A)%>",
02894 DECL_NAME (OVL_CURRENT (fns)), args);
02895 else
02896 error ("call of overloaded %<%D(%A)%> is ambiguous",
02897 DECL_NAME (OVL_CURRENT (fns)), args);
02898 if (candidates)
02899 print_z_candidates (candidates);
02900 return error_mark_node;
02901 }
02902
02903
02904
02905
02906 if (*cookie_size)
02907 {
02908 bool use_cookie = true;
02909 if (!abi_version_at_least (2))
02910 {
02911 tree placement = TREE_CHAIN (args);
02912
02913
02914
02915 if (placement && !TREE_CHAIN (placement)
02916 && same_type_p (TREE_TYPE (TREE_VALUE (placement)),
02917 ptr_type_node))
02918 use_cookie = false;
02919 }
02920 else
02921 {
02922 tree arg_types;
02923
02924 arg_types = TYPE_ARG_TYPES (TREE_TYPE (cand->fn));
02925
02926 arg_types = TREE_CHAIN (arg_types);
02927
02928 if (arg_types
02929 && TREE_CHAIN (arg_types) == void_list_node
02930 && same_type_p (TREE_VALUE (arg_types),
02931 ptr_type_node))
02932 use_cookie = false;
02933 }
02934
02935 if (use_cookie)
02936 {
02937
02938 *size = size_binop (PLUS_EXPR, *size, *cookie_size);
02939
02940 TREE_VALUE (args) = *size;
02941 }
02942 else
02943 *cookie_size = NULL_TREE;
02944 }
02945
02946
02947 if (fn)
02948 *fn = cand->fn;
02949
02950
02951 return build_over_call (cand, LOOKUP_NORMAL);
02952 }
02953
02954 static tree
02955 build_object_call (tree obj, tree args)
02956 {
02957 struct z_candidate *candidates = 0, *cand;
02958 tree fns, convs, mem_args = NULL_TREE;
02959 tree type = TREE_TYPE (obj);
02960 bool any_viable_p;
02961 tree result = NULL_TREE;
02962 void *p;
02963
02964 if (TYPE_PTRMEMFUNC_P (type))
02965 {
02966
02967
02968 error ("pointer-to-member function %E cannot be called without an object; consider using .* or ->*", obj);
02969 return error_mark_node;
02970 }
02971
02972 if (TYPE_BINFO (type))
02973 {
02974 fns = lookup_fnfields (TYPE_BINFO (type), ansi_opname (CALL_EXPR), 1);
02975 if (fns == error_mark_node)
02976 return error_mark_node;
02977 }
02978 else
02979 fns = NULL_TREE;
02980
02981 args = resolve_args (args);
02982
02983 if (args == error_mark_node)
02984 return error_mark_node;
02985
02986
02987 p = conversion_obstack_alloc (0);
02988
02989 if (fns)
02990 {
02991 tree base = BINFO_TYPE (BASELINK_BINFO (fns));
02992 mem_args = tree_cons (NULL_TREE, build_this (obj), args);
02993
02994 for (fns = BASELINK_FUNCTIONS (fns); fns; fns = OVL_NEXT (fns))
02995 {
02996 tree fn = OVL_CURRENT (fns);
02997 if (TREE_CODE (fn) == TEMPLATE_DECL)
02998 add_template_candidate (&candidates, fn, base, NULL_TREE,
02999 mem_args, NULL_TREE,
03000 TYPE_BINFO (type),
03001 TYPE_BINFO (type),
03002 LOOKUP_NORMAL, DEDUCE_CALL);
03003 else
03004 add_function_candidate
03005 (&candidates, fn, base, mem_args, TYPE_BINFO (type),
03006 TYPE_BINFO (type), LOOKUP_NORMAL);
03007 }
03008 }
03009
03010 convs = lookup_conversions (type);
03011
03012 for (; convs; convs = TREE_CHAIN (convs))
03013 {
03014 tree fns = TREE_VALUE (convs);
03015 tree totype = TREE_TYPE (TREE_TYPE (OVL_CURRENT (fns)));
03016
03017 if ((TREE_CODE (totype) == POINTER_TYPE
03018 && TREE_CODE (TREE_TYPE (totype)) == FUNCTION_TYPE)
03019 || (TREE_CODE (totype) == REFERENCE_TYPE
03020 && TREE_CODE (TREE_TYPE (totype)) == FUNCTION_TYPE)
03021 || (TREE_CODE (totype) == REFERENCE_TYPE
03022 && TREE_CODE (TREE_TYPE (totype)) == POINTER_TYPE
03023 && TREE_CODE (TREE_TYPE (TREE_TYPE (totype))) == FUNCTION_TYPE))
03024 for (; fns; fns = OVL_NEXT (fns))
03025 {
03026 tree fn = OVL_CURRENT (fns);
03027 if (TREE_CODE (fn) == TEMPLATE_DECL)
03028 add_template_conv_candidate
03029 (&candidates, fn, obj, args, totype,
03030 NULL_TREE,
03031 NULL_TREE);
03032 else
03033 add_conv_candidate (&candidates, fn, obj, args,
03034 NULL_TREE,
03035 NULL_TREE);
03036 }
03037 }
03038
03039 candidates = splice_viable (candidates, pedantic, &any_viable_p);
03040 if (!any_viable_p)
03041 {
03042 error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj), args);
03043 print_z_candidates (candidates);
03044 result = error_mark_node;
03045 }
03046 else
03047 {
03048 cand = tourney (candidates);
03049 if (cand == 0)
03050 {
03051 error ("call of %<(%T) (%A)%> is ambiguous", TREE_TYPE (obj), args);
03052 print_z_candidates (candidates);
03053 result = error_mark_node;
03054 }
03055
03056
03057
03058 else if (TREE_CODE (cand->fn) == FUNCTION_DECL
03059 && DECL_OVERLOADED_OPERATOR_P (cand->fn) == CALL_EXPR)
03060 result = build_over_call (cand, LOOKUP_NORMAL);
03061 else
03062 {
03063 obj = convert_like_with_context (cand->convs[0], obj, cand->fn, -1);
03064 obj = convert_from_reference (obj);
03065 result = build_function_call (obj, args);
03066 }
03067 }
03068
03069
03070 obstack_free (&conversion_obstack, p);
03071
03072 return result;
03073 }
03074
03075 static void
03076 op_error (enum tree_code code, enum tree_code code2,
03077 tree arg1, tree arg2, tree arg3, const char *problem)
03078 {
03079 const char *opname;
03080
03081 if (code == MODIFY_EXPR)
03082 opname = assignment_operator_name_info[code2].name;
03083 else
03084 opname = operator_name_info[code].name;
03085
03086 switch (code)
03087 {
03088 case COND_EXPR:
03089 error ("%s for ternary %<operator?:%> in %<%E ? %E : %E%>",
03090 problem, arg1, arg2, arg3);
03091 break;
03092
03093 case POSTINCREMENT_EXPR:
03094 case POSTDECREMENT_EXPR:
03095 error ("%s for %<operator%s%> in %<%E%s%>", problem, opname, arg1, opname);
03096 break;
03097
03098 case ARRAY_REF:
03099 error ("%s for %<operator[]%> in %<%E[%E]%>", problem, arg1, arg2);
03100 break;
03101
03102 case REALPART_EXPR:
03103 case IMAGPART_EXPR:
03104 error ("%s for %qs in %<%s %E%>", problem, opname, opname, arg1);
03105 break;
03106
03107 default:
03108 if (arg2)
03109 error ("%s for %<operator%s%> in %<%E %s %E%>",
03110 problem, opname, arg1, opname, arg2);
03111 else
03112 error ("%s for %<operator%s%> in %<%s%E%>",
03113 problem, opname, opname, arg1);
03114 break;
03115 }
03116 }
03117
03118
03119
03120
03121 static conversion *
03122 conditional_conversion (tree e1, tree e2)
03123 {
03124 tree t1 = non_reference (TREE_TYPE (e1));
03125 tree t2 = non_reference (TREE_TYPE (e2));
03126 conversion *conv;
03127 bool good_base;
03128
03129
03130
03131
03132
03133
03134
03135 if (real_lvalue_p (e2))
03136 {
03137 conv = implicit_conversion (build_reference_type (t2),
03138 t1,
03139 e1,
03140 false,
03141 LOOKUP_NO_TEMP_BIND);
03142 if (conv)
03143 return conv;
03144 }
03145
03146
03147
03148
03149
03150
03151
03152
03153
03154
03155
03156 if (CLASS_TYPE_P (t1) && CLASS_TYPE_P (t2)
03157 && ((good_base = DERIVED_FROM_P (t2, t1)) || DERIVED_FROM_P (t1, t2)))
03158 {
03159 if (good_base && at_least_as_qualified_p (t2, t1))
03160 {
03161 conv = build_identity_conv (t1, e1);
03162 if (!same_type_p (TYPE_MAIN_VARIANT (t1),
03163 TYPE_MAIN_VARIANT (t2)))
03164 conv = build_conv (ck_base, t2, conv);
03165 else
03166 conv = build_conv (ck_rvalue, t2, conv);
03167 return conv;
03168 }
03169 else
03170 return NULL;
03171 }
03172 else
03173
03174
03175
03176
03177
03178 return implicit_conversion (t2, t1, e1, false,
03179 LOOKUP_NORMAL);
03180 }
03181
03182
03183
03184
03185 tree
03186 build_conditional_expr (tree arg1, tree arg2, tree arg3)
03187 {
03188 tree arg2_type;
03189 tree arg3_type;
03190 tree result = NULL_TREE;
03191 tree result_type = NULL_TREE;
03192 bool lvalue_p = true;
03193 struct z_candidate *candidates = 0;
03194 struct z_candidate *cand;
03195 void *p;
03196
03197
03198
03199
03200
03201 if (!arg2)
03202 {
03203 if (pedantic)
03204 pedwarn ("ISO C++ forbids omitting the middle term of a ?: expression");
03205
03206
03207 if (real_lvalue_p (arg1))
03208 arg2 = arg1 = stabilize_reference (arg1);
03209 else
03210 arg2 = arg1 = save_expr (arg1);
03211 }
03212
03213
03214
03215
03216
03217 arg1 = perform_implicit_conversion (boolean_type_node, arg1);
03218
03219
03220
03221 if (error_operand_p (arg1)
03222 || error_operand_p (arg2)
03223 || error_operand_p (arg3))
03224 return error_mark_node;
03225
03226
03227
03228
03229
03230
03231
03232
03233 arg2_type = unlowered_expr_type (arg2);
03234 arg3_type = unlowered_expr_type (arg3);
03235 if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type))
03236 {
03237
03238
03239
03240 if (!VOID_TYPE_P (arg2_type))
03241 arg2 = decay_conversion (arg2);
03242 if (!VOID_TYPE_P (arg3_type))
03243 arg3 = decay_conversion (arg3);
03244 arg2_type = TREE_TYPE (arg2);
03245 arg3_type = TREE_TYPE (arg3);
03246
03247
03248
03249
03250
03251
03252
03253
03254
03255
03256
03257
03258
03259
03260
03261 if (TREE_CODE (arg2) == THROW_EXPR
03262 && TREE_CODE (arg3) != THROW_EXPR)
03263 {
03264 if (!VOID_TYPE_P (arg3_type))
03265 arg3 = force_rvalue (arg3);
03266 arg3_type = TREE_TYPE (arg3);
03267 result_type = arg3_type;
03268 }
03269 else if (TREE_CODE (arg2) != THROW_EXPR
03270 && TREE_CODE (arg3) == THROW_EXPR)
03271 {
03272 if (!VOID_TYPE_P (arg2_type))
03273 arg2 = force_rvalue (arg2);
03274 arg2_type = TREE_TYPE (arg2);
03275 result_type = arg2_type;
03276 }
03277 else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
03278 result_type = void_type_node;
03279 else
03280 {
03281 error ("%qE has type %<void%> and is not a throw-expression",
03282 VOID_TYPE_P (arg2_type) ? arg2 : arg3);
03283 return error_mark_node;
03284 }
03285
03286 lvalue_p = false;
03287 goto valid_operands;
03288 }
03289
03290
03291
03292
03293
03294 else if (!same_type_p (arg2_type, arg3_type)
03295 && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
03296 {
03297 conversion *conv2;
03298 conversion *conv3;
03299
03300
03301 p = conversion_obstack_alloc (0);
03302
03303 conv2 = conditional_conversion (arg2, arg3);
03304 conv3 = conditional_conversion (arg3, arg2);
03305
03306
03307
03308
03309
03310
03311
03312
03313
03314
03315 if ((conv2 && !conv2->bad_p
03316 && conv3 && !conv3->bad_p)
03317 || (conv2 && conv2->kind == ck_ambig)
03318 || (conv3 && conv3->kind == ck_ambig))
03319 {
03320 error ("operands to ?: have different types %qT and %qT",
03321 arg2_type, arg3_type);
03322 result = error_mark_node;
03323 }
03324 else if (conv2 && (!conv2->bad_p || !conv3))
03325 {
03326 arg2 = convert_like (conv2, arg2);
03327 arg2 = convert_from_reference (arg2);
03328 arg2_type = TREE_TYPE (arg2);
03329
03330
03331
03332
03333
03334 if (error_operand_p (arg2))
03335 result = error_mark_node;
03336 }
03337 else if (conv3 && (!conv3->bad_p || !conv2))
03338 {
03339 arg3 = convert_like (conv3, arg3);
03340 arg3 = convert_from_reference (arg3);
03341 arg3_type = TREE_TYPE (arg3);
03342 if (error_operand_p (arg3))
03343 result = error_mark_node;
03344 }
03345
03346
03347 obstack_free (&conversion_obstack, p);
03348
03349 if (result)
03350 return result;
03351
03352
03353
03354
03355
03356
03357
03358
03359
03360
03361
03362
03363
03364
03365
03366
03367 if ((conv2 || conv3)
03368 && CLASS_TYPE_P (arg2_type)
03369 && TYPE_QUALS (arg2_type) != TYPE_QUALS (arg3_type))
03370 arg2_type = arg3_type =
03371 cp_build_qualified_type (arg2_type,
03372 TYPE_QUALS (arg2_type)
03373 | TYPE_QUALS (arg3_type));
03374 }
03375
03376
03377
03378
03379
03380 if (real_lvalue_p (arg2)
03381 && real_lvalue_p (arg3)
03382 && same_type_p (arg2_type, arg3_type))
03383 {
03384 result_type = arg2_type;
03385 goto valid_operands;
03386 }
03387
03388
03389
03390
03391
03392
03393
03394
03395 lvalue_p = false;
03396 if (!same_type_p (arg2_type, arg3_type)
03397 && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
03398 {
03399 tree args[3];
03400 conversion *conv;
03401 bool any_viable_p;
03402
03403
03404
03405
03406 args[0] = arg2;
03407 args[1] = arg3;
03408 args[2] = arg1;
03409 add_builtin_candidates (&candidates,
03410 COND_EXPR,
03411 NOP_EXPR,
03412 ansi_opname (COND_EXPR),
03413 args,
03414 LOOKUP_NORMAL);
03415
03416
03417
03418
03419
03420 candidates = splice_viable (candidates, pedantic, &any_viable_p);
03421 if (!any_viable_p)
03422 {
03423 op_error (COND_EXPR, NOP_EXPR, arg1, arg2, arg3, "no match");
03424 print_z_candidates (candidates);
03425 return error_mark_node;
03426 }
03427 cand = tourney (candidates);
03428 if (!cand)
03429 {
03430 op_error (COND_EXPR, NOP_EXPR, arg1, arg2, arg3, "no match");
03431 print_z_candidates (candidates);
03432 return error_mark_node;
03433 }
03434
03435
03436
03437
03438
03439
03440 conv = cand->convs[0];
03441 arg1 = convert_like (conv, arg1);
03442 conv = cand->convs[1];
03443 arg2 = convert_like (conv, arg2);
03444 conv = cand->convs[2];
03445 arg3 = convert_like (conv, arg3);
03446 }
03447
03448
03449
03450
03451
03452
03453
03454
03455
03456
03457
03458
03459 arg2 = force_rvalue (arg2);
03460 if (!CLASS_TYPE_P (arg2_type))
03461 arg2_type = TREE_TYPE (arg2);
03462
03463 arg3 = force_rvalue (arg3);
03464 if (!CLASS_TYPE_P (arg2_type))
03465 arg3_type = TREE_TYPE (arg3);
03466
03467 if (arg2 == error_mark_node || arg3 == error_mark_node)
03468 return error_mark_node;
03469
03470
03471
03472
03473
03474
03475
03476 if (same_type_p (arg2_type, arg3_type))
03477 result_type = arg2_type;
03478
03479
03480
03481
03482
03483 else if ((ARITHMETIC_TYPE_P (arg2_type)
03484 || TREE_CODE (arg2_type) == ENUMERAL_TYPE)
03485 && (ARITHMETIC_TYPE_P (arg3_type)
03486 || TREE_CODE (arg3_type) == ENUMERAL_TYPE))
03487 {
03488
03489 result_type = type_after_usual_arithmetic_conversions (arg2_type,
03490 arg3_type);
03491
03492 if (TREE_CODE (arg2_type) == ENUMERAL_TYPE
03493 && TREE_CODE (arg3_type) == ENUMERAL_TYPE)
03494 warning (0, "enumeral mismatch in conditional expression: %qT vs %qT",
03495 arg2_type, arg3_type);
03496 else if (extra_warnings
03497 && ((TREE_CODE (arg2_type) == ENUMERAL_TYPE
03498 && !same_type_p (arg3_type, type_promotes_to (arg2_type)))
03499 || (TREE_CODE (arg3_type) == ENUMERAL_TYPE
03500 && !same_type_p (arg2_type, type_promotes_to (arg3_type)))))
03501 warning (0, "enumeral and non-enumeral type in conditional expression");
03502
03503 arg2 = perform_implicit_conversion (result_type, arg2);
03504 arg3 = perform_implicit_conversion (result_type, arg3);
03505 }
03506
03507
03508
03509
03510
03511
03512
03513
03514
03515
03516
03517
03518
03519
03520
03521
03522 else if ((null_ptr_cst_p (arg2)
03523 && (TYPE_PTR_P (arg3_type) || TYPE_PTR_TO_MEMBER_P (arg3_type)))
03524 || (null_ptr_cst_p (arg3)
03525 && (TYPE_PTR_P (arg2_type) || TYPE_PTR_TO_MEMBER_P (arg2_type)))
03526 || (TYPE_PTR_P (arg2_type) && TYPE_PTR_P (arg3_type))
03527 || (TYPE_PTRMEM_P (arg2_type) && TYPE_PTRMEM_P (arg3_type))
03528 || (TYPE_PTRMEMFUNC_P (arg2_type) && TYPE_PTRMEMFUNC_P (arg3_type)))
03529 {
03530 result_type = composite_pointer_type (arg2_type, arg3_type, arg2,
03531 arg3, "conditional expression");
03532 if (result_type == error_mark_node)
03533 return error_mark_node;
03534 arg2 = perform_implicit_conversion (result_type, arg2);
03535 arg3 = perform_implicit_conversion (result_type, arg3);
03536 }
03537
03538 if (!result_type)
03539 {
03540 error ("operands to ?: have different types %qT and %qT",
03541 arg2_type, arg3_type);
03542 return error_mark_node;
03543 }
03544
03545 valid_operands:
03546 result = fold_if_not_in_template (build3 (COND_EXPR, result_type, arg1,
03547 arg2, arg3));
03548
03549
03550
03551 if (!lvalue_p)
03552 {
03553
03554
03555
03556
03557 if (CLASS_TYPE_P (TREE_TYPE (result)))
03558 result = get_target_expr (result);
03559
03560
03561 result = rvalue (result);
03562 }
03563
03564 return result;
03565 }
03566
03567
03568
03569
03570
03571 static tree
03572 prep_operand (tree operand)
03573 {
03574 if (operand)
03575 {
03576 if (CLASS_TYPE_P (TREE_TYPE (operand))
03577 && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (operand)))
03578
03579 instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (operand)));
03580 }
03581
03582 return operand;
03583 }
03584
03585
03586
03587
03588
03589
03590
03591
03592
03593 static void
03594 add_candidates (tree fns, tree args,
03595 tree explicit_targs, bool template_only,
03596 tree conversion_path, tree access_path,
03597 int flags,
03598 struct z_candidate **candidates)
03599 {
03600 tree ctype;
03601 tree non_static_args;
03602
03603 ctype = conversion_path ? BINFO_TYPE (conversion_path) : NULL_TREE;
03604
03605 non_static_args = NULL_TREE;
03606
03607 while (fns)
03608 {
03609 tree fn;
03610 tree fn_args;
03611
03612 fn = OVL_CURRENT (fns);
03613
03614 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
03615 {
03616
03617
03618 if (!non_static_args)
03619 non_static_args = tree_cons (NULL_TREE,
03620 build_this (TREE_VALUE (args)),
03621 TREE_CHAIN (args));
03622 fn_args = non_static_args;
03623 }
03624 else
03625
03626 fn_args = args;
03627
03628 if (TREE_CODE (fn) == TEMPLATE_DECL)
03629 add_template_candidate (candidates,
03630 fn,
03631 ctype,
03632 explicit_targs,
03633 fn_args,
03634 NULL_TREE,
03635 access_path,
03636 conversion_path,
03637 flags,
03638 DEDUCE_CALL);
03639 else if (!template_only)
03640 add_function_candidate (candidates,
03641 fn,
03642 ctype,
03643 fn_args,
03644 access_path,
03645 conversion_path,
03646 flags);
03647 fns = OVL_NEXT (fns);
03648 }
03649 }
03650
03651 tree
03652 build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3,
03653 bool *overloaded_p)
03654 {
03655 struct z_candidate *candidates = 0, *cand;
03656 tree arglist, fnname;
03657 tree args[3];
03658 tree result = NULL_TREE;
03659 bool result_valid_p = false;
03660 enum tree_code code2 = NOP_EXPR;
03661 conversion *conv;
03662 void *p;
03663 bool strict_p;
03664 bool any_viable_p;
03665
03666 if (error_operand_p (arg1)
03667 || error_operand_p (arg2)
03668 || error_operand_p (arg3))
03669 return error_mark_node;
03670
03671 if (code == MODIFY_EXPR)
03672 {
03673 code2 = TREE_CODE (arg3);
03674 arg3 = NULL_TREE;
03675 fnname = ansi_assopname (code2);
03676 }
03677 else
03678 fnname = ansi_opname (code);
03679
03680 arg1 = prep_operand (arg1);
03681
03682 switch (code)
03683 {
03684 case NEW_EXPR:
03685 case VEC_NEW_EXPR:
03686 case VEC_DELETE_EXPR:
03687 case DELETE_EXPR:
03688
03689 gcc_unreachable ();
03690
03691 case CALL_EXPR:
03692 return build_object_call (arg1, arg2);
03693
03694 default:
03695 break;
03696 }
03697
03698 arg2 = prep_operand (arg2);
03699 arg3 = prep_operand (arg3);
03700
03701 if (code == COND_EXPR)
03702 {
03703 if (arg2 == NULL_TREE
03704 || TREE_CODE (TREE_TYPE (arg2)) == VOID_TYPE
03705 || TREE_CODE (TREE_TYPE (arg3)) == VOID_TYPE
03706 || (! IS_OVERLOAD_TYPE (TREE_TYPE (arg2))
03707 && ! IS_OVERLOAD_TYPE (TREE_TYPE (arg3))))
03708 goto builtin;
03709 }
03710 else if (! IS_OVERLOAD_TYPE (TREE_TYPE (arg1))
03711 && (! arg2 || ! IS_OVERLOAD_TYPE (TREE_TYPE (arg2))))
03712 goto builtin;
03713
03714 if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
03715 arg2 = integer_zero_node;
03716
03717 arglist = NULL_TREE;
03718 if (arg3)
03719 arglist = tree_cons (NULL_TREE, arg3, arglist);
03720 if (arg2)
03721 arglist = tree_cons (NULL_TREE, arg2, arglist);
03722 arglist = tree_cons (NULL_TREE, arg1, arglist);
03723
03724
03725 p = conversion_obstack_alloc (0);
03726
03727
03728
03729 add_candidates (lookup_function_nonclass (fnname, arglist, true),
03730 arglist, NULL_TREE, false, NULL_TREE, NULL_TREE,
03731 flags, &candidates);
03732
03733 if (CLASS_TYPE_P (TREE_TYPE (arg1)))
03734 {
03735 tree fns;
03736
03737 fns = lookup_fnfields (TREE_TYPE (arg1), fnname, 1);
03738 if (fns == error_mark_node)
03739 {
03740 result = error_mark_node;
03741 goto user_defined_result_ready;
03742 }
03743 if (fns)
03744 add_candidates (BASELINK_FUNCTIONS (fns), arglist,
03745 NULL_TREE, false,
03746 BASELINK_BINFO (fns),
03747 TYPE_BINFO (TREE_TYPE (arg1)),
03748 flags, &candidates);
03749 }
03750
03751
03752
03753
03754
03755 if (code == COND_EXPR)
03756 {
03757 args[0] = arg2;
03758 args[1] = arg3;
03759 args[2] = arg1;
03760 }
03761 else
03762 {
03763 args[0] = arg1;
03764 args[1] = arg2;
03765 args[2] = NULL_TREE;
03766 }
03767
03768 add_builtin_candidates (&candidates, code, code2, fnname, args, flags);
03769
03770 switch (code)
03771 {
03772 case COMPOUND_EXPR:
03773 case ADDR_EXPR:
03774
03775
03776
03777
03778
03779
03780 strict_p = true;
03781 break;
03782
03783 default:
03784 strict_p = pedantic;
03785 break;
03786 }
03787
03788 candidates = splice_viable (candidates, strict_p, &any_viable_p);
03789 if (!any_viable_p)
03790 {
03791 switch (code)
03792 {
03793 case POSTINCREMENT_EXPR:
03794 case POSTDECREMENT_EXPR:
03795
03796
03797 if (flags & LOOKUP_COMPLAIN)
03798 pedwarn ("no %<%D(int)%> declared for postfix %qs, "
03799 "trying prefix operator instead",
03800 fnname,
03801 operator_name_info[code].name);
03802 if (code == POSTINCREMENT_EXPR)
03803 code = PREINCREMENT_EXPR;
03804 else
03805 code = PREDECREMENT_EXPR;
03806 result = build_new_op (code, flags, arg1, NULL_TREE, NULL_TREE,
03807 overloaded_p);
03808 break;
03809
03810
03811 case ADDR_EXPR:
03812 case COMPOUND_EXPR:
03813 case COMPONENT_REF:
03814 result = NULL_TREE;
03815 result_valid_p = true;
03816 break;
03817
03818 default:
03819 if (flags & LOOKUP_COMPLAIN)
03820 {
03821 op_error (code, code2, arg1, arg2, arg3, "no match");
03822 print_z_candidates (candidates);
03823 }
03824 result = error_mark_node;
03825 break;
03826 }
03827 }
03828 else
03829 {
03830 cand = tourney (candidates);
03831 if (cand == 0)
03832 {
03833 if (flags & LOOKUP_COMPLAIN)
03834 {
03835 op_error (code, code2, arg1, arg2, arg3, "ambiguous overload");
03836 print_z_candidates (candidates);
03837 }
03838 result = error_mark_node;
03839 }
03840 else if (TREE_CODE (cand->fn) == FUNCTION_DECL)
03841 {
03842 if (overloaded_p)
03843 *overloaded_p = true;
03844
03845 result = build_over_call (cand, LOOKUP_NORMAL);
03846 }
03847 else
03848 {
03849
03850 if (cand->warnings)
03851 {
03852 struct candidate_warning *w;
03853 for (w = cand->warnings; w; w = w->next)
03854 joust (cand, w->loser, 1);
03855 }
03856
03857
03858 switch (code)
03859 {
03860 case GT_EXPR:
03861 case LT_EXPR:
03862 case GE_EXPR:
03863 case LE_EXPR:
03864 case EQ_EXPR:
03865 case NE_EXPR:
03866 if (TREE_CODE (TREE_TYPE (arg1)) == ENUMERAL_TYPE
03867 && TREE_CODE (TREE_TYPE (arg2)) == ENUMERAL_TYPE
03868 && (TYPE_MAIN_VARIANT (TREE_TYPE (arg1))
03869 != TYPE_MAIN_VARIANT (TREE_TYPE (arg2))))
03870 {
03871 warning (0, "comparison between %q#T and %q#T",
03872 TREE_TYPE (arg1), TREE_TYPE (arg2));
03873 }
03874 break;
03875 default:
03876 break;
03877 }
03878
03879
03880
03881
03882
03883 conv = cand->convs[0];
03884 if (conv->kind == ck_ref_bind)
03885 conv = conv->u.next;
03886 arg1 = convert_like (conv, arg1);
03887 if (arg2)
03888 {
03889 conv = cand->convs[1];
03890 if (conv->kind == ck_ref_bind)
03891 conv = conv->u.next;
03892 arg2 = convert_like (conv, arg2);
03893 }
03894 if (arg3)
03895 {
03896 conv = cand->convs[2];
03897 if (conv->kind == ck_ref_bind)
03898 conv = conv->u.next;
03899 arg3 = convert_like (conv, arg3);
03900 }
03901 }
03902 }
03903
03904 user_defined_result_ready:
03905
03906
03907 obstack_free (&conversion_obstack, p);
03908
03909 if (result || result_valid_p)
03910 return result;
03911
03912 builtin:
03913 switch (code)
03914 {
03915 case MODIFY_EXPR:
03916 return build_modify_expr (arg1, code2, arg2);
03917
03918 case INDIRECT_REF:
03919 return build_indirect_ref (arg1, "unary *");
03920
03921 case PLUS_EXPR:
03922 case MINUS_EXPR:
03923 case MULT_EXPR:
03924 case TRUNC_DIV_EXPR:
03925 case GT_EXPR:
03926 case LT_EXPR:
03927 case GE_EXPR:
03928 case LE_EXPR:
03929 case EQ_EXPR:
03930 case NE_EXPR:
03931 case MAX_EXPR:
03932 case MIN_EXPR:
03933 case LSHIFT_EXPR:
03934 case RSHIFT_EXPR:
03935 case TRUNC_MOD_EXPR:
03936 case BIT_AND_EXPR:
03937 case BIT_IOR_EXPR:
03938 case BIT_XOR_EXPR:
03939 case TRUTH_ANDIF_EXPR:
03940 case TRUTH_ORIF_EXPR:
03941 return cp_build_binary_op (code, arg1, arg2);
03942
03943 case UNARY_PLUS_EXPR:
03944 case NEGATE_EXPR:
03945 case BIT_NOT_EXPR:
03946 case TRUTH_NOT_EXPR:
03947 case PREINCREMENT_EXPR:
03948 case POSTINCREMENT_EXPR:
03949 case PREDECREMENT_EXPR:
03950 case POSTDECREMENT_EXPR:
03951 case REALPART_EXPR:
03952 case IMAGPART_EXPR:
03953 return build_unary_op (code, arg1, candidates != 0);
03954
03955 case ARRAY_REF:
03956 return build_array_ref (arg1, arg2);
03957
03958 case COND_EXPR:
03959 return build_conditional_expr (arg1, arg2, arg3);
03960
03961 case MEMBER_REF:
03962 return build_m_component_ref (build_indirect_ref (arg1, NULL), arg2);
03963
03964
03965 case ADDR_EXPR:
03966 case COMPONENT_REF:
03967 case COMPOUND_EXPR:
03968 return NULL_TREE;
03969
03970 default:
03971 gcc_unreachable ();
03972 }
03973 return NULL_TREE;
03974 }
03975
03976
03977
03978
03979
03980
03981
03982
03983
03984
03985
03986
03987
03988
03989
03990
03991 tree
03992 build_op_delete_call (enum tree_code code, tree addr, tree size,
03993 bool global_p, tree placement,
03994 tree alloc_fn)
03995 {
03996 tree fn = NULL_TREE;
03997 tree fns, fnname, argtypes, args, type;
03998 int pass;
03999
04000 if (addr == error_mark_node)
04001 return error_mark_node;
04002
04003 type = strip_array_types (TREE_TYPE (TREE_TYPE (addr)));
04004
04005 fnname = ansi_opname (code);
04006
04007 if (CLASS_TYPE_P (type)
04008 && COMPLETE_TYPE_P (complete_type (type))
04009 && !global_p)
04010
04011
04012
04013
04014
04015
04016
04017 {
04018 fns = lookup_fnfields (TYPE_BINFO (type), fnname, 1);
04019 if (fns == error_mark_node)
04020 return error_mark_node;
04021 }
04022 else
04023 fns = NULL_TREE;
04024
04025 if (fns == NULL_TREE)
04026 fns = lookup_name_nonclass (fnname);
04027
04028 if (placement)
04029 {
04030
04031
04032 gcc_assert (alloc_fn != NULL_TREE);
04033 argtypes = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (alloc_fn)));
04034
04035 args = TREE_CHAIN (TREE_OPERAND (placement, 1));
04036 }
04037 else
04038 {
04039
04040 argtypes = void_list_node;
04041 args = NULL_TREE;
04042 }
04043
04044
04045 addr = cp_convert (ptr_type_node, addr);
04046
04047
04048
04049
04050
04051 for (pass = 0; pass < (placement ? 1 : 2); ++pass)
04052 {
04053
04054
04055 for (fn = BASELINK_P (fns) ? BASELINK_FUNCTIONS (fns) : fns;
04056 fn;
04057 fn = OVL_NEXT (fn))
04058 {
04059 tree t;
04060
04061
04062 t = TYPE_ARG_TYPES (TREE_TYPE (OVL_CURRENT (fn)));
04063 if (!same_type_p (TREE_VALUE (t), ptr_type_node))
04064 continue;
04065 t = TREE_CHAIN (t);
04066
04067 if (pass == 0)
04068 {
04069 tree a = argtypes;
04070 while (a && t)
04071 {
04072 if (!same_type_p (TREE_VALUE (a), TREE_VALUE (t)))
04073 break;
04074 a = TREE_CHAIN (a);
04075 t = TREE_CHAIN (t);
04076 }
04077 if (!a && !t)
04078 break;
04079 }
04080
04081
04082 else if (pass == 1
04083 && same_type_p (TREE_VALUE (t), sizetype)
04084 && TREE_CHAIN (t) == void_list_node)
04085 break;
04086 }
04087
04088
04089 if (fn)
04090 break;
04091 }
04092
04093
04094 if (fn)
04095 {
04096
04097
04098 fn = OVL_CURRENT (fn);
04099
04100
04101
04102 if (DECL_CLASS_SCOPE_P (fn))
04103 perform_or_defer_access_check (TYPE_BINFO (type), fn, fn);
04104
04105 if (pass == 0)
04106 args = tree_cons (NULL_TREE, addr, args);
04107 else
04108 args = tree_cons (NULL_TREE, addr,
04109 build_tree_list (NULL_TREE, size));
04110
04111 if (placement)
04112 {
04113
04114
04115 mark_used (fn);
04116 return build_cxx_call (fn, args);
04117 }
04118 else
04119 return build_function_call (fn, args);
04120 }
04121
04122
04123
04124 if (placement)
04125 return NULL_TREE;
04126
04127 error ("no suitable %<operator %s%> for %qT",
04128 operator_name_info[(int)code].name, type);
04129 return error_mark_node;
04130 }
04131
04132
04133
04134
04135
04136
04137 bool
04138 enforce_access (tree basetype_path, tree decl, tree diag_decl)
04139 {
04140 gcc_assert (TREE_CODE (basetype_path) == TREE_BINFO);
04141
04142 if (!accessible_p (basetype_path, decl, true))
04143 {
04144 if (TREE_PRIVATE (decl))
04145 error ("%q+#D is private", diag_decl);
04146 else if (TREE_PROTECTED (decl))
04147 error ("%q+#D is protected", diag_decl);
04148 else
04149 error ("%q+#D is inaccessible", diag_decl);
04150 error ("within this context");
04151 return false;
04152 }
04153
04154 return true;
04155 }
04156
04157
04158
04159
04160 static void
04161 check_constructor_callable (tree type, tree expr)
04162 {
04163 build_special_member_call (NULL_TREE,
04164 complete_ctor_identifier,
04165 build_tree_list (NULL_TREE, expr),
04166 type,
04167 LOOKUP_NORMAL | LOOKUP_ONLYCONVERTING
04168 | LOOKUP_NO_CONVERSION
04169 | LOOKUP_CONSTRUCTOR_CALLABLE);
04170 }
04171
04172
04173
04174
04175
04176
04177
04178 static tree
04179 build_temp (tree expr, tree type, int flags,
04180 diagnostic_fn_t *diagnostic_fn)
04181 {
04182 int savew, savee;
04183
04184 savew = warningcount, savee = errorcount;
04185 expr = build_special_member_call (NULL_TREE,
04186 complete_ctor_identifier,
04187 build_tree_list (NULL_TREE, expr),
04188 type, flags);
04189 if (warningcount > savew)
04190 *diagnostic_fn = warning0;
04191 else if (errorcount > savee)
04192 *diagnostic_fn = error;
04193 else
04194 *diagnostic_fn = NULL;
04195 return expr;
04196 }
04197
04198
04199
04200
04201
04202
04203
04204
04205
04206
04207
04208
04209 static tree
04210 convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
04211 int inner, bool issue_conversion_warnings,
04212 bool c_cast_p)
04213 {
04214 tree totype = convs->type;
04215 diagnostic_fn_t diagnostic_fn;
04216
04217 if (convs->bad_p
04218 && convs->kind != ck_user
04219 && convs->kind != ck_ambig
04220 && convs->kind != ck_ref_bind)
04221 {
04222 conversion *t = convs;
04223 for (; t; t = convs->u.next)
04224 {
04225 if (t->kind == ck_user || !t->bad_p)
04226 {
04227 expr = convert_like_real (t, expr, fn, argnum, 1,
04228 false,
04229 false);
04230 break;
04231 }
04232 else if (t->kind == ck_ambig)
04233 return convert_like_real (t, expr, fn, argnum, 1,
04234 false,
04235 false);
04236 else if (t->kind == ck_identity)
04237 break;
04238 }
04239 pedwarn ("invalid conversion from %qT to %qT", TREE_TYPE (expr), totype);
04240 if (fn)
04241 pedwarn (" initializing argument %P of %qD", argnum, fn);
04242 return cp_convert (totype, expr);
04243 }
04244
04245 if (issue_conversion_warnings)
04246 {
04247 tree t = non_reference (totype);
04248
04249
04250 if (ARITHMETIC_TYPE_P (t) && expr == null_node)
04251 {
04252 if (fn)
04253 warning (OPT_Wconversion, "passing NULL to non-pointer argument %P of %qD",
04254 argnum, fn);
04255 else
04256 warning (OPT_Wconversion, "converting to non-pointer type %qT from NULL", t);
04257 }
04258
04259
04260 if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
04261 && TREE_CODE (t) == INTEGER_TYPE)
04262 {
04263 if (fn)
04264 warning (OPT_Wconversion, "passing %qT for argument %P to %qD",
04265 TREE_TYPE (expr), argnum, fn);
04266 else
04267 warning (OPT_Wconversion, "converting to %qT from %qT", t, TREE_TYPE (expr));
04268 }
04269 }
04270
04271 switch (convs->kind)
04272 {
04273 case ck_user:
04274 {
04275 struct z_candidate *cand = convs->cand;
04276 tree convfn = cand->fn;
04277 tree args;
04278
04279 if (DECL_CONSTRUCTOR_P (convfn))
04280 {
04281 tree t = build_int_cst (build_pointer_type (DECL_CONTEXT (convfn)),
04282 0);
04283
04284 args = build_tree_list (NULL_TREE, expr);
04285
04286
04287 gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (convfn)
04288 && !DECL_HAS_VTT_PARM_P (convfn));
04289 args = tree_cons (NULL_TREE, t, args);
04290 }
04291 else
04292 args = build_this (expr);
04293 expr = build_over_call (cand, LOOKUP_NORMAL);
04294
04295
04296
04297 if (DECL_CONSTRUCTOR_P (convfn))
04298 expr = build_cplus_new (totype, expr);
04299
04300
04301
04302
04303
04304
04305
04306
04307
04308 if (IS_AGGR_TYPE (totype)
04309 && (inner >= 0 || !lvalue_p (expr)))
04310 {
04311 expr = (build_temp
04312 (expr, totype,
04313
04314
04315
04316
04317 LOOKUP_NORMAL|LOOKUP_ONLYCONVERTING|LOOKUP_NO_CONVERSION,
04318 &diagnostic_fn));
04319
04320 if (diagnostic_fn)
04321 {
04322 if (fn)
04323 diagnostic_fn
04324 (" initializing argument %P of %qD from result of %qD",
04325 argnum, fn, convfn);
04326 else
04327 diagnostic_fn
04328 (" initializing temporary from result of %qD", convfn);
04329 }
04330 expr = build_cplus_new (totype, expr);
04331 }
04332 return expr;
04333 }
04334 case ck_identity:
04335 if (type_unknown_p (expr))
04336 expr = instantiate_type (totype, expr, tf_warning_or_error);
04337
04338
04339
04340 if (inner >= 0)
04341 expr = decl_constant_value (expr);
04342 if (convs->check_copy_constructor_p)
04343 check_constructor_callable (totype, expr);
04344 return expr;
04345 case ck_ambig:
04346
04347 return build_user_type_conversion
04348 (totype, convs->u.expr, LOOKUP_NORMAL);
04349
04350 default:
04351 break;
04352 };
04353
04354 expr = convert_like_real (convs->u.next, expr, fn, argnum,
04355 convs->kind == ck_ref_bind ? -1 : 1,
04356 false,
04357 c_cast_p);
04358 if (expr == error_mark_node)
04359 return error_mark_node;
04360
04361 switch (convs->kind)
04362 {
04363 case ck_rvalue:
04364 expr = convert_bitfield_to_declared_type (expr);
04365 if (! IS_AGGR_TYPE (totype))
04366 return expr;
04367
04368 case ck_base:
04369 if (convs->kind == ck_base && !convs->need_temporary_p)
04370 {
04371
04372
04373 if (convs->check_copy_constructor_p)
04374 check_constructor_callable (TREE_TYPE (expr), expr);
04375
04376 expr = build_unary_op (ADDR_EXPR, expr, 0);
04377 expr = convert_to_base (expr, build_pointer_type (totype),
04378 !c_cast_p, true);
04379 expr = build_indirect_ref (expr, "implicit conversion");
04380 return expr;
04381 }
04382
04383
04384
04385
04386 expr = build_temp (expr, totype, LOOKUP_NORMAL|LOOKUP_ONLYCONVERTING,
04387 &diagnostic_fn);
04388 if (diagnostic_fn && fn)
04389 diagnostic_fn (" initializing argument %P of %qD", argnum, fn);
04390 return build_cplus_new (totype, expr);
04391
04392 case ck_ref_bind:
04393 {
04394 tree ref_type = totype;
04395
04396
04397 if (convs->need_temporary_p || !lvalue_p (expr))
04398 {
04399 tree type = convs->u.next->type;
04400 cp_lvalue_kind lvalue = real_lvalue_p (expr);
04401
04402 if (!CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (ref_type)))
04403 {
04404
04405
04406 if (lvalue & clk_bitfield)
04407 error ("cannot bind bitfield %qE to %qT",
04408 expr, ref_type);
04409 else if (lvalue & clk_packed)
04410 error ("cannot bind packed field %qE to %qT",
04411 expr, ref_type);
04412 else
04413 error ("cannot bind rvalue %qE to %qT", expr, ref_type);
04414 return error_mark_node;
04415 }
04416
04417
04418
04419
04420
04421
04422 if ((lvalue & clk_packed)
04423 && CLASS_TYPE_P (type)
04424 && !TYPE_HAS_TRIVIAL_INIT_REF (type))
04425 {
04426 error ("cannot bind packed field %qE to %qT",
04427 expr, ref_type);
04428 return error_mark_node;
04429 }
04430 expr = build_target_expr_with_type (expr, type);
04431 }
04432
04433
04434
04435 expr = build_unary_op (ADDR_EXPR, expr, 1);
04436 if (expr == error_mark_node)
04437 return error_mark_node;
04438
04439
04440
04441
04442 expr = cp_convert (build_pointer_type (TREE_TYPE (ref_type)),
04443 expr);
04444
04445 return build_nop (ref_type, expr);
04446 }
04447
04448 case ck_lvalue:
04449 return decay_conversion (expr);
04450
04451 case ck_qual:
04452
04453 string_conv_p (totype, expr, 1);
04454 break;
04455
04456 case ck_ptr:
04457 if (convs->base_p)
04458 expr = convert_to_base (expr, totype, !c_cast_p,
04459 false);
04460 return build_nop (totype, expr);
04461
04462 case ck_pmem:
04463 return convert_ptrmem (totype, expr, false,
04464 c_cast_p);
04465
04466 default:
04467 break;
04468 }
04469
04470 if (issue_conversion_warnings)
04471 expr = convert_and_check (totype, expr);
04472 else
04473 expr = convert (totype, expr);
04474
04475 return expr;
04476 }
04477
04478
04479
04480 static tree
04481 call_builtin_trap (void)
04482 {
04483 tree fn = implicit_built_in_decls[BUILT_IN_TRAP];
04484
04485 gcc_assert (fn != NULL);
04486 fn = build_call (fn, NULL_TREE);
04487 return fn;
04488 }
04489
04490
04491
04492
04493 tree
04494 convert_arg_to_ellipsis (tree arg)
04495 {
04496
04497
04498
04499
04500 arg = decay_conversion (arg);
04501
04502
04503
04504
04505
04506
04507
04508 if (TREE_CODE (TREE_TYPE (arg)) == REAL_TYPE
04509 && (TYPE_PRECISION (TREE_TYPE (arg))
04510 < TYPE_PRECISION (double_type_node)))
04511 arg = convert_to_real (double_type_node, arg);
04512 else if (INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (arg)))
04513 arg = perform_integral_promotions (arg);
04514
04515 arg = require_complete_type (arg);
04516
04517 if (arg != error_mark_node
04518 && !pod_type_p (TREE_TYPE (arg)))
04519 {
04520
04521
04522
04523
04524
04525
04526 if (!skip_evaluation)
04527 warning (0, "cannot pass objects of non-POD type %q#T through %<...%>; "
04528 "call will abort at runtime", TREE_TYPE (arg));
04529 arg = call_builtin_trap ();
04530 arg = build2 (COMPOUND_EXPR, integer_type_node, arg,
04531 integer_zero_node);
04532 }
04533
04534 return arg;
04535 }
04536
04537
04538
04539 tree
04540 build_x_va_arg (tree expr, tree type)
04541 {
04542 if (processing_template_decl)
04543 return build_min (VA_ARG_EXPR, type, expr);
04544
04545 type = complete_type_or_else (type, NULL_TREE);
04546
04547 if (expr == error_mark_node || !type)
04548 return error_mark_node;
04549
04550 if (! pod_type_p (type))
04551 {
04552
04553 tree type1 = non_reference (type);
04554
04555 warning (0, "cannot receive objects of non-POD type %q#T through %<...%>; "
04556 "call will abort at runtime", type);
04557 expr = convert (build_pointer_type (type1), null_node);
04558 expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr),
04559 call_builtin_trap (), expr);
04560 expr = build_indirect_ref (expr, NULL);
04561 return expr;
04562 }
04563
04564 return build_va_arg (expr, type);
04565 }
04566
04567
04568
04569
04570
04571 tree
04572 cxx_type_promotes_to (tree type)
04573 {
04574 tree promote;
04575
04576
04577
04578 type = type_decays_to (type);
04579
04580 promote = type_promotes_to (type);
04581 if (same_type_p (type, promote))
04582 promote = type;
04583
04584 return promote;
04585 }
04586
04587
04588
04589
04590
04591 tree
04592 convert_default_arg (tree type, tree arg, tree fn, int parmnum)
04593 {
04594
04595
04596 if (TREE_CODE (arg) == DEFAULT_ARG)
04597 {
04598 error ("the default argument for parameter %d of %qD has "
04599 "not yet been parsed",
04600 parmnum, fn);
04601 return error_mark_node;
04602 }
04603
04604 if (fn && DECL_TEMPLATE_INFO (fn))
04605 arg = tsubst_default_argument (fn, type, arg);
04606
04607 arg = break_out_target_exprs (arg);
04608
04609 if (TREE_CODE (arg) == CONSTRUCTOR)
04610 {
04611 arg = digest_init (type, arg);
04612 arg = convert_for_initialization (0, type, arg, LOOKUP_NORMAL,
04613 "default argument", fn, parmnum);
04614 }
04615 else
04616 {
04617
04618
04619
04620
04621
04622
04623 if (!CONSTANT_CLASS_P (arg))
04624 arg = unshare_expr (arg);
04625 arg = convert_for_initialization (0, type, arg, LOOKUP_NORMAL,
04626 "default argument", fn, parmnum);
04627 arg = convert_for_arg_passing (type, arg);
04628 }
04629
04630 return arg;
04631 }
04632
04633
04634
04635
04636 tree
04637 type_passed_as (tree type)
04638 {
04639
04640 if (TREE_ADDRESSABLE (type))
04641 {
04642 type = build_reference_type (type);
04643
04644 type = build_qualified_type (type, TYPE_QUAL_RESTRICT);
04645 }
04646 else if (targetm.calls.promote_prototypes (type)
04647 && INTEGRAL_TYPE_P (type)
04648 && COMPLETE_TYPE_P (type)
04649 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type),
04650 TYPE_SIZE (integer_type_node)))
04651 type = integer_type_node;
04652
04653 return type;
04654 }
04655
04656
04657
04658 tree
04659 convert_for_arg_passing (tree type, tree val)
04660 {
04661 val = convert_bitfield_to_declared_type (val);
04662 if (val == error_mark_node)
04663 ;
04664
04665 else if (TREE_ADDRESSABLE (type))
04666 val = build1 (ADDR_EXPR, build_reference_type (type), val);
04667 else if (targetm.calls.promote_prototypes (type)
04668 && INTEGRAL_TYPE_P (type)
04669 && COMPLETE_TYPE_P (type)
04670 && INT_CST_LT_UNSIGNED (TYPE_SIZE (type),
04671 TYPE_SIZE (integer_type_node)))
04672 val = perform_integral_promotions (val);
04673 if (warn_missing_format_attribute)
04674 {
04675 tree rhstype = TREE_TYPE (val);
04676 const enum tree_code coder = TREE_CODE (rhstype);
04677 const enum tree_code codel = TREE_CODE (type);
04678 if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
04679 && coder == codel
04680 && check_missing_format_attribute (type, rhstype))
04681 warning (OPT_Wmissing_format_attribute,
04682 "argument of function call might be a candidate for a format attribute");
04683 }
04684 return val;
04685 }
04686
04687
04688
04689
04690
04691 static bool
04692 magic_varargs_p (tree fn)
04693 {
04694 if (DECL_BUILT_IN (fn))
04695 switch (DECL_FUNCTION_CODE (fn))
04696 {
04697 case BUILT_IN_CLASSIFY_TYPE:
04698 case BUILT_IN_CONSTANT_P:
04699 case BUILT_IN_NEXT_ARG:
04700 case BUILT_IN_STDARG_START:
04701 case BUILT_IN_VA_START:
04702 return true;
04703
04704 default:;
04705 }
04706
04707 return false;
04708 }
04709
04710
04711
04712
04713
04714
04715 static tree
04716 build_over_call (struct z_candidate *cand, int flags)
04717 {
04718 tree fn = cand->fn;
04719 tree args = cand->args;
04720 conversion **convs = cand->convs;
04721 conversion *conv;
04722 tree converted_args = NULL_TREE;
04723 tree parm = TYPE_ARG_TYPES (TREE_TYPE (fn));
04724 tree arg, val;
04725 int i = 0;
04726 int is_method = 0;
04727
04728
04729
04730
04731
04732 if (processing_template_decl)
04733 {
04734 tree expr;
04735 tree return_type;
04736 return_type = TREE_TYPE (TREE_TYPE (fn));
04737 expr = build3 (CALL_EXPR, return_type, fn, args, NULL_TREE);
04738 if (TREE_THIS_VOLATILE (fn) && cfun)
04739 current_function_returns_abnormally = 1;
04740 if (!VOID_TYPE_P (return_type))
04741 require_complete_type (return_type);
04742 return convert_from_reference (expr);
04743 }
04744
04745
04746 if (cand->warnings)
04747 {
04748 struct candidate_warning *w;
04749 for (w = cand->warnings; w; w = w->next)
04750 joust (cand, w->loser, 1);
04751 }
04752
04753 if (DECL_FUNCTION_MEMBER_P (fn))
04754 {
04755
04756
04757
04758
04759
04760
04761
04762
04763
04764
04765
04766
04767
04768
04769
04770
04771
04772
04773
04774
04775
04776
04777
04778
04779
04780 if (DECL_TEMPLATE_INFO (fn)
04781 && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (fn)))
04782 perform_or_defer_access_check (cand->access_path,
04783 DECL_TI_TEMPLATE (fn), fn);
04784 else
04785 perform_or_defer_access_check (cand->access_path, fn, fn);
04786 }
04787
04788 if (args && TREE_CODE (args) != TREE_LIST)
04789 args = build_tree_list (NULL_TREE, args);
04790 arg = args;
04791
04792
04793
04794 if (DECL_CONSTRUCTOR_P (fn))
04795 {
04796 converted_args = tree_cons (NULL_TREE, TREE_VALUE (arg), converted_args);
04797 arg = TREE_CHAIN (arg);
04798 parm = TREE_CHAIN (parm);
04799
04800 gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (fn));
04801
04802 if (DECL_HAS_VTT_PARM_P (fn))
04803 {
04804 converted_args = tree_cons
04805 (NULL_TREE, TREE_VALUE (arg), converted_args);
04806 arg = TREE_CHAIN (arg);
04807 parm = TREE_CHAIN (parm);
04808 }
04809 }
04810
04811 else if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
04812 {
04813 tree parmtype = TREE_VALUE (parm);
04814 tree argtype = TREE_TYPE (TREE_VALUE (arg));
04815 tree converted_arg;
04816 tree base_binfo;
04817
04818 if (convs[i]->bad_p)
04819 pedwarn ("passing %qT as %<this%> argument of %q#D discards qualifiers",
04820 TREE_TYPE (argtype), fn);
04821
04822
04823
04824
04825
04826
04827
04828 gcc_assert (TREE_CODE (parmtype) == POINTER_TYPE);
04829
04830 gcc_assert (cand->conversion_path != NULL_TREE);
04831 converted_arg = build_base_path (PLUS_EXPR,
04832 TREE_VALUE (arg),
04833 cand->conversion_path,
04834 1);
04835
04836 if (!accessible_base_p (TREE_TYPE (argtype),
04837 BINFO_TYPE (cand->conversion_path), true))
04838 error ("%qT is not an accessible base of %qT",
04839 BINFO_TYPE (cand->conversion_path),
04840 TREE_TYPE (argtype));
04841
04842
04843
04844 base_binfo = lookup_base (TREE_TYPE (TREE_TYPE (converted_arg)),
04845 TREE_TYPE (parmtype), ba_unique, NULL);
04846 converted_arg = build_base_path (PLUS_EXPR, converted_arg,
04847 base_binfo, 1);
04848
04849 converted_args = tree_cons (NULL_TREE, converted_arg, converted_args);
04850 parm = TREE_CHAIN (parm);
04851 arg = TREE_CHAIN (arg);
04852 ++i;
04853 is_method = 1;
04854 }
04855
04856 for (; arg && parm;
04857 parm = TREE_CHAIN (parm), arg = TREE_CHAIN (arg), ++i)
04858 {
04859 tree type = TREE_VALUE (parm);
04860
04861 conv = convs[i];
04862
04863
04864 if (conv->kind == ck_rvalue
04865 && !TREE_ADDRESSABLE (complete_type (type)))
04866 conv = conv->u.next;
04867
04868 val = convert_like_with_context
04869 (conv, TREE_VALUE (arg), fn, i - is_method);
04870
04871 val = convert_for_arg_passing (type, val);
04872 converted_args = tree_cons (NULL_TREE, val, converted_args);
04873 }
04874
04875
04876 for (; parm && parm != void_list_node; parm = TREE_CHAIN (parm), i++)
04877 converted_args
04878 = tree_cons (NULL_TREE,
04879 convert_default_arg (TREE_VALUE (parm),
04880 TREE_PURPOSE (parm),
04881 fn, i - is_method),
04882 converted_args);
04883
04884
04885 for (; arg; arg = TREE_CHAIN (arg))
04886 {
04887 tree a = TREE_VALUE (arg);
04888 if (magic_varargs_p (fn))
04889 ;
04890 else
04891 a = convert_arg_to_ellipsis (a);
04892 converted_args = tree_cons (NULL_TREE, a, converted_args);
04893 }
04894
04895 converted_args = nreverse (converted_args);
04896
04897 check_function_arguments (TYPE_ATTRIBUTES (TREE_TYPE (fn)),
04898 converted_args, TYPE_ARG_TYPES (TREE_TYPE (fn)));
04899
04900
04901
04902
04903 if (! flag_elide_constructors)
04904 ;
04905 else if (cand->num_convs == 1 && DECL_COPY_CONSTRUCTOR_P (fn))
04906 {
04907 tree targ;
04908 arg = skip_artificial_parms_for (fn, converted_args);
04909 arg = TREE_VALUE (arg);
04910
04911
04912 targ = arg;
04913 while (TREE_CODE (targ) == NOP_EXPR
04914 || TREE_CODE (targ) == NON_LVALUE_EXPR
04915 || TREE_CODE (targ) == CONVERT_EXPR)
04916 targ = TREE_OPERAND (targ, 0);
04917 if (TREE_CODE (targ) == ADDR_EXPR)
04918 {
04919 targ = TREE_OPERAND (targ, 0);
04920 if (!same_type_ignoring_top_level_qualifiers_p
04921 (TREE_TYPE (TREE_TYPE (arg)), TREE_TYPE (targ)))
04922 targ = NULL_TREE;
04923 }
04924 else
04925 targ = NULL_TREE;
04926
04927 if (targ)
04928 arg = targ;
04929 else
04930 arg = build_indirect_ref (arg, 0);
04931
04932
04933
04934 if (TYPE_HAS_COMPLEX_INIT_REF (DECL_CONTEXT (fn)))
04935 mark_used (fn);
04936
04937
04938
04939
04940
04941
04942 if (integer_zerop (TREE_VALUE (args)))
04943 {
04944 if (TREE_CODE (arg) == TARGET_EXPR)
04945 return arg;
04946 else if (TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
04947 return build_target_expr_with_type (arg, DECL_CONTEXT (fn));
04948 }
04949 else if (TREE_CODE (arg) == TARGET_EXPR
04950 || TYPE_HAS_TRIVIAL_INIT_REF (DECL_CONTEXT (fn)))
04951 {
04952 tree to = stabilize_reference
04953 (build_indirect_ref (TREE_VALUE (args), 0));
04954
04955 val = build2 (INIT_EXPR, DECL_CONTEXT (fn), to, arg);
04956 return val;
04957 }
04958 }
04959 else if (DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR
04960 && copy_fn_p (fn)
04961 && TYPE_HAS_TRIVIAL_ASSIGN_REF (DECL_CONTEXT (fn)))
04962 {
04963 tree to = stabilize_reference
04964 (build_indirect_ref (TREE_VALUE (converted_args), 0));
04965 tree type = TREE_TYPE (to);
04966 tree as_base = CLASSTYPE_AS_BASE (type);
04967
04968 arg = TREE_VALUE (TREE_CHAIN (converted_args));
04969 if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base)))
04970 {
04971 arg = build_indirect_ref (arg, 0);
04972 val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg);
04973 }
04974 else
04975 {
04976
04977
04978
04979 tree args, t;
04980
04981 args = tree_cons (NULL, TYPE_SIZE_UNIT (as_base), NULL);
04982 args = tree_cons (NULL, arg, args);
04983 t = build_unary_op (ADDR_EXPR, to, 0);
04984 args = tree_cons (NULL, t, args);
04985 t = implicit_built_in_decls[BUILT_IN_MEMCPY];
04986 t = build_call (t, args);
04987
04988 t = convert (TREE_TYPE (TREE_VALUE (args)), t);
04989 val = build_indirect_ref (t, 0);
04990 }
04991
04992 return val;
04993 }
04994
04995 mark_used (fn);
04996
04997 if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
04998 {
04999 tree t, *p = &TREE_VALUE (converted_args);
05000 tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (*p)),
05001 DECL_CONTEXT (fn),
05002 ba_any, NULL);
05003 gcc_assert (binfo && binfo != error_mark_node);
05004
05005 *p = build_base_path (PLUS_EXPR, *p, binfo, 1);
05006 if (TREE_SIDE_EFFECTS (*p))
05007 *p = save_expr (*p);
05008 t = build_pointer_type (TREE_TYPE (fn));
05009 if (DECL_CONTEXT (fn) && TYPE_JAVA_INTERFACE (DECL_CONTEXT (fn)))
05010 fn = build_java_interface_fn_ref (fn, *p);
05011 else
05012 fn = build_vfn_ref (*p, DECL_VINDEX (fn));
05013 TREE_TYPE (fn) = t;
05014 }
05015 else if (DECL_INLINE (fn))
05016 fn = inline_conversion (fn);
05017 else
05018 fn = build_addr_func (fn);
05019
05020 return build_cxx_call (fn, converted_args);
05021 }
05022
05023
05024
05025
05026
05027 tree
05028 build_cxx_call (tree fn, tree args)
05029 {
05030 tree fndecl;
05031
05032 fn = build_call (fn, args);
05033
05034
05035 fndecl = get_callee_fndecl (fn);
05036 if ((!fndecl || !TREE_NOTHROW (fndecl))
05037 && at_function_scope_p ()
05038 && cfun)
05039 cp_function_chain->can_throw = 1;
05040
05041
05042
05043 fn = fold_if_not_in_template (fn);
05044
05045 if (VOID_TYPE_P (TREE_TYPE (fn)))
05046 return fn;
05047
05048 fn = require_complete_type (fn);
05049 if (fn == error_mark_node)
05050 return error_mark_node;
05051
05052 if (IS_AGGR_TYPE (TREE_TYPE (fn)))
05053 fn = build_cplus_new (TREE_TYPE (fn), fn);
05054 return convert_from_reference (fn);
05055 }
05056
05057 static GTY(()) tree java_iface_lookup_fn;
05058
05059
05060
05061
05062
05063 static tree
05064 build_java_interface_fn_ref (tree fn, tree instance)
05065 {
05066 tree lookup_args, lookup_fn, method, idx;
05067 tree klass_ref, iface, iface_ref;
05068 int i;
05069
05070 if (!java_iface_lookup_fn)
05071 {
05072 tree endlink = build_void_list_node ();
05073 tree t = tree_cons (NULL_TREE, ptr_type_node,
05074 tree_cons (NULL_TREE, ptr_type_node,
05075 tree_cons (NULL_TREE, java_int_type_node,
05076 endlink)));
05077 java_iface_lookup_fn
05078 = builtin_function ("_Jv_LookupInterfaceMethodIdx",
05079 build_function_type (ptr_type_node, t),
05080 0, NOT_BUILT_IN, NULL, NULL_TREE);
05081 }
05082
05083
05084
05085 klass_ref = build_vtbl_ref (build_indirect_ref (instance, 0),
05086 integer_zero_node);
05087
05088
05089 iface = DECL_CONTEXT (fn);
05090 iface_ref = lookup_field (iface, get_identifier ("class$"), 0, false);
05091 if (!iface_ref || TREE_CODE (iface_ref) != VAR_DECL
05092 || DECL_CONTEXT (iface_ref) != iface)
05093 {
05094 error ("could not find class$ field in java interface type %qT",
05095 iface);
05096 return error_mark_node;
05097 }
05098 iface_ref = build_address (iface_ref);
05099 iface_ref = convert (build_pointer_type (iface), iface_ref);
05100
05101
05102 i = 1;
05103 for (method = TYPE_METHODS (iface); method; method = TREE_CHAIN (method))
05104 {
05105 if (!DECL_VIRTUAL_P (method))
05106 continue;
05107 if (fn == method)
05108 break;
05109 i++;
05110 }
05111 idx = build_int_cst (NULL_TREE, i);
05112
05113 lookup_args = tree_cons (NULL_TREE, klass_ref,
05114 tree_cons (NULL_TREE, iface_ref,
05115 build_tree_list (NULL_TREE, idx)));
05116 lookup_fn = build1 (ADDR_EXPR,
05117 build_pointer_type (TREE_TYPE (java_iface_lookup_fn)),
05118 java_iface_lookup_fn);
05119 return build3 (CALL_EXPR, ptr_type_node, lookup_fn, lookup_args, NULL_TREE);
05120 }
05121
05122
05123
05124
05125
05126
05127 tree
05128 in_charge_arg_for_name (tree name)
05129 {
05130 if (name == base_ctor_identifier
05131 || name == base_dtor_identifier)
05132 return integer_zero_node;
05133 else if (name == complete_ctor_identifier)
05134 return integer_one_node;
05135 else if (name == complete_dtor_identifier)
05136 return integer_two_node;
05137 else if (name == deleting_dtor_identifier)
05138 return integer_three_node;
05139
05140
05141
05142 gcc_unreachable ();
05143 return NULL_TREE;
05144 }
05145
05146
05147
05148
05149
05150
05151
05152
05153
05154
05155
05156
05157
05158 tree
05159 build_special_member_call (tree instance, tree name, tree args,
05160 tree binfo, int flags)
05161 {
05162 tree fns;
05163
05164 tree class_type;
05165
05166 gcc_assert (name == complete_ctor_identifier
05167 || name == base_ctor_identifier
05168 || name == complete_dtor_identifier
05169 || name == base_dtor_identifier
05170 || name == deleting_dtor_identifier
05171 || name == ansi_assopname (NOP_EXPR));
05172 if (TYPE_P (binfo))
05173 {
05174
05175 if (!complete_type_or_else (binfo, NULL_TREE))
05176 return error_mark_node;
05177
05178 binfo = TYPE_BINFO (binfo);
05179 }
05180
05181 gcc_assert (binfo != NULL_TREE);
05182
05183 class_type = BINFO_TYPE (binfo);
05184
05185
05186 if (name == complete_ctor_identifier && !instance)
05187 {
05188 instance = build_int_cst (build_pointer_type (class_type), 0);
05189 instance = build1 (INDIRECT_REF, class_type, instance);
05190 }
05191 else
05192 {
05193 if (name == complete_dtor_identifier
05194 || name == base_dtor_identifier
05195 || name == deleting_dtor_identifier)
05196 gcc_assert (args == NULL_TREE);
05197
05198
05199 if (!same_type_ignoring_top_level_qualifiers_p
05200 (TREE_TYPE (instance), BINFO_TYPE (binfo)))
05201 {
05202 if (name != ansi_assopname (NOP_EXPR))
05203
05204
05205
05206
05207
05208 instance = convert_to_base_statically (instance, binfo);
05209 else
05210
05211
05212 instance = build_base_path (PLUS_EXPR, instance,
05213 binfo, 1);
05214 }
05215 }
05216
05217 gcc_assert (instance != NULL_TREE);
05218
05219 fns = lookup_fnfields (binfo, name, 1);
05220
05221
05222
05223
05224 if ((name == base_ctor_identifier
05225 || name == base_dtor_identifier)
05226 && CLASSTYPE_VBASECLASSES (class_type))
05227 {
05228 tree vtt;
05229 tree sub_vtt;
05230
05231
05232
05233
05234 vtt = TREE_CHAIN (CLASSTYPE_VTABLES (current_class_type));
05235 vtt = decay_conversion (vtt);
05236 vtt = build3 (COND_EXPR, TREE_TYPE (vtt),
05237 build2 (EQ_EXPR, boolean_type_node,
05238 current_in_charge_parm, integer_zero_node),
05239 current_vtt_parm,
05240 vtt);
05241 gcc_assert (BINFO_SUBVTT_INDEX (binfo));
05242 sub_vtt = build2 (PLUS_EXPR, TREE_TYPE (vtt), vtt,
05243 BINFO_SUBVTT_INDEX (binfo));
05244
05245 args = tree_cons (NULL_TREE, sub_vtt, args);
05246 }
05247
05248 return build_new_method_call (instance, fns, args,
05249 TYPE_BINFO (BINFO_TYPE (binfo)),
05250 flags, NULL);
05251 }
05252
05253
05254
05255
05256
05257
05258
05259
05260
05261 static char *
05262 name_as_c_string (tree name, tree type, bool *free_p)
05263 {
05264 char *pretty_name;
05265
05266
05267 *free_p = false;
05268
05269 if (IDENTIFIER_CTOR_OR_DTOR_P (name))
05270 {
05271 pretty_name
05272 = (char *) IDENTIFIER_POINTER (constructor_name (type));
05273
05274 if (name == complete_dtor_identifier
05275 || name == base_dtor_identifier
05276 || name == deleting_dtor_identifier)
05277 {
05278 pretty_name = concat ("~", pretty_name, NULL);
05279
05280 *free_p = true;
05281 }
05282 }
05283 else if (IDENTIFIER_TYPENAME_P (name))
05284 {
05285 pretty_name = concat ("operator ",
05286 type_as_string (TREE_TYPE (name),
05287 TFF_PLAIN_IDENTIFIER),
05288 NULL);
05289
05290 *free_p = true;
05291 }
05292 else
05293 pretty_name = (char *) IDENTIFIER_POINTER (name);
05294
05295 return pretty_name;
05296 }
05297
05298
05299
05300
05301 tree
05302 build_new_method_call (tree instance, tree fns, tree args,
05303 tree conversion_path, int flags,
05304 tree *fn_p)
05305 {
05306 struct z_candidate *candidates = 0, *cand;
05307 tree explicit_targs = NULL_TREE;
05308 tree basetype = NULL_TREE;
05309 tree access_binfo;
05310 tree optype;
05311 tree mem_args = NULL_TREE, instance_ptr;
05312 tree name;
05313 tree user_args;
05314 tree call;
05315 tree fn;
05316 tree class_type;
05317 int template_only = 0;
05318 bool any_viable_p;
05319 tree orig_instance;
05320 tree orig_fns;
05321 tree orig_args;
05322 void *p;
05323
05324 gcc_assert (instance != NULL_TREE);
05325
05326
05327 if (fn_p)
05328 *fn_p = NULL_TREE;
05329
05330 if (error_operand_p (instance)
05331 || error_operand_p (fns)
05332 || args == error_mark_node)
05333 return error_mark_node;
05334
05335 if (!BASELINK_P (fns))
05336 {
05337 error ("call to non-function %qD", fns);
05338 return error_mark_node;
05339 }
05340
05341 orig_instance = instance;
05342 orig_fns = fns;
05343 orig_args = args;
05344
05345
05346 if (!conversion_path)
05347 conversion_path = BASELINK_BINFO (fns);
05348 access_binfo = BASELINK_ACCESS_BINFO (fns);
05349 optype = BASELINK_OPTYPE (fns);
05350 fns = BASELINK_FUNCTIONS (fns);
05351 if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
05352 {
05353 explicit_targs = TREE_OPERAND (fns, 1);
05354 fns = TREE_OPERAND (fns, 0);
05355 template_only = 1;
05356 }
05357 gcc_assert (TREE_CODE (fns) == FUNCTION_DECL
05358 || TREE_CODE (fns) == TEMPLATE_DECL
05359 || TREE_CODE (fns) == OVERLOAD);
05360 fn = get_first_fn (fns);
05361 name = DECL_NAME (fn);
05362
05363 basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance));
05364 gcc_assert (CLASS_TYPE_P (basetype));
05365
05366 if (processing_template_decl)
05367 {
05368 instance = build_non_dependent_expr (instance);
05369 args = build_non_dependent_args (orig_args);
05370 }
05371
05372
05373
05374
05375
05376
05377 user_args = args;
05378 if (IDENTIFIER_CTOR_OR_DTOR_P (name))
05379 {
05380
05381
05382 gcc_assert (name != ctor_identifier);
05383
05384 gcc_assert (name != dtor_identifier);
05385
05386 if ((name == base_ctor_identifier || name == base_dtor_identifier)
05387 && CLASSTYPE_VBASECLASSES (basetype))
05388 user_args = TREE_CHAIN (user_args);
05389 }
05390
05391
05392 args = resolve_args (args);
05393 if (args == error_mark_node)
05394 return error_mark_node;
05395
05396 instance_ptr = build_this (instance);
05397
05398
05399
05400 if (DECL_DESTRUCTOR_P (fn))
05401 {
05402 tree type = build_pointer_type (basetype);
05403 if (!same_type_p (type, TREE_TYPE (instance_ptr)))
05404 instance_ptr = build_nop (type, instance_ptr);
05405 name = complete_dtor_identifier;
05406 }
05407
05408 class_type = (conversion_path ? BINFO_TYPE (conversion_path) : NULL_TREE);
05409 mem_args = tree_cons (NULL_TREE, instance_ptr, args);
05410
05411
05412 p = conversion_obstack_alloc (0);
05413
05414 for (fn = fns; fn; fn = OVL_NEXT (fn))
05415 {
05416 tree t = OVL_CURRENT (fn);
05417 tree this_arglist;
05418
05419
05420 if ((flags & LOOKUP_ONLYCONVERTING)
05421 && DECL_NONCONVERTING_P (t))
05422 continue;
05423
05424 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (t))
05425 this_arglist = mem_args;
05426 else
05427 this_arglist = args;
05428
05429 if (TREE_CODE (t) == TEMPLATE_DECL)
05430
05431 add_template_candidate (&candidates, t,
05432 class_type,
05433 explicit_targs,
05434 this_arglist, optype,
05435 access_binfo,
05436 conversion_path,
05437 flags,
05438 DEDUCE_CALL);
05439 else if (! template_only)
05440 add_function_candidate (&candidates, t,
05441 class_type,
05442 this_arglist,
05443 access_binfo,
05444 conversion_path,
05445 flags);
05446 }
05447
05448 candidates = splice_viable (candidates, pedantic, &any_viable_p);
05449 if (!any_viable_p)
05450 {
05451 if (!COMPLETE_TYPE_P (basetype))
05452 cxx_incomplete_type_error (instance_ptr, basetype);
05453 else
05454 {
05455 char *pretty_name;
05456 bool free_p;
05457
05458 pretty_name = name_as_c_string (name, basetype, &free_p);
05459 error ("no matching function for call to %<%T::%s(%A)%#V%>",
05460 basetype, pretty_name, user_args,
05461 TREE_TYPE (TREE_TYPE (instance_ptr)));
05462 if (free_p)
05463 free (pretty_name);
05464 }
05465 print_z_candidates (candidates);
05466 call = error_mark_node;
05467 }
05468 else
05469 {
05470 cand = tourney (candidates);
05471 if (cand == 0)
05472 {
05473 char *pretty_name;
05474 bool free_p;
05475
05476 pretty_name = name_as_c_string (name, basetype, &free_p);
05477 error ("call of overloaded %<%s(%A)%> is ambiguous", pretty_name,
05478 user_args);
05479 print_z_candidates (candidates);
05480 if (free_p)
05481 free (pretty_name);
05482 call = error_mark_node;
05483 }
05484 else
05485 {
05486 fn = cand->fn;
05487
05488 if (!(flags & LOOKUP_NONVIRTUAL)
05489 && DECL_PURE_VIRTUAL_P (fn)
05490 && instance == current_class_ref
05491 && (DECL_CONSTRUCTOR_P (current_function_decl)
05492 || DECL_DESTRUCTOR_P (current_function_decl)))
05493
05494
05495 warning (0, (DECL_CONSTRUCTOR_P (current_function_decl) ?
05496 "abstract virtual %q#D called from constructor"
05497 : "abstract virtual %q#D called from destructor"),
05498 fn);
05499
05500 if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE
05501 && is_dummy_object (instance_ptr))
05502 {
05503 error ("cannot call member function %qD without object",
05504 fn);
05505 call = error_mark_node;
05506 }
05507 else
05508 {
05509 if (DECL_VINDEX (fn) && ! (flags & LOOKUP_NONVIRTUAL)
05510 && resolves_to_fixed_type_p (instance, 0))
05511 flags |= LOOKUP_NONVIRTUAL;
05512
05513 if (fn_p)
05514 *fn_p = fn;
05515
05516 call = build_over_call (cand, flags);
05517
05518
05519
05520 if (TREE_CODE (TREE_TYPE (fn)) != METHOD_TYPE
05521 && !is_dummy_object (instance_ptr)
05522 && TREE_SIDE_EFFECTS (instance_ptr))
05523 call = build2 (COMPOUND_EXPR, TREE_TYPE (call),
05524 instance_ptr, call);
05525 else if (call != error_mark_node
05526 && DECL_DESTRUCTOR_P (cand->fn)
05527 && !VOID_TYPE_P (TREE_TYPE (call)))
05528
05529
05530
05531
05532
05533
05534
05535
05536
05537
05538 call = build_nop (void_type_node, call);
05539 }
05540 }
05541 }
05542
05543 if (processing_template_decl && call != error_mark_node)
05544 call = (build_min_non_dep
05545 (CALL_EXPR, call,
05546 build_min_nt (COMPONENT_REF, orig_instance, orig_fns, NULL_TREE),
05547 orig_args, NULL_TREE));
05548
05549
05550 obstack_free (&conversion_obstack, p);
05551
05552 return call;
05553 }
05554
05555
05556
05557
05558 static bool
05559 is_subseq (conversion *ics1, conversion *ics2)
05560 {
05561
05562
05563
05564
05565 while (ics1->kind == ck_rvalue
05566 || ics1->kind == ck_lvalue)
05567 ics1 = ics1->u.next;
05568
05569 while (1)
05570 {
05571 while (ics2->kind == ck_rvalue
05572 || ics2->kind == ck_lvalue)
05573 ics2 = ics2->u.next;
05574
05575 if (ics2->kind == ck_user
05576 || ics2->kind == ck_ambig
05577 || ics2->kind == ck_identity)
05578
05579
05580
05581
05582 return false;
05583
05584 ics2 = ics2->u.next;
05585
05586 if (ics2->kind == ics1->kind
05587 && same_type_p (ics2->type, ics1->type)
05588 && same_type_p (ics2->u.next->type,
05589 ics1->u.next->type))
05590 return true;
05591 }
05592 }
05593
05594
05595
05596
05597 bool
05598 is_properly_derived_from (tree derived, tree base)
05599 {
05600 if (!IS_AGGR_TYPE_CODE (TREE_CODE (derived))
05601 || !IS_AGGR_TYPE_CODE (TREE_CODE (base)))
05602 return false;
05603
05604
05605
05606 return (!same_type_ignoring_top_level_qualifiers_p (derived, base)
05607 && DERIVED_FROM_P (base, derived));
05608 }
05609
05610
05611
05612
05613
05614
05615
05616 static void
05617 maybe_handle_implicit_object (conversion **ics)
05618 {
05619 if ((*ics)->this_p)
05620 {
05621
05622
05623
05624
05625
05626
05627
05628 conversion *t = *ics;
05629 tree reference_type;
05630
05631
05632
05633
05634 reference_type = TREE_TYPE (t->type);
05635 reference_type = build_reference_type (reference_type);
05636
05637 if (t->kind == ck_qual)
05638 t = t->u.next;
05639 if (t->kind == ck_ptr)
05640 t = t->u.next;
05641 t = build_identity_conv (TREE_TYPE (t->type), NULL_TREE);
05642 t = direct_reference_binding (reference_type, t);
05643 *ics = t;
05644 }
05645 }
05646
05647
05648
05649
05650
05651 static tree
05652 maybe_handle_ref_bind (conversion **ics)
05653 {
05654 if ((*ics)->kind == ck_ref_bind)
05655 {
05656 conversion *old_ics = *ics;
05657 tree type = TREE_TYPE (old_ics->type);
05658 *ics = old_ics->u.next;
05659 (*ics)->user_conv_p = old_ics->user_conv_p;
05660 (*ics)->bad_p = old_ics->bad_p;
05661 return type;
05662 }
05663
05664 return NULL_TREE;
05665 }
05666
05667
05668
05669
05670
05671
05672
05673
05674 static int
05675 compare_ics (conversion *ics1, conversion *ics2)
05676 {
05677 tree from_type1;
05678 tree from_type2;
05679 tree to_type1;
05680 tree to_type2;
05681 tree deref_from_type1 = NULL_TREE;
05682 tree deref_from_type2 = NULL_TREE;
05683 tree deref_to_type1 = NULL_TREE;
05684 tree deref_to_type2 = NULL_TREE;
05685 conversion_rank rank1, rank2;
05686
05687
05688
05689
05690 tree target_type1;
05691 tree target_type2;
05692
05693
05694 maybe_handle_implicit_object (&ics1);
05695 maybe_handle_implicit_object (&ics2);
05696
05697
05698 target_type1 = maybe_handle_ref_bind (&ics1);
05699 target_type2 = maybe_handle_ref_bind (&ics2);
05700
05701
05702
05703
05704
05705
05706
05707
05708
05709
05710
05711
05712
05713 rank1 = CONVERSION_RANK (ics1);
05714 rank2 = CONVERSION_RANK (ics2);
05715
05716 if (rank1 > rank2)
05717 return -1;
05718 else if (rank1 < rank2)
05719 return 1;
05720
05721 if (rank1 == cr_bad)
05722 {
05723
05724
05725
05726 if (ics1->user_conv_p > ics2->user_conv_p
05727 || ics1->rank > ics2->rank)
05728 return -1;
05729 else if (ics1->user_conv_p < ics2->user_conv_p
05730 || ics1->rank < ics2->rank)
05731 return 1;
05732
05733
05734 }
05735
05736 if (ics1->ellipsis_p)
05737
05738 return 0;
05739
05740
05741
05742
05743
05744
05745
05746 if (ics1->user_conv_p)
05747 {
05748 conversion *t1;
05749 conversion *t2;
05750
05751 for (t1 = ics1; t1->kind != ck_user; t1 = t1->u.next)
05752 if (t1->kind == ck_ambig)
05753 return 0;
05754 for (t2 = ics2; t2->kind != ck_user; t2 = t2->u.next)
05755 if (t2->kind == ck_ambig)
05756 return 0;
05757
05758 if (t1->cand->fn != t2->cand->fn)
05759 return 0;
05760
05761
05762
05763 from_type1 = t1->type;
05764 from_type2 = t2->type;
05765 }
05766 else
05767 {
05768 conversion *t1;
05769 conversion *t2;
05770
05771
05772
05773
05774
05775
05776
05777
05778
05779
05780
05781
05782
05783
05784 t1 = ics1;
05785 while (t1->kind != ck_identity)
05786 t1 = t1->u.next;
05787 from_type1 = t1->type;
05788
05789 t2 = ics2;
05790 while (t2->kind != ck_identity)
05791 t2 = t2->u.next;
05792 from_type2 = t2->type;
05793 }
05794
05795 if (same_type_p (from_type1, from_type2))
05796 {
05797 if (is_subseq (ics1, ics2))
05798 return 1;
05799 if (is_subseq (ics2, ics1))
05800 return -1;
05801 }
05802
05803
05804
05805
05806
05807
05808
05809
05810
05811
05812
05813
05814
05815
05816
05817
05818
05819
05820
05821
05822
05823
05824
05825
05826
05827 if (ics1->rank < ics2->rank)
05828 return 1;
05829 else if (ics2->rank < ics1->rank)
05830 return -1;
05831
05832 to_type1 = ics1->type;
05833 to_type2 = ics2->type;
05834
05835 if (TYPE_PTR_P (from_type1)
05836 && TYPE_PTR_P (from_type2)
05837 && TYPE_PTR_P (to_type1)
05838 && TYPE_PTR_P (to_type2))
05839 {
05840 deref_from_type1 = TREE_TYPE (from_type1);
05841 deref_from_type2 = TREE_TYPE (from_type2);
05842 deref_to_type1 = TREE_TYPE (to_type1);
05843 deref_to_type2 = TREE_TYPE (to_type2);
05844 }
05845
05846
05847
05848
05849 else if ((TYPE_PTRMEM_P (from_type1) && TYPE_PTRMEM_P (from_type2)
05850 && TYPE_PTRMEM_P (to_type1) && TYPE_PTRMEM_P (to_type2))
05851 || (TYPE_PTRMEMFUNC_P (from_type1)
05852 && TYPE_PTRMEMFUNC_P (from_type2)
05853 && TYPE_PTRMEMFUNC_P (to_type1)
05854 && TYPE_PTRMEMFUNC_P (to_type2)))
05855 {
05856 deref_to_type1 = TYPE_PTRMEM_CLASS_TYPE (from_type1);
05857 deref_to_type2 = TYPE_PTRMEM_CLASS_TYPE (from_type2);
05858 deref_from_type1 = TYPE_PTRMEM_CLASS_TYPE (to_type1);
05859 deref_from_type2 = TYPE_PTRMEM_CLASS_TYPE (to_type2);
05860 }
05861
05862 if (deref_from_type1 != NULL_TREE
05863 && IS_AGGR_TYPE_CODE (TREE_CODE (deref_from_type1))
05864 && IS_AGGR_TYPE_CODE (TREE_CODE (deref_from_type2)))
05865 {
05866
05867
05868
05869
05870
05871
05872
05873
05874 if (TREE_CODE (deref_to_type1) == VOID_TYPE
05875 && TREE_CODE (deref_to_type2) == VOID_TYPE)
05876 {
05877 if (is_properly_derived_from (deref_from_type1,
05878 deref_from_type2))
05879 return -1;
05880 else if (is_properly_derived_from (deref_from_type2,
05881 deref_from_type1))
05882 return 1;
05883 }
05884 else if (TREE_CODE (deref_to_type1) == VOID_TYPE
05885 || TREE_CODE (deref_to_type2) == VOID_TYPE)
05886 {
05887 if (same_type_p (deref_from_type1, deref_from_type2))
05888 {
05889 if (TREE_CODE (deref_to_type2) == VOID_TYPE)
05890 {
05891 if (is_properly_derived_from (deref_from_type1,
05892 deref_to_type1))
05893 return 1;
05894 }
05895
05896 else if (is_properly_derived_from (deref_from_type1,
05897 deref_to_type2))
05898 return -1;
05899 }
05900 }
05901 else if (IS_AGGR_TYPE_CODE (TREE_CODE (deref_to_type1))
05902 && IS_AGGR_TYPE_CODE (TREE_CODE (deref_to_type2)))
05903 {
05904
05905
05906
05907
05908
05909
05910
05911
05912
05913
05914 if (same_type_p (deref_from_type1, deref_from_type2))
05915 {
05916 if (is_properly_derived_from (deref_to_type1,
05917 deref_to_type2))
05918 return 1;
05919 else if (is_properly_derived_from (deref_to_type2,
05920 deref_to_type1))
05921 return -1;
05922 }
05923 else if (same_type_p (deref_to_type1, deref_to_type2))
05924 {
05925 if (is_properly_derived_from (deref_from_type2,
05926 deref_from_type1))
05927 return 1;
05928 else if (is_properly_derived_from (deref_from_type1,
05929 deref_from_type2))
05930 return -1;
05931 }
05932 }
05933 }
05934 else if (CLASS_TYPE_P (non_reference (from_type1))
05935 && same_type_p (from_type1, from_type2))
05936 {
05937 tree from = non_reference (from_type1);
05938
05939
05940
05941
05942
05943
05944
05945
05946 if (is_properly_derived_from (from, to_type1)
05947 && is_properly_derived_from (from, to_type2))
05948 {
05949 if (is_properly_derived_from (to_type1, to_type2))
05950 return 1;
05951 else if (is_properly_derived_from (to_type2, to_type1))
05952 return -1;
05953 }
05954 }
05955 else if (CLASS_TYPE_P (non_reference (to_type1))
05956 && same_type_p (to_type1, to_type2))
05957 {
05958 tree to = non_reference (to_type1);
05959
05960
05961
05962
05963
05964
05965
05966
05967 if (is_properly_derived_from (from_type1, to)
05968 && is_properly_derived_from (from_type2, to))
05969 {
05970 if (is_properly_derived_from (from_type2, from_type1))
05971 return 1;
05972 else if (is_properly_derived_from (from_type1, from_type2))
05973 return -1;
05974 }
05975 }
05976
05977
05978
05979
05980
05981
05982
05983 if (ics1->kind == ck_qual
05984 && ics2->kind == ck_qual
05985 && same_type_p (from_type1, from_type2))
05986 return comp_cv_qual_signature (to_type1, to_type2);
05987
05988
05989
05990
05991
05992
05993
05994
05995
05996 if (target_type1 && target_type2
05997 && same_type_ignoring_top_level_qualifiers_p (to_type1, to_type2))
05998 return comp_cv_qualification (target_type2, target_type1);
05999
06000
06001 return 0;
06002 }
06003
06004
06005
06006 static tree
06007 source_type (conversion *t)
06008 {
06009 for (;; t = t->u.next)
06010 {
06011 if (t->kind == ck_user
06012 || t->kind == ck_ambig
06013 || t->kind == ck_identity)
06014 return t->type;
06015 }
06016 gcc_unreachable ();
06017 }
06018
06019
06020
06021
06022
06023 static void
06024 add_warning (struct z_candidate *winner, struct z_candidate *loser)
06025 {
06026 candidate_warning *cw = (candidate_warning *)
06027 conversion_obstack_alloc (sizeof (candidate_warning));
06028 cw->loser = loser;
06029 cw->next = winner->warnings;
06030 winner->warnings = cw;
06031 }
06032
06033
06034
06035
06036
06037
06038
06039
06040 static int
06041 joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn)
06042 {
06043 int winner = 0;
06044 int off1 = 0, off2 = 0;
06045 size_t i;
06046 size_t len;
06047
06048
06049
06050 if (cand1->viable > cand2->viable)
06051 return 1;
06052 if (cand1->viable < cand2->viable)
06053 return -1;
06054
06055
06056
06057 if (cand1->fn == cand2->fn
06058 && (IS_TYPE_OR_DECL_P (cand1->fn)))
06059 return 1;
06060
06061
06062
06063
06064
06065
06066
06067
06068
06069
06070
06071
06072
06073 len = cand1->num_convs;
06074 if (len != cand2->num_convs)
06075 {
06076 int static_1 = DECL_STATIC_FUNCTION_P (cand1->fn);
06077 int static_2 = DECL_STATIC_FUNCTION_P (cand2->fn);
06078
06079 gcc_assert (static_1 != static_2);
06080
06081 if (static_1)
06082 off2 = 1;
06083 else
06084 {
06085 off1 = 1;
06086 --len;
06087 }
06088 }
06089
06090 for (i = 0; i < len; ++i)
06091 {
06092 conversion *t1 = cand1->convs[i + off1];
06093 conversion *t2 = cand2->convs[i + off2];
06094 int comp = compare_ics (t1, t2);
06095
06096 if (comp != 0)
06097 {
06098 if (warn_sign_promo
06099 && (CONVERSION_RANK (t1) + CONVERSION_RANK (t2)
06100 == cr_std + cr_promotion)
06101 && t1->kind == ck_std
06102 && t2->kind == ck_std
06103 && TREE_CODE (t1->type) == INTEGER_TYPE
06104 && TREE_CODE (t2->type) == INTEGER_TYPE
06105 && (TYPE_PRECISION (t1->type)
06106 == TYPE_PRECISION (t2->type))
06107 && (TYPE_UNSIGNED (t1->u.next->type)
06108 || (TREE_CODE (t1->u.next->type)
06109 == ENUMERAL_TYPE)))
06110 {
06111 tree type = t1->u.next->type;
06112 tree type1, type2;
06113 struct z_candidate *w, *l;
06114 if (comp > 0)
06115 type1 = t1->type, type2 = t2->type,
06116 w = cand1, l = cand2;
06117 else
06118 type1 = t2->type, type2 = t1->type,
06119 w = cand2, l = cand1;
06120
06121 if (warn)
06122 {
06123 warning (OPT_Wsign_promo, "passing %qT chooses %qT over %qT",
06124 type, type1, type2);
06125 warning (OPT_Wsign_promo, " in call to %qD", w->fn);
06126 }
06127 else
06128 add_warning (w, l);
06129 }
06130
06131 if (winner && comp != winner)
06132 {
06133 winner = 0;
06134 goto tweak;
06135 }
06136 winner = comp;
06137 }
06138 }
06139
06140
06141
06142
06143 if (winner && warn_conversion && cand1->second_conv
06144 && (!DECL_CONSTRUCTOR_P (cand1->fn) || !DECL_CONSTRUCTOR_P (cand2->fn))
06145 && winner != compare_ics (cand1->second_conv, cand2->second_conv))
06146 {
06147 struct z_candidate *w, *l;
06148 bool give_warning = false;
06149
06150 if (winner == 1)
06151 w = cand1, l = cand2;
06152 else
06153 w = cand2, l = cand1;
06154
06155
06156
06157
06158 if (DECL_CONTEXT (w->fn) == DECL_CONTEXT (l->fn)
06159 && !DECL_CONSTRUCTOR_P (w->fn) && !DECL_CONSTRUCTOR_P (l->fn))
06160 {
06161 tree t = TREE_TYPE (TREE_TYPE (l->fn));
06162 tree f = TREE_TYPE (TREE_TYPE (w->fn));
06163
06164 if (TREE_CODE (t) == TREE_CODE (f) && POINTER_TYPE_P (t))
06165 {
06166 t = TREE_TYPE (t);
06167 f = TREE_TYPE (f);
06168 }
06169 if (!comp_ptr_ttypes (t, f))
06170 give_warning = true;
06171 }
06172 else
06173 give_warning = true;
06174
06175 if (!give_warning)
06176 ;
06177 else if (warn)
06178 {
06179 tree source = source_type (w->convs[0]);
06180 if (! DECL_CONSTRUCTOR_P (w->fn))
06181 source = TREE_TYPE (source);
06182 warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn);
06183 warning (OPT_Wconversion, " for conversion from %qT to %qT",
06184 source, w->second_conv->type);
06185 inform (" because conversion sequence for the argument is better");
06186 }
06187 else
06188 add_warning (w, l);
06189 }
06190
06191 if (winner)
06192 return winner;
06193
06194
06195
06196
06197
06198 if (!cand1->template_decl && cand2->template_decl)
06199 return 1;
06200 else if (cand1->template_decl && !cand2->template_decl)
06201 return -1;
06202
06203
06204
06205
06206
06207
06208 if (cand1->template_decl && cand2->template_decl)
06209 {
06210 winner = more_specialized_fn
06211 (TI_TEMPLATE (cand1->template_decl),
06212 TI_TEMPLATE (cand2->template_decl),
06213
06214
06215
06216
06217 cand1->num_convs + DECL_CONSTRUCTOR_P (cand1->fn));
06218 if (winner)
06219 return winner;
06220 }
06221
06222
06223
06224
06225
06226
06227
06228
06229
06230 if (cand1->second_conv)
06231 {
06232 winner = compare_ics (cand1->second_conv, cand2->second_conv);
06233 if (winner)
06234 return winner;
06235 }
06236
06237
06238
06239
06240
06241
06242
06243
06244
06245
06246
06247
06248 if (TREE_CODE (cand1->fn) == IDENTIFIER_NODE
06249 || TREE_CODE (cand2->fn) == IDENTIFIER_NODE)
06250 {
06251 for (i = 0; i < len; ++i)
06252 if (!same_type_p (cand1->convs[i]->type,
06253 cand2->convs[i]->type))
06254 break;
06255 if (i == cand1->num_convs)
06256 {
06257 if (cand1->fn == cand2->fn)
06258
06259 return 1;
06260 else if (TREE_CODE (cand1->fn) == IDENTIFIER_NODE)
06261
06262 return -1;
06263 else
06264
06265 return 1;
06266 }
06267 }
06268
06269
06270
06271 if (DECL_P (cand1->fn) && DECL_P (cand2->fn)
06272 && equal_functions (cand1->fn, cand2->fn))
06273 return 1;
06274
06275 tweak:
06276
06277
06278
06279 if (!pedantic)
06280 {
06281 conversion_rank rank1 = cr_identity, rank2 = cr_identity;
06282 struct z_candidate *w = 0, *l = 0;
06283
06284 for (i = 0; i < len; ++i)
06285 {
06286 if (CONVERSION_RANK (cand1->convs[i+off1]) > rank1)
06287 rank1 = CONVERSION_RANK (cand1->convs[i+off1]);
06288 if (CONVERSION_RANK (cand2->convs[i + off2]) > rank2)
06289 rank2 = CONVERSION_RANK (cand2->convs[i + off2]);
06290 }
06291 if (rank1 < rank2)
06292 winner = 1, w = cand1, l = cand2;
06293 if (rank1 > rank2)
06294 winner = -1, w = cand2, l = cand1;
06295 if (winner)
06296 {
06297 if (warn)
06298 {
06299 pedwarn ("\
06300 ISO C++ says that these are ambiguous, even \
06301 though the worst conversion for the first is better than \
06302 the worst conversion for the second:");
06303 print_z_candidate (_("candidate 1:"), w);
06304 print_z_candidate (_("candidate 2:"), l);
06305 }
06306 else
06307 add_warning (w, l);
06308 return winner;
06309 }
06310 }
06311
06312 gcc_assert (!winner);
06313 return 0;
06314 }
06315
06316
06317
06318
06319
06320
06321 static struct z_candidate *
06322 tourney (struct z_candidate *candidates)
06323 {
06324 struct z_candidate *champ = candidates, *challenger;
06325 int fate;
06326 int champ_compared_to_predecessor = 0;
06327
06328
06329
06330
06331 for (challenger = champ->next; challenger; )
06332 {
06333 fate = joust (champ, challenger, 0);
06334 if (fate == 1)
06335 challenger = challenger->next;
06336 else
06337 {
06338 if (fate == 0)
06339 {
06340 champ = challenger->next;
06341 if (champ == 0)
06342 return NULL;
06343 champ_compared_to_predecessor = 0;
06344 }
06345 else
06346 {
06347 champ = challenger;
06348 champ_compared_to_predecessor = 1;
06349 }
06350
06351 challenger = champ->next;
06352 }
06353 }
06354
06355
06356
06357
06358 for (challenger = candidates;
06359 challenger != champ
06360 && !(champ_compared_to_predecessor && challenger->next == champ);
06361 challenger = challenger->next)
06362 {
06363 fate = joust (champ, challenger, 0);
06364 if (fate != 1)
06365 return NULL;
06366 }
06367
06368 return champ;
06369 }
06370
06371
06372
06373 bool
06374 can_convert (tree to, tree from)
06375 {
06376 return can_convert_arg (to, from, NULL_TREE, LOOKUP_NORMAL);
06377 }
06378
06379
06380
06381 bool
06382 can_convert_arg (tree to, tree from, tree arg, int flags)
06383 {
06384 conversion *t;
06385 void *p;
06386 bool ok_p;
06387
06388
06389 p = conversion_obstack_alloc (0);
06390
06391 t = implicit_conversion (to, from, arg, false,
06392 flags);
06393 ok_p = (t && !t->bad_p);
06394
06395
06396 obstack_free (&conversion_obstack, p);
06397
06398 return ok_p;
06399 }
06400
06401
06402
06403 bool
06404 can_convert_arg_bad (tree to, tree from, tree arg)
06405 {
06406 conversion *t;
06407 void *p;
06408
06409
06410 p = conversion_obstack_alloc (0);
06411
06412 t = implicit_conversion (to, from, arg, false,
06413 LOOKUP_NORMAL);
06414
06415 obstack_free (&conversion_obstack, p);
06416
06417 return t != NULL;
06418 }
06419
06420
06421
06422
06423
06424
06425
06426 tree
06427 perform_implicit_conversion (tree type, tree expr)
06428 {
06429 conversion *conv;
06430 void *p;
06431
06432 if (error_operand_p (expr))
06433 return error_mark_node;
06434
06435
06436 p = conversion_obstack_alloc (0);
06437
06438 conv = implicit_conversion (type, TREE_TYPE (expr), expr,
06439 false,
06440 LOOKUP_NORMAL);
06441 if (!conv)
06442 {
06443 error ("could not convert %qE to %qT", expr, type);
06444 expr = error_mark_node;
06445 }
06446 else if (processing_template_decl)
06447 {
06448
06449
06450
06451 if (TREE_TYPE (expr) != type)
06452 expr = build_nop (type, expr);
06453 }
06454 else
06455 expr = convert_like (conv, expr);
06456
06457
06458 obstack_free (&conversion_obstack, p);
06459
06460 return expr;
06461 }
06462
06463
06464
06465
06466
06467
06468
06469
06470
06471 tree
06472 perform_direct_initialization_if_possible (tree type,
06473 tree expr,
06474 bool c_cast_p)
06475 {
06476 conversion *conv;
06477 void *p;
06478
06479 if (type == error_mark_node || error_operand_p (expr))
06480 return error_mark_node;
06481
06482
06483
06484
06485
06486
06487
06488
06489 if (CLASS_TYPE_P (type))
06490 {
06491 expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
06492 build_tree_list (NULL_TREE, expr),
06493 type, LOOKUP_NORMAL);
06494 return build_cplus_new (type, expr);
06495 }
06496
06497
06498 p = conversion_obstack_alloc (0);
06499
06500 conv = implicit_conversion (type, TREE_TYPE (expr), expr,
06501 c_cast_p,
06502 LOOKUP_NORMAL);
06503 if (!conv || conv->bad_p)
06504 expr = NULL_TREE;
06505 else
06506 expr = convert_like_real (conv, expr, NULL_TREE, 0, 0,
06507 false,
06508 c_cast_p);
06509
06510
06511 obstack_free (&conversion_obstack, p);
06512
06513 return expr;
06514 }
06515
06516
06517
06518
06519
06520
06521 tree
06522 make_temporary_var_for_ref_to_temp (tree decl, tree type)
06523 {
06524 tree var;
06525
06526
06527 var = create_temporary_var (type);
06528
06529
06530 if (TREE_STATIC (decl))
06531 {
06532
06533 tree name;
06534
06535 TREE_STATIC (var) = 1;
06536 name = mangle_ref_init_variable (decl);
06537 DECL_NAME (var) = name;
06538 SET_DECL_ASSEMBLER_NAME (var, name);
06539 var = pushdecl_top_level (var);
06540 }
06541 else
06542
06543 maybe_push_cleanup_level (type);
06544
06545 return var;
06546 }
06547
06548
06549
06550
06551
06552
06553
06554
06555
06556
06557
06558
06559 tree
06560 initialize_reference (tree type, tree expr, tree decl, tree *cleanup)
06561 {
06562 conversion *conv;
06563 void *p;
06564
06565 if (type == error_mark_node || error_operand_p (expr))
06566 return error_mark_node;
06567
06568
06569 p = conversion_obstack_alloc (0);
06570
06571 conv = reference_binding (type, TREE_TYPE (expr), expr, false,
06572 LOOKUP_NORMAL);
06573 if (!conv || conv->bad_p)
06574 {
06575 if (!(TYPE_QUALS (TREE_TYPE (type)) & TYPE_QUAL_CONST)
06576 && !real_lvalue_p (expr))
06577 error ("invalid initialization of non-const reference of "
06578 "type %qT from a temporary of type %qT",
06579 type, TREE_TYPE (expr));
06580 else
06581 error ("invalid initialization of reference of type "
06582 "%qT from expression of type %qT", type,
06583 TREE_TYPE (expr));
06584 return error_mark_node;
06585 }
06586
06587
06588
06589
06590
06591
06592
06593
06594
06595
06596
06597
06598
06599
06600
06601
06602
06603
06604
06605
06606
06607
06608
06609
06610
06611
06612
06613
06614
06615
06616
06617
06618
06619
06620
06621 gcc_assert (conv->kind == ck_ref_bind);
06622 if (decl)
06623 {
06624 tree var;
06625 tree base_conv_type;
06626
06627
06628 conv = conv->u.next;
06629
06630
06631 if (conv->kind == ck_base)
06632 {
06633 if (conv->check_copy_constructor_p)
06634 check_constructor_callable (TREE_TYPE (expr), expr);
06635 base_conv_type = conv->type;
06636 conv = conv->u.next;
06637 }
06638 else
06639 base_conv_type = NULL_TREE;
06640
06641 expr = convert_like_real (conv, expr,
06642 NULL_TREE, 0,
06643 -1,
06644 true,
06645 false);
06646 if (error_operand_p (expr))
06647 expr = error_mark_node;
06648 else
06649 {
06650 if (!real_lvalue_p (expr))
06651 {
06652 tree init;
06653 tree type;
06654
06655
06656 type = TREE_TYPE (expr);
06657 var = make_temporary_var_for_ref_to_temp (decl, type);
06658 layout_decl (var, 0);
06659
06660
06661
06662
06663
06664
06665
06666
06667 if (TREE_CODE (expr) != TARGET_EXPR)
06668 expr = get_target_expr (expr);
06669
06670
06671 init = build2 (INIT_EXPR, type, var, expr);
06672 if (at_function_scope_p ())
06673 {
06674 add_decl_expr (var);
06675 *cleanup = cxx_maybe_build_cleanup (var);
06676
06677
06678
06679
06680
06681
06682
06683
06684
06685
06686
06687
06688
06689
06690
06691
06692
06693
06694
06695 }
06696 else
06697 {
06698 rest_of_decl_compilation (var, 1, at_eof);
06699 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
06700 static_aggregates = tree_cons (NULL_TREE, var,
06701 static_aggregates);
06702 }
06703
06704 expr = build_address (var);
06705 if (base_conv_type)
06706 expr = convert_to_base (expr,
06707 build_pointer_type (base_conv_type),
06708 true,
06709 true);
06710 expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), init, expr);
06711 }
06712 else
06713
06714 expr = build_unary_op (ADDR_EXPR, expr, 0);
06715
06716 if (base_conv_type)
06717 expr = (perform_implicit_conversion
06718 (build_pointer_type (base_conv_type), expr));
06719 expr = build_nop (type, expr);
06720 }
06721 }
06722 else
06723
06724 expr = convert_like (conv, expr);
06725
06726
06727 obstack_free (&conversion_obstack, p);
06728
06729 return expr;
06730 }
06731
06732 #include "gt-cp-call.h"