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