Mercurial > hg > CbC > CbC_gcc
comparison gcc/cp/tree.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-dependent node constructors for parse phase of GNU compiler. | 1 /* Language-dependent node constructors for parse phase of GNU compiler. |
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 |
33 #include "convert.h" | 33 #include "convert.h" |
34 #include "gimplify.h" | 34 #include "gimplify.h" |
35 #include "stringpool.h" | 35 #include "stringpool.h" |
36 #include "attribs.h" | 36 #include "attribs.h" |
37 #include "flags.h" | 37 #include "flags.h" |
38 #include "selftest.h" | |
38 | 39 |
39 static tree bot_manip (tree *, int *, void *); | 40 static tree bot_manip (tree *, int *, void *); |
40 static tree bot_replace (tree *, int *, void *); | 41 static tree bot_replace (tree *, int *, void *); |
41 static hashval_t list_hash_pieces (tree, tree, tree); | 42 static hashval_t list_hash_pieces (tree, tree, tree); |
42 static tree build_target_expr (tree, tree, tsubst_flags_t); | 43 static tree build_target_expr (tree, tree, tsubst_flags_t); |
62 through them. */ | 63 through them. */ |
63 if (REFERENCE_REF_P (ref)) | 64 if (REFERENCE_REF_P (ref)) |
64 return lvalue_kind (TREE_OPERAND (ref, 0)); | 65 return lvalue_kind (TREE_OPERAND (ref, 0)); |
65 | 66 |
66 if (TREE_TYPE (ref) | 67 if (TREE_TYPE (ref) |
67 && TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE) | 68 && TYPE_REF_P (TREE_TYPE (ref))) |
68 { | 69 { |
69 /* unnamed rvalue references are rvalues */ | 70 /* unnamed rvalue references are rvalues */ |
70 if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref)) | 71 if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref)) |
71 && TREE_CODE (ref) != PARM_DECL | 72 && TREE_CODE (ref) != PARM_DECL |
72 && !VAR_P (ref) | 73 && !VAR_P (ref) |
84 | 85 |
85 switch (TREE_CODE (ref)) | 86 switch (TREE_CODE (ref)) |
86 { | 87 { |
87 case SAVE_EXPR: | 88 case SAVE_EXPR: |
88 return clk_none; | 89 return clk_none; |
90 | |
89 /* preincrements and predecrements are valid lvals, provided | 91 /* preincrements and predecrements are valid lvals, provided |
90 what they refer to are valid lvals. */ | 92 what they refer to are valid lvals. */ |
91 case PREINCREMENT_EXPR: | 93 case PREINCREMENT_EXPR: |
92 case PREDECREMENT_EXPR: | 94 case PREDECREMENT_EXPR: |
93 case TRY_CATCH_EXPR: | 95 case TRY_CATCH_EXPR: |
94 case REALPART_EXPR: | 96 case REALPART_EXPR: |
95 case IMAGPART_EXPR: | 97 case IMAGPART_EXPR: |
98 case VIEW_CONVERT_EXPR: | |
96 return lvalue_kind (TREE_OPERAND (ref, 0)); | 99 return lvalue_kind (TREE_OPERAND (ref, 0)); |
100 | |
101 case ARRAY_REF: | |
102 { | |
103 tree op1 = TREE_OPERAND (ref, 0); | |
104 if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE) | |
105 { | |
106 op1_lvalue_kind = lvalue_kind (op1); | |
107 if (op1_lvalue_kind == clk_class) | |
108 /* in the case of an array operand, the result is an lvalue if | |
109 that operand is an lvalue and an xvalue otherwise */ | |
110 op1_lvalue_kind = clk_rvalueref; | |
111 return op1_lvalue_kind; | |
112 } | |
113 else | |
114 return clk_ordinary; | |
115 } | |
97 | 116 |
98 case MEMBER_REF: | 117 case MEMBER_REF: |
99 case DOTSTAR_EXPR: | 118 case DOTSTAR_EXPR: |
100 if (TREE_CODE (ref) == MEMBER_REF) | 119 if (TREE_CODE (ref) == MEMBER_REF) |
101 op1_lvalue_kind = clk_ordinary; | 120 op1_lvalue_kind = clk_ordinary; |
102 else | 121 else |
103 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); | 122 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); |
104 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1)))) | 123 if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1)))) |
105 op1_lvalue_kind = clk_none; | 124 op1_lvalue_kind = clk_none; |
125 else if (op1_lvalue_kind == clk_class) | |
126 /* The result of a .* expression whose second operand is a pointer to a | |
127 data member is an lvalue if the first operand is an lvalue and an | |
128 xvalue otherwise. */ | |
129 op1_lvalue_kind = clk_rvalueref; | |
106 return op1_lvalue_kind; | 130 return op1_lvalue_kind; |
107 | 131 |
108 case COMPONENT_REF: | 132 case COMPONENT_REF: |
109 if (BASELINK_P (TREE_OPERAND (ref, 1))) | 133 if (BASELINK_P (TREE_OPERAND (ref, 1))) |
110 { | 134 { |
116 resolve_address_of_overloaded_function. */ | 140 resolve_address_of_overloaded_function. */ |
117 if (TREE_CODE (fn) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (fn)) | 141 if (TREE_CODE (fn) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (fn)) |
118 return lvalue_kind (TREE_OPERAND (ref, 1)); | 142 return lvalue_kind (TREE_OPERAND (ref, 1)); |
119 } | 143 } |
120 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); | 144 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); |
145 if (op1_lvalue_kind == clk_class) | |
146 /* If E1 is an lvalue, then E1.E2 is an lvalue; | |
147 otherwise E1.E2 is an xvalue. */ | |
148 op1_lvalue_kind = clk_rvalueref; | |
149 | |
121 /* Look at the member designator. */ | 150 /* Look at the member designator. */ |
122 if (!op1_lvalue_kind) | 151 if (!op1_lvalue_kind) |
123 ; | 152 ; |
124 else if (is_overloaded_fn (TREE_OPERAND (ref, 1))) | 153 else if (is_overloaded_fn (TREE_OPERAND (ref, 1))) |
125 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some | 154 /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some |
162 && DECL_IN_AGGR_P (ref)) | 191 && DECL_IN_AGGR_P (ref)) |
163 return clk_none; | 192 return clk_none; |
164 /* FALLTHRU */ | 193 /* FALLTHRU */ |
165 case INDIRECT_REF: | 194 case INDIRECT_REF: |
166 case ARROW_EXPR: | 195 case ARROW_EXPR: |
167 case ARRAY_REF: | |
168 case ARRAY_NOTATION_REF: | |
169 case PARM_DECL: | 196 case PARM_DECL: |
170 case RESULT_DECL: | 197 case RESULT_DECL: |
171 case PLACEHOLDER_EXPR: | 198 case PLACEHOLDER_EXPR: |
172 return clk_ordinary; | 199 return clk_ordinary; |
173 | 200 |
192 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); | 219 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); |
193 op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1)); | 220 op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1)); |
194 break; | 221 break; |
195 | 222 |
196 case COND_EXPR: | 223 case COND_EXPR: |
224 if (processing_template_decl) | |
225 { | |
226 /* Within templates, a REFERENCE_TYPE will indicate whether | |
227 the COND_EXPR result is an ordinary lvalue or rvalueref. | |
228 Since REFERENCE_TYPEs are handled above, if we reach this | |
229 point, we know we got a plain rvalue. Unless we have a | |
230 type-dependent expr, that is, but we shouldn't be testing | |
231 lvalueness if we can't even tell the types yet! */ | |
232 gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref))); | |
233 goto default_; | |
234 } | |
197 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1) | 235 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1) |
198 ? TREE_OPERAND (ref, 1) | 236 ? TREE_OPERAND (ref, 1) |
199 : TREE_OPERAND (ref, 0)); | 237 : TREE_OPERAND (ref, 0)); |
200 op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 2)); | 238 op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 2)); |
201 break; | 239 break; |
237 /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns | 275 /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns |
238 its argument unmodified and we assign it to a const_tree. */ | 276 its argument unmodified and we assign it to a const_tree. */ |
239 return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref))); | 277 return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref))); |
240 | 278 |
241 case NON_DEPENDENT_EXPR: | 279 case NON_DEPENDENT_EXPR: |
280 case PAREN_EXPR: | |
242 return lvalue_kind (TREE_OPERAND (ref, 0)); | 281 return lvalue_kind (TREE_OPERAND (ref, 0)); |
243 | 282 |
244 default: | 283 default: |
284 default_: | |
245 if (!TREE_TYPE (ref)) | 285 if (!TREE_TYPE (ref)) |
246 return clk_none; | 286 return clk_none; |
247 if (CLASS_TYPE_P (TREE_TYPE (ref)) | 287 if (CLASS_TYPE_P (TREE_TYPE (ref)) |
248 || TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE) | 288 || TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE) |
249 return clk_class; | 289 return clk_class; |
250 break; | 290 return clk_none; |
251 } | 291 } |
252 | 292 |
253 /* If one operand is not an lvalue at all, then this expression is | 293 /* If one operand is not an lvalue at all, then this expression is |
254 not an lvalue. */ | 294 not an lvalue. */ |
255 if (!op1_lvalue_kind || !op2_lvalue_kind) | 295 if (!op1_lvalue_kind || !op2_lvalue_kind) |
373 constant-expression. */ | 413 constant-expression. */ |
374 | 414 |
375 bool | 415 bool |
376 builtin_valid_in_constant_expr_p (const_tree decl) | 416 builtin_valid_in_constant_expr_p (const_tree decl) |
377 { | 417 { |
378 if (!(TREE_CODE (decl) == FUNCTION_DECL | 418 if (TREE_CODE (decl) != FUNCTION_DECL) |
379 && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)) | 419 /* Not a function. */ |
380 /* Not a built-in. */ | |
381 return false; | 420 return false; |
421 if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL) | |
422 { | |
423 if (fndecl_built_in_p (decl, CP_BUILT_IN_IS_CONSTANT_EVALUATED, | |
424 BUILT_IN_FRONTEND)) | |
425 return true; | |
426 /* Not a built-in. */ | |
427 return false; | |
428 } | |
382 switch (DECL_FUNCTION_CODE (decl)) | 429 switch (DECL_FUNCTION_CODE (decl)) |
383 { | 430 { |
384 /* These always have constant results like the corresponding | 431 /* These always have constant results like the corresponding |
385 macros/symbol. */ | 432 macros/symbol. */ |
386 case BUILT_IN_FILE: | 433 case BUILT_IN_FILE: |
419 || (TYPE_PTR_P (TREE_TYPE (value)) | 466 || (TYPE_PTR_P (TREE_TYPE (value)) |
420 && TREE_CODE (value) == CALL_EXPR) | 467 && TREE_CODE (value) == CALL_EXPR) |
421 || useless_type_conversion_p (TREE_TYPE (decl), | 468 || useless_type_conversion_p (TREE_TYPE (decl), |
422 TREE_TYPE (value))); | 469 TREE_TYPE (value))); |
423 | 470 |
471 /* Set TREE_READONLY for optimization, such as gimplify_init_constructor | |
472 moving a constant aggregate into .rodata. */ | |
473 if (CP_TYPE_CONST_NON_VOLATILE_P (type) | |
474 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type) | |
475 && !VOID_TYPE_P (TREE_TYPE (value)) | |
476 && reduced_constant_expression_p (value)) | |
477 TREE_READONLY (decl) = true; | |
478 | |
424 if (complain & tf_no_cleanup) | 479 if (complain & tf_no_cleanup) |
425 /* The caller is building a new-expr and does not need a cleanup. */ | 480 /* The caller is building a new-expr and does not need a cleanup. */ |
426 t = NULL_TREE; | 481 t = NULL_TREE; |
427 else | 482 else |
428 { | 483 { |
429 t = cxx_maybe_build_cleanup (decl, complain); | 484 t = cxx_maybe_build_cleanup (decl, complain); |
430 if (t == error_mark_node) | 485 if (t == error_mark_node) |
431 return error_mark_node; | 486 return error_mark_node; |
432 } | 487 } |
433 t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE); | 488 t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE); |
434 if (EXPR_HAS_LOCATION (value)) | 489 if (location_t eloc = cp_expr_location (value)) |
435 SET_EXPR_LOCATION (t, EXPR_LOCATION (value)); | 490 SET_EXPR_LOCATION (t, eloc); |
436 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not | 491 /* We always set TREE_SIDE_EFFECTS so that expand_expr does not |
437 ignore the TARGET_EXPR. If there really turn out to be no | 492 ignore the TARGET_EXPR. If there really turn out to be no |
438 side-effects, then the optimizer should be able to get rid of | 493 side-effects, then the optimizer should be able to get rid of |
439 whatever code is generated anyhow. */ | 494 whatever code is generated anyhow. */ |
440 TREE_SIDE_EFFECTS (t) = 1; | 495 TREE_SIDE_EFFECTS (t) = 1; |
589 build_cplus_new (tree type, tree init, tsubst_flags_t complain) | 644 build_cplus_new (tree type, tree init, tsubst_flags_t complain) |
590 { | 645 { |
591 tree rval = build_aggr_init_expr (type, init); | 646 tree rval = build_aggr_init_expr (type, init); |
592 tree slot; | 647 tree slot; |
593 | 648 |
649 if (init == error_mark_node) | |
650 return error_mark_node; | |
651 | |
594 if (!complete_type_or_maybe_complain (type, init, complain)) | 652 if (!complete_type_or_maybe_complain (type, init, complain)) |
595 return error_mark_node; | 653 return error_mark_node; |
596 | 654 |
597 /* Make sure that we're not trying to create an instance of an | 655 /* Make sure that we're not trying to create an instance of an |
598 abstract class. */ | 656 abstract class. */ |
1028 build_array_of_n_type (tree elt, int n) | 1086 build_array_of_n_type (tree elt, int n) |
1029 { | 1087 { |
1030 return build_cplus_array_type (elt, build_index_type (size_int (n - 1))); | 1088 return build_cplus_array_type (elt, build_index_type (size_int (n - 1))); |
1031 } | 1089 } |
1032 | 1090 |
1033 /* True iff T is an N3639 array of runtime bound (VLA). These were | 1091 /* True iff T is an N3639 array of runtime bound (VLA). These were approved |
1034 approved for C++14 but then removed. */ | 1092 for C++14 but then removed. This should only be used for N3639 |
1093 specifically; code wondering more generally if something is a VLA should use | |
1094 vla_type_p. */ | |
1035 | 1095 |
1036 bool | 1096 bool |
1037 array_of_runtime_bound_p (tree t) | 1097 array_of_runtime_bound_p (tree t) |
1038 { | 1098 { |
1039 if (!t || TREE_CODE (t) != ARRAY_TYPE) | 1099 if (!t || TREE_CODE (t) != ARRAY_TYPE) |
1100 return false; | |
1101 if (variably_modified_type_p (TREE_TYPE (t), NULL_TREE)) | |
1040 return false; | 1102 return false; |
1041 tree dom = TYPE_DOMAIN (t); | 1103 tree dom = TYPE_DOMAIN (t); |
1042 if (!dom) | 1104 if (!dom) |
1043 return false; | 1105 return false; |
1044 tree max = TYPE_MAX_VALUE (dom); | 1106 tree max = TYPE_MAX_VALUE (dom); |
1045 return (!potential_rvalue_constant_expression (max) | 1107 return (!potential_rvalue_constant_expression (max) |
1046 || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max))); | 1108 || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max))); |
1047 } | 1109 } |
1048 | 1110 |
1111 /* True iff T is a variable length array. */ | |
1112 | |
1113 bool | |
1114 vla_type_p (tree t) | |
1115 { | |
1116 for (; t && TREE_CODE (t) == ARRAY_TYPE; | |
1117 t = TREE_TYPE (t)) | |
1118 if (tree dom = TYPE_DOMAIN (t)) | |
1119 { | |
1120 tree max = TYPE_MAX_VALUE (dom); | |
1121 if (!potential_rvalue_constant_expression (max) | |
1122 || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max))) | |
1123 return true; | |
1124 } | |
1125 return false; | |
1126 } | |
1127 | |
1049 /* Return a reference type node referring to TO_TYPE. If RVAL is | 1128 /* Return a reference type node referring to TO_TYPE. If RVAL is |
1050 true, return an rvalue reference type, otherwise return an lvalue | 1129 true, return an rvalue reference type, otherwise return an lvalue |
1051 reference type. If a type node exists, reuse it, otherwise create | 1130 reference type. If a type node exists, reuse it, otherwise create |
1052 a new one. */ | 1131 a new one. */ |
1053 tree | 1132 tree |
1054 cp_build_reference_type (tree to_type, bool rval) | 1133 cp_build_reference_type (tree to_type, bool rval) |
1055 { | 1134 { |
1056 tree lvalue_ref, t; | 1135 tree lvalue_ref, t; |
1057 | 1136 |
1058 if (TREE_CODE (to_type) == REFERENCE_TYPE) | 1137 if (to_type == error_mark_node) |
1138 return error_mark_node; | |
1139 | |
1140 if (TYPE_REF_P (to_type)) | |
1059 { | 1141 { |
1060 rval = rval && TYPE_REF_IS_RVALUE (to_type); | 1142 rval = rval && TYPE_REF_IS_RVALUE (to_type); |
1061 to_type = TREE_TYPE (to_type); | 1143 to_type = TREE_TYPE (to_type); |
1062 } | 1144 } |
1063 | 1145 |
1101 | 1183 |
1102 tree | 1184 tree |
1103 move (tree expr) | 1185 move (tree expr) |
1104 { | 1186 { |
1105 tree type = TREE_TYPE (expr); | 1187 tree type = TREE_TYPE (expr); |
1106 gcc_assert (TREE_CODE (type) != REFERENCE_TYPE); | 1188 gcc_assert (!TYPE_REF_P (type)); |
1107 type = cp_build_reference_type (type, /*rval*/true); | 1189 type = cp_build_reference_type (type, /*rval*/true); |
1108 return build_static_cast (type, expr, tf_warning_or_error); | 1190 return build_static_cast (type, expr, tf_warning_or_error); |
1109 } | 1191 } |
1110 | 1192 |
1111 /* Used by the C++ front end to build qualified array types. However, | 1193 /* Used by the C++ front end to build qualified array types. However, |
1206 else if (TREE_CODE (type) == TYPE_PACK_EXPANSION) | 1288 else if (TREE_CODE (type) == TYPE_PACK_EXPANSION) |
1207 { | 1289 { |
1208 tree t = PACK_EXPANSION_PATTERN (type); | 1290 tree t = PACK_EXPANSION_PATTERN (type); |
1209 | 1291 |
1210 t = cp_build_qualified_type_real (t, type_quals, complain); | 1292 t = cp_build_qualified_type_real (t, type_quals, complain); |
1211 return make_pack_expansion (t); | 1293 return make_pack_expansion (t, complain); |
1212 } | 1294 } |
1213 | 1295 |
1214 /* A reference or method type shall not be cv-qualified. | 1296 /* A reference or method type shall not be cv-qualified. |
1215 [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295 | 1297 [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295 |
1216 (in CD1) we always ignore extra cv-quals on functions. */ | 1298 (in CD1) we always ignore extra cv-quals on functions. */ |
1217 if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE) | 1299 if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE) |
1218 && (TREE_CODE (type) == REFERENCE_TYPE | 1300 && (TYPE_REF_P (type) |
1219 || TREE_CODE (type) == FUNCTION_TYPE | 1301 || TREE_CODE (type) == FUNCTION_TYPE |
1220 || TREE_CODE (type) == METHOD_TYPE)) | 1302 || TREE_CODE (type) == METHOD_TYPE)) |
1221 { | 1303 { |
1222 if (TREE_CODE (type) == REFERENCE_TYPE) | 1304 if (TYPE_REF_P (type)) |
1223 bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); | 1305 bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); |
1224 type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); | 1306 type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); |
1225 } | 1307 } |
1226 | 1308 |
1227 /* But preserve any function-cv-quals on a FUNCTION_TYPE. */ | 1309 /* But preserve any function-cv-quals on a FUNCTION_TYPE. */ |
1231 /* A restrict-qualified type must be a pointer (or reference) | 1313 /* A restrict-qualified type must be a pointer (or reference) |
1232 to object or incomplete type. */ | 1314 to object or incomplete type. */ |
1233 if ((type_quals & TYPE_QUAL_RESTRICT) | 1315 if ((type_quals & TYPE_QUAL_RESTRICT) |
1234 && TREE_CODE (type) != TEMPLATE_TYPE_PARM | 1316 && TREE_CODE (type) != TEMPLATE_TYPE_PARM |
1235 && TREE_CODE (type) != TYPENAME_TYPE | 1317 && TREE_CODE (type) != TYPENAME_TYPE |
1236 && !POINTER_TYPE_P (type)) | 1318 && !INDIRECT_TYPE_P (type)) |
1237 { | 1319 { |
1238 bad_quals |= TYPE_QUAL_RESTRICT; | 1320 bad_quals |= TYPE_QUAL_RESTRICT; |
1239 type_quals &= ~TYPE_QUAL_RESTRICT; | 1321 type_quals &= ~TYPE_QUAL_RESTRICT; |
1240 } | 1322 } |
1241 | 1323 |
1251 bad_type, type); | 1333 bad_type, type); |
1252 } | 1334 } |
1253 | 1335 |
1254 /* Retrieve (or create) the appropriately qualified variant. */ | 1336 /* Retrieve (or create) the appropriately qualified variant. */ |
1255 result = build_qualified_type (type, type_quals); | 1337 result = build_qualified_type (type, type_quals); |
1256 | |
1257 /* Preserve exception specs and ref-qualifier since build_qualified_type | |
1258 doesn't know about them. */ | |
1259 if (TREE_CODE (result) == FUNCTION_TYPE | |
1260 || TREE_CODE (result) == METHOD_TYPE) | |
1261 { | |
1262 result = build_exception_variant (result, TYPE_RAISES_EXCEPTIONS (type)); | |
1263 result = build_ref_qualified_type (result, type_memfn_rqual (type)); | |
1264 } | |
1265 | 1338 |
1266 return result; | 1339 return result; |
1267 } | 1340 } |
1268 | 1341 |
1269 /* Return TYPE with const and volatile removed. */ | 1342 /* Return TYPE with const and volatile removed. */ |
1488 tree class_type = TREE_TYPE (TREE_VALUE (arg_types)); | 1561 tree class_type = TREE_TYPE (TREE_VALUE (arg_types)); |
1489 gcc_assert (class_type); | 1562 gcc_assert (class_type); |
1490 result = | 1563 result = |
1491 build_method_type_directly (class_type, type, | 1564 build_method_type_directly (class_type, type, |
1492 TREE_CHAIN (arg_types)); | 1565 TREE_CHAIN (arg_types)); |
1493 result | |
1494 = build_ref_qualified_type (result, type_memfn_rqual (t)); | |
1495 } | 1566 } |
1496 else | 1567 else |
1497 { | 1568 { |
1498 result = build_function_type (type, | 1569 result = build_function_type (type, arg_types); |
1499 arg_types); | 1570 result = apply_memfn_quals (result, type_memfn_quals (t)); |
1500 result = apply_memfn_quals (result, | |
1501 type_memfn_quals (t), | |
1502 type_memfn_rqual (t)); | |
1503 } | 1571 } |
1504 | 1572 |
1505 if (canon_spec) | 1573 result = build_cp_fntype_variant (result, |
1506 result = build_exception_variant (result, canon_spec); | 1574 type_memfn_rqual (t), canon_spec, |
1507 if (TYPE_HAS_LATE_RETURN_TYPE (t)) | 1575 TYPE_HAS_LATE_RETURN_TYPE (t)); |
1508 TYPE_HAS_LATE_RETURN_TYPE (result) = 1; | |
1509 } | 1576 } |
1510 break; | 1577 break; |
1511 case TYPENAME_TYPE: | 1578 case TYPENAME_TYPE: |
1512 { | 1579 { |
1513 bool changed = false; | 1580 bool changed = false; |
1676 vec<tree, va_gc> *vec = make_tree_vector (); | 1743 vec<tree, va_gc> *vec = make_tree_vector (); |
1677 bool changed = false; | 1744 bool changed = false; |
1678 tree it; | 1745 tree it; |
1679 for (it = t; it; it = TREE_CHAIN (it)) | 1746 for (it = t; it; it = TREE_CHAIN (it)) |
1680 { | 1747 { |
1681 tree val = strip_typedefs_expr (TREE_VALUE (t), remove_attributes); | 1748 tree val = strip_typedefs_expr (TREE_VALUE (it), remove_attributes); |
1682 vec_safe_push (vec, val); | 1749 vec_safe_push (vec, val); |
1683 if (val != TREE_VALUE (t)) | 1750 if (val != TREE_VALUE (it)) |
1684 changed = true; | 1751 changed = true; |
1685 gcc_assert (TREE_PURPOSE (it) == NULL_TREE); | 1752 gcc_assert (TREE_PURPOSE (it) == NULL_TREE); |
1686 } | 1753 } |
1687 if (changed) | 1754 if (changed) |
1688 { | 1755 { |
1760 | 1827 |
1761 case LAMBDA_EXPR: | 1828 case LAMBDA_EXPR: |
1762 error ("lambda-expression in a constant expression"); | 1829 error ("lambda-expression in a constant expression"); |
1763 return error_mark_node; | 1830 return error_mark_node; |
1764 | 1831 |
1832 case STATEMENT_LIST: | |
1833 error ("statement-expression in a constant expression"); | |
1834 return error_mark_node; | |
1835 | |
1765 default: | 1836 default: |
1766 break; | 1837 break; |
1767 } | 1838 } |
1768 | 1839 |
1769 gcc_assert (EXPR_P (t)); | 1840 gcc_assert (EXPR_P (t)); |
1770 | 1841 |
1771 n = TREE_OPERAND_LENGTH (t); | 1842 n = cp_tree_operand_length (t); |
1772 ops = XALLOCAVEC (tree, n); | 1843 ops = XALLOCAVEC (tree, n); |
1773 type = TREE_TYPE (t); | 1844 type = TREE_TYPE (t); |
1774 | 1845 |
1775 switch (code) | 1846 switch (code) |
1776 { | 1847 { |
2042 if (type) | 2113 if (type) |
2043 t = convert_from_reference (t); | 2114 t = convert_from_reference (t); |
2044 return t; | 2115 return t; |
2045 } | 2116 } |
2046 | 2117 |
2047 /* Like check_qualified_type, but also check ref-qualifier and exception | 2118 /* Like check_qualified_type, but also check ref-qualifier, exception |
2048 specification. */ | 2119 specification, and whether the return type was specified after the |
2120 parameters. */ | |
2049 | 2121 |
2050 static bool | 2122 static bool |
2051 cp_check_qualified_type (const_tree cand, const_tree base, int type_quals, | 2123 cp_check_qualified_type (const_tree cand, const_tree base, int type_quals, |
2052 cp_ref_qualifier rqual, tree raises) | 2124 cp_ref_qualifier rqual, tree raises, bool late) |
2053 { | 2125 { |
2054 return (TYPE_QUALS (cand) == type_quals | 2126 return (TYPE_QUALS (cand) == type_quals |
2055 && check_base_type (cand, base) | 2127 && check_base_type (cand, base) |
2056 && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand), | 2128 && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand), |
2057 ce_exact) | 2129 ce_exact) |
2130 && TYPE_HAS_LATE_RETURN_TYPE (cand) == late | |
2058 && type_memfn_rqual (cand) == rqual); | 2131 && type_memfn_rqual (cand) == rqual); |
2059 } | 2132 } |
2060 | 2133 |
2061 /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */ | 2134 /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL. */ |
2062 | 2135 |
2063 tree | 2136 tree |
2064 build_ref_qualified_type (tree type, cp_ref_qualifier rqual) | 2137 build_ref_qualified_type (tree type, cp_ref_qualifier rqual) |
2065 { | 2138 { |
2066 tree t; | |
2067 | |
2068 if (rqual == type_memfn_rqual (type)) | |
2069 return type; | |
2070 | |
2071 int type_quals = TYPE_QUALS (type); | |
2072 tree raises = TYPE_RAISES_EXCEPTIONS (type); | 2139 tree raises = TYPE_RAISES_EXCEPTIONS (type); |
2073 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) | 2140 bool late = TYPE_HAS_LATE_RETURN_TYPE (type); |
2074 if (cp_check_qualified_type (t, type, type_quals, rqual, raises)) | 2141 return build_cp_fntype_variant (type, rqual, raises, late); |
2075 return t; | 2142 } |
2076 | |
2077 t = build_variant_type_copy (type); | |
2078 switch (rqual) | |
2079 { | |
2080 case REF_QUAL_RVALUE: | |
2081 FUNCTION_RVALUE_QUALIFIED (t) = 1; | |
2082 FUNCTION_REF_QUALIFIED (t) = 1; | |
2083 break; | |
2084 case REF_QUAL_LVALUE: | |
2085 FUNCTION_RVALUE_QUALIFIED (t) = 0; | |
2086 FUNCTION_REF_QUALIFIED (t) = 1; | |
2087 break; | |
2088 default: | |
2089 FUNCTION_REF_QUALIFIED (t) = 0; | |
2090 break; | |
2091 } | |
2092 | |
2093 if (TYPE_STRUCTURAL_EQUALITY_P (type)) | |
2094 /* Propagate structural equality. */ | |
2095 SET_TYPE_STRUCTURAL_EQUALITY (t); | |
2096 else if (TYPE_CANONICAL (type) != type) | |
2097 /* Build the underlying canonical type, since it is different | |
2098 from TYPE. */ | |
2099 TYPE_CANONICAL (t) = build_ref_qualified_type (TYPE_CANONICAL (type), | |
2100 rqual); | |
2101 else | |
2102 /* T is its own canonical type. */ | |
2103 TYPE_CANONICAL (t) = t; | |
2104 | |
2105 return t; | |
2106 } | |
2107 | |
2108 /* Cache of free ovl nodes. Uses OVL_FUNCTION for chaining. */ | |
2109 static GTY((deletable)) tree ovl_cache; | |
2110 | 2143 |
2111 /* Make a raw overload node containing FN. */ | 2144 /* Make a raw overload node containing FN. */ |
2112 | 2145 |
2113 tree | 2146 tree |
2114 ovl_make (tree fn, tree next) | 2147 ovl_make (tree fn, tree next) |
2115 { | 2148 { |
2116 tree result = ovl_cache; | 2149 tree result = make_node (OVERLOAD); |
2117 | |
2118 if (result) | |
2119 { | |
2120 ovl_cache = OVL_FUNCTION (result); | |
2121 /* Zap the flags. */ | |
2122 memset (result, 0, sizeof (tree_base)); | |
2123 TREE_SET_CODE (result, OVERLOAD); | |
2124 } | |
2125 else | |
2126 result = make_node (OVERLOAD); | |
2127 | 2150 |
2128 if (TREE_CODE (fn) == OVERLOAD) | 2151 if (TREE_CODE (fn) == OVERLOAD) |
2129 OVL_NESTED_P (result) = true; | 2152 OVL_NESTED_P (result) = true; |
2130 | 2153 |
2131 TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL | 2154 TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL |
2136 } | 2159 } |
2137 | 2160 |
2138 static tree | 2161 static tree |
2139 ovl_copy (tree ovl) | 2162 ovl_copy (tree ovl) |
2140 { | 2163 { |
2141 tree result = ovl_cache; | 2164 tree result = make_node (OVERLOAD); |
2142 | |
2143 if (result) | |
2144 { | |
2145 ovl_cache = OVL_FUNCTION (result); | |
2146 /* Zap the flags. */ | |
2147 memset (result, 0, sizeof (tree_base)); | |
2148 TREE_SET_CODE (result, OVERLOAD); | |
2149 } | |
2150 else | |
2151 result = make_node (OVERLOAD); | |
2152 | 2165 |
2153 gcc_checking_assert (!OVL_NESTED_P (ovl) && OVL_USED_P (ovl)); | 2166 gcc_checking_assert (!OVL_NESTED_P (ovl) && OVL_USED_P (ovl)); |
2154 TREE_TYPE (result) = TREE_TYPE (ovl); | 2167 TREE_TYPE (result) = TREE_TYPE (ovl); |
2155 OVL_FUNCTION (result) = OVL_FUNCTION (ovl); | 2168 OVL_FUNCTION (result) = OVL_FUNCTION (ovl); |
2156 OVL_CHAIN (result) = OVL_CHAIN (ovl); | 2169 OVL_CHAIN (result) = OVL_CHAIN (ovl); |
2385 gcc_checking_assert (!OVL_LOOKUP_P (ovl)); | 2398 gcc_checking_assert (!OVL_LOOKUP_P (ovl)); |
2386 OVL_USED_P (ovl) = true; | 2399 OVL_USED_P (ovl) = true; |
2387 } | 2400 } |
2388 } | 2401 } |
2389 | 2402 |
2390 /* If KEEP is true, preserve the contents of a lookup so that it is | 2403 /* Preserve the contents of a lookup so that it is available for a |
2391 available for a later instantiation. Otherwise release the LOOKUP | 2404 later instantiation. */ |
2392 nodes for reuse. */ | |
2393 | 2405 |
2394 void | 2406 void |
2395 lookup_keep (tree lookup, bool keep) | 2407 lookup_keep (tree lookup) |
2396 { | 2408 { |
2397 for (; | 2409 for (; |
2398 lookup && TREE_CODE (lookup) == OVERLOAD | 2410 lookup && TREE_CODE (lookup) == OVERLOAD |
2399 && OVL_LOOKUP_P (lookup) && !OVL_USED_P (lookup); | 2411 && OVL_LOOKUP_P (lookup) && !OVL_USED_P (lookup); |
2400 lookup = OVL_CHAIN (lookup)) | 2412 lookup = OVL_CHAIN (lookup)) |
2401 if (keep) | 2413 { |
2402 { | 2414 OVL_USED_P (lookup) = true; |
2403 OVL_USED_P (lookup) = true; | 2415 ovl_used (OVL_FUNCTION (lookup)); |
2404 ovl_used (OVL_FUNCTION (lookup)); | 2416 } |
2405 } | 2417 |
2406 else | 2418 ovl_used (lookup); |
2407 { | |
2408 OVL_FUNCTION (lookup) = ovl_cache; | |
2409 ovl_cache = lookup; | |
2410 } | |
2411 | |
2412 if (keep) | |
2413 ovl_used (lookup); | |
2414 } | 2419 } |
2415 | 2420 |
2416 /* Returns nonzero if X is an expression for a (possibly overloaded) | 2421 /* Returns nonzero if X is an expression for a (possibly overloaded) |
2417 function. If "f" is a function or function template, "f", "c->f", | 2422 function. If "f" is a function or function template, "f", "c->f", |
2418 "c.f", "C::f", and "f<int>" will all be considered possibly | 2423 "c.f", "C::f", and "f<int>" will all be considered possibly |
2463 really_overloaded_fn (tree x) | 2468 really_overloaded_fn (tree x) |
2464 { | 2469 { |
2465 return is_overloaded_fn (x) == 2; | 2470 return is_overloaded_fn (x) == 2; |
2466 } | 2471 } |
2467 | 2472 |
2468 /* Get the overload set FROM refers to. */ | 2473 /* Get the overload set FROM refers to. Returns NULL if it's not an |
2469 | 2474 overload set. */ |
2470 tree | 2475 |
2471 get_fns (tree from) | 2476 tree |
2477 maybe_get_fns (tree from) | |
2472 { | 2478 { |
2473 /* A baselink is also considered an overloaded function. */ | 2479 /* A baselink is also considered an overloaded function. */ |
2474 if (TREE_CODE (from) == OFFSET_REF | 2480 if (TREE_CODE (from) == OFFSET_REF |
2475 || TREE_CODE (from) == COMPONENT_REF) | 2481 || TREE_CODE (from) == COMPONENT_REF) |
2476 from = TREE_OPERAND (from, 1); | 2482 from = TREE_OPERAND (from, 1); |
2477 if (BASELINK_P (from)) | 2483 if (BASELINK_P (from)) |
2478 from = BASELINK_FUNCTIONS (from); | 2484 from = BASELINK_FUNCTIONS (from); |
2479 if (TREE_CODE (from) == TEMPLATE_ID_EXPR) | 2485 if (TREE_CODE (from) == TEMPLATE_ID_EXPR) |
2480 from = TREE_OPERAND (from, 0); | 2486 from = TREE_OPERAND (from, 0); |
2481 gcc_assert (TREE_CODE (from) == OVERLOAD | 2487 |
2482 || TREE_CODE (from) == FUNCTION_DECL); | 2488 if (TREE_CODE (from) == OVERLOAD |
2483 return from; | 2489 || TREE_CODE (from) == FUNCTION_DECL) |
2490 return from; | |
2491 | |
2492 return NULL; | |
2493 } | |
2494 | |
2495 /* FROM refers to an overload set. Return that set (or die). */ | |
2496 | |
2497 tree | |
2498 get_fns (tree from) | |
2499 { | |
2500 tree res = maybe_get_fns (from); | |
2501 | |
2502 gcc_assert (res); | |
2503 return res; | |
2484 } | 2504 } |
2485 | 2505 |
2486 /* Return the first function of the overload set FROM refers to. */ | 2506 /* Return the first function of the overload set FROM refers to. */ |
2487 | 2507 |
2488 tree | 2508 tree |
2591 else | 2611 else |
2592 /* For C++17 type matching, anything else -> nothing. */ | 2612 /* For C++17 type matching, anything else -> nothing. */ |
2593 return NULL_TREE; | 2613 return NULL_TREE; |
2594 } | 2614 } |
2595 | 2615 |
2596 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions | 2616 tree |
2597 listed in RAISES. */ | 2617 build_cp_fntype_variant (tree type, cp_ref_qualifier rqual, |
2598 | 2618 tree raises, bool late) |
2599 tree | 2619 { |
2600 build_exception_variant (tree type, tree raises) | 2620 cp_cv_quals type_quals = TYPE_QUALS (type); |
2601 { | 2621 |
2602 tree v; | 2622 if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late)) |
2603 int type_quals; | |
2604 | |
2605 if (comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (type), ce_exact)) | |
2606 return type; | 2623 return type; |
2607 | 2624 |
2608 type_quals = TYPE_QUALS (type); | 2625 tree v = TYPE_MAIN_VARIANT (type); |
2609 cp_ref_qualifier rqual = type_memfn_rqual (type); | 2626 for (; v; v = TYPE_NEXT_VARIANT (v)) |
2610 for (v = TYPE_MAIN_VARIANT (type); v; v = TYPE_NEXT_VARIANT (v)) | 2627 if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late)) |
2611 if (cp_check_qualified_type (v, type, type_quals, rqual, raises)) | |
2612 return v; | 2628 return v; |
2613 | 2629 |
2614 /* Need to build a new variant. */ | 2630 /* Need to build a new variant. */ |
2615 v = build_variant_type_copy (type); | 2631 v = build_variant_type_copy (type); |
2616 TYPE_RAISES_EXCEPTIONS (v) = raises; | 2632 TYPE_RAISES_EXCEPTIONS (v) = raises; |
2617 | 2633 TYPE_HAS_LATE_RETURN_TYPE (v) = late; |
2618 if (!flag_noexcept_type) | 2634 switch (rqual) |
2619 /* The exception-specification is not part of the canonical type. */ | 2635 { |
2620 return v; | 2636 case REF_QUAL_RVALUE: |
2637 FUNCTION_RVALUE_QUALIFIED (v) = 1; | |
2638 FUNCTION_REF_QUALIFIED (v) = 1; | |
2639 break; | |
2640 case REF_QUAL_LVALUE: | |
2641 FUNCTION_RVALUE_QUALIFIED (v) = 0; | |
2642 FUNCTION_REF_QUALIFIED (v) = 1; | |
2643 break; | |
2644 default: | |
2645 FUNCTION_REF_QUALIFIED (v) = 0; | |
2646 break; | |
2647 } | |
2621 | 2648 |
2622 /* Canonicalize the exception specification. */ | 2649 /* Canonicalize the exception specification. */ |
2623 tree cr = canonical_eh_spec (raises); | 2650 tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE; |
2624 | 2651 |
2625 if (TYPE_STRUCTURAL_EQUALITY_P (type)) | 2652 if (TYPE_STRUCTURAL_EQUALITY_P (type)) |
2626 /* Propagate structural equality. */ | 2653 /* Propagate structural equality. */ |
2627 SET_TYPE_STRUCTURAL_EQUALITY (v); | 2654 SET_TYPE_STRUCTURAL_EQUALITY (v); |
2628 else if (TYPE_CANONICAL (type) != type || cr != raises) | 2655 else if (TYPE_CANONICAL (type) != type || cr != raises || late) |
2629 /* Build the underlying canonical type, since it is different | 2656 /* Build the underlying canonical type, since it is different |
2630 from TYPE. */ | 2657 from TYPE. */ |
2631 TYPE_CANONICAL (v) = build_exception_variant (TYPE_CANONICAL (type), cr); | 2658 TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type), |
2659 rqual, cr, false); | |
2632 else | 2660 else |
2633 /* T is its own canonical type. */ | 2661 /* T is its own canonical type. */ |
2634 TYPE_CANONICAL (v) = v; | 2662 TYPE_CANONICAL (v) = v; |
2635 | 2663 |
2636 return v; | 2664 return v; |
2665 } | |
2666 | |
2667 /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions | |
2668 listed in RAISES. */ | |
2669 | |
2670 tree | |
2671 build_exception_variant (tree type, tree raises) | |
2672 { | |
2673 cp_ref_qualifier rqual = type_memfn_rqual (type); | |
2674 bool late = TYPE_HAS_LATE_RETURN_TYPE (type); | |
2675 return build_cp_fntype_variant (type, rqual, raises, late); | |
2637 } | 2676 } |
2638 | 2677 |
2639 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new | 2678 /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new |
2640 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template | 2679 BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template |
2641 arguments. */ | 2680 arguments. */ |
2824 extern int depth_reached; | 2863 extern int depth_reached; |
2825 | 2864 |
2826 void | 2865 void |
2827 cxx_print_statistics (void) | 2866 cxx_print_statistics (void) |
2828 { | 2867 { |
2829 print_class_statistics (); | |
2830 print_template_statistics (); | 2868 print_template_statistics (); |
2831 if (GATHER_STATISTICS) | 2869 if (GATHER_STATISTICS) |
2832 fprintf (stderr, "maximum template instantiation depth reached: %d\n", | 2870 fprintf (stderr, "maximum template instantiation depth reached: %d\n", |
2833 depth_reached); | 2871 depth_reached); |
2834 } | 2872 } |
2863 type = TREE_TYPE (type); | 2901 type = TREE_TYPE (type); |
2864 } | 2902 } |
2865 return sz; | 2903 return sz; |
2866 } | 2904 } |
2867 | 2905 |
2906 struct bot_data | |
2907 { | |
2908 splay_tree target_remap; | |
2909 bool clear_location; | |
2910 }; | |
2911 | |
2868 /* Called from break_out_target_exprs via mapcar. */ | 2912 /* Called from break_out_target_exprs via mapcar. */ |
2869 | 2913 |
2870 static tree | 2914 static tree |
2871 bot_manip (tree* tp, int* walk_subtrees, void* data) | 2915 bot_manip (tree* tp, int* walk_subtrees, void* data_) |
2872 { | 2916 { |
2873 splay_tree target_remap = ((splay_tree) data); | 2917 bot_data &data = *(bot_data*)data_; |
2918 splay_tree target_remap = data.target_remap; | |
2874 tree t = *tp; | 2919 tree t = *tp; |
2875 | 2920 |
2876 if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t)) | 2921 if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t)) |
2877 { | 2922 { |
2878 /* There can't be any TARGET_EXPRs or their slot variables below this | 2923 /* There can't be any TARGET_EXPRs or their slot variables below this |
2890 | 2935 |
2891 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR) | 2936 if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR) |
2892 { | 2937 { |
2893 u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1), | 2938 u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1), |
2894 tf_warning_or_error); | 2939 tf_warning_or_error); |
2940 if (u == error_mark_node) | |
2941 return u; | |
2895 if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t, 1))) | 2942 if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t, 1))) |
2896 AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u, 1)) = true; | 2943 AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u, 1)) = true; |
2897 } | 2944 } |
2898 else | 2945 else |
2899 u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t), | 2946 u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t), |
2906 /* Map the old variable to the new one. */ | 2953 /* Map the old variable to the new one. */ |
2907 splay_tree_insert (target_remap, | 2954 splay_tree_insert (target_remap, |
2908 (splay_tree_key) TREE_OPERAND (t, 0), | 2955 (splay_tree_key) TREE_OPERAND (t, 0), |
2909 (splay_tree_value) TREE_OPERAND (u, 0)); | 2956 (splay_tree_value) TREE_OPERAND (u, 0)); |
2910 | 2957 |
2911 TREE_OPERAND (u, 1) = break_out_target_exprs (TREE_OPERAND (u, 1)); | 2958 TREE_OPERAND (u, 1) = break_out_target_exprs (TREE_OPERAND (u, 1), |
2959 data.clear_location); | |
2960 if (TREE_OPERAND (u, 1) == error_mark_node) | |
2961 return error_mark_node; | |
2912 | 2962 |
2913 /* Replace the old expression with the new version. */ | 2963 /* Replace the old expression with the new version. */ |
2914 *tp = u; | 2964 *tp = u; |
2915 /* We don't have to go below this point; the recursive call to | 2965 /* We don't have to go below this point; the recursive call to |
2916 break_out_target_exprs will have handled anything below this | 2966 break_out_target_exprs will have handled anything below this |
2942 return NULL_TREE; | 2992 return NULL_TREE; |
2943 } | 2993 } |
2944 | 2994 |
2945 /* Make a copy of this node. */ | 2995 /* Make a copy of this node. */ |
2946 t = copy_tree_r (tp, walk_subtrees, NULL); | 2996 t = copy_tree_r (tp, walk_subtrees, NULL); |
2947 if (TREE_CODE (*tp) == CALL_EXPR) | 2997 if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR) |
2948 { | 2998 if (!processing_template_decl) |
2949 set_flags_from_callee (*tp); | 2999 set_flags_from_callee (*tp); |
2950 | 3000 if (data.clear_location && EXPR_HAS_LOCATION (*tp)) |
2951 /* builtin_LINE and builtin_FILE get the location where the default | 3001 SET_EXPR_LOCATION (*tp, input_location); |
2952 argument is expanded, not where the call was written. */ | |
2953 tree callee = get_callee_fndecl (*tp); | |
2954 if (callee && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL) | |
2955 switch (DECL_FUNCTION_CODE (callee)) | |
2956 { | |
2957 case BUILT_IN_FILE: | |
2958 case BUILT_IN_LINE: | |
2959 SET_EXPR_LOCATION (*tp, input_location); | |
2960 default: | |
2961 break; | |
2962 } | |
2963 } | |
2964 return t; | 3002 return t; |
2965 } | 3003 } |
2966 | 3004 |
2967 /* Replace all remapped VAR_DECLs in T with their new equivalents. | 3005 /* Replace all remapped VAR_DECLs in T with their new equivalents. |
2968 DATA is really a splay-tree mapping old variables to new | 3006 DATA is really a splay-tree mapping old variables to new |
2969 variables. */ | 3007 variables. */ |
2970 | 3008 |
2971 static tree | 3009 static tree |
2972 bot_replace (tree* t, int* /*walk_subtrees*/, void* data) | 3010 bot_replace (tree* t, int* /*walk_subtrees*/, void* data_) |
2973 { | 3011 { |
2974 splay_tree target_remap = ((splay_tree) data); | 3012 bot_data &data = *(bot_data*)data_; |
3013 splay_tree target_remap = data.target_remap; | |
2975 | 3014 |
2976 if (VAR_P (*t)) | 3015 if (VAR_P (*t)) |
2977 { | 3016 { |
2978 splay_tree_node n = splay_tree_lookup (target_remap, | 3017 splay_tree_node n = splay_tree_lookup (target_remap, |
2979 (splay_tree_key) *t); | 3018 (splay_tree_key) *t); |
3007 } | 3046 } |
3008 | 3047 |
3009 /* When we parse a default argument expression, we may create | 3048 /* When we parse a default argument expression, we may create |
3010 temporary variables via TARGET_EXPRs. When we actually use the | 3049 temporary variables via TARGET_EXPRs. When we actually use the |
3011 default-argument expression, we make a copy of the expression | 3050 default-argument expression, we make a copy of the expression |
3012 and replace the temporaries with appropriate local versions. */ | 3051 and replace the temporaries with appropriate local versions. |
3013 | 3052 |
3014 tree | 3053 If CLEAR_LOCATION is true, override any EXPR_LOCATION with |
3015 break_out_target_exprs (tree t) | 3054 input_location. */ |
3055 | |
3056 tree | |
3057 break_out_target_exprs (tree t, bool clear_location /* = false */) | |
3016 { | 3058 { |
3017 static int target_remap_count; | 3059 static int target_remap_count; |
3018 static splay_tree target_remap; | 3060 static splay_tree target_remap; |
3019 | 3061 |
3020 if (!target_remap_count++) | 3062 if (!target_remap_count++) |
3021 target_remap = splay_tree_new (splay_tree_compare_pointers, | 3063 target_remap = splay_tree_new (splay_tree_compare_pointers, |
3022 /*splay_tree_delete_key_fn=*/NULL, | 3064 /*splay_tree_delete_key_fn=*/NULL, |
3023 /*splay_tree_delete_value_fn=*/NULL); | 3065 /*splay_tree_delete_value_fn=*/NULL); |
3024 cp_walk_tree (&t, bot_manip, target_remap, NULL); | 3066 bot_data data = { target_remap, clear_location }; |
3025 cp_walk_tree (&t, bot_replace, target_remap, NULL); | 3067 if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node) |
3068 t = error_mark_node; | |
3069 cp_walk_tree (&t, bot_replace, &data, NULL); | |
3026 | 3070 |
3027 if (!--target_remap_count) | 3071 if (!--target_remap_count) |
3028 { | 3072 { |
3029 splay_tree_delete (target_remap); | 3073 splay_tree_delete (target_remap); |
3030 target_remap = NULL; | 3074 target_remap = NULL; |
3067 } | 3111 } |
3068 | 3112 |
3069 struct replace_placeholders_t | 3113 struct replace_placeholders_t |
3070 { | 3114 { |
3071 tree obj; /* The object to be substituted for a PLACEHOLDER_EXPR. */ | 3115 tree obj; /* The object to be substituted for a PLACEHOLDER_EXPR. */ |
3116 tree exp; /* The outermost exp. */ | |
3072 bool seen; /* Whether we've encountered a PLACEHOLDER_EXPR. */ | 3117 bool seen; /* Whether we've encountered a PLACEHOLDER_EXPR. */ |
3073 hash_set<tree> *pset; /* To avoid walking same trees multiple times. */ | 3118 hash_set<tree> *pset; /* To avoid walking same trees multiple times. */ |
3074 }; | 3119 }; |
3075 | 3120 |
3076 /* Like substitute_placeholder_in_expr, but handle C++ tree codes and | 3121 /* Like substitute_placeholder_in_expr, but handle C++ tree codes and |
3080 replace_placeholders_r (tree* t, int* walk_subtrees, void* data_) | 3125 replace_placeholders_r (tree* t, int* walk_subtrees, void* data_) |
3081 { | 3126 { |
3082 replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_); | 3127 replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_); |
3083 tree obj = d->obj; | 3128 tree obj = d->obj; |
3084 | 3129 |
3085 if (TREE_CONSTANT (*t)) | 3130 if (TYPE_P (*t) || TREE_CONSTANT (*t)) |
3086 { | 3131 { |
3087 *walk_subtrees = false; | 3132 *walk_subtrees = false; |
3088 return NULL_TREE; | 3133 return NULL_TREE; |
3089 } | 3134 } |
3090 | 3135 |
3094 { | 3139 { |
3095 tree x = obj; | 3140 tree x = obj; |
3096 for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t), | 3141 for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t), |
3097 TREE_TYPE (x)); | 3142 TREE_TYPE (x)); |
3098 x = TREE_OPERAND (x, 0)) | 3143 x = TREE_OPERAND (x, 0)) |
3099 gcc_assert (TREE_CODE (x) == COMPONENT_REF); | 3144 gcc_assert (handled_component_p (x)); |
3100 *t = x; | 3145 *t = unshare_expr (x); |
3101 *walk_subtrees = false; | 3146 *walk_subtrees = false; |
3102 d->seen = true; | 3147 d->seen = true; |
3103 } | 3148 } |
3104 break; | 3149 break; |
3105 | 3150 |
3106 case CONSTRUCTOR: | 3151 case CONSTRUCTOR: |
3107 { | 3152 { |
3108 constructor_elt *ce; | 3153 constructor_elt *ce; |
3109 vec<constructor_elt,va_gc> *v = CONSTRUCTOR_ELTS (*t); | 3154 vec<constructor_elt,va_gc> *v = CONSTRUCTOR_ELTS (*t); |
3155 /* Don't walk into CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctors | |
3156 other than the d->exp one, those have PLACEHOLDER_EXPRs | |
3157 related to another object. */ | |
3158 if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t) | |
3159 && *t != d->exp) | |
3160 || d->pset->add (*t)) | |
3161 { | |
3162 *walk_subtrees = false; | |
3163 return NULL_TREE; | |
3164 } | |
3110 for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i) | 3165 for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i) |
3111 { | 3166 { |
3112 tree *valp = &ce->value; | 3167 tree *valp = &ce->value; |
3113 tree type = TREE_TYPE (*valp); | 3168 tree type = TREE_TYPE (*valp); |
3114 tree subob = obj; | 3169 tree subob = obj; |
3124 subob = build_ctor_subob_ref (ce->index, type, obj); | 3179 subob = build_ctor_subob_ref (ce->index, type, obj); |
3125 if (TREE_CODE (*valp) == TARGET_EXPR) | 3180 if (TREE_CODE (*valp) == TARGET_EXPR) |
3126 valp = &TARGET_EXPR_INITIAL (*valp); | 3181 valp = &TARGET_EXPR_INITIAL (*valp); |
3127 } | 3182 } |
3128 d->obj = subob; | 3183 d->obj = subob; |
3129 cp_walk_tree (valp, replace_placeholders_r, data_, d->pset); | 3184 cp_walk_tree (valp, replace_placeholders_r, data_, NULL); |
3130 d->obj = obj; | 3185 d->obj = obj; |
3131 } | 3186 } |
3132 *walk_subtrees = false; | 3187 *walk_subtrees = false; |
3133 break; | 3188 break; |
3134 } | 3189 } |
3135 | 3190 |
3136 default: | 3191 default: |
3192 if (d->pset->add (*t)) | |
3193 *walk_subtrees = false; | |
3137 break; | 3194 break; |
3138 } | 3195 } |
3139 | 3196 |
3140 return NULL_TREE; | 3197 return NULL_TREE; |
3141 } | 3198 } |
3156 op0 = TREE_OPERAND (op0, 0); | 3213 op0 = TREE_OPERAND (op0, 0); |
3157 if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0)))) | 3214 if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0)))) |
3158 return exp; | 3215 return exp; |
3159 | 3216 |
3160 tree *tp = &exp; | 3217 tree *tp = &exp; |
3161 hash_set<tree> pset; | |
3162 replace_placeholders_t data = { obj, false, &pset }; | |
3163 if (TREE_CODE (exp) == TARGET_EXPR) | 3218 if (TREE_CODE (exp) == TARGET_EXPR) |
3164 tp = &TARGET_EXPR_INITIAL (exp); | 3219 tp = &TARGET_EXPR_INITIAL (exp); |
3165 cp_walk_tree (tp, replace_placeholders_r, &data, &pset); | 3220 hash_set<tree> pset; |
3221 replace_placeholders_t data = { obj, *tp, false, &pset }; | |
3222 cp_walk_tree (tp, replace_placeholders_r, &data, NULL); | |
3166 if (seen_p) | 3223 if (seen_p) |
3167 *seen_p = data.seen; | 3224 *seen_p = data.seen; |
3168 return exp; | 3225 return exp; |
3226 } | |
3227 | |
3228 /* Callback function for find_placeholders. */ | |
3229 | |
3230 static tree | |
3231 find_placeholders_r (tree *t, int *walk_subtrees, void *) | |
3232 { | |
3233 if (TYPE_P (*t) || TREE_CONSTANT (*t)) | |
3234 { | |
3235 *walk_subtrees = false; | |
3236 return NULL_TREE; | |
3237 } | |
3238 | |
3239 switch (TREE_CODE (*t)) | |
3240 { | |
3241 case PLACEHOLDER_EXPR: | |
3242 return *t; | |
3243 | |
3244 case CONSTRUCTOR: | |
3245 if (CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)) | |
3246 *walk_subtrees = false; | |
3247 break; | |
3248 | |
3249 default: | |
3250 break; | |
3251 } | |
3252 | |
3253 return NULL_TREE; | |
3254 } | |
3255 | |
3256 /* Return true if EXP contains a PLACEHOLDER_EXPR. Don't walk into | |
3257 ctors with CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag set. */ | |
3258 | |
3259 bool | |
3260 find_placeholders (tree exp) | |
3261 { | |
3262 /* This is only relevant for C++14. */ | |
3263 if (cxx_dialect < cxx14) | |
3264 return false; | |
3265 | |
3266 return cp_walk_tree_without_duplicates (&exp, find_placeholders_r, NULL); | |
3169 } | 3267 } |
3170 | 3268 |
3171 /* Similar to `build_nt', but for template definitions of dependent | 3269 /* Similar to `build_nt', but for template definitions of dependent |
3172 expressions */ | 3270 expressions */ |
3173 | 3271 |
3186 t = make_node (code); | 3284 t = make_node (code); |
3187 SET_EXPR_LOCATION (t, loc); | 3285 SET_EXPR_LOCATION (t, loc); |
3188 length = TREE_CODE_LENGTH (code); | 3286 length = TREE_CODE_LENGTH (code); |
3189 | 3287 |
3190 for (i = 0; i < length; i++) | 3288 for (i = 0; i < length; i++) |
3191 { | 3289 TREE_OPERAND (t, i) = va_arg (p, tree); |
3192 tree x = va_arg (p, tree); | |
3193 TREE_OPERAND (t, i) = x; | |
3194 if (x && TREE_CODE (x) == OVERLOAD) | |
3195 lookup_keep (x, true); | |
3196 } | |
3197 | 3290 |
3198 va_end (p); | 3291 va_end (p); |
3199 return t; | 3292 return t; |
3200 } | 3293 } |
3201 | 3294 |
3219 | 3312 |
3220 for (i = 0; i < length; i++) | 3313 for (i = 0; i < length; i++) |
3221 { | 3314 { |
3222 tree x = va_arg (p, tree); | 3315 tree x = va_arg (p, tree); |
3223 TREE_OPERAND (t, i) = x; | 3316 TREE_OPERAND (t, i) = x; |
3224 if (x) | 3317 if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x)) |
3225 { | 3318 TREE_SIDE_EFFECTS (t) = 1; |
3226 if (!TYPE_P (x) && TREE_SIDE_EFFECTS (x)) | |
3227 TREE_SIDE_EFFECTS (t) = 1; | |
3228 if (TREE_CODE (x) == OVERLOAD) | |
3229 lookup_keep (x, true); | |
3230 } | |
3231 } | 3319 } |
3232 | 3320 |
3233 va_end (p); | 3321 va_end (p); |
3322 | |
3234 return t; | 3323 return t; |
3235 } | 3324 } |
3236 | 3325 |
3237 /* Similar to `build', but for template definitions of non-dependent | 3326 /* Similar to `build', but for template definitions of non-dependent |
3238 expressions. NON_DEP is the non-dependent expression that has been | 3327 expressions. NON_DEP is the non-dependent expression that has been |
3257 length = TREE_CODE_LENGTH (code); | 3346 length = TREE_CODE_LENGTH (code); |
3258 TREE_TYPE (t) = unlowered_expr_type (non_dep); | 3347 TREE_TYPE (t) = unlowered_expr_type (non_dep); |
3259 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep); | 3348 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep); |
3260 | 3349 |
3261 for (i = 0; i < length; i++) | 3350 for (i = 0; i < length; i++) |
3262 { | 3351 TREE_OPERAND (t, i) = va_arg (p, tree); |
3263 tree x = va_arg (p, tree); | |
3264 TREE_OPERAND (t, i) = x; | |
3265 if (x && TREE_CODE (x) == OVERLOAD) | |
3266 lookup_keep (x, true); | |
3267 } | |
3268 | 3352 |
3269 if (code == COMPOUND_EXPR && TREE_CODE (non_dep) != COMPOUND_EXPR) | 3353 if (code == COMPOUND_EXPR && TREE_CODE (non_dep) != COMPOUND_EXPR) |
3270 /* This should not be considered a COMPOUND_EXPR, because it | 3354 /* This should not be considered a COMPOUND_EXPR, because it |
3271 resolves to an overload. */ | 3355 resolves to an overload. */ |
3272 COMPOUND_EXPR_OVERLOADED (t) = 1; | 3356 COMPOUND_EXPR_OVERLOADED (t) = 1; |
3285 | 3369 |
3286 ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3); | 3370 ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3); |
3287 CALL_EXPR_FN (ret) = fn; | 3371 CALL_EXPR_FN (ret) = fn; |
3288 CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE; | 3372 CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE; |
3289 FOR_EACH_VEC_SAFE_ELT (args, ix, t) | 3373 FOR_EACH_VEC_SAFE_ELT (args, ix, t) |
3290 { | 3374 CALL_EXPR_ARG (ret, ix) = t; |
3291 CALL_EXPR_ARG (ret, ix) = t; | 3375 |
3292 if (TREE_CODE (t) == OVERLOAD) | |
3293 lookup_keep (t, true); | |
3294 } | |
3295 return ret; | 3376 return ret; |
3296 } | 3377 } |
3297 | 3378 |
3298 /* Similar to `build_min_nt_call_vec', but for template definitions of | 3379 /* Similar to `build_min_nt_call_vec', but for template definitions of |
3299 non-dependent expressions. NON_DEP is the non-dependent expression | 3380 non-dependent expressions. NON_DEP is the non-dependent expression |
3490 | 3571 |
3491 code1 = TREE_CODE (t1); | 3572 code1 = TREE_CODE (t1); |
3492 code2 = TREE_CODE (t2); | 3573 code2 = TREE_CODE (t2); |
3493 | 3574 |
3494 if (code1 != code2) | 3575 if (code1 != code2) |
3576 return false; | |
3577 | |
3578 if (CONSTANT_CLASS_P (t1) | |
3579 && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))) | |
3495 return false; | 3580 return false; |
3496 | 3581 |
3497 switch (code1) | 3582 switch (code1) |
3498 { | 3583 { |
3499 case VOID_CST: | 3584 case VOID_CST: |
3749 DEFERRED_NOEXCEPT_PATTERN (t2)) | 3834 DEFERRED_NOEXCEPT_PATTERN (t2)) |
3750 && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1), | 3835 && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1), |
3751 DEFERRED_NOEXCEPT_ARGS (t2))); | 3836 DEFERRED_NOEXCEPT_ARGS (t2))); |
3752 break; | 3837 break; |
3753 | 3838 |
3839 case USING_DECL: | |
3840 if (DECL_DEPENDENT_P (t1) && DECL_DEPENDENT_P (t2)) | |
3841 return (cp_tree_equal (USING_DECL_SCOPE (t1), | |
3842 USING_DECL_SCOPE (t2)) | |
3843 && cp_tree_equal (DECL_NAME (t1), | |
3844 DECL_NAME (t2))); | |
3845 return false; | |
3846 | |
3754 default: | 3847 default: |
3755 break; | 3848 break; |
3756 } | 3849 } |
3757 | 3850 |
3758 switch (TREE_CODE_CLASS (code1)) | 3851 switch (TREE_CODE_CLASS (code1)) |
3839 | 3932 |
3840 tree | 3933 tree |
3841 build_dummy_object (tree type) | 3934 build_dummy_object (tree type) |
3842 { | 3935 { |
3843 tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node); | 3936 tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node); |
3844 return cp_build_indirect_ref (decl, RO_NULL, tf_warning_or_error); | 3937 return cp_build_fold_indirect_ref (decl); |
3845 } | 3938 } |
3846 | 3939 |
3847 /* We've gotten a reference to a member of TYPE. Return *this if appropriate, | 3940 /* We've gotten a reference to a member of TYPE. Return *this if appropriate, |
3848 or a dummy object otherwise. If BINFOP is non-0, it is filled with the | 3941 or a dummy object otherwise. If BINFOP is non-0, it is filled with the |
3849 binfo path from current_class_type to TYPE, or 0. */ | 3942 binfo path from current_class_type to TYPE, or 0. */ |
3934 { | 4027 { |
3935 if (!deleted_copy_types | 4028 if (!deleted_copy_types |
3936 || !deleted_copy_types->contains (t)) | 4029 || !deleted_copy_types->contains (t)) |
3937 return; | 4030 return; |
3938 | 4031 |
3939 warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in " | 4032 if ((flag_abi_version == 12 || warn_abi_version == 12) |
3940 "-fabi-version=12 (GCC 8)", t); | 4033 && classtype_has_non_deleted_move_ctor (t)) |
3941 static bool explained = false; | 4034 { |
3942 if (!explained) | 4035 bool w; |
3943 { | 4036 auto_diagnostic_group d; |
3944 inform (loc, " because all of its copy and move constructors " | 4037 if (flag_abi_version > 12) |
3945 "are deleted"); | 4038 w = warning_at (loc, OPT_Wabi, "-fabi-version=13 (GCC 8.2) fixes the " |
3946 explained = true; | 4039 "calling convention for %qT, which was accidentally " |
3947 } | 4040 "changed in 8.1", t); |
4041 else | |
4042 w = warning_at (loc, OPT_Wabi, "-fabi-version=12 (GCC 8.1) accident" | |
4043 "ally changes the calling convention for %qT", t); | |
4044 if (w) | |
4045 inform (location_of (t), " declared here"); | |
4046 return; | |
4047 } | |
4048 | |
4049 auto_diagnostic_group d; | |
4050 if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in " | |
4051 "-fabi-version=13 (GCC 8.2)", t)) | |
4052 inform (location_of (t), " because all of its copy and move " | |
4053 "constructors are deleted"); | |
3948 } | 4054 } |
3949 | 4055 |
3950 /* Returns true iff copying an object of type T (including via move | 4056 /* Returns true iff copying an object of type T (including via move |
3951 constructor) is non-trivial. That is, T has no non-trivial copy | 4057 constructor) is non-trivial. That is, T has no non-trivial copy |
3952 constructors and no non-trivial move constructors, and not all copy/move | 4058 constructors and no non-trivial move constructors, and not all copy/move |
3977 && !(warn_abi && abi_version_crosses (12))) | 4083 && !(warn_abi && abi_version_crosses (12))) |
3978 return false; | 4084 return false; |
3979 | 4085 |
3980 bool saw_copy = false; | 4086 bool saw_copy = false; |
3981 bool saw_non_deleted = false; | 4087 bool saw_non_deleted = false; |
4088 bool saw_non_deleted_move = false; | |
3982 | 4089 |
3983 if (CLASSTYPE_LAZY_MOVE_CTOR (t)) | 4090 if (CLASSTYPE_LAZY_MOVE_CTOR (t)) |
3984 saw_copy = saw_non_deleted = true; | 4091 saw_copy = saw_non_deleted = true; |
3985 else if (CLASSTYPE_LAZY_COPY_CTOR (t)) | 4092 else if (CLASSTYPE_LAZY_COPY_CTOR (t)) |
3986 { | 4093 { |
4008 /* Not deleted, therefore trivial. */ | 4115 /* Not deleted, therefore trivial. */ |
4009 saw_non_deleted = true; | 4116 saw_non_deleted = true; |
4010 break; | 4117 break; |
4011 } | 4118 } |
4012 } | 4119 } |
4120 else if (move_fn_p (fn)) | |
4121 if (!DECL_DELETED_FN (fn)) | |
4122 saw_non_deleted_move = true; | |
4013 } | 4123 } |
4014 | 4124 |
4015 gcc_assert (saw_copy); | 4125 gcc_assert (saw_copy); |
4016 | 4126 |
4017 if (saw_copy && !saw_non_deleted) | 4127 /* ABI v12 buggily ignored move constructors. */ |
4018 { | 4128 bool v11nontriv = false; |
4019 if (warn_abi && abi_version_crosses (12)) | 4129 bool v12nontriv = !saw_non_deleted; |
4020 remember_deleted_copy (t); | 4130 bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move; |
4021 if (abi_version_at_least (12)) | 4131 bool nontriv = (abi_version_at_least (13) ? v13nontriv |
4022 return true; | 4132 : flag_abi_version == 12 ? v12nontriv |
4023 } | 4133 : v11nontriv); |
4024 | 4134 bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv |
4025 return false; | 4135 : warn_abi_version == 12 ? v12nontriv |
4136 : v11nontriv); | |
4137 if (nontriv != warn_nontriv) | |
4138 remember_deleted_copy (t); | |
4139 | |
4140 return nontriv; | |
4026 } | 4141 } |
4027 else | 4142 else |
4028 return 0; | 4143 return 0; |
4029 } | 4144 } |
4030 | 4145 |
4314 *no_add_attrs = true; | 4429 *no_add_attrs = true; |
4315 } | 4430 } |
4316 return NULL_TREE; | 4431 return NULL_TREE; |
4317 } | 4432 } |
4318 | 4433 |
4434 /* Handle a C++2a "no_unique_address" attribute; arguments as in | |
4435 struct attribute_spec.handler. */ | |
4436 static tree | |
4437 handle_no_unique_addr_attribute (tree* node, | |
4438 tree name, | |
4439 tree /*args*/, | |
4440 int /*flags*/, | |
4441 bool* no_add_attrs) | |
4442 { | |
4443 if (TREE_CODE (*node) != FIELD_DECL) | |
4444 { | |
4445 warning (OPT_Wattributes, "%qE attribute can only be applied to " | |
4446 "non-static data members", name); | |
4447 *no_add_attrs = true; | |
4448 } | |
4449 else if (DECL_C_BIT_FIELD (*node)) | |
4450 { | |
4451 warning (OPT_Wattributes, "%qE attribute cannot be applied to " | |
4452 "a bit-field", name); | |
4453 *no_add_attrs = true; | |
4454 } | |
4455 | |
4456 return NULL_TREE; | |
4457 } | |
4458 | |
4319 /* Table of valid C++ attributes. */ | 4459 /* Table of valid C++ attributes. */ |
4320 const struct attribute_spec cxx_attribute_table[] = | 4460 const struct attribute_spec cxx_attribute_table[] = |
4321 { | 4461 { |
4322 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler, | 4462 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, |
4323 affects_type_identity } */ | 4463 affects_type_identity, handler, exclude } */ |
4324 { "init_priority", 1, 1, true, false, false, | 4464 { "init_priority", 1, 1, true, false, false, false, |
4325 handle_init_priority_attribute, false }, | 4465 handle_init_priority_attribute, NULL }, |
4326 { "abi_tag", 1, -1, false, false, false, | 4466 { "abi_tag", 1, -1, false, false, false, true, |
4327 handle_abi_tag_attribute, true }, | 4467 handle_abi_tag_attribute, NULL }, |
4328 { NULL, 0, 0, false, false, false, NULL, false } | 4468 { NULL, 0, 0, false, false, false, false, NULL, NULL } |
4329 }; | 4469 }; |
4330 | 4470 |
4331 /* Table of C++ standard attributes. */ | 4471 /* Table of C++ standard attributes. */ |
4332 const struct attribute_spec std_attribute_table[] = | 4472 const struct attribute_spec std_attribute_table[] = |
4333 { | 4473 { |
4334 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler, | 4474 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, |
4335 affects_type_identity } */ | 4475 affects_type_identity, handler, exclude } */ |
4336 { "maybe_unused", 0, 0, false, false, false, | 4476 { "maybe_unused", 0, 0, false, false, false, false, |
4337 handle_unused_attribute, false }, | 4477 handle_unused_attribute, NULL }, |
4338 { "nodiscard", 0, 0, false, false, false, | 4478 { "nodiscard", 0, 0, false, false, false, false, |
4339 handle_nodiscard_attribute, false }, | 4479 handle_nodiscard_attribute, NULL }, |
4340 { NULL, 0, 0, false, false, false, NULL, false } | 4480 { "no_unique_address", 0, 0, true, false, false, false, |
4481 handle_no_unique_addr_attribute, NULL }, | |
4482 { NULL, 0, 0, false, false, false, false, NULL, NULL } | |
4341 }; | 4483 }; |
4342 | 4484 |
4343 /* Handle an "init_priority" attribute; arguments as in | 4485 /* Handle an "init_priority" attribute; arguments as in |
4344 struct attribute_spec.handler. */ | 4486 struct attribute_spec.handler. */ |
4345 static tree | 4487 static tree |
4604 tree new_type; | 4746 tree new_type; |
4605 | 4747 |
4606 new_type = build_type_attribute_variant (type, attributes); | 4748 new_type = build_type_attribute_variant (type, attributes); |
4607 if (TREE_CODE (new_type) == FUNCTION_TYPE | 4749 if (TREE_CODE (new_type) == FUNCTION_TYPE |
4608 || TREE_CODE (new_type) == METHOD_TYPE) | 4750 || TREE_CODE (new_type) == METHOD_TYPE) |
4609 { | 4751 gcc_checking_assert (cxx_type_hash_eq (type, new_type)); |
4610 new_type = build_exception_variant (new_type, | |
4611 TYPE_RAISES_EXCEPTIONS (type)); | |
4612 new_type = build_ref_qualified_type (new_type, | |
4613 type_memfn_rqual (type)); | |
4614 } | |
4615 | 4752 |
4616 /* Making a new main variant of a class type is broken. */ | 4753 /* Making a new main variant of a class type is broken. */ |
4617 gcc_assert (!CLASS_TYPE_P (type) || new_type == type); | 4754 gcc_assert (!CLASS_TYPE_P (type) || new_type == type); |
4618 | 4755 |
4619 return new_type; | 4756 return new_type; |
4628 gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE | 4765 gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE |
4629 || TREE_CODE (typea) == METHOD_TYPE); | 4766 || TREE_CODE (typea) == METHOD_TYPE); |
4630 | 4767 |
4631 if (type_memfn_rqual (typea) != type_memfn_rqual (typeb)) | 4768 if (type_memfn_rqual (typea) != type_memfn_rqual (typeb)) |
4632 return false; | 4769 return false; |
4770 if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb)) | |
4771 return false; | |
4633 return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea), | 4772 return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea), |
4634 TYPE_RAISES_EXCEPTIONS (typeb), ce_exact); | 4773 TYPE_RAISES_EXCEPTIONS (typeb), ce_exact); |
4635 } | 4774 } |
4636 | 4775 |
4637 /* Copy the language-specific type variant modifiers from TYPEB to TYPEA. For | 4776 /* Copy the language-specific type variant modifiers from TYPEB to TYPEA. For |
4640 tree | 4779 tree |
4641 cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb) | 4780 cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb) |
4642 { | 4781 { |
4643 tree type = CONST_CAST_TREE (typea); | 4782 tree type = CONST_CAST_TREE (typea); |
4644 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | 4783 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) |
4645 { | 4784 type = build_cp_fntype_variant (type, type_memfn_rqual (typeb), |
4646 type = build_exception_variant (type, TYPE_RAISES_EXCEPTIONS (typeb)); | 4785 TYPE_RAISES_EXCEPTIONS (typeb), |
4647 type = build_ref_qualified_type (type, type_memfn_rqual (typeb)); | 4786 TYPE_HAS_LATE_RETURN_TYPE (typeb)); |
4648 } | |
4649 return type; | 4787 return type; |
4650 } | 4788 } |
4651 | 4789 |
4652 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order | 4790 /* Apply FUNC to all language-specific sub-trees of TP in a pre-order |
4653 traversal. Called from walk_tree. */ | 4791 traversal. Called from walk_tree. */ |
4764 WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp)); | 4902 WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp)); |
4765 *walk_subtrees_p = 0; | 4903 *walk_subtrees_p = 0; |
4766 break; | 4904 break; |
4767 | 4905 |
4768 case DECLTYPE_TYPE: | 4906 case DECLTYPE_TYPE: |
4769 WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp)); | 4907 ++cp_unevaluated_operand; |
4908 /* We can't use WALK_SUBTREE here because of the goto. */ | |
4909 result = cp_walk_tree (&DECLTYPE_TYPE_EXPR (*tp), func, data, pset); | |
4910 --cp_unevaluated_operand; | |
4911 *walk_subtrees_p = 0; | |
4912 break; | |
4913 | |
4914 case ALIGNOF_EXPR: | |
4915 case SIZEOF_EXPR: | |
4916 case NOEXCEPT_EXPR: | |
4917 ++cp_unevaluated_operand; | |
4918 result = cp_walk_tree (&TREE_OPERAND (*tp, 0), func, data, pset); | |
4919 --cp_unevaluated_operand; | |
4770 *walk_subtrees_p = 0; | 4920 *walk_subtrees_p = 0; |
4771 break; | 4921 break; |
4772 | 4922 |
4773 case REQUIRES_EXPR: | 4923 case REQUIRES_EXPR: |
4774 // Only recurse through the nested expression. Do not | 4924 // Only recurse through the nested expression. Do not |
4781 | 4931 |
4782 case DECL_EXPR: | 4932 case DECL_EXPR: |
4783 /* User variables should be mentioned in BIND_EXPR_VARS | 4933 /* User variables should be mentioned in BIND_EXPR_VARS |
4784 and their initializers and sizes walked when walking | 4934 and their initializers and sizes walked when walking |
4785 the containing BIND_EXPR. Compiler temporaries are | 4935 the containing BIND_EXPR. Compiler temporaries are |
4786 handled here. */ | 4936 handled here. And also normal variables in templates, |
4937 since do_poplevel doesn't build a BIND_EXPR then. */ | |
4787 if (VAR_P (TREE_OPERAND (*tp, 0)) | 4938 if (VAR_P (TREE_OPERAND (*tp, 0)) |
4788 && DECL_ARTIFICIAL (TREE_OPERAND (*tp, 0)) | 4939 && (processing_template_decl |
4789 && !TREE_STATIC (TREE_OPERAND (*tp, 0))) | 4940 || (DECL_ARTIFICIAL (TREE_OPERAND (*tp, 0)) |
4941 && !TREE_STATIC (TREE_OPERAND (*tp, 0))))) | |
4790 { | 4942 { |
4791 tree decl = TREE_OPERAND (*tp, 0); | 4943 tree decl = TREE_OPERAND (*tp, 0); |
4792 WALK_SUBTREE (DECL_INITIAL (decl)); | 4944 WALK_SUBTREE (DECL_INITIAL (decl)); |
4793 WALK_SUBTREE (DECL_SIZE (decl)); | 4945 WALK_SUBTREE (DECL_SIZE (decl)); |
4794 WALK_SUBTREE (DECL_SIZE_UNIT (decl)); | 4946 WALK_SUBTREE (DECL_SIZE_UNIT (decl)); |
4815 needed, we can create the SAVE_EXPR when instantiating the | 4967 needed, we can create the SAVE_EXPR when instantiating the |
4816 template. Furthermore, the middle-end cannot handle C++-specific | 4968 template. Furthermore, the middle-end cannot handle C++-specific |
4817 tree codes. */ | 4969 tree codes. */ |
4818 if (processing_template_decl) | 4970 if (processing_template_decl) |
4819 return expr; | 4971 return expr; |
4972 | |
4973 /* TARGET_EXPRs are only expanded once. */ | |
4974 if (TREE_CODE (expr) == TARGET_EXPR) | |
4975 return expr; | |
4976 | |
4820 return save_expr (expr); | 4977 return save_expr (expr); |
4821 } | 4978 } |
4822 | 4979 |
4823 /* Initialize tree.c. */ | 4980 /* Initialize tree.c. */ |
4824 | 4981 |
4845 return sfk_copy_constructor; | 5002 return sfk_copy_constructor; |
4846 if (DECL_MOVE_CONSTRUCTOR_P (decl)) | 5003 if (DECL_MOVE_CONSTRUCTOR_P (decl)) |
4847 return sfk_move_constructor; | 5004 return sfk_move_constructor; |
4848 if (DECL_CONSTRUCTOR_P (decl)) | 5005 if (DECL_CONSTRUCTOR_P (decl)) |
4849 return sfk_constructor; | 5006 return sfk_constructor; |
4850 if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR) | 5007 if (DECL_ASSIGNMENT_OPERATOR_P (decl) |
5008 && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR)) | |
4851 { | 5009 { |
4852 if (copy_fn_p (decl)) | 5010 if (copy_fn_p (decl)) |
4853 return sfk_copy_assignment; | 5011 return sfk_copy_assignment; |
4854 if (move_fn_p (decl)) | 5012 if (move_fn_p (decl)) |
4855 return sfk_move_assignment; | 5013 return sfk_move_assignment; |
4912 if (TREE_PUBLIC (decl)) | 5070 if (TREE_PUBLIC (decl)) |
4913 return lk_external; | 5071 return lk_external; |
4914 | 5072 |
4915 /* maybe_thunk_body clears TREE_PUBLIC on the maybe-in-charge 'tor variants, | 5073 /* maybe_thunk_body clears TREE_PUBLIC on the maybe-in-charge 'tor variants, |
4916 check one of the "clones" for the real linkage. */ | 5074 check one of the "clones" for the real linkage. */ |
4917 if ((DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl) | 5075 if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl) |
4918 || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl)) | |
4919 && DECL_CHAIN (decl) | 5076 && DECL_CHAIN (decl) |
4920 && DECL_CLONED_FUNCTION (DECL_CHAIN (decl))) | 5077 && DECL_CLONED_FUNCTION_P (DECL_CHAIN (decl))) |
4921 return decl_linkage (DECL_CHAIN (decl)); | 5078 return decl_linkage (DECL_CHAIN (decl)); |
4922 | 5079 |
4923 if (TREE_CODE (decl) == NAMESPACE_DECL) | 5080 if (TREE_CODE (decl) == NAMESPACE_DECL) |
4924 return lk_external; | 5081 return lk_external; |
4925 | 5082 |
4991 init_expr = exp; | 5148 init_expr = exp; |
4992 exp = void_node; | 5149 exp = void_node; |
4993 } | 5150 } |
4994 /* There are no expressions with REFERENCE_TYPE, but there can be call | 5151 /* There are no expressions with REFERENCE_TYPE, but there can be call |
4995 arguments with such a type; just treat it as a pointer. */ | 5152 arguments with such a type; just treat it as a pointer. */ |
4996 else if (TREE_CODE (TREE_TYPE (exp)) == REFERENCE_TYPE | 5153 else if (TYPE_REF_P (TREE_TYPE (exp)) |
4997 || SCALAR_TYPE_P (TREE_TYPE (exp)) | 5154 || SCALAR_TYPE_P (TREE_TYPE (exp)) |
4998 || !glvalue_p (exp)) | 5155 || !glvalue_p (exp)) |
4999 { | 5156 { |
5000 init_expr = get_target_expr (exp); | 5157 init_expr = get_target_expr (exp); |
5001 exp = TARGET_EXPR_SLOT (init_expr); | 5158 exp = TARGET_EXPR_SLOT (init_expr); |
5008 { | 5165 { |
5009 bool xval = !lvalue_p (exp); | 5166 bool xval = !lvalue_p (exp); |
5010 exp = cp_build_addr_expr (exp, tf_warning_or_error); | 5167 exp = cp_build_addr_expr (exp, tf_warning_or_error); |
5011 init_expr = get_target_expr (exp); | 5168 init_expr = get_target_expr (exp); |
5012 exp = TARGET_EXPR_SLOT (init_expr); | 5169 exp = TARGET_EXPR_SLOT (init_expr); |
5013 exp = cp_build_indirect_ref (exp, RO_NULL, tf_warning_or_error); | 5170 exp = cp_build_fold_indirect_ref (exp); |
5014 if (xval) | 5171 if (xval) |
5015 exp = move (exp); | 5172 exp = move (exp); |
5016 } | 5173 } |
5017 *initp = init_expr; | 5174 *initp = init_expr; |
5018 | 5175 |
5152 vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t); | 5309 vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t); |
5153 for (i = 0; vec_safe_iterate (v, i, &ce); ++i) | 5310 for (i = 0; vec_safe_iterate (v, i, &ce); ++i) |
5154 { | 5311 { |
5155 tree type = TREE_TYPE (ce->value); | 5312 tree type = TREE_TYPE (ce->value); |
5156 tree subinit; | 5313 tree subinit; |
5157 if (TREE_CODE (type) == REFERENCE_TYPE | 5314 if (TYPE_REF_P (type) |
5158 || SCALAR_TYPE_P (type)) | 5315 || SCALAR_TYPE_P (type)) |
5159 ce->value = stabilize_expr (ce->value, &subinit); | 5316 ce->value = stabilize_expr (ce->value, &subinit); |
5160 else if (!stabilize_init (ce->value, &subinit)) | 5317 else if (!stabilize_init (ce->value, &subinit)) |
5161 good = false; | 5318 good = false; |
5162 *initp = add_stmt_to_compound (*initp, subinit); | 5319 *initp = add_stmt_to_compound (*initp, subinit); |
5299 default: | 5456 default: |
5300 return TREE_CODE_LENGTH (code); | 5457 return TREE_CODE_LENGTH (code); |
5301 } | 5458 } |
5302 } | 5459 } |
5303 | 5460 |
5461 /* Like EXPR_LOCATION, but also handle some tcc_exceptional that have | |
5462 locations. */ | |
5463 | |
5464 location_t | |
5465 cp_expr_location (const_tree t_) | |
5466 { | |
5467 tree t = CONST_CAST_TREE (t_); | |
5468 if (t == NULL_TREE) | |
5469 return UNKNOWN_LOCATION; | |
5470 switch (TREE_CODE (t)) | |
5471 { | |
5472 case LAMBDA_EXPR: | |
5473 return LAMBDA_EXPR_LOCATION (t); | |
5474 case STATIC_ASSERT: | |
5475 return STATIC_ASSERT_SOURCE_LOCATION (t); | |
5476 default: | |
5477 return EXPR_LOCATION (t); | |
5478 } | |
5479 } | |
5480 | |
5304 /* Implement -Wzero_as_null_pointer_constant. Return true if the | 5481 /* Implement -Wzero_as_null_pointer_constant. Return true if the |
5305 conditions for the warning hold, false otherwise. */ | 5482 conditions for the warning hold, false otherwise. */ |
5306 bool | 5483 bool |
5307 maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc) | 5484 maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc) |
5308 { | 5485 { |
5309 if (c_inhibit_evaluation_warnings == 0 | 5486 if (c_inhibit_evaluation_warnings == 0 |
5310 && !NULLPTR_TYPE_P (TREE_TYPE (expr))) | 5487 && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr))) |
5311 { | 5488 { |
5312 warning_at (loc, OPT_Wzero_as_null_pointer_constant, | 5489 warning_at (loc, OPT_Wzero_as_null_pointer_constant, |
5313 "zero as null pointer constant"); | 5490 "zero as null pointer constant"); |
5314 return true; | 5491 return true; |
5315 } | 5492 } |
5326 internal_error ("lang_* check: failed in %s, at %s:%d", | 5503 internal_error ("lang_* check: failed in %s, at %s:%d", |
5327 function, trim_filename (file), line); | 5504 function, trim_filename (file), line); |
5328 } | 5505 } |
5329 #endif /* ENABLE_TREE_CHECKING */ | 5506 #endif /* ENABLE_TREE_CHECKING */ |
5330 | 5507 |
5508 #if CHECKING_P | |
5509 | |
5510 namespace selftest { | |
5511 | |
5512 /* Verify that lvalue_kind () works, for various expressions, | |
5513 and that location wrappers don't affect the results. */ | |
5514 | |
5515 static void | |
5516 test_lvalue_kind () | |
5517 { | |
5518 location_t loc = BUILTINS_LOCATION; | |
5519 | |
5520 /* Verify constants and parameters, without and with | |
5521 location wrappers. */ | |
5522 tree int_cst = build_int_cst (integer_type_node, 42); | |
5523 ASSERT_EQ (clk_none, lvalue_kind (int_cst)); | |
5524 | |
5525 tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc); | |
5526 ASSERT_TRUE (location_wrapper_p (wrapped_int_cst)); | |
5527 ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst)); | |
5528 | |
5529 tree string_lit = build_string (4, "foo"); | |
5530 TREE_TYPE (string_lit) = char_array_type_node; | |
5531 string_lit = fix_string_type (string_lit); | |
5532 ASSERT_EQ (clk_ordinary, lvalue_kind (string_lit)); | |
5533 | |
5534 tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc); | |
5535 ASSERT_TRUE (location_wrapper_p (wrapped_string_lit)); | |
5536 ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_string_lit)); | |
5537 | |
5538 tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL, | |
5539 get_identifier ("some_parm"), | |
5540 integer_type_node); | |
5541 ASSERT_EQ (clk_ordinary, lvalue_kind (parm)); | |
5542 | |
5543 tree wrapped_parm = maybe_wrap_with_location (parm, loc); | |
5544 ASSERT_TRUE (location_wrapper_p (wrapped_parm)); | |
5545 ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm)); | |
5546 | |
5547 /* Verify that lvalue_kind of std::move on a parm isn't | |
5548 affected by location wrappers. */ | |
5549 tree rvalue_ref_of_parm = move (parm); | |
5550 ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm)); | |
5551 tree rvalue_ref_of_wrapped_parm = move (wrapped_parm); | |
5552 ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm)); | |
5553 } | |
5554 | |
5555 /* Run all of the selftests within this file. */ | |
5556 | |
5557 void | |
5558 cp_tree_c_tests () | |
5559 { | |
5560 test_lvalue_kind (); | |
5561 } | |
5562 | |
5563 } // namespace selftest | |
5564 | |
5565 #endif /* #if CHECKING_P */ | |
5566 | |
5567 | |
5331 #include "gt-cp-tree.h" | 5568 #include "gt-cp-tree.h" |