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