Mercurial > hg > CbC > CbC_gcc
comparison gcc/cp/cvt.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Language-level data type conversion for GNU C++. | 1 /* Language-level data type conversion for GNU C++. |
2 Copyright (C) 1987-2017 Free Software Foundation, Inc. | 2 Copyright (C) 1987-2018 Free Software Foundation, Inc. |
3 Hacked by Michael Tiemann (tiemann@cygnus.com) | 3 Hacked by Michael Tiemann (tiemann@cygnus.com) |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify | 7 GCC is free software; you can redistribute it and/or modify |
75 tsubst_flags_t complain) | 75 tsubst_flags_t complain) |
76 { | 76 { |
77 tree intype = TREE_TYPE (expr); | 77 tree intype = TREE_TYPE (expr); |
78 enum tree_code form; | 78 enum tree_code form; |
79 tree rval; | 79 tree rval; |
80 location_t loc = EXPR_LOC_OR_LOC (expr, input_location); | 80 location_t loc = cp_expr_loc_or_loc (expr, input_location); |
81 | 81 |
82 if (intype == error_mark_node) | 82 if (intype == error_mark_node) |
83 return error_mark_node; | 83 return error_mark_node; |
84 | 84 |
85 if (MAYBE_CLASS_TYPE_P (intype)) | 85 if (MAYBE_CLASS_TYPE_P (intype)) |
120 if (expr == error_mark_node) | 120 if (expr == error_mark_node) |
121 return error_mark_node; | 121 return error_mark_node; |
122 | 122 |
123 form = TREE_CODE (intype); | 123 form = TREE_CODE (intype); |
124 | 124 |
125 if (POINTER_TYPE_P (intype)) | 125 if (INDIRECT_TYPE_P (intype)) |
126 { | 126 { |
127 intype = TYPE_MAIN_VARIANT (intype); | 127 intype = TYPE_MAIN_VARIANT (intype); |
128 | 128 |
129 if (TYPE_MAIN_VARIANT (type) != intype | 129 if (TYPE_MAIN_VARIANT (type) != intype |
130 && TYPE_PTR_P (type) | 130 && TYPE_PTR_P (type) |
237 is supposed to be some integral type that is the same width | 237 is supposed to be some integral type that is the same width |
238 as a pointer. */ | 238 as a pointer. */ |
239 gcc_assert (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (expr))) | 239 gcc_assert (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (expr))) |
240 == GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type))); | 240 == GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type))); |
241 | 241 |
242 /* FIXME needed because convert_to_pointer_maybe_fold still folds | |
243 conversion of constants. */ | |
244 if (!dofold) | |
245 return build1 (CONVERT_EXPR, type, expr); | |
246 | |
242 return convert_to_pointer_maybe_fold (type, expr, dofold); | 247 return convert_to_pointer_maybe_fold (type, expr, dofold); |
243 } | 248 } |
244 | 249 |
245 if (type_unknown_p (expr)) | 250 if (type_unknown_p (expr)) |
246 return instantiate_type (type, expr, complain); | 251 return instantiate_type (type, expr, complain); |
315 { | 320 { |
316 tree rval; | 321 tree rval; |
317 tree argtype = TREE_TYPE (arg); | 322 tree argtype = TREE_TYPE (arg); |
318 tree target_type = TREE_TYPE (type); | 323 tree target_type = TREE_TYPE (type); |
319 | 324 |
320 gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); | 325 gcc_assert (TYPE_REF_P (type)); |
321 | 326 |
322 if ((flags & DIRECT_BIND) && ! lvalue_p (arg)) | 327 if ((flags & DIRECT_BIND) && ! lvalue_p (arg)) |
323 { | 328 { |
324 /* Create a new temporary variable. We can't just use a TARGET_EXPR | 329 /* Create a new temporary variable. We can't just use a TARGET_EXPR |
325 here because it needs to live as long as DECL. */ | 330 here because it needs to live as long as DECL. */ |
374 static void | 379 static void |
375 diagnose_ref_binding (location_t loc, tree reftype, tree intype, tree decl) | 380 diagnose_ref_binding (location_t loc, tree reftype, tree intype, tree decl) |
376 { | 381 { |
377 tree ttl = TREE_TYPE (reftype); | 382 tree ttl = TREE_TYPE (reftype); |
378 | 383 |
379 if (!CP_TYPE_CONST_NON_VOLATILE_P (ttl)) | 384 if (!TYPE_REF_IS_RVALUE (reftype) |
385 && !CP_TYPE_CONST_NON_VOLATILE_P (ttl)) | |
380 { | 386 { |
381 const char *msg; | 387 const char *msg; |
382 | 388 |
383 if (CP_TYPE_VOLATILE_P (ttl) && decl) | 389 if (CP_TYPE_VOLATILE_P (ttl) && decl) |
384 msg = G_("initialization of volatile reference type %q#T from " | 390 msg = G_("initialization of volatile reference type %q#T from " |
411 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (reftype)); | 417 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (reftype)); |
412 tree intype; | 418 tree intype; |
413 tree rval = NULL_TREE; | 419 tree rval = NULL_TREE; |
414 tree rval_as_conversion = NULL_TREE; | 420 tree rval_as_conversion = NULL_TREE; |
415 bool can_convert_intype_to_type; | 421 bool can_convert_intype_to_type; |
416 location_t loc = EXPR_LOC_OR_LOC (expr, input_location); | 422 location_t loc = cp_expr_loc_or_loc (expr, input_location); |
417 | 423 |
418 if (TREE_CODE (type) == FUNCTION_TYPE | 424 if (TREE_CODE (type) == FUNCTION_TYPE |
419 && TREE_TYPE (expr) == unknown_type_node) | 425 && TREE_TYPE (expr) == unknown_type_node) |
420 expr = instantiate_type (type, expr, complain); | 426 expr = instantiate_type (type, expr, complain); |
421 | 427 |
422 if (expr == error_mark_node) | 428 if (expr == error_mark_node) |
423 return error_mark_node; | 429 return error_mark_node; |
424 | 430 |
425 intype = TREE_TYPE (expr); | 431 intype = TREE_TYPE (expr); |
426 | 432 |
427 gcc_assert (TREE_CODE (intype) != REFERENCE_TYPE); | 433 gcc_assert (!TYPE_REF_P (intype)); |
428 gcc_assert (TREE_CODE (reftype) == REFERENCE_TYPE); | 434 gcc_assert (TYPE_REF_P (reftype)); |
429 | 435 |
430 intype = TYPE_MAIN_VARIANT (intype); | 436 intype = TYPE_MAIN_VARIANT (intype); |
431 | 437 |
432 can_convert_intype_to_type = can_convert_standard (type, intype, complain); | 438 can_convert_intype_to_type = can_convert_standard (type, intype, complain); |
433 | 439 |
526 | 532 |
527 tree | 533 tree |
528 convert_from_reference (tree val) | 534 convert_from_reference (tree val) |
529 { | 535 { |
530 if (TREE_TYPE (val) | 536 if (TREE_TYPE (val) |
531 && TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE) | 537 && TYPE_REF_P (TREE_TYPE (val))) |
532 { | 538 { |
533 tree t = TREE_TYPE (TREE_TYPE (val)); | 539 tree t = TREE_TYPE (TREE_TYPE (val)); |
534 tree ref = build1 (INDIRECT_REF, t, val); | 540 tree ref = build1 (INDIRECT_REF, t, val); |
535 | 541 |
536 mark_exp_read (val); | 542 mark_exp_read (val); |
594 cp_fold_convert (tree type, tree expr) | 600 cp_fold_convert (tree type, tree expr) |
595 { | 601 { |
596 tree conv; | 602 tree conv; |
597 if (TREE_TYPE (expr) == type) | 603 if (TREE_TYPE (expr) == type) |
598 conv = expr; | 604 conv = expr; |
599 else if (TREE_CODE (expr) == PTRMEM_CST) | 605 else if (TREE_CODE (expr) == PTRMEM_CST |
606 && same_type_p (TYPE_PTRMEM_CLASS_TYPE (type), | |
607 PTRMEM_CST_CLASS (expr))) | |
600 { | 608 { |
601 /* Avoid wrapping a PTRMEM_CST in NOP_EXPR. */ | 609 /* Avoid wrapping a PTRMEM_CST in NOP_EXPR. */ |
602 conv = copy_node (expr); | 610 conv = copy_node (expr); |
603 TREE_TYPE (conv) = type; | 611 TREE_TYPE (conv) = type; |
612 } | |
613 else if (TYPE_PTRMEM_P (type)) | |
614 { | |
615 conv = convert_ptrmem (type, expr, true, false, | |
616 tf_warning_or_error); | |
617 conv = cp_fully_fold (conv); | |
604 } | 618 } |
605 else | 619 else |
606 { | 620 { |
607 conv = fold_convert (type, expr); | 621 conv = fold_convert (type, expr); |
608 conv = ignore_overflows (conv, expr); | 622 conv = ignore_overflows (conv, expr); |
651 folded_result = cp_convert (type, folded, tf_none); | 665 folded_result = cp_convert (type, folded, tf_none); |
652 } | 666 } |
653 folded_result = fold_simple (folded_result); | 667 folded_result = fold_simple (folded_result); |
654 if (!TREE_OVERFLOW_P (folded) | 668 if (!TREE_OVERFLOW_P (folded) |
655 && folded_result != error_mark_node) | 669 && folded_result != error_mark_node) |
656 warnings_for_convert_and_check (EXPR_LOC_OR_LOC (expr, input_location), | 670 warnings_for_convert_and_check (cp_expr_loc_or_loc (expr, input_location), |
657 type, folded, folded_result); | 671 type, folded, folded_result); |
658 } | 672 } |
659 | 673 |
660 return result; | 674 return result; |
661 } | 675 } |
670 { | 684 { |
671 tree e = expr; | 685 tree e = expr; |
672 enum tree_code code = TREE_CODE (type); | 686 enum tree_code code = TREE_CODE (type); |
673 const char *invalid_conv_diag; | 687 const char *invalid_conv_diag; |
674 tree e1; | 688 tree e1; |
675 location_t loc = EXPR_LOC_OR_LOC (expr, input_location); | 689 location_t loc = cp_expr_loc_or_loc (expr, input_location); |
676 bool dofold = (convtype & CONV_FOLD); | 690 bool dofold = (convtype & CONV_FOLD); |
677 | 691 |
678 if (error_operand_p (e) || type == error_mark_node) | 692 if (error_operand_p (e) || type == error_mark_node) |
679 return error_mark_node; | 693 return error_mark_node; |
680 | 694 |
689 return error_mark_node; | 703 return error_mark_node; |
690 } | 704 } |
691 | 705 |
692 /* FIXME remove when moving to c_fully_fold model. */ | 706 /* FIXME remove when moving to c_fully_fold model. */ |
693 if (!CLASS_TYPE_P (type)) | 707 if (!CLASS_TYPE_P (type)) |
694 e = scalar_constant_value (e); | 708 { |
709 e = mark_rvalue_use (e); | |
710 e = scalar_constant_value (e); | |
711 } | |
695 if (error_operand_p (e)) | 712 if (error_operand_p (e)) |
696 return error_mark_node; | 713 return error_mark_node; |
714 | |
715 if (NULLPTR_TYPE_P (type) && null_ptr_cst_p (e)) | |
716 { | |
717 if (complain & tf_warning) | |
718 maybe_warn_zero_as_null_pointer_constant (e, loc); | |
719 | |
720 if (!TREE_SIDE_EFFECTS (e)) | |
721 return nullptr_node; | |
722 } | |
697 | 723 |
698 if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP)) | 724 if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP)) |
699 /* We need a new temporary; don't take this shortcut. */; | 725 /* We need a new temporary; don't take this shortcut. */; |
700 else if (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (e))) | 726 else if (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (e))) |
701 { | 727 { |
814 converted = convert_to_integer_maybe_fold (type, e, dofold); | 840 converted = convert_to_integer_maybe_fold (type, e, dofold); |
815 | 841 |
816 /* Ignore any integer overflow caused by the conversion. */ | 842 /* Ignore any integer overflow caused by the conversion. */ |
817 return ignore_overflows (converted, e); | 843 return ignore_overflows (converted, e); |
818 } | 844 } |
819 if (NULLPTR_TYPE_P (type) && e && null_ptr_cst_p (e)) | 845 if (INDIRECT_TYPE_P (type) || TYPE_PTRMEM_P (type)) |
820 { | |
821 if (complain & tf_warning) | |
822 maybe_warn_zero_as_null_pointer_constant (e, loc); | |
823 return nullptr_node; | |
824 } | |
825 if (POINTER_TYPE_P (type) || TYPE_PTRMEM_P (type)) | |
826 return cp_convert_to_pointer (type, e, dofold, complain); | 846 return cp_convert_to_pointer (type, e, dofold, complain); |
827 if (code == VECTOR_TYPE) | 847 if (code == VECTOR_TYPE) |
828 { | 848 { |
829 tree in_vtype = TREE_TYPE (e); | 849 tree in_vtype = TREE_TYPE (e); |
830 if (MAYBE_CLASS_TYPE_P (in_vtype)) | 850 if (MAYBE_CLASS_TYPE_P (in_vtype)) |
931 | 951 |
932 /* FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL | 952 /* FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL |
933 if we can. */ | 953 if we can. */ |
934 | 954 |
935 tree | 955 tree |
936 cp_get_fndecl_from_callee (tree fn) | 956 cp_get_fndecl_from_callee (tree fn, bool fold /* = true */) |
937 { | 957 { |
938 if (fn == NULL_TREE) | 958 if (fn == NULL_TREE) |
939 return fn; | 959 return fn; |
940 if (TREE_CODE (fn) == FUNCTION_DECL) | 960 if (TREE_CODE (fn) == FUNCTION_DECL) |
941 return fn; | 961 return fn; |
942 tree type = TREE_TYPE (fn); | 962 tree type = TREE_TYPE (fn); |
943 if (type == unknown_type_node) | 963 if (type == unknown_type_node) |
944 return NULL_TREE; | 964 return NULL_TREE; |
945 gcc_assert (POINTER_TYPE_P (type)); | 965 gcc_assert (INDIRECT_TYPE_P (type)); |
946 fn = maybe_constant_init (fn); | 966 if (fold) |
967 fn = maybe_constant_init (fn); | |
947 STRIP_NOPS (fn); | 968 STRIP_NOPS (fn); |
948 if (TREE_CODE (fn) == ADDR_EXPR) | 969 if (TREE_CODE (fn) == ADDR_EXPR) |
949 { | 970 { |
950 fn = TREE_OPERAND (fn, 0); | 971 fn = TREE_OPERAND (fn, 0); |
951 if (TREE_CODE (fn) == FUNCTION_DECL) | 972 if (TREE_CODE (fn) == FUNCTION_DECL) |
961 cp_get_callee_fndecl (tree call) | 982 cp_get_callee_fndecl (tree call) |
962 { | 983 { |
963 return cp_get_fndecl_from_callee (cp_get_callee (call)); | 984 return cp_get_fndecl_from_callee (cp_get_callee (call)); |
964 } | 985 } |
965 | 986 |
987 /* As above, but not using the constexpr machinery. */ | |
988 | |
989 tree | |
990 cp_get_callee_fndecl_nofold (tree call) | |
991 { | |
992 return cp_get_fndecl_from_callee (cp_get_callee (call), false); | |
993 } | |
994 | |
966 /* Subroutine of convert_to_void. Warn if we're discarding something with | 995 /* Subroutine of convert_to_void. Warn if we're discarding something with |
967 attribute [[nodiscard]]. */ | 996 attribute [[nodiscard]]. */ |
968 | 997 |
969 static void | 998 static void |
970 maybe_warn_nodiscard (tree expr, impl_conv_void implicit) | 999 maybe_warn_nodiscard (tree expr, impl_conv_void implicit) |
971 { | 1000 { |
972 tree call = expr; | 1001 tree call = expr; |
973 if (TREE_CODE (expr) == TARGET_EXPR) | 1002 if (TREE_CODE (expr) == TARGET_EXPR) |
974 call = TARGET_EXPR_INITIAL (expr); | 1003 call = TARGET_EXPR_INITIAL (expr); |
975 location_t loc = EXPR_LOC_OR_LOC (call, input_location); | 1004 location_t loc = cp_expr_loc_or_loc (call, input_location); |
976 tree callee = cp_get_callee (call); | 1005 tree callee = cp_get_callee (call); |
977 if (!callee) | 1006 if (!callee) |
978 return; | 1007 return; |
979 | 1008 |
980 tree type = TREE_TYPE (callee); | 1009 tree type = TREE_TYPE (callee); |
981 if (TYPE_PTRMEMFUNC_P (type)) | 1010 if (TYPE_PTRMEMFUNC_P (type)) |
982 type = TYPE_PTRMEMFUNC_FN_TYPE (type); | 1011 type = TYPE_PTRMEMFUNC_FN_TYPE (type); |
983 if (POINTER_TYPE_P (type)) | 1012 if (INDIRECT_TYPE_P (type)) |
984 type = TREE_TYPE (type); | 1013 type = TREE_TYPE (type); |
985 | 1014 |
986 tree rettype = TREE_TYPE (type); | 1015 tree rettype = TREE_TYPE (type); |
987 tree fn = cp_get_fndecl_from_callee (callee); | 1016 tree fn = cp_get_fndecl_from_callee (callee); |
988 if (implicit != ICV_CAST && fn | 1017 if (implicit != ICV_CAST && fn |
989 && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn))) | 1018 && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn))) |
990 { | 1019 { |
1020 auto_diagnostic_group d; | |
991 if (warning_at (loc, OPT_Wunused_result, | 1021 if (warning_at (loc, OPT_Wunused_result, |
992 "ignoring return value of %qD, " | 1022 "ignoring return value of %qD, " |
993 "declared with attribute nodiscard", fn)) | 1023 "declared with attribute nodiscard", fn)) |
994 inform (DECL_SOURCE_LOCATION (fn), "declared here"); | 1024 inform (DECL_SOURCE_LOCATION (fn), "declared here"); |
995 } | 1025 } |
996 else if (implicit != ICV_CAST | 1026 else if (implicit != ICV_CAST |
997 && lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype))) | 1027 && lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype))) |
998 { | 1028 { |
1029 auto_diagnostic_group d; | |
999 if (warning_at (loc, OPT_Wunused_result, | 1030 if (warning_at (loc, OPT_Wunused_result, |
1000 "ignoring returned value of type %qT, " | 1031 "ignoring returned value of type %qT, " |
1001 "declared with attribute nodiscard", rettype)) | 1032 "declared with attribute nodiscard", rettype)) |
1002 { | 1033 { |
1003 if (fn) | 1034 if (fn) |
1012 { | 1043 { |
1013 /* The TARGET_EXPR confuses do_warn_unused_result into thinking that the | 1044 /* The TARGET_EXPR confuses do_warn_unused_result into thinking that the |
1014 result is used, so handle that case here. */ | 1045 result is used, so handle that case here. */ |
1015 if (fn) | 1046 if (fn) |
1016 { | 1047 { |
1048 auto_diagnostic_group d; | |
1017 if (warning_at (loc, OPT_Wunused_result, | 1049 if (warning_at (loc, OPT_Wunused_result, |
1018 "ignoring return value of %qD, " | 1050 "ignoring return value of %qD, " |
1019 "declared with attribute warn_unused_result", | 1051 "declared with attribute warn_unused_result", |
1020 fn)) | 1052 fn)) |
1021 inform (DECL_SOURCE_LOCATION (fn), "declared here"); | 1053 inform (DECL_SOURCE_LOCATION (fn), "declared here"); |
1047 indicates the context of the implicit conversion. */ | 1079 indicates the context of the implicit conversion. */ |
1048 | 1080 |
1049 tree | 1081 tree |
1050 convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) | 1082 convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) |
1051 { | 1083 { |
1052 location_t loc = EXPR_LOC_OR_LOC (expr, input_location); | 1084 location_t loc = cp_expr_loc_or_loc (expr, input_location); |
1053 | 1085 |
1054 if (expr == error_mark_node | 1086 if (expr == error_mark_node |
1055 || TREE_TYPE (expr) == error_mark_node) | 1087 || TREE_TYPE (expr) == error_mark_node) |
1056 return error_mark_node; | 1088 return error_mark_node; |
1089 | |
1090 expr = maybe_undo_parenthesized_ref (expr); | |
1057 | 1091 |
1058 expr = mark_discarded_use (expr); | 1092 expr = mark_discarded_use (expr); |
1059 if (implicit == ICV_CAST) | 1093 if (implicit == ICV_CAST) |
1060 /* An explicit cast to void avoids all -Wunused-but-set* warnings. */ | 1094 /* An explicit cast to void avoids all -Wunused-but-set* warnings. */ |
1061 mark_exp_read (expr); | 1095 mark_exp_read (expr); |
1131 break; | 1165 break; |
1132 | 1166 |
1133 case INDIRECT_REF: | 1167 case INDIRECT_REF: |
1134 { | 1168 { |
1135 tree type = TREE_TYPE (expr); | 1169 tree type = TREE_TYPE (expr); |
1136 int is_reference = TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) | 1170 int is_reference = TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0))); |
1137 == REFERENCE_TYPE; | |
1138 int is_volatile = TYPE_VOLATILE (type); | 1171 int is_volatile = TYPE_VOLATILE (type); |
1139 int is_complete = COMPLETE_TYPE_P (complete_type (type)); | 1172 int is_complete = COMPLETE_TYPE_P (complete_type (type)); |
1140 | 1173 |
1141 /* Can't load the value if we don't know the type. */ | 1174 /* Can't load the value if we don't know the type. */ |
1142 if (is_volatile && !is_complete) | 1175 if (is_volatile && !is_complete) |
1570 if (type == error_mark_node || expr == error_mark_node) | 1603 if (type == error_mark_node || expr == error_mark_node) |
1571 return error_mark_node; | 1604 return error_mark_node; |
1572 | 1605 |
1573 intype = TREE_TYPE (expr); | 1606 intype = TREE_TYPE (expr); |
1574 | 1607 |
1575 if (POINTER_TYPE_P (type) && POINTER_TYPE_P (intype)) | 1608 if (INDIRECT_TYPE_P (type) && INDIRECT_TYPE_P (intype)) |
1576 return build_nop (type, expr); | 1609 return build_nop (type, expr); |
1577 | 1610 |
1578 return ocp_convert (type, expr, CONV_BACKEND_CONVERT, | 1611 return ocp_convert (type, expr, CONV_BACKEND_CONVERT, |
1579 LOOKUP_NORMAL|LOOKUP_NO_CONVERSION, | 1612 LOOKUP_NORMAL|LOOKUP_NO_CONVERSION, |
1580 tf_warning_or_error); | 1613 tf_warning_or_error); |
1640 { | 1673 { |
1641 tree basetype = TREE_TYPE (expr); | 1674 tree basetype = TREE_TYPE (expr); |
1642 tree conv = NULL_TREE; | 1675 tree conv = NULL_TREE; |
1643 tree winner = NULL_TREE; | 1676 tree winner = NULL_TREE; |
1644 | 1677 |
1645 if (expr == null_node | 1678 if (null_node_p (expr) |
1646 && (desires & WANT_INT) | 1679 && (desires & WANT_INT) |
1647 && !(desires & WANT_NULL)) | 1680 && !(desires & WANT_NULL)) |
1648 { | 1681 { |
1649 source_location loc = | 1682 source_location loc = |
1650 expansion_point_location_if_in_system_header (input_location); | 1683 expansion_point_location_if_in_system_header (input_location); |
1913 return false; | 1946 return false; |
1914 } | 1947 } |
1915 | 1948 |
1916 /* Attempt to perform qualification conversions on EXPR to convert it | 1949 /* Attempt to perform qualification conversions on EXPR to convert it |
1917 to TYPE. Return the resulting expression, or error_mark_node if | 1950 to TYPE. Return the resulting expression, or error_mark_node if |
1918 the conversion was impossible. */ | 1951 the conversion was impossible. Since this is only used by |
1952 convert_nontype_argument, we fold the conversion. */ | |
1919 | 1953 |
1920 tree | 1954 tree |
1921 perform_qualification_conversions (tree type, tree expr) | 1955 perform_qualification_conversions (tree type, tree expr) |
1922 { | 1956 { |
1923 tree expr_type; | 1957 tree expr_type; |
1925 expr_type = TREE_TYPE (expr); | 1959 expr_type = TREE_TYPE (expr); |
1926 | 1960 |
1927 if (same_type_p (type, expr_type)) | 1961 if (same_type_p (type, expr_type)) |
1928 return expr; | 1962 return expr; |
1929 else if (can_convert_qual (type, expr)) | 1963 else if (can_convert_qual (type, expr)) |
1930 return build_nop (type, expr); | 1964 return cp_fold_convert (type, expr); |
1931 else | 1965 else |
1932 return error_mark_node; | 1966 return error_mark_node; |
1933 } | 1967 } |
1934 | 1968 |
1935 /* True iff T is a transaction-safe function type. */ | 1969 /* True iff T is a transaction-safe function type. */ |
1979 && TYPE_PTRMEMFUNC_P (f)) | 2013 && TYPE_PTRMEMFUNC_P (f)) |
1980 { | 2014 { |
1981 t = TYPE_PTRMEMFUNC_FN_TYPE (t); | 2015 t = TYPE_PTRMEMFUNC_FN_TYPE (t); |
1982 f = TYPE_PTRMEMFUNC_FN_TYPE (f); | 2016 f = TYPE_PTRMEMFUNC_FN_TYPE (f); |
1983 } | 2017 } |
1984 if (TREE_CODE (t) == POINTER_TYPE | 2018 if (TYPE_PTR_P (t) |
1985 && TREE_CODE (f) == POINTER_TYPE) | 2019 && TYPE_PTR_P (f)) |
1986 { | 2020 { |
1987 t = TREE_TYPE (t); | 2021 t = TREE_TYPE (t); |
1988 f = TREE_TYPE (f); | 2022 f = TREE_TYPE (f); |
1989 } | 2023 } |
1990 tree_code code = TREE_CODE (f); | 2024 tree_code code = TREE_CODE (f); |
2010 && TYPE_PTRMEMFUNC_P (f)) | 2044 && TYPE_PTRMEMFUNC_P (f)) |
2011 { | 2045 { |
2012 t = TYPE_PTRMEMFUNC_FN_TYPE (t); | 2046 t = TYPE_PTRMEMFUNC_FN_TYPE (t); |
2013 f = TYPE_PTRMEMFUNC_FN_TYPE (f); | 2047 f = TYPE_PTRMEMFUNC_FN_TYPE (f); |
2014 } | 2048 } |
2015 if (TREE_CODE (t) == POINTER_TYPE | 2049 if (TYPE_PTR_P (t) |
2016 && TREE_CODE (f) == POINTER_TYPE) | 2050 && TYPE_PTR_P (f)) |
2017 { | 2051 { |
2018 t = TREE_TYPE (t); | 2052 t = TREE_TYPE (t); |
2019 f = TREE_TYPE (f); | 2053 f = TREE_TYPE (f); |
2020 } | 2054 } |
2021 | 2055 |