Mercurial > hg > CbC > CbC_gcc
comparison gcc/cp/cvt.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* Language-level data type conversion for GNU C++. | 1 /* Language-level data type conversion for GNU C++. |
2 Copyright (C) 1987-2018 Free Software Foundation, Inc. | 2 Copyright (C) 1987-2020 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 |
33 #include "flags.h" | 33 #include "flags.h" |
34 #include "intl.h" | 34 #include "intl.h" |
35 #include "convert.h" | 35 #include "convert.h" |
36 #include "stringpool.h" | 36 #include "stringpool.h" |
37 #include "attribs.h" | 37 #include "attribs.h" |
38 #include "escaped_string.h" | |
38 | 39 |
39 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t); | 40 static tree convert_to_pointer_force (tree, tree, tsubst_flags_t); |
40 static tree build_type_conversion (tree, tree); | 41 static tree build_type_conversion (tree, tree); |
41 static tree build_up_reference (tree, tree, int, tree, tsubst_flags_t); | 42 static tree build_up_reference (tree, tree, int, tree, tsubst_flags_t); |
42 static void diagnose_ref_binding (location_t, tree, tree, tree); | 43 static void diagnose_ref_binding (location_t, tree, tree, tree); |
75 tsubst_flags_t complain) | 76 tsubst_flags_t complain) |
76 { | 77 { |
77 tree intype = TREE_TYPE (expr); | 78 tree intype = TREE_TYPE (expr); |
78 enum tree_code form; | 79 enum tree_code form; |
79 tree rval; | 80 tree rval; |
80 location_t loc = cp_expr_loc_or_loc (expr, input_location); | 81 location_t loc = cp_expr_loc_or_input_loc (expr); |
81 | 82 |
82 if (intype == error_mark_node) | 83 if (intype == error_mark_node) |
83 return error_mark_node; | 84 return error_mark_node; |
84 | 85 |
85 if (MAYBE_CLASS_TYPE_P (intype)) | 86 if (MAYBE_CLASS_TYPE_P (intype)) |
86 { | 87 { |
87 intype = complete_type (intype); | 88 intype = complete_type (intype); |
88 if (!COMPLETE_TYPE_P (intype)) | 89 if (!COMPLETE_TYPE_P (intype)) |
89 { | 90 { |
90 if (complain & tf_error) | 91 if (complain & tf_error) |
91 error_at (loc, "can%'t convert from incomplete type %qH to %qI", | 92 error_at (loc, "cannot convert from incomplete type %qH to %qI", |
92 intype, type); | 93 intype, type); |
93 return error_mark_node; | 94 return error_mark_node; |
94 } | 95 } |
95 | 96 |
96 rval = build_type_conversion (type, expr); | 97 rval = build_type_conversion (type, expr); |
417 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (reftype)); | 418 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (reftype)); |
418 tree intype; | 419 tree intype; |
419 tree rval = NULL_TREE; | 420 tree rval = NULL_TREE; |
420 tree rval_as_conversion = NULL_TREE; | 421 tree rval_as_conversion = NULL_TREE; |
421 bool can_convert_intype_to_type; | 422 bool can_convert_intype_to_type; |
422 location_t loc = cp_expr_loc_or_loc (expr, input_location); | 423 location_t loc = cp_expr_loc_or_input_loc (expr); |
423 | 424 |
424 if (TREE_CODE (type) == FUNCTION_TYPE | 425 if (TREE_CODE (type) == FUNCTION_TYPE |
425 && TREE_TYPE (expr) == unknown_type_node) | 426 && TREE_TYPE (expr) == unknown_type_node) |
426 expr = instantiate_type (type, expr, complain); | 427 expr = instantiate_type (type, expr, complain); |
427 | 428 |
560 force_rvalue (tree expr, tsubst_flags_t complain) | 561 force_rvalue (tree expr, tsubst_flags_t complain) |
561 { | 562 { |
562 tree type = TREE_TYPE (expr); | 563 tree type = TREE_TYPE (expr); |
563 if (MAYBE_CLASS_TYPE_P (type) && TREE_CODE (expr) != TARGET_EXPR) | 564 if (MAYBE_CLASS_TYPE_P (type) && TREE_CODE (expr) != TARGET_EXPR) |
564 { | 565 { |
565 vec<tree, va_gc> *args = make_tree_vector_single (expr); | 566 releasing_vec args (make_tree_vector_single (expr)); |
566 expr = build_special_member_call (NULL_TREE, complete_ctor_identifier, | 567 expr = build_special_member_call (NULL_TREE, complete_ctor_identifier, |
567 &args, type, LOOKUP_NORMAL, complain); | 568 &args, type, LOOKUP_NORMAL, complain); |
568 release_tree_vector (args); | |
569 expr = build_cplus_new (type, expr, complain); | 569 expr = build_cplus_new (type, expr, complain); |
570 } | 570 } |
571 else | 571 else |
572 expr = decay_conversion (expr, complain); | 572 expr = decay_conversion (expr, complain); |
573 | 573 |
580 unchanged. */ | 580 unchanged. */ |
581 | 581 |
582 static tree | 582 static tree |
583 ignore_overflows (tree expr, tree orig) | 583 ignore_overflows (tree expr, tree orig) |
584 { | 584 { |
585 if (TREE_CODE (expr) == INTEGER_CST | 585 tree stripped_expr = tree_strip_any_location_wrapper (expr); |
586 && TREE_CODE (orig) == INTEGER_CST | 586 tree stripped_orig = tree_strip_any_location_wrapper (orig); |
587 && TREE_OVERFLOW (expr) != TREE_OVERFLOW (orig)) | 587 |
588 { | 588 if (TREE_CODE (stripped_expr) == INTEGER_CST |
589 gcc_assert (!TREE_OVERFLOW (orig)); | 589 && TREE_CODE (stripped_orig) == INTEGER_CST |
590 && TREE_OVERFLOW (stripped_expr) != TREE_OVERFLOW (stripped_orig)) | |
591 { | |
592 gcc_assert (!TREE_OVERFLOW (stripped_orig)); | |
590 /* Ensure constant sharing. */ | 593 /* Ensure constant sharing. */ |
591 expr = wide_int_to_tree (TREE_TYPE (expr), wi::to_wide (expr)); | 594 stripped_expr = wide_int_to_tree (TREE_TYPE (stripped_expr), |
592 } | 595 wi::to_wide (stripped_expr)); |
593 return expr; | 596 } |
597 | |
598 return preserve_any_location_wrapper (stripped_expr, expr); | |
594 } | 599 } |
595 | 600 |
596 /* Fold away simple conversions, but make sure TREE_OVERFLOW is set | 601 /* Fold away simple conversions, but make sure TREE_OVERFLOW is set |
597 properly. */ | 602 properly. */ |
598 | 603 |
665 folded_result = cp_convert (type, folded, tf_none); | 670 folded_result = cp_convert (type, folded, tf_none); |
666 } | 671 } |
667 folded_result = fold_simple (folded_result); | 672 folded_result = fold_simple (folded_result); |
668 if (!TREE_OVERFLOW_P (folded) | 673 if (!TREE_OVERFLOW_P (folded) |
669 && folded_result != error_mark_node) | 674 && folded_result != error_mark_node) |
670 warnings_for_convert_and_check (cp_expr_loc_or_loc (expr, input_location), | 675 warnings_for_convert_and_check (cp_expr_loc_or_input_loc (expr), |
671 type, folded, folded_result); | 676 type, folded, folded_result); |
672 } | 677 } |
673 | 678 |
674 return result; | 679 return result; |
675 } | 680 } |
684 { | 689 { |
685 tree e = expr; | 690 tree e = expr; |
686 enum tree_code code = TREE_CODE (type); | 691 enum tree_code code = TREE_CODE (type); |
687 const char *invalid_conv_diag; | 692 const char *invalid_conv_diag; |
688 tree e1; | 693 tree e1; |
689 location_t loc = cp_expr_loc_or_loc (expr, input_location); | 694 location_t loc = cp_expr_loc_or_input_loc (expr); |
690 bool dofold = (convtype & CONV_FOLD); | 695 bool dofold = (convtype & CONV_FOLD); |
691 | 696 |
692 if (error_operand_p (e) || type == error_mark_node) | 697 if (error_operand_p (e) || type == error_mark_node) |
693 return error_mark_node; | 698 return error_mark_node; |
694 | 699 |
723 | 728 |
724 if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP)) | 729 if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP)) |
725 /* We need a new temporary; don't take this shortcut. */; | 730 /* We need a new temporary; don't take this shortcut. */; |
726 else if (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (e))) | 731 else if (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (e))) |
727 { | 732 { |
728 if (same_type_p (type, TREE_TYPE (e))) | 733 tree etype = TREE_TYPE (e); |
734 if (same_type_p (type, etype)) | |
729 /* The call to fold will not always remove the NOP_EXPR as | 735 /* The call to fold will not always remove the NOP_EXPR as |
730 might be expected, since if one of the types is a typedef; | 736 might be expected, since if one of the types is a typedef; |
731 the comparison in fold is just equality of pointers, not a | 737 the comparison in fold is just equality of pointers, not a |
732 call to comptypes. We don't call fold in this case because | 738 call to comptypes. We don't call fold in this case because |
733 that can result in infinite recursion; fold will call | 739 that can result in infinite recursion; fold will call |
736 /* For complex data types, we need to perform componentwise | 742 /* For complex data types, we need to perform componentwise |
737 conversion. */ | 743 conversion. */ |
738 else if (TREE_CODE (type) == COMPLEX_TYPE) | 744 else if (TREE_CODE (type) == COMPLEX_TYPE) |
739 return convert_to_complex_maybe_fold (type, e, dofold); | 745 return convert_to_complex_maybe_fold (type, e, dofold); |
740 else if (VECTOR_TYPE_P (type)) | 746 else if (VECTOR_TYPE_P (type)) |
741 return convert_to_vector (type, e); | 747 return convert_to_vector (type, rvalue (e)); |
742 else if (TREE_CODE (e) == TARGET_EXPR) | 748 else if (TREE_CODE (e) == TARGET_EXPR) |
743 { | 749 { |
744 /* Don't build a NOP_EXPR of class type. Instead, change the | 750 /* Don't build a NOP_EXPR of class type. Instead, change the |
745 type of the temporary. */ | 751 type of the temporary. */ |
752 gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, etype)); | |
746 TREE_TYPE (e) = TREE_TYPE (TARGET_EXPR_SLOT (e)) = type; | 753 TREE_TYPE (e) = TREE_TYPE (TARGET_EXPR_SLOT (e)) = type; |
754 return e; | |
755 } | |
756 else if (TREE_CODE (e) == CONSTRUCTOR) | |
757 { | |
758 gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, etype)); | |
759 TREE_TYPE (e) = type; | |
747 return e; | 760 return e; |
748 } | 761 } |
749 else | 762 else |
750 { | 763 { |
751 /* We shouldn't be treating objects of ADDRESSABLE type as | 764 /* We shouldn't be treating objects of ADDRESSABLE type as |
790 8. A value of integral or enumeration type can be explicitly | 803 8. A value of integral or enumeration type can be explicitly |
791 converted to an enumeration type. The value is unchanged if | 804 converted to an enumeration type. The value is unchanged if |
792 the original value is within the range of the enumeration | 805 the original value is within the range of the enumeration |
793 values. Otherwise, the resulting enumeration value is | 806 values. Otherwise, the resulting enumeration value is |
794 unspecified. */ | 807 unspecified. */ |
808 tree val = fold_for_warn (e); | |
795 if ((complain & tf_warning) | 809 if ((complain & tf_warning) |
796 && TREE_CODE (e) == INTEGER_CST | 810 && TREE_CODE (val) == INTEGER_CST |
797 && ENUM_UNDERLYING_TYPE (type) | 811 && ENUM_UNDERLYING_TYPE (type) |
798 && !int_fits_type_p (e, ENUM_UNDERLYING_TYPE (type))) | 812 && !int_fits_type_p (val, ENUM_UNDERLYING_TYPE (type))) |
799 warning_at (loc, OPT_Wconversion, | 813 warning_at (loc, OPT_Wconversion, |
800 "the result of the conversion is unspecified because " | 814 "the result of the conversion is unspecified because " |
801 "%qE is outside the range of type %qT", | 815 "%qE is outside the range of type %qT", |
802 expr, type); | 816 expr, type); |
803 } | 817 } |
820 "could not convert %qE from %<void%> to %<bool%>", | 834 "could not convert %qE from %<void%> to %<bool%>", |
821 expr); | 835 expr); |
822 return error_mark_node; | 836 return error_mark_node; |
823 } | 837 } |
824 | 838 |
839 if (VECTOR_TYPE_P (intype) && !gnu_vector_type_p (intype)) | |
840 { | |
841 if (complain & tf_error) | |
842 error_at (loc, "could not convert %qE from %qH to %qI", expr, | |
843 TREE_TYPE (expr), type); | |
844 return error_mark_node; | |
845 } | |
846 | |
825 /* We can't implicitly convert a scoped enum to bool, so convert | 847 /* We can't implicitly convert a scoped enum to bool, so convert |
826 to the underlying type first. */ | 848 to the underlying type first. */ |
827 if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC)) | 849 if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC)) |
828 e = build_nop (ENUM_UNDERLYING_TYPE (intype), e); | 850 e = build_nop (ENUM_UNDERLYING_TYPE (intype), e); |
829 if (complain & tf_warning) | 851 if (complain & tf_warning) |
830 return cp_truthvalue_conversion (e); | 852 return cp_truthvalue_conversion (e, complain); |
831 else | 853 else |
832 { | 854 { |
833 /* Prevent bogus -Wint-in-bool-context warnings coming | 855 /* Prevent bogus -Wint-in-bool-context warnings coming |
834 from c_common_truthvalue_conversion down the line. */ | 856 from c_common_truthvalue_conversion down the line. */ |
835 warning_sentinel w (warn_int_in_bool_context); | 857 warning_sentinel w (warn_int_in_bool_context); |
836 return cp_truthvalue_conversion (e); | 858 warning_sentinel c (warn_sign_compare); |
859 return cp_truthvalue_conversion (e, complain); | |
837 } | 860 } |
838 } | 861 } |
839 | 862 |
840 converted = convert_to_integer_maybe_fold (type, e, dofold); | 863 converted = convert_to_integer_maybe_fold (type, e, dofold); |
841 | 864 |
856 if (complain & tf_error) | 879 if (complain & tf_error) |
857 error_at (loc, "%q#T used where a %qT was expected", | 880 error_at (loc, "%q#T used where a %qT was expected", |
858 in_vtype, type); | 881 in_vtype, type); |
859 return error_mark_node; | 882 return error_mark_node; |
860 } | 883 } |
861 return convert_to_vector (type, e); | 884 return convert_to_vector (type, rvalue (e)); |
862 } | 885 } |
863 if (code == REAL_TYPE || code == COMPLEX_TYPE) | 886 if (code == REAL_TYPE || code == COMPLEX_TYPE) |
864 { | 887 { |
865 if (MAYBE_CLASS_TYPE_P (TREE_TYPE (e))) | 888 if (MAYBE_CLASS_TYPE_P (TREE_TYPE (e))) |
866 { | 889 { |
868 rval = build_type_conversion (type, e); | 891 rval = build_type_conversion (type, e); |
869 if (rval) | 892 if (rval) |
870 return rval; | 893 return rval; |
871 else if (complain & tf_error) | 894 else if (complain & tf_error) |
872 error_at (loc, | 895 error_at (loc, |
873 "%q#T used where a floating point value was expected", | 896 "%q#T used where a floating-point value was expected", |
874 TREE_TYPE (e)); | 897 TREE_TYPE (e)); |
875 } | 898 } |
876 if (code == REAL_TYPE) | 899 if (code == REAL_TYPE) |
877 return convert_to_real_maybe_fold (type, e, dofold); | 900 return convert_to_real_maybe_fold (type, e, dofold); |
878 else if (code == COMPLEX_TYPE) | 901 else if (code == COMPLEX_TYPE) |
909 with a user-defined conversion sequence, then we direct-initialize | 932 with a user-defined conversion sequence, then we direct-initialize |
910 the target with the temp (see [dcl.init]). */ | 933 the target with the temp (see [dcl.init]). */ |
911 ctor = build_user_type_conversion (type, ctor, flags, complain); | 934 ctor = build_user_type_conversion (type, ctor, flags, complain); |
912 else | 935 else |
913 { | 936 { |
914 vec<tree, va_gc> *ctor_vec = make_tree_vector_single (ctor); | 937 releasing_vec ctor_vec (make_tree_vector_single (ctor)); |
915 ctor = build_special_member_call (NULL_TREE, | 938 ctor = build_special_member_call (NULL_TREE, |
916 complete_ctor_identifier, | 939 complete_ctor_identifier, |
917 &ctor_vec, | 940 &ctor_vec, |
918 type, flags, complain); | 941 type, flags, complain); |
919 release_tree_vector (ctor_vec); | |
920 } | 942 } |
921 if (ctor) | 943 if (ctor) |
922 return build_cplus_new (type, ctor, complain); | 944 return build_cplus_new (type, ctor, complain); |
923 } | 945 } |
924 | 946 |
999 maybe_warn_nodiscard (tree expr, impl_conv_void implicit) | 1021 maybe_warn_nodiscard (tree expr, impl_conv_void implicit) |
1000 { | 1022 { |
1001 tree call = expr; | 1023 tree call = expr; |
1002 if (TREE_CODE (expr) == TARGET_EXPR) | 1024 if (TREE_CODE (expr) == TARGET_EXPR) |
1003 call = TARGET_EXPR_INITIAL (expr); | 1025 call = TARGET_EXPR_INITIAL (expr); |
1004 location_t loc = cp_expr_loc_or_loc (call, input_location); | 1026 location_t loc = cp_expr_loc_or_input_loc (call); |
1005 tree callee = cp_get_callee (call); | 1027 tree callee = cp_get_callee (call); |
1006 if (!callee) | 1028 if (!callee) |
1007 return; | 1029 return; |
1008 | 1030 |
1009 tree type = TREE_TYPE (callee); | 1031 tree type = TREE_TYPE (callee); |
1012 if (INDIRECT_TYPE_P (type)) | 1034 if (INDIRECT_TYPE_P (type)) |
1013 type = TREE_TYPE (type); | 1035 type = TREE_TYPE (type); |
1014 | 1036 |
1015 tree rettype = TREE_TYPE (type); | 1037 tree rettype = TREE_TYPE (type); |
1016 tree fn = cp_get_fndecl_from_callee (callee); | 1038 tree fn = cp_get_fndecl_from_callee (callee); |
1039 tree attr; | |
1017 if (implicit != ICV_CAST && fn | 1040 if (implicit != ICV_CAST && fn |
1018 && lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn))) | 1041 && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn)))) |
1019 { | 1042 { |
1043 escaped_string msg; | |
1044 tree args = TREE_VALUE (attr); | |
1045 if (args) | |
1046 msg.escape (TREE_STRING_POINTER (TREE_VALUE (args))); | |
1047 const char *format | |
1048 = (msg | |
1049 ? G_("ignoring return value of %qD, " | |
1050 "declared with attribute %<nodiscard%>: %<%s%>") | |
1051 : G_("ignoring return value of %qD, " | |
1052 "declared with attribute %<nodiscard%>%s")); | |
1053 const char *raw_msg = msg ? (const char *) msg : ""; | |
1020 auto_diagnostic_group d; | 1054 auto_diagnostic_group d; |
1021 if (warning_at (loc, OPT_Wunused_result, | 1055 if (warning_at (loc, OPT_Wunused_result, format, fn, raw_msg)) |
1022 "ignoring return value of %qD, " | |
1023 "declared with attribute nodiscard", fn)) | |
1024 inform (DECL_SOURCE_LOCATION (fn), "declared here"); | 1056 inform (DECL_SOURCE_LOCATION (fn), "declared here"); |
1025 } | 1057 } |
1026 else if (implicit != ICV_CAST | 1058 else if (implicit != ICV_CAST |
1027 && lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype))) | 1059 && (attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype)))) |
1028 { | 1060 { |
1061 escaped_string msg; | |
1062 tree args = TREE_VALUE (attr); | |
1063 if (args) | |
1064 msg.escape (TREE_STRING_POINTER (TREE_VALUE (args))); | |
1065 const char *format | |
1066 = (msg | |
1067 ? G_("ignoring returned value of type %qT, " | |
1068 "declared with attribute %<nodiscard%>: %<%s%>") | |
1069 : G_("ignoring returned value of type %qT, " | |
1070 "declared with attribute %<nodiscard%>%s")); | |
1071 const char *raw_msg = msg ? (const char *) msg : ""; | |
1029 auto_diagnostic_group d; | 1072 auto_diagnostic_group d; |
1030 if (warning_at (loc, OPT_Wunused_result, | 1073 if (warning_at (loc, OPT_Wunused_result, format, rettype, raw_msg)) |
1031 "ignoring returned value of type %qT, " | |
1032 "declared with attribute nodiscard", rettype)) | |
1033 { | 1074 { |
1034 if (fn) | 1075 if (fn) |
1035 inform (DECL_SOURCE_LOCATION (fn), | 1076 inform (DECL_SOURCE_LOCATION (fn), |
1036 "in call to %qD, declared here", fn); | 1077 "in call to %qD, declared here", fn); |
1037 inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype)), | 1078 inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype)), |
1046 if (fn) | 1087 if (fn) |
1047 { | 1088 { |
1048 auto_diagnostic_group d; | 1089 auto_diagnostic_group d; |
1049 if (warning_at (loc, OPT_Wunused_result, | 1090 if (warning_at (loc, OPT_Wunused_result, |
1050 "ignoring return value of %qD, " | 1091 "ignoring return value of %qD, " |
1051 "declared with attribute warn_unused_result", | 1092 "declared with attribute %<warn_unused_result%>", |
1052 fn)) | 1093 fn)) |
1053 inform (DECL_SOURCE_LOCATION (fn), "declared here"); | 1094 inform (DECL_SOURCE_LOCATION (fn), "declared here"); |
1054 } | 1095 } |
1055 else | 1096 else |
1056 warning_at (loc, OPT_Wunused_result, | 1097 warning_at (loc, OPT_Wunused_result, |
1057 "ignoring return value of function " | 1098 "ignoring return value of function " |
1058 "declared with attribute warn_unused_result"); | 1099 "declared with attribute %<warn_unused_result%>"); |
1059 } | 1100 } |
1060 } | 1101 } |
1061 | 1102 |
1062 /* When an expression is used in a void context, its value is discarded and | 1103 /* When an expression is used in a void context, its value is discarded and |
1063 no lvalue-rvalue and similar conversions happen [expr.static.cast/4, | 1104 no lvalue-rvalue and similar conversions happen [expr.static.cast/4, |
1079 indicates the context of the implicit conversion. */ | 1120 indicates the context of the implicit conversion. */ |
1080 | 1121 |
1081 tree | 1122 tree |
1082 convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) | 1123 convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) |
1083 { | 1124 { |
1084 location_t loc = cp_expr_loc_or_loc (expr, input_location); | 1125 location_t loc = cp_expr_loc_or_input_loc (expr); |
1085 | 1126 |
1086 if (expr == error_mark_node | 1127 if (expr == error_mark_node |
1087 || TREE_TYPE (expr) == error_mark_node) | 1128 || TREE_TYPE (expr) == error_mark_node) |
1088 return error_mark_node; | 1129 return error_mark_node; |
1089 | 1130 |
1102 { | 1143 { |
1103 if (complain & tf_error) | 1144 if (complain & tf_error) |
1104 error_at (loc, "pseudo-destructor is not called"); | 1145 error_at (loc, "pseudo-destructor is not called"); |
1105 return error_mark_node; | 1146 return error_mark_node; |
1106 } | 1147 } |
1148 | |
1149 /* Explicitly evaluate void-converted concept checks since their | |
1150 satisfaction may produce ill-formed programs. */ | |
1151 if (concept_check_p (expr)) | |
1152 expr = evaluate_concept_check (expr, tf_warning_or_error); | |
1153 | |
1107 if (VOID_TYPE_P (TREE_TYPE (expr))) | 1154 if (VOID_TYPE_P (TREE_TYPE (expr))) |
1108 return expr; | 1155 return expr; |
1109 switch (TREE_CODE (expr)) | 1156 switch (TREE_CODE (expr)) |
1110 { | 1157 { |
1111 case COND_EXPR: | 1158 case COND_EXPR: |
1159 case NOP_EXPR: | 1206 case NOP_EXPR: |
1160 /* These have already decayed to rvalue. */ | 1207 /* These have already decayed to rvalue. */ |
1161 break; | 1208 break; |
1162 | 1209 |
1163 case CALL_EXPR: /* We have a special meaning for volatile void fn(). */ | 1210 case CALL_EXPR: /* We have a special meaning for volatile void fn(). */ |
1164 maybe_warn_nodiscard (expr, implicit); | 1211 /* cdtors may return this or void, depending on |
1212 targetm.cxx.cdtor_returns_this, but this shouldn't affect our | |
1213 decisions here: neither nodiscard warnings (nodiscard cdtors | |
1214 are nonsensical), nor should any constexpr or template | |
1215 instantiations be affected by an ABI property that is, or at | |
1216 least ought to be transparent to the language. */ | |
1217 if (tree fn = cp_get_callee_fndecl_nofold (expr)) | |
1218 if (DECL_DESTRUCTOR_P (fn)) | |
1219 return expr; | |
1220 | |
1221 if (complain & tf_warning) | |
1222 maybe_warn_nodiscard (expr, implicit); | |
1165 break; | 1223 break; |
1166 | 1224 |
1167 case INDIRECT_REF: | 1225 case INDIRECT_REF: |
1168 { | 1226 { |
1169 tree type = TREE_TYPE (expr); | 1227 tree type = TREE_TYPE (expr); |
1315 && (complain & tf_warning) | 1373 && (complain & tf_warning) |
1316 && !TREE_NO_WARNING (expr) | 1374 && !TREE_NO_WARNING (expr) |
1317 && !is_reference) | 1375 && !is_reference) |
1318 warning_at (loc, OPT_Wunused_value, "value computed is not used"); | 1376 warning_at (loc, OPT_Wunused_value, "value computed is not used"); |
1319 expr = TREE_OPERAND (expr, 0); | 1377 expr = TREE_OPERAND (expr, 0); |
1320 if (TREE_CODE (expr) == CALL_EXPR) | 1378 if (TREE_CODE (expr) == CALL_EXPR |
1379 && (complain & tf_warning)) | |
1321 maybe_warn_nodiscard (expr, implicit); | 1380 maybe_warn_nodiscard (expr, implicit); |
1322 } | 1381 } |
1323 | 1382 |
1324 break; | 1383 break; |
1325 } | 1384 } |
1393 fn, | 1452 fn, |
1394 aggr_init_expr_nargs (init), | 1453 aggr_init_expr_nargs (init), |
1395 AGGR_INIT_EXPR_ARGP (init)); | 1454 AGGR_INIT_EXPR_ARGP (init)); |
1396 } | 1455 } |
1397 } | 1456 } |
1398 maybe_warn_nodiscard (expr, implicit); | 1457 if (complain & tf_warning) |
1458 maybe_warn_nodiscard (expr, implicit); | |
1399 break; | 1459 break; |
1400 | 1460 |
1401 default:; | 1461 default:; |
1402 } | 1462 } |
1403 expr = resolve_nondeduced_context (expr, complain); | 1463 expr = resolve_nondeduced_context (expr, complain); |
1494 if (expr != error_mark_node && !VOID_TYPE_P (TREE_TYPE (expr))) | 1554 if (expr != error_mark_node && !VOID_TYPE_P (TREE_TYPE (expr))) |
1495 { | 1555 { |
1496 if (implicit != ICV_CAST | 1556 if (implicit != ICV_CAST |
1497 && warn_unused_value | 1557 && warn_unused_value |
1498 && !TREE_NO_WARNING (expr) | 1558 && !TREE_NO_WARNING (expr) |
1499 && !processing_template_decl) | 1559 && !processing_template_decl |
1560 && !cp_unevaluated_operand) | |
1500 { | 1561 { |
1501 /* The middle end does not warn about expressions that have | 1562 /* The middle end does not warn about expressions that have |
1502 been explicitly cast to void, so we must do so here. */ | 1563 been explicitly cast to void, so we must do so here. */ |
1503 if (!TREE_SIDE_EFFECTS (expr)) { | 1564 if (!TREE_SIDE_EFFECTS (expr)) { |
1504 if (complain & tf_warning) | 1565 if (complain & tf_warning) |
1677 | 1738 |
1678 if (null_node_p (expr) | 1739 if (null_node_p (expr) |
1679 && (desires & WANT_INT) | 1740 && (desires & WANT_INT) |
1680 && !(desires & WANT_NULL)) | 1741 && !(desires & WANT_NULL)) |
1681 { | 1742 { |
1682 source_location loc = | 1743 location_t loc = |
1683 expansion_point_location_if_in_system_header (input_location); | 1744 expansion_point_location_if_in_system_header (input_location); |
1684 | 1745 |
1685 warning_at (loc, OPT_Wconversion_null, | 1746 warning_at (loc, OPT_Wconversion_null, |
1686 "converting NULL to non-pointer type"); | 1747 "converting NULL to non-pointer type"); |
1687 } | 1748 } |
1710 case ARRAY_TYPE: | 1771 case ARRAY_TYPE: |
1711 return (desires & WANT_POINTER) ? decay_conversion (expr, | 1772 return (desires & WANT_POINTER) ? decay_conversion (expr, |
1712 tf_warning_or_error) | 1773 tf_warning_or_error) |
1713 : NULL_TREE; | 1774 : NULL_TREE; |
1714 | 1775 |
1776 case VECTOR_TYPE: | |
1777 if (!gnu_vector_type_p (basetype)) | |
1778 return NULL_TREE; | |
1779 /* FALLTHROUGH */ | |
1715 case COMPLEX_TYPE: | 1780 case COMPLEX_TYPE: |
1716 case VECTOR_TYPE: | |
1717 if ((desires & WANT_VECTOR_OR_COMPLEX) == 0) | 1781 if ((desires & WANT_VECTOR_OR_COMPLEX) == 0) |
1718 return NULL_TREE; | 1782 return NULL_TREE; |
1719 switch (TREE_CODE (TREE_TYPE (basetype))) | 1783 switch (TREE_CODE (TREE_TYPE (basetype))) |
1720 { | 1784 { |
1721 case INTEGER_TYPE: | 1785 case INTEGER_TYPE: |
1796 if (win) | 1860 if (win) |
1797 { | 1861 { |
1798 if (TREE_CODE (cand) == TEMPLATE_DECL) | 1862 if (TREE_CODE (cand) == TEMPLATE_DECL) |
1799 { | 1863 { |
1800 if (complain) | 1864 if (complain) |
1801 error ("default type conversion can't deduce template" | 1865 error ("default type conversion cannot deduce template" |
1802 " argument for %qD", cand); | 1866 " argument for %qD", cand); |
1803 return error_mark_node; | 1867 return error_mark_node; |
1804 } | 1868 } |
1805 | 1869 |
1806 if (winner) | 1870 if (winner) |
1861 | 1925 |
1862 /* Normally convert enums to int, but convert wide enums to something | 1926 /* Normally convert enums to int, but convert wide enums to something |
1863 wider. Scoped enums don't promote, but pretend they do for backward | 1927 wider. Scoped enums don't promote, but pretend they do for backward |
1864 ABI bug compatibility wrt varargs. */ | 1928 ABI bug compatibility wrt varargs. */ |
1865 else if (TREE_CODE (type) == ENUMERAL_TYPE | 1929 else if (TREE_CODE (type) == ENUMERAL_TYPE |
1930 || type == char8_type_node | |
1866 || type == char16_type_node | 1931 || type == char16_type_node |
1867 || type == char32_type_node | 1932 || type == char32_type_node |
1868 || type == wchar_type_node) | 1933 || type == wchar_type_node) |
1869 { | 1934 { |
1870 tree prom = type; | 1935 tree prom = type; |
1895 prom = totype; | 1960 prom = totype; |
1896 if (SCOPED_ENUM_P (type)) | 1961 if (SCOPED_ENUM_P (type)) |
1897 { | 1962 { |
1898 if (abi_version_crosses (6) | 1963 if (abi_version_crosses (6) |
1899 && TYPE_MODE (prom) != TYPE_MODE (type)) | 1964 && TYPE_MODE (prom) != TYPE_MODE (type)) |
1900 warning (OPT_Wabi, "scoped enum %qT passed through ... as " | 1965 warning (OPT_Wabi, "scoped enum %qT passed through %<...%> as " |
1901 "%qT before -fabi-version=6, %qT after", | 1966 "%qT before %<-fabi-version=6%>, %qT after", |
1902 type, prom, ENUM_UNDERLYING_TYPE (type)); | 1967 type, prom, ENUM_UNDERLYING_TYPE (type)); |
1903 if (!abi_version_at_least (6)) | 1968 if (!abi_version_at_least (6)) |
1904 type = prom; | 1969 type = prom; |
1905 } | 1970 } |
1906 else | 1971 else |
1969 /* True iff T is a transaction-safe function type. */ | 2034 /* True iff T is a transaction-safe function type. */ |
1970 | 2035 |
1971 bool | 2036 bool |
1972 tx_safe_fn_type_p (tree t) | 2037 tx_safe_fn_type_p (tree t) |
1973 { | 2038 { |
1974 if (TREE_CODE (t) != FUNCTION_TYPE | 2039 if (!FUNC_OR_METHOD_TYPE_P (t)) |
1975 && TREE_CODE (t) != METHOD_TYPE) | |
1976 return false; | 2040 return false; |
1977 return !!lookup_attribute ("transaction_safe", TYPE_ATTRIBUTES (t)); | 2041 return !!lookup_attribute ("transaction_safe", TYPE_ATTRIBUTES (t)); |
1978 } | 2042 } |
1979 | 2043 |
1980 /* Return the transaction-unsafe variant of transaction-safe function type | 2044 /* Return the transaction-unsafe variant of transaction-safe function type |