Mercurial > hg > CbC > CbC_gcc
comparison gcc/cp/tree.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-dependent node constructors for parse phase of GNU compiler. | 1 /* Language-dependent node constructors for parse phase of GNU compiler. |
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 |
41 static tree bot_replace (tree *, int *, void *); | 41 static tree bot_replace (tree *, int *, void *); |
42 static hashval_t list_hash_pieces (tree, tree, tree); | 42 static hashval_t list_hash_pieces (tree, tree, tree); |
43 static tree build_target_expr (tree, tree, tsubst_flags_t); | 43 static tree build_target_expr (tree, tree, tsubst_flags_t); |
44 static tree count_trees_r (tree *, int *, void *); | 44 static tree count_trees_r (tree *, int *, void *); |
45 static tree verify_stmt_tree_r (tree *, int *, void *); | 45 static tree verify_stmt_tree_r (tree *, int *, void *); |
46 static tree build_local_temp (tree); | |
47 | 46 |
48 static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *); | 47 static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *); |
49 static tree handle_abi_tag_attribute (tree *, tree, tree, int, bool *); | 48 static tree handle_abi_tag_attribute (tree *, tree, tree, int, bool *); |
50 | 49 |
51 /* If REF is an lvalue, returns the kind of lvalue that REF is. | 50 /* If REF is an lvalue, returns the kind of lvalue that REF is. |
79 /* lvalue references and named rvalue references are lvalues. */ | 78 /* lvalue references and named rvalue references are lvalues. */ |
80 return clk_ordinary; | 79 return clk_ordinary; |
81 } | 80 } |
82 | 81 |
83 if (ref == current_class_ptr) | 82 if (ref == current_class_ptr) |
83 return clk_none; | |
84 | |
85 /* Expressions with cv void type are prvalues. */ | |
86 if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref))) | |
84 return clk_none; | 87 return clk_none; |
85 | 88 |
86 switch (TREE_CODE (ref)) | 89 switch (TREE_CODE (ref)) |
87 { | 90 { |
88 case SAVE_EXPR: | 91 case SAVE_EXPR: |
230 type-dependent expr, that is, but we shouldn't be testing | 233 type-dependent expr, that is, but we shouldn't be testing |
231 lvalueness if we can't even tell the types yet! */ | 234 lvalueness if we can't even tell the types yet! */ |
232 gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref))); | 235 gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref))); |
233 goto default_; | 236 goto default_; |
234 } | 237 } |
235 op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1) | 238 { |
236 ? TREE_OPERAND (ref, 1) | 239 tree op1 = TREE_OPERAND (ref, 1); |
237 : TREE_OPERAND (ref, 0)); | 240 if (!op1) op1 = TREE_OPERAND (ref, 0); |
238 op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 2)); | 241 tree op2 = TREE_OPERAND (ref, 2); |
242 op1_lvalue_kind = lvalue_kind (op1); | |
243 op2_lvalue_kind = lvalue_kind (op2); | |
244 if (!op1_lvalue_kind != !op2_lvalue_kind) | |
245 { | |
246 /* The second or the third operand (but not both) is a | |
247 throw-expression; the result is of the type | |
248 and value category of the other. */ | |
249 if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR) | |
250 op2_lvalue_kind = op1_lvalue_kind; | |
251 else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR) | |
252 op1_lvalue_kind = op2_lvalue_kind; | |
253 } | |
254 } | |
239 break; | 255 break; |
240 | 256 |
241 case MODOP_EXPR: | 257 case MODOP_EXPR: |
242 /* We expect to see unlowered MODOP_EXPRs only during | 258 /* We expect to see unlowered MODOP_EXPRs only during |
243 template processing. */ | 259 template processing. */ |
277 return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref))); | 293 return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref))); |
278 | 294 |
279 case NON_DEPENDENT_EXPR: | 295 case NON_DEPENDENT_EXPR: |
280 case PAREN_EXPR: | 296 case PAREN_EXPR: |
281 return lvalue_kind (TREE_OPERAND (ref, 0)); | 297 return lvalue_kind (TREE_OPERAND (ref, 0)); |
298 | |
299 case TEMPLATE_PARM_INDEX: | |
300 if (CLASS_TYPE_P (TREE_TYPE (ref))) | |
301 /* A template parameter object is an lvalue. */ | |
302 return clk_ordinary; | |
303 return clk_none; | |
282 | 304 |
283 default: | 305 default: |
284 default_: | 306 default_: |
285 if (!TREE_TYPE (ref)) | 307 if (!TREE_TYPE (ref)) |
286 return clk_none; | 308 return clk_none; |
369 /* C++-specific version of stabilize_reference. */ | 391 /* C++-specific version of stabilize_reference. */ |
370 | 392 |
371 tree | 393 tree |
372 cp_stabilize_reference (tree ref) | 394 cp_stabilize_reference (tree ref) |
373 { | 395 { |
396 STRIP_ANY_LOCATION_WRAPPER (ref); | |
374 switch (TREE_CODE (ref)) | 397 switch (TREE_CODE (ref)) |
375 { | 398 { |
376 case NON_DEPENDENT_EXPR: | 399 case NON_DEPENDENT_EXPR: |
377 /* We aren't actually evaluating this. */ | 400 /* We aren't actually evaluating this. */ |
378 return ref; | 401 return ref; |
400 bool rval = !!(kind & clk_rvalueref); | 423 bool rval = !!(kind & clk_rvalueref); |
401 type = cp_build_reference_type (type, rval); | 424 type = cp_build_reference_type (type, rval); |
402 /* This inhibits warnings in, eg, cxx_mark_addressable | 425 /* This inhibits warnings in, eg, cxx_mark_addressable |
403 (c++/60955). */ | 426 (c++/60955). */ |
404 warning_sentinel s (extra_warnings); | 427 warning_sentinel s (extra_warnings); |
405 ref = build_static_cast (type, ref, tf_error); | 428 ref = build_static_cast (input_location, type, ref, |
429 tf_error); | |
406 } | 430 } |
407 } | 431 } |
408 | 432 |
409 return stabilize_reference (ref); | 433 return stabilize_reference (ref); |
410 } | 434 } |
413 constant-expression. */ | 437 constant-expression. */ |
414 | 438 |
415 bool | 439 bool |
416 builtin_valid_in_constant_expr_p (const_tree decl) | 440 builtin_valid_in_constant_expr_p (const_tree decl) |
417 { | 441 { |
442 STRIP_ANY_LOCATION_WRAPPER (decl); | |
418 if (TREE_CODE (decl) != FUNCTION_DECL) | 443 if (TREE_CODE (decl) != FUNCTION_DECL) |
419 /* Not a function. */ | 444 /* Not a function. */ |
420 return false; | 445 return false; |
421 if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL) | 446 if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL) |
422 { | 447 { |
423 if (fndecl_built_in_p (decl, CP_BUILT_IN_IS_CONSTANT_EVALUATED, | 448 if (fndecl_built_in_p (decl, CP_BUILT_IN_IS_CONSTANT_EVALUATED, |
424 BUILT_IN_FRONTEND)) | 449 BUILT_IN_FRONTEND) |
450 || fndecl_built_in_p (decl, CP_BUILT_IN_SOURCE_LOCATION, | |
451 BUILT_IN_FRONTEND)) | |
425 return true; | 452 return true; |
426 /* Not a built-in. */ | 453 /* Not a built-in. */ |
427 return false; | 454 return false; |
428 } | 455 } |
429 switch (DECL_FUNCTION_CODE (decl)) | 456 switch (DECL_FUNCTION_CODE (decl)) |
498 } | 525 } |
499 | 526 |
500 /* Return an undeclared local temporary of type TYPE for use in building a | 527 /* Return an undeclared local temporary of type TYPE for use in building a |
501 TARGET_EXPR. */ | 528 TARGET_EXPR. */ |
502 | 529 |
503 static tree | 530 tree |
504 build_local_temp (tree type) | 531 build_local_temp (tree type) |
505 { | 532 { |
506 tree slot = build_decl (input_location, | 533 tree slot = build_decl (input_location, |
507 VAR_DECL, NULL_TREE, type); | 534 VAR_DECL, NULL_TREE, type); |
508 DECL_ARTIFICIAL (slot) = 1; | 535 DECL_ARTIFICIAL (slot) = 1; |
509 DECL_IGNORED_P (slot) = 1; | 536 DECL_IGNORED_P (slot) = 1; |
510 DECL_CONTEXT (slot) = current_function_decl; | 537 DECL_CONTEXT (slot) = current_function_decl; |
511 layout_decl (slot, 0); | 538 layout_decl (slot, 0); |
512 return slot; | 539 return slot; |
540 } | |
541 | |
542 /* Return whether DECL is such a local temporary (or one from | |
543 create_tmp_var_raw). */ | |
544 | |
545 bool | |
546 is_local_temp (tree decl) | |
547 { | |
548 return (VAR_P (decl) && DECL_ARTIFICIAL (decl) | |
549 && !TREE_STATIC (decl) | |
550 && DECL_FUNCTION_SCOPE_P (decl)); | |
513 } | 551 } |
514 | 552 |
515 /* Set various status flags when building an AGGR_INIT_EXPR object T. */ | 553 /* Set various status flags when building an AGGR_INIT_EXPR object T. */ |
516 | 554 |
517 static void | 555 static void |
573 { | 611 { |
574 tree fn; | 612 tree fn; |
575 tree slot; | 613 tree slot; |
576 tree rval; | 614 tree rval; |
577 int is_ctor; | 615 int is_ctor; |
616 | |
617 gcc_assert (!VOID_TYPE_P (type)); | |
578 | 618 |
579 /* Don't build AGGR_INIT_EXPR in a template. */ | 619 /* Don't build AGGR_INIT_EXPR in a template. */ |
580 if (processing_template_decl) | 620 if (processing_template_decl) |
581 return init; | 621 return init; |
582 | 622 |
641 and language-specific expression expanders. */ | 681 and language-specific expression expanders. */ |
642 | 682 |
643 tree | 683 tree |
644 build_cplus_new (tree type, tree init, tsubst_flags_t complain) | 684 build_cplus_new (tree type, tree init, tsubst_flags_t complain) |
645 { | 685 { |
686 /* This function should cope with what build_special_member_call | |
687 can produce. When performing parenthesized aggregate initialization, | |
688 it can produce a { }. */ | |
689 if (BRACE_ENCLOSED_INITIALIZER_P (init)) | |
690 { | |
691 gcc_assert (cxx_dialect >= cxx2a); | |
692 return finish_compound_literal (type, init, complain); | |
693 } | |
694 | |
646 tree rval = build_aggr_init_expr (type, init); | 695 tree rval = build_aggr_init_expr (type, init); |
647 tree slot; | 696 tree slot; |
648 | 697 |
649 if (init == error_mark_node) | 698 if (init == error_mark_node) |
650 return error_mark_node; | 699 return error_mark_node; |
686 | 735 |
687 static tree | 736 static tree |
688 build_vec_init_elt (tree type, tree init, tsubst_flags_t complain) | 737 build_vec_init_elt (tree type, tree init, tsubst_flags_t complain) |
689 { | 738 { |
690 tree inner_type = strip_array_types (type); | 739 tree inner_type = strip_array_types (type); |
691 vec<tree, va_gc> *argvec; | |
692 | 740 |
693 if (integer_zerop (array_type_nelts_total (type)) | 741 if (integer_zerop (array_type_nelts_total (type)) |
694 || !CLASS_TYPE_P (inner_type)) | 742 || !CLASS_TYPE_P (inner_type)) |
695 /* No interesting initialization to do. */ | 743 /* No interesting initialization to do. */ |
696 return integer_zero_node; | 744 return integer_zero_node; |
699 | 747 |
700 gcc_assert (init == NULL_TREE | 748 gcc_assert (init == NULL_TREE |
701 || (same_type_ignoring_top_level_qualifiers_p | 749 || (same_type_ignoring_top_level_qualifiers_p |
702 (type, TREE_TYPE (init)))); | 750 (type, TREE_TYPE (init)))); |
703 | 751 |
704 argvec = make_tree_vector (); | 752 releasing_vec argvec; |
705 if (init) | 753 if (init) |
706 { | 754 { |
707 tree init_type = strip_array_types (TREE_TYPE (init)); | 755 tree init_type = strip_array_types (TREE_TYPE (init)); |
708 tree dummy = build_dummy_object (init_type); | 756 tree dummy = build_dummy_object (init_type); |
709 if (!lvalue_p (init)) | 757 if (!lvalue_p (init)) |
711 argvec->quick_push (dummy); | 759 argvec->quick_push (dummy); |
712 } | 760 } |
713 init = build_special_member_call (NULL_TREE, complete_ctor_identifier, | 761 init = build_special_member_call (NULL_TREE, complete_ctor_identifier, |
714 &argvec, inner_type, LOOKUP_NORMAL, | 762 &argvec, inner_type, LOOKUP_NORMAL, |
715 complain); | 763 complain); |
716 release_tree_vector (argvec); | |
717 | 764 |
718 /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But | 765 /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But |
719 we don't want one here because we aren't creating a temporary. */ | 766 we don't want one here because we aren't creating a temporary. */ |
720 if (TREE_CODE (init) == TARGET_EXPR) | 767 if (TREE_CODE (init) == TARGET_EXPR) |
721 init = TARGET_EXPR_INITIAL (init); | 768 init = TARGET_EXPR_INITIAL (init); |
1086 build_array_of_n_type (tree elt, int n) | 1133 build_array_of_n_type (tree elt, int n) |
1087 { | 1134 { |
1088 return build_cplus_array_type (elt, build_index_type (size_int (n - 1))); | 1135 return build_cplus_array_type (elt, build_index_type (size_int (n - 1))); |
1089 } | 1136 } |
1090 | 1137 |
1138 /* True iff T is an array of unknown bound. */ | |
1139 | |
1140 bool | |
1141 array_of_unknown_bound_p (const_tree t) | |
1142 { | |
1143 return (TREE_CODE (t) == ARRAY_TYPE | |
1144 && !TYPE_DOMAIN (t)); | |
1145 } | |
1146 | |
1091 /* True iff T is an N3639 array of runtime bound (VLA). These were approved | 1147 /* True iff T is an N3639 array of runtime bound (VLA). These were approved |
1092 for C++14 but then removed. This should only be used for N3639 | 1148 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 | 1149 specifically; code wondering more generally if something is a VLA should use |
1094 vla_type_p. */ | 1150 vla_type_p. */ |
1095 | 1151 |
1185 move (tree expr) | 1241 move (tree expr) |
1186 { | 1242 { |
1187 tree type = TREE_TYPE (expr); | 1243 tree type = TREE_TYPE (expr); |
1188 gcc_assert (!TYPE_REF_P (type)); | 1244 gcc_assert (!TYPE_REF_P (type)); |
1189 type = cp_build_reference_type (type, /*rval*/true); | 1245 type = cp_build_reference_type (type, /*rval*/true); |
1190 return build_static_cast (type, expr, tf_warning_or_error); | 1246 return build_static_cast (input_location, type, expr, |
1247 tf_warning_or_error); | |
1191 } | 1248 } |
1192 | 1249 |
1193 /* Used by the C++ front end to build qualified array types. However, | 1250 /* Used by the C++ front end to build qualified array types. However, |
1194 the C version of this function does not properly maintain canonical | 1251 the C version of this function does not properly maintain canonical |
1195 types (which are not used in C). */ | 1252 types (which are not used in C). */ |
1296 /* A reference or method type shall not be cv-qualified. | 1353 /* A reference or method type shall not be cv-qualified. |
1297 [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295 | 1354 [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295 |
1298 (in CD1) we always ignore extra cv-quals on functions. */ | 1355 (in CD1) we always ignore extra cv-quals on functions. */ |
1299 if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE) | 1356 if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE) |
1300 && (TYPE_REF_P (type) | 1357 && (TYPE_REF_P (type) |
1301 || TREE_CODE (type) == FUNCTION_TYPE | 1358 || FUNC_OR_METHOD_TYPE_P (type))) |
1302 || TREE_CODE (type) == METHOD_TYPE)) | |
1303 { | 1359 { |
1304 if (TYPE_REF_P (type)) | 1360 if (TYPE_REF_P (type)) |
1305 bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); | 1361 bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); |
1306 type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); | 1362 type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); |
1307 } | 1363 } |
1405 *remove_attributes = true; | 1461 *remove_attributes = true; |
1406 | 1462 |
1407 return cp_build_type_attribute_variant (result, new_attribs); | 1463 return cp_build_type_attribute_variant (result, new_attribs); |
1408 } | 1464 } |
1409 | 1465 |
1410 /* Builds a qualified variant of T that is not a typedef variant. | 1466 /* Builds a qualified variant of T that is either not a typedef variant |
1467 (the default behavior) or not a typedef variant of a user-facing type | |
1468 (if FLAGS contains STF_USER_FACING). | |
1469 | |
1411 E.g. consider the following declarations: | 1470 E.g. consider the following declarations: |
1412 typedef const int ConstInt; | 1471 typedef const int ConstInt; |
1413 typedef ConstInt* PtrConstInt; | 1472 typedef ConstInt* PtrConstInt; |
1414 If T is PtrConstInt, this function returns a type representing | 1473 If T is PtrConstInt, this function returns a type representing |
1415 const int*. | 1474 const int*. |
1430 If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't | 1489 If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't |
1431 affect type identity, and set the referent to true if any were | 1490 affect type identity, and set the referent to true if any were |
1432 stripped. */ | 1491 stripped. */ |
1433 | 1492 |
1434 tree | 1493 tree |
1435 strip_typedefs (tree t, bool *remove_attributes) | 1494 strip_typedefs (tree t, bool *remove_attributes, unsigned int flags) |
1436 { | 1495 { |
1437 tree result = NULL, type = NULL, t0 = NULL; | 1496 tree result = NULL, type = NULL, t0 = NULL; |
1438 | 1497 |
1439 if (!t || t == error_mark_node) | 1498 if (!t || t == error_mark_node) |
1440 return t; | 1499 return t; |
1441 | 1500 |
1442 if (TREE_CODE (t) == TREE_LIST) | 1501 if (TREE_CODE (t) == TREE_LIST) |
1443 { | 1502 { |
1444 bool changed = false; | 1503 bool changed = false; |
1445 vec<tree,va_gc> *vec = make_tree_vector (); | 1504 releasing_vec vec; |
1446 tree r = t; | 1505 tree r = t; |
1447 for (; t; t = TREE_CHAIN (t)) | 1506 for (; t; t = TREE_CHAIN (t)) |
1448 { | 1507 { |
1449 gcc_assert (!TREE_PURPOSE (t)); | 1508 gcc_assert (!TREE_PURPOSE (t)); |
1450 tree elt = strip_typedefs (TREE_VALUE (t), remove_attributes); | 1509 tree elt = strip_typedefs (TREE_VALUE (t), remove_attributes, flags); |
1451 if (elt != TREE_VALUE (t)) | 1510 if (elt != TREE_VALUE (t)) |
1452 changed = true; | 1511 changed = true; |
1453 vec_safe_push (vec, elt); | 1512 vec_safe_push (vec, elt); |
1454 } | 1513 } |
1455 if (changed) | 1514 if (changed) |
1456 r = build_tree_list_vec (vec); | 1515 r = build_tree_list_vec (vec); |
1457 release_tree_vector (vec); | |
1458 return r; | 1516 return r; |
1459 } | 1517 } |
1460 | 1518 |
1461 gcc_assert (TYPE_P (t)); | 1519 gcc_assert (TYPE_P (t)); |
1462 | 1520 |
1463 if (t == TYPE_CANONICAL (t)) | 1521 if (t == TYPE_CANONICAL (t)) |
1464 return t; | 1522 return t; |
1465 | 1523 |
1466 if (dependent_alias_template_spec_p (t)) | 1524 if (!(flags & STF_STRIP_DEPENDENT) |
1525 && dependent_alias_template_spec_p (t, nt_opaque)) | |
1467 /* DR 1558: However, if the template-id is dependent, subsequent | 1526 /* DR 1558: However, if the template-id is dependent, subsequent |
1468 template argument substitution still applies to the template-id. */ | 1527 template argument substitution still applies to the template-id. */ |
1469 return t; | 1528 return t; |
1470 | 1529 |
1471 switch (TREE_CODE (t)) | 1530 switch (TREE_CODE (t)) |
1472 { | 1531 { |
1473 case POINTER_TYPE: | 1532 case POINTER_TYPE: |
1474 type = strip_typedefs (TREE_TYPE (t), remove_attributes); | 1533 type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags); |
1475 result = build_pointer_type (type); | 1534 result = build_pointer_type (type); |
1476 break; | 1535 break; |
1477 case REFERENCE_TYPE: | 1536 case REFERENCE_TYPE: |
1478 type = strip_typedefs (TREE_TYPE (t), remove_attributes); | 1537 type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags); |
1479 result = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t)); | 1538 result = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t)); |
1480 break; | 1539 break; |
1481 case OFFSET_TYPE: | 1540 case OFFSET_TYPE: |
1482 t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes); | 1541 t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags); |
1483 type = strip_typedefs (TREE_TYPE (t), remove_attributes); | 1542 type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags); |
1484 result = build_offset_type (t0, type); | 1543 result = build_offset_type (t0, type); |
1485 break; | 1544 break; |
1486 case RECORD_TYPE: | 1545 case RECORD_TYPE: |
1487 if (TYPE_PTRMEMFUNC_P (t)) | 1546 if (TYPE_PTRMEMFUNC_P (t)) |
1488 { | 1547 { |
1489 t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t), remove_attributes); | 1548 t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t), |
1549 remove_attributes, flags); | |
1490 result = build_ptrmemfunc_type (t0); | 1550 result = build_ptrmemfunc_type (t0); |
1491 } | 1551 } |
1492 break; | 1552 break; |
1493 case ARRAY_TYPE: | 1553 case ARRAY_TYPE: |
1494 type = strip_typedefs (TREE_TYPE (t), remove_attributes); | 1554 type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags); |
1495 t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes); | 1555 t0 = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags); |
1496 result = build_cplus_array_type (type, t0); | 1556 result = build_cplus_array_type (type, t0); |
1497 break; | 1557 break; |
1498 case FUNCTION_TYPE: | 1558 case FUNCTION_TYPE: |
1499 case METHOD_TYPE: | 1559 case METHOD_TYPE: |
1500 { | 1560 { |
1509 bool is_variant = typedef_variant_p (t); | 1569 bool is_variant = typedef_variant_p (t); |
1510 if (remove_attributes | 1570 if (remove_attributes |
1511 && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t))) | 1571 && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t))) |
1512 is_variant = true; | 1572 is_variant = true; |
1513 | 1573 |
1514 type = strip_typedefs (TREE_TYPE (t), remove_attributes); | 1574 type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags); |
1515 tree canon_spec = (flag_noexcept_type | 1575 tree canon_spec = (flag_noexcept_type |
1516 ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t)) | 1576 ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t)) |
1517 : NULL_TREE); | 1577 : NULL_TREE); |
1518 changed = (type != TREE_TYPE (t) || is_variant | 1578 changed = (type != TREE_TYPE (t) || is_variant |
1519 || TYPE_RAISES_EXCEPTIONS (t) != canon_spec); | 1579 || TYPE_RAISES_EXCEPTIONS (t) != canon_spec); |
1523 arg_node = TREE_CHAIN (arg_node)) | 1583 arg_node = TREE_CHAIN (arg_node)) |
1524 { | 1584 { |
1525 if (arg_node == void_list_node) | 1585 if (arg_node == void_list_node) |
1526 break; | 1586 break; |
1527 arg_type = strip_typedefs (TREE_VALUE (arg_node), | 1587 arg_type = strip_typedefs (TREE_VALUE (arg_node), |
1528 remove_attributes); | 1588 remove_attributes, flags); |
1529 gcc_assert (arg_type); | 1589 gcc_assert (arg_type); |
1530 if (arg_type == TREE_VALUE (arg_node) && !changed) | 1590 if (arg_type == TREE_VALUE (arg_node) && !changed) |
1531 continue; | 1591 continue; |
1532 | 1592 |
1533 if (!changed) | 1593 if (!changed) |
1587 for (int i = 0; i < TREE_VEC_LENGTH (args); ++i) | 1647 for (int i = 0; i < TREE_VEC_LENGTH (args); ++i) |
1588 { | 1648 { |
1589 tree arg = TREE_VEC_ELT (args, i); | 1649 tree arg = TREE_VEC_ELT (args, i); |
1590 tree strip_arg; | 1650 tree strip_arg; |
1591 if (TYPE_P (arg)) | 1651 if (TYPE_P (arg)) |
1592 strip_arg = strip_typedefs (arg, remove_attributes); | 1652 strip_arg = strip_typedefs (arg, remove_attributes, flags); |
1593 else | 1653 else |
1594 strip_arg = strip_typedefs_expr (arg, remove_attributes); | 1654 strip_arg = strip_typedefs_expr (arg, remove_attributes, |
1655 flags); | |
1595 TREE_VEC_ELT (new_args, i) = strip_arg; | 1656 TREE_VEC_ELT (new_args, i) = strip_arg; |
1596 if (strip_arg != arg) | 1657 if (strip_arg != arg) |
1597 changed = true; | 1658 changed = true; |
1598 } | 1659 } |
1599 if (changed) | 1660 if (changed) |
1605 new_args); | 1666 new_args); |
1606 } | 1667 } |
1607 else | 1668 else |
1608 ggc_free (new_args); | 1669 ggc_free (new_args); |
1609 } | 1670 } |
1610 tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes); | 1671 tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags); |
1611 if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t)) | 1672 if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t)) |
1612 return t; | 1673 return t; |
1613 tree name = fullname; | 1674 tree name = fullname; |
1614 if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR) | 1675 if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR) |
1615 name = TREE_OPERAND (fullname, 0); | 1676 name = TREE_OPERAND (fullname, 0); |
1618 result = build_typename_type (ctx, name, fullname, typename_type); | 1679 result = build_typename_type (ctx, name, fullname, typename_type); |
1619 } | 1680 } |
1620 break; | 1681 break; |
1621 case DECLTYPE_TYPE: | 1682 case DECLTYPE_TYPE: |
1622 result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t), | 1683 result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t), |
1623 remove_attributes); | 1684 remove_attributes, flags); |
1624 if (result == DECLTYPE_TYPE_EXPR (t)) | 1685 if (result == DECLTYPE_TYPE_EXPR (t)) |
1625 result = NULL_TREE; | 1686 result = NULL_TREE; |
1626 else | 1687 else |
1627 result = (finish_decltype_type | 1688 result = (finish_decltype_type |
1628 (result, | 1689 (result, |
1629 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t), | 1690 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t), |
1630 tf_none)); | 1691 tf_none)); |
1631 break; | 1692 break; |
1632 case UNDERLYING_TYPE: | 1693 case UNDERLYING_TYPE: |
1633 type = strip_typedefs (UNDERLYING_TYPE_TYPE (t), remove_attributes); | 1694 type = strip_typedefs (UNDERLYING_TYPE_TYPE (t), |
1695 remove_attributes, flags); | |
1634 result = finish_underlying_type (type); | 1696 result = finish_underlying_type (type); |
1635 break; | 1697 break; |
1636 default: | 1698 default: |
1637 break; | 1699 break; |
1638 } | 1700 } |
1639 | 1701 |
1640 if (!result) | 1702 if (!result) |
1641 { | 1703 { |
1642 if (typedef_variant_p (t)) | 1704 if (typedef_variant_p (t)) |
1643 { | 1705 { |
1644 /* Explicitly get the underlying type, as TYPE_MAIN_VARIANT doesn't | 1706 if ((flags & STF_USER_VISIBLE) |
1645 strip typedefs with attributes. */ | 1707 && !user_facing_original_type_p (t)) |
1646 result = TYPE_MAIN_VARIANT (DECL_ORIGINAL_TYPE (TYPE_NAME (t))); | 1708 return t; |
1647 result = strip_typedefs (result); | 1709 /* If T is a non-template alias or typedef, we can assume that |
1710 instantiating its definition will hit any substitution failure, | |
1711 so we don't need to retain it here as well. */ | |
1712 if (!alias_template_specialization_p (t, nt_opaque)) | |
1713 flags |= STF_STRIP_DEPENDENT; | |
1714 result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)), | |
1715 remove_attributes, flags); | |
1648 } | 1716 } |
1649 else | 1717 else |
1650 result = TYPE_MAIN_VARIANT (t); | 1718 result = TYPE_MAIN_VARIANT (t); |
1651 } | 1719 } |
1652 gcc_assert (!typedef_variant_p (result)); | 1720 /*gcc_assert (!typedef_variant_p (result) |
1721 || dependent_alias_template_spec_p (result, nt_opaque) | |
1722 || ((flags & STF_USER_VISIBLE) | |
1723 && !user_facing_original_type_p (result)));*/ | |
1653 | 1724 |
1654 if (COMPLETE_TYPE_P (result) && !COMPLETE_TYPE_P (t)) | 1725 if (COMPLETE_TYPE_P (result) && !COMPLETE_TYPE_P (t)) |
1655 /* If RESULT is complete and T isn't, it's likely the case that T | 1726 /* If RESULT is complete and T isn't, it's likely the case that T |
1656 is a variant of RESULT which hasn't been updated yet. Skip the | 1727 is a variant of RESULT which hasn't been updated yet. Skip the |
1657 attribute handling. */; | 1728 attribute handling. */; |
1696 }; | 1767 }; |
1697 | 1768 |
1698 sizeof(TT) is replaced by sizeof(T). */ | 1769 sizeof(TT) is replaced by sizeof(T). */ |
1699 | 1770 |
1700 tree | 1771 tree |
1701 strip_typedefs_expr (tree t, bool *remove_attributes) | 1772 strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags) |
1702 { | 1773 { |
1703 unsigned i,n; | 1774 unsigned i,n; |
1704 tree r, type, *ops; | 1775 tree r, type, *ops; |
1705 enum tree_code code; | 1776 enum tree_code code; |
1706 | 1777 |
1707 if (t == NULL_TREE || t == error_mark_node) | 1778 if (t == NULL_TREE || t == error_mark_node) |
1708 return t; | 1779 return t; |
1709 | 1780 |
1781 STRIP_ANY_LOCATION_WRAPPER (t); | |
1782 | |
1710 if (DECL_P (t) || CONSTANT_CLASS_P (t)) | 1783 if (DECL_P (t) || CONSTANT_CLASS_P (t)) |
1711 return t; | 1784 return t; |
1712 | 1785 |
1713 /* Some expressions have type operands, so let's handle types here rather | 1786 /* Some expressions have type operands, so let's handle types here rather |
1714 than check TYPE_P in multiple places below. */ | 1787 than check TYPE_P in multiple places below. */ |
1715 if (TYPE_P (t)) | 1788 if (TYPE_P (t)) |
1716 return strip_typedefs (t, remove_attributes); | 1789 return strip_typedefs (t, remove_attributes, flags); |
1717 | 1790 |
1718 code = TREE_CODE (t); | 1791 code = TREE_CODE (t); |
1719 switch (code) | 1792 switch (code) |
1720 { | 1793 { |
1721 case IDENTIFIER_NODE: | 1794 case IDENTIFIER_NODE: |
1725 case ARGUMENT_PACK_SELECT: | 1798 case ARGUMENT_PACK_SELECT: |
1726 return t; | 1799 return t; |
1727 | 1800 |
1728 case TRAIT_EXPR: | 1801 case TRAIT_EXPR: |
1729 { | 1802 { |
1730 tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t), remove_attributes); | 1803 tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t), |
1731 tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t), remove_attributes); | 1804 remove_attributes, flags); |
1805 tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t), | |
1806 remove_attributes, flags); | |
1732 if (type1 == TRAIT_EXPR_TYPE1 (t) | 1807 if (type1 == TRAIT_EXPR_TYPE1 (t) |
1733 && type2 == TRAIT_EXPR_TYPE2 (t)) | 1808 && type2 == TRAIT_EXPR_TYPE2 (t)) |
1734 return t; | 1809 return t; |
1735 r = copy_node (t); | 1810 r = copy_node (t); |
1736 TRAIT_EXPR_TYPE1 (r) = type1; | 1811 TRAIT_EXPR_TYPE1 (r) = type1; |
1738 return r; | 1813 return r; |
1739 } | 1814 } |
1740 | 1815 |
1741 case TREE_LIST: | 1816 case TREE_LIST: |
1742 { | 1817 { |
1743 vec<tree, va_gc> *vec = make_tree_vector (); | 1818 releasing_vec vec; |
1744 bool changed = false; | 1819 bool changed = false; |
1745 tree it; | 1820 tree it; |
1746 for (it = t; it; it = TREE_CHAIN (it)) | 1821 for (it = t; it; it = TREE_CHAIN (it)) |
1747 { | 1822 { |
1748 tree val = strip_typedefs_expr (TREE_VALUE (it), remove_attributes); | 1823 tree val = strip_typedefs_expr (TREE_VALUE (it), |
1824 remove_attributes, flags); | |
1749 vec_safe_push (vec, val); | 1825 vec_safe_push (vec, val); |
1750 if (val != TREE_VALUE (it)) | 1826 if (val != TREE_VALUE (it)) |
1751 changed = true; | 1827 changed = true; |
1752 gcc_assert (TREE_PURPOSE (it) == NULL_TREE); | 1828 gcc_assert (TREE_PURPOSE (it) == NULL_TREE); |
1753 } | 1829 } |
1757 FOR_EACH_VEC_ELT_REVERSE (*vec, i, it) | 1833 FOR_EACH_VEC_ELT_REVERSE (*vec, i, it) |
1758 r = tree_cons (NULL_TREE, it, r); | 1834 r = tree_cons (NULL_TREE, it, r); |
1759 } | 1835 } |
1760 else | 1836 else |
1761 r = t; | 1837 r = t; |
1762 release_tree_vector (vec); | |
1763 return r; | 1838 return r; |
1764 } | 1839 } |
1765 | 1840 |
1766 case TREE_VEC: | 1841 case TREE_VEC: |
1767 { | 1842 { |
1768 bool changed = false; | 1843 bool changed = false; |
1769 vec<tree, va_gc> *vec = make_tree_vector (); | 1844 releasing_vec vec; |
1770 n = TREE_VEC_LENGTH (t); | 1845 n = TREE_VEC_LENGTH (t); |
1771 vec_safe_reserve (vec, n); | 1846 vec_safe_reserve (vec, n); |
1772 for (i = 0; i < n; ++i) | 1847 for (i = 0; i < n; ++i) |
1773 { | 1848 { |
1774 tree op = strip_typedefs_expr (TREE_VEC_ELT (t, i), | 1849 tree op = strip_typedefs_expr (TREE_VEC_ELT (t, i), |
1775 remove_attributes); | 1850 remove_attributes, flags); |
1776 vec->quick_push (op); | 1851 vec->quick_push (op); |
1777 if (op != TREE_VEC_ELT (t, i)) | 1852 if (op != TREE_VEC_ELT (t, i)) |
1778 changed = true; | 1853 changed = true; |
1779 } | 1854 } |
1780 if (changed) | 1855 if (changed) |
1785 NON_DEFAULT_TEMPLATE_ARGS_COUNT (r) | 1860 NON_DEFAULT_TEMPLATE_ARGS_COUNT (r) |
1786 = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t); | 1861 = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t); |
1787 } | 1862 } |
1788 else | 1863 else |
1789 r = t; | 1864 r = t; |
1790 release_tree_vector (vec); | |
1791 return r; | 1865 return r; |
1792 } | 1866 } |
1793 | 1867 |
1794 case CONSTRUCTOR: | 1868 case CONSTRUCTOR: |
1795 { | 1869 { |
1796 bool changed = false; | 1870 bool changed = false; |
1797 vec<constructor_elt, va_gc> *vec | 1871 vec<constructor_elt, va_gc> *vec |
1798 = vec_safe_copy (CONSTRUCTOR_ELTS (t)); | 1872 = vec_safe_copy (CONSTRUCTOR_ELTS (t)); |
1799 n = CONSTRUCTOR_NELTS (t); | 1873 n = CONSTRUCTOR_NELTS (t); |
1800 type = strip_typedefs (TREE_TYPE (t), remove_attributes); | 1874 type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags); |
1801 for (i = 0; i < n; ++i) | 1875 for (i = 0; i < n; ++i) |
1802 { | 1876 { |
1803 constructor_elt *e = &(*vec)[i]; | 1877 constructor_elt *e = &(*vec)[i]; |
1804 tree op = strip_typedefs_expr (e->value, remove_attributes); | 1878 tree op = strip_typedefs_expr (e->value, remove_attributes, flags); |
1805 if (op != e->value) | 1879 if (op != e->value) |
1806 { | 1880 { |
1807 changed = true; | 1881 changed = true; |
1808 e->value = op; | 1882 e->value = op; |
1809 } | 1883 } |
1810 gcc_checking_assert | 1884 gcc_checking_assert |
1811 (e->index == strip_typedefs_expr (e->index, remove_attributes)); | 1885 (e->index == strip_typedefs_expr (e->index, remove_attributes, |
1886 flags)); | |
1812 } | 1887 } |
1813 | 1888 |
1814 if (!changed && type == TREE_TYPE (t)) | 1889 if (!changed && type == TREE_TYPE (t)) |
1815 { | 1890 { |
1816 vec_free (vec); | 1891 vec_free (vec); |
1824 return r; | 1899 return r; |
1825 } | 1900 } |
1826 } | 1901 } |
1827 | 1902 |
1828 case LAMBDA_EXPR: | 1903 case LAMBDA_EXPR: |
1829 error ("lambda-expression in a constant expression"); | 1904 return t; |
1830 return error_mark_node; | |
1831 | 1905 |
1832 case STATEMENT_LIST: | 1906 case STATEMENT_LIST: |
1833 error ("statement-expression in a constant expression"); | 1907 error ("statement-expression in a constant expression"); |
1834 return error_mark_node; | 1908 return error_mark_node; |
1835 | 1909 |
1851 case STATIC_CAST_EXPR: | 1925 case STATIC_CAST_EXPR: |
1852 case CONST_CAST_EXPR: | 1926 case CONST_CAST_EXPR: |
1853 case REINTERPRET_CAST_EXPR: | 1927 case REINTERPRET_CAST_EXPR: |
1854 case CAST_EXPR: | 1928 case CAST_EXPR: |
1855 case NEW_EXPR: | 1929 case NEW_EXPR: |
1856 type = strip_typedefs (type, remove_attributes); | 1930 type = strip_typedefs (type, remove_attributes, flags); |
1857 /* fallthrough */ | 1931 /* fallthrough */ |
1858 | 1932 |
1859 default: | 1933 default: |
1860 for (i = 0; i < n; ++i) | 1934 for (i = 0; i < n; ++i) |
1861 ops[i] = strip_typedefs_expr (TREE_OPERAND (t, i), remove_attributes); | 1935 ops[i] = strip_typedefs_expr (TREE_OPERAND (t, i), |
1936 remove_attributes, flags); | |
1862 break; | 1937 break; |
1863 } | 1938 } |
1864 | 1939 |
1865 /* If nothing changed, return t. */ | 1940 /* If nothing changed, return t. */ |
1866 for (i = 0; i < n; ++i) | 1941 for (i = 0; i < n; ++i) |
2151 if (TREE_CODE (fn) == OVERLOAD) | 2226 if (TREE_CODE (fn) == OVERLOAD) |
2152 OVL_NESTED_P (result) = true; | 2227 OVL_NESTED_P (result) = true; |
2153 | 2228 |
2154 TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL | 2229 TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL |
2155 ? unknown_type_node : TREE_TYPE (fn)); | 2230 ? unknown_type_node : TREE_TYPE (fn)); |
2231 if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next)) | |
2232 OVL_DEDUP_P (result) = true; | |
2156 OVL_FUNCTION (result) = fn; | 2233 OVL_FUNCTION (result) = fn; |
2157 OVL_CHAIN (result) = next; | 2234 OVL_CHAIN (result) = next; |
2158 return result; | 2235 return result; |
2159 } | 2236 } |
2160 | 2237 |
2161 static tree | |
2162 ovl_copy (tree ovl) | |
2163 { | |
2164 tree result = make_node (OVERLOAD); | |
2165 | |
2166 gcc_checking_assert (!OVL_NESTED_P (ovl) && OVL_USED_P (ovl)); | |
2167 TREE_TYPE (result) = TREE_TYPE (ovl); | |
2168 OVL_FUNCTION (result) = OVL_FUNCTION (ovl); | |
2169 OVL_CHAIN (result) = OVL_CHAIN (ovl); | |
2170 OVL_HIDDEN_P (result) = OVL_HIDDEN_P (ovl); | |
2171 OVL_USING_P (result) = OVL_USING_P (ovl); | |
2172 OVL_LOOKUP_P (result) = OVL_LOOKUP_P (ovl); | |
2173 | |
2174 return result; | |
2175 } | |
2176 | |
2177 /* Add FN to the (potentially NULL) overload set OVL. USING_P is | 2238 /* Add FN to the (potentially NULL) overload set OVL. USING_P is |
2178 true, if FN is via a using declaration. We also pay attention to | 2239 true, if FN is via a using declaration. We also pay attention to |
2179 DECL_HIDDEN. Overloads are ordered as hidden, using, regular. */ | 2240 DECL_HIDDEN. We keep the hidden decls first, but remaining ones |
2241 are unordered. */ | |
2180 | 2242 |
2181 tree | 2243 tree |
2182 ovl_insert (tree fn, tree maybe_ovl, bool using_p) | 2244 ovl_insert (tree fn, tree maybe_ovl, bool using_p) |
2183 { | 2245 { |
2184 bool copying = false; /* Checking use only. */ | 2246 tree result = maybe_ovl; |
2247 tree insert_after = NULL_TREE; | |
2248 | |
2249 /* Skip hidden. */ | |
2250 for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD | |
2251 && OVL_HIDDEN_P (maybe_ovl); | |
2252 maybe_ovl = OVL_CHAIN (maybe_ovl)) | |
2253 { | |
2254 gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl)); | |
2255 insert_after = maybe_ovl; | |
2256 } | |
2257 | |
2185 bool hidden_p = DECL_HIDDEN_P (fn); | 2258 bool hidden_p = DECL_HIDDEN_P (fn); |
2186 int weight = (hidden_p << 1) | (using_p << 0); | |
2187 | |
2188 tree result = NULL_TREE; | |
2189 tree insert_after = NULL_TREE; | |
2190 | |
2191 /* Find insertion point. */ | |
2192 while (maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD | |
2193 && (weight < ((OVL_HIDDEN_P (maybe_ovl) << 1) | |
2194 | (OVL_USING_P (maybe_ovl) << 0)))) | |
2195 { | |
2196 gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl) | |
2197 && (!copying || OVL_USED_P (maybe_ovl))); | |
2198 if (OVL_USED_P (maybe_ovl)) | |
2199 { | |
2200 copying = true; | |
2201 maybe_ovl = ovl_copy (maybe_ovl); | |
2202 if (insert_after) | |
2203 OVL_CHAIN (insert_after) = maybe_ovl; | |
2204 } | |
2205 if (!result) | |
2206 result = maybe_ovl; | |
2207 insert_after = maybe_ovl; | |
2208 maybe_ovl = OVL_CHAIN (maybe_ovl); | |
2209 } | |
2210 | |
2211 tree trail = fn; | |
2212 if (maybe_ovl || using_p || hidden_p || TREE_CODE (fn) == TEMPLATE_DECL) | 2259 if (maybe_ovl || using_p || hidden_p || TREE_CODE (fn) == TEMPLATE_DECL) |
2213 { | 2260 { |
2214 trail = ovl_make (fn, maybe_ovl); | 2261 maybe_ovl = ovl_make (fn, maybe_ovl); |
2215 if (hidden_p) | 2262 if (hidden_p) |
2216 OVL_HIDDEN_P (trail) = true; | 2263 OVL_HIDDEN_P (maybe_ovl) = true; |
2217 if (using_p) | 2264 if (using_p) |
2218 OVL_USING_P (trail) = true; | 2265 OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true; |
2219 } | 2266 } |
2267 else | |
2268 maybe_ovl = fn; | |
2220 | 2269 |
2221 if (insert_after) | 2270 if (insert_after) |
2222 { | 2271 { |
2223 OVL_CHAIN (insert_after) = trail; | 2272 OVL_CHAIN (insert_after) = maybe_ovl; |
2224 TREE_TYPE (insert_after) = unknown_type_node; | 2273 TREE_TYPE (insert_after) = unknown_type_node; |
2225 } | 2274 } |
2226 else | 2275 else |
2227 result = trail; | 2276 result = maybe_ovl; |
2228 | 2277 |
2229 return result; | 2278 return result; |
2230 } | 2279 } |
2231 | 2280 |
2232 /* Skip any hidden names at the beginning of OVL. */ | 2281 /* Skip any hidden names at the beginning of OVL. */ |
2253 /* NODE is an OVL_HIDDEN_P node which is now revealed. */ | 2302 /* NODE is an OVL_HIDDEN_P node which is now revealed. */ |
2254 | 2303 |
2255 tree | 2304 tree |
2256 ovl_iterator::reveal_node (tree overload, tree node) | 2305 ovl_iterator::reveal_node (tree overload, tree node) |
2257 { | 2306 { |
2258 /* We cannot have returned NODE as part of a lookup overload, so it | 2307 /* We cannot have returned NODE as part of a lookup overload, so we |
2259 cannot be USED. */ | 2308 don't have to worry about preserving that. */ |
2260 gcc_checking_assert (!OVL_USED_P (node)); | |
2261 | 2309 |
2262 OVL_HIDDEN_P (node) = false; | 2310 OVL_HIDDEN_P (node) = false; |
2263 if (tree chain = OVL_CHAIN (node)) | 2311 if (tree chain = OVL_CHAIN (node)) |
2264 if (TREE_CODE (chain) == OVERLOAD | 2312 if (TREE_CODE (chain) == OVERLOAD) |
2265 && (OVL_USING_P (chain) || OVL_HIDDEN_P (chain))) | |
2266 { | 2313 { |
2267 /* The node needs moving, and the simplest way is to remove it | 2314 if (OVL_HIDDEN_P (chain)) |
2268 and reinsert. */ | 2315 { |
2269 overload = remove_node (overload, node); | 2316 /* The node needs moving, and the simplest way is to remove it |
2270 overload = ovl_insert (OVL_FUNCTION (node), overload); | 2317 and reinsert. */ |
2318 overload = remove_node (overload, node); | |
2319 overload = ovl_insert (OVL_FUNCTION (node), overload); | |
2320 } | |
2321 else if (OVL_DEDUP_P (chain)) | |
2322 OVL_DEDUP_P (node) = true; | |
2271 } | 2323 } |
2272 return overload; | 2324 return overload; |
2273 } | 2325 } |
2274 | 2326 |
2275 /* NODE is on the overloads of OVL. Remove it. If a predecessor is | 2327 /* NODE is on the overloads of OVL. Remove it. |
2276 OVL_USED_P we must copy OVL nodes, because those are immutable. | |
2277 The removed node is unaltered and may continue to be iterated | 2328 The removed node is unaltered and may continue to be iterated |
2278 from (i.e. it is safe to remove a node from an overload one is | 2329 from (i.e. it is safe to remove a node from an overload one is |
2279 currently iterating over). */ | 2330 currently iterating over). */ |
2280 | 2331 |
2281 tree | 2332 tree |
2282 ovl_iterator::remove_node (tree overload, tree node) | 2333 ovl_iterator::remove_node (tree overload, tree node) |
2283 { | 2334 { |
2284 bool copying = false; /* Checking use only. */ | |
2285 | |
2286 tree *slot = &overload; | 2335 tree *slot = &overload; |
2287 while (*slot != node) | 2336 while (*slot != node) |
2288 { | 2337 { |
2289 tree probe = *slot; | 2338 tree probe = *slot; |
2290 gcc_checking_assert (!OVL_LOOKUP_P (probe) | 2339 gcc_checking_assert (!OVL_LOOKUP_P (probe)); |
2291 && (!copying || OVL_USED_P (probe))); | |
2292 if (OVL_USED_P (probe)) | |
2293 { | |
2294 copying = true; | |
2295 probe = ovl_copy (probe); | |
2296 *slot = probe; | |
2297 } | |
2298 | 2340 |
2299 slot = &OVL_CHAIN (probe); | 2341 slot = &OVL_CHAIN (probe); |
2300 } | 2342 } |
2301 | 2343 |
2302 /* Stitch out NODE. We don't have to worry about now making a | 2344 /* Stitch out NODE. We don't have to worry about now making a |
2327 /* Add a set of new FNS into a lookup. */ | 2369 /* Add a set of new FNS into a lookup. */ |
2328 | 2370 |
2329 tree | 2371 tree |
2330 lookup_add (tree fns, tree lookup) | 2372 lookup_add (tree fns, tree lookup) |
2331 { | 2373 { |
2374 if (fns == error_mark_node || lookup == error_mark_node) | |
2375 return error_mark_node; | |
2376 | |
2332 if (lookup || TREE_CODE (fns) == TEMPLATE_DECL) | 2377 if (lookup || TREE_CODE (fns) == TEMPLATE_DECL) |
2333 { | 2378 { |
2334 lookup = ovl_make (fns, lookup); | 2379 lookup = ovl_make (fns, lookup); |
2335 OVL_LOOKUP_P (lookup) = true; | 2380 OVL_LOOKUP_P (lookup) = true; |
2336 } | 2381 } |
2365 /* This function was already seen. Insert all the | 2410 /* This function was already seen. Insert all the |
2366 predecessors onto the lookup. */ | 2411 predecessors onto the lookup. */ |
2367 for (; fns != probe; fns = OVL_CHAIN (fns)) | 2412 for (; fns != probe; fns = OVL_CHAIN (fns)) |
2368 { | 2413 { |
2369 lookup = lookup_add (OVL_FUNCTION (fns), lookup); | 2414 lookup = lookup_add (OVL_FUNCTION (fns), lookup); |
2370 /* Propagate OVL_USING, but OVL_HIDDEN doesn't matter. */ | 2415 /* Propagate OVL_USING, but OVL_HIDDEN & |
2416 OVL_DEDUP_P don't matter. */ | |
2371 if (OVL_USING_P (fns)) | 2417 if (OVL_USING_P (fns)) |
2372 OVL_USING_P (lookup) = true; | 2418 OVL_USING_P (lookup) = true; |
2373 } | 2419 } |
2374 | 2420 |
2375 /* And now skip this function. */ | 2421 /* And now skip this function. */ |
2380 if (fns) | 2426 if (fns) |
2381 /* We ended in a set of new functions. Add them all in one go. */ | 2427 /* We ended in a set of new functions. Add them all in one go. */ |
2382 lookup = lookup_add (fns, lookup); | 2428 lookup = lookup_add (fns, lookup); |
2383 | 2429 |
2384 return lookup; | 2430 return lookup; |
2385 } | |
2386 | |
2387 /* Regular overload OVL is part of a kept lookup. Mark the nodes on | |
2388 it as immutable. */ | |
2389 | |
2390 static void | |
2391 ovl_used (tree ovl) | |
2392 { | |
2393 for (; | |
2394 ovl && TREE_CODE (ovl) == OVERLOAD | |
2395 && !OVL_USED_P (ovl); | |
2396 ovl = OVL_CHAIN (ovl)) | |
2397 { | |
2398 gcc_checking_assert (!OVL_LOOKUP_P (ovl)); | |
2399 OVL_USED_P (ovl) = true; | |
2400 } | |
2401 } | |
2402 | |
2403 /* Preserve the contents of a lookup so that it is available for a | |
2404 later instantiation. */ | |
2405 | |
2406 void | |
2407 lookup_keep (tree lookup) | |
2408 { | |
2409 for (; | |
2410 lookup && TREE_CODE (lookup) == OVERLOAD | |
2411 && OVL_LOOKUP_P (lookup) && !OVL_USED_P (lookup); | |
2412 lookup = OVL_CHAIN (lookup)) | |
2413 { | |
2414 OVL_USED_P (lookup) = true; | |
2415 ovl_used (OVL_FUNCTION (lookup)); | |
2416 } | |
2417 | |
2418 ovl_used (lookup); | |
2419 } | 2431 } |
2420 | 2432 |
2421 /* Returns nonzero if X is an expression for a (possibly overloaded) | 2433 /* Returns nonzero if X is an expression for a (possibly overloaded) |
2422 function. If "f" is a function or function template, "f", "c->f", | 2434 function. If "f" is a function or function template, "f", "c->f", |
2423 "c.f", "C::f", and "f<int>" will all be considered possibly | 2435 "c.f", "C::f", and "f<int>" will all be considered possibly |
2426 function without performing overload resolution. */ | 2438 function without performing overload resolution. */ |
2427 | 2439 |
2428 int | 2440 int |
2429 is_overloaded_fn (tree x) | 2441 is_overloaded_fn (tree x) |
2430 { | 2442 { |
2443 STRIP_ANY_LOCATION_WRAPPER (x); | |
2444 | |
2431 /* A baselink is also considered an overloaded function. */ | 2445 /* A baselink is also considered an overloaded function. */ |
2432 if (TREE_CODE (x) == OFFSET_REF | 2446 if (TREE_CODE (x) == OFFSET_REF |
2433 || TREE_CODE (x) == COMPONENT_REF) | 2447 || TREE_CODE (x) == COMPONENT_REF) |
2434 x = TREE_OPERAND (x, 1); | 2448 x = TREE_OPERAND (x, 1); |
2435 x = MAYBE_BASELINK_FUNCTIONS (x); | 2449 x = MAYBE_BASELINK_FUNCTIONS (x); |
2438 | 2452 |
2439 if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x)) | 2453 if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x)) |
2440 || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x))) | 2454 || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x))) |
2441 return 2; | 2455 return 2; |
2442 | 2456 |
2443 return (TREE_CODE (x) == FUNCTION_DECL | 2457 return OVL_P (x); |
2444 || TREE_CODE (x) == OVERLOAD); | |
2445 } | 2458 } |
2446 | 2459 |
2447 /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name | 2460 /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name |
2448 (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return | 2461 (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return |
2449 NULL_TREE. */ | 2462 NULL_TREE. */ |
2453 { | 2466 { |
2454 if (identifier_p (x)) | 2467 if (identifier_p (x)) |
2455 return x; | 2468 return x; |
2456 if (TREE_CODE (x) == TEMPLATE_ID_EXPR) | 2469 if (TREE_CODE (x) == TEMPLATE_ID_EXPR) |
2457 x = TREE_OPERAND (x, 0); | 2470 x = TREE_OPERAND (x, 0); |
2458 if (TREE_CODE (x) == OVERLOAD || TREE_CODE (x) == FUNCTION_DECL) | 2471 if (OVL_P (x)) |
2459 return OVL_NAME (x); | 2472 return OVL_NAME (x); |
2460 return NULL_TREE; | 2473 return NULL_TREE; |
2461 } | 2474 } |
2462 | 2475 |
2463 /* Returns true iff X is an expression for an overloaded function | 2476 /* Returns true iff X is an expression for an overloaded function |
2474 overload set. */ | 2487 overload set. */ |
2475 | 2488 |
2476 tree | 2489 tree |
2477 maybe_get_fns (tree from) | 2490 maybe_get_fns (tree from) |
2478 { | 2491 { |
2492 STRIP_ANY_LOCATION_WRAPPER (from); | |
2493 | |
2479 /* A baselink is also considered an overloaded function. */ | 2494 /* A baselink is also considered an overloaded function. */ |
2480 if (TREE_CODE (from) == OFFSET_REF | 2495 if (TREE_CODE (from) == OFFSET_REF |
2481 || TREE_CODE (from) == COMPONENT_REF) | 2496 || TREE_CODE (from) == COMPONENT_REF) |
2482 from = TREE_OPERAND (from, 1); | 2497 from = TREE_OPERAND (from, 1); |
2483 if (BASELINK_P (from)) | 2498 if (BASELINK_P (from)) |
2484 from = BASELINK_FUNCTIONS (from); | 2499 from = BASELINK_FUNCTIONS (from); |
2485 if (TREE_CODE (from) == TEMPLATE_ID_EXPR) | 2500 if (TREE_CODE (from) == TEMPLATE_ID_EXPR) |
2486 from = TREE_OPERAND (from, 0); | 2501 from = TREE_OPERAND (from, 0); |
2487 | 2502 |
2488 if (TREE_CODE (from) == OVERLOAD | 2503 if (OVL_P (from)) |
2489 || TREE_CODE (from) == FUNCTION_DECL) | |
2490 return from; | 2504 return from; |
2491 | 2505 |
2492 return NULL; | 2506 return NULL; |
2493 } | 2507 } |
2494 | 2508 |
2599 canonical_eh_spec (tree raises) | 2613 canonical_eh_spec (tree raises) |
2600 { | 2614 { |
2601 if (raises == NULL_TREE) | 2615 if (raises == NULL_TREE) |
2602 return raises; | 2616 return raises; |
2603 else if (DEFERRED_NOEXCEPT_SPEC_P (raises) | 2617 else if (DEFERRED_NOEXCEPT_SPEC_P (raises) |
2618 || UNPARSED_NOEXCEPT_SPEC_P (raises) | |
2604 || uses_template_parms (raises) | 2619 || uses_template_parms (raises) |
2605 || uses_template_parms (TREE_PURPOSE (raises))) | 2620 || uses_template_parms (TREE_PURPOSE (raises))) |
2606 /* Keep a dependent or deferred exception specification. */ | 2621 /* Keep a dependent or deferred exception specification. */ |
2607 return raises; | 2622 return raises; |
2608 else if (nothrow_spec_p (raises)) | 2623 else if (nothrow_spec_p (raises)) |
2770 tree | 2785 tree |
2771 no_linkage_check (tree t, bool relaxed_p) | 2786 no_linkage_check (tree t, bool relaxed_p) |
2772 { | 2787 { |
2773 tree r; | 2788 tree r; |
2774 | 2789 |
2775 /* There's no point in checking linkage on template functions; we | 2790 /* Lambda types that don't have mangling scope have no linkage. We |
2791 check CLASSTYPE_LAMBDA_EXPR for error_mark_node because | |
2792 when we get here from pushtag none of the lambda information is | |
2793 set up yet, so we want to assume that the lambda has linkage and | |
2794 fix it up later if not. We need to check this even in templates so | |
2795 that we properly handle a lambda-expression in the signature. */ | |
2796 if (LAMBDA_TYPE_P (t) | |
2797 && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node | |
2798 && LAMBDA_TYPE_EXTRA_SCOPE (t) == NULL_TREE) | |
2799 return t; | |
2800 | |
2801 /* Otherwise there's no point in checking linkage on template functions; we | |
2776 can't know their complete types. */ | 2802 can't know their complete types. */ |
2777 if (processing_template_decl) | 2803 if (processing_template_decl) |
2778 return NULL_TREE; | 2804 return NULL_TREE; |
2779 | 2805 |
2780 switch (TREE_CODE (t)) | 2806 switch (TREE_CODE (t)) |
2781 { | 2807 { |
2782 case RECORD_TYPE: | 2808 case RECORD_TYPE: |
2783 if (TYPE_PTRMEMFUNC_P (t)) | 2809 if (TYPE_PTRMEMFUNC_P (t)) |
2784 goto ptrmem; | 2810 goto ptrmem; |
2785 /* Lambda types that don't have mangling scope have no linkage. We | |
2786 check CLASSTYPE_LAMBDA_EXPR for error_mark_node because | |
2787 when we get here from pushtag none of the lambda information is | |
2788 set up yet, so we want to assume that the lambda has linkage and | |
2789 fix it up later if not. */ | |
2790 if (CLASSTYPE_LAMBDA_EXPR (t) | |
2791 && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node | |
2792 && LAMBDA_TYPE_EXTRA_SCOPE (t) == NULL_TREE) | |
2793 return t; | |
2794 /* Fall through. */ | 2811 /* Fall through. */ |
2795 case UNION_TYPE: | 2812 case UNION_TYPE: |
2796 if (!CLASS_TYPE_P (t)) | 2813 if (!CLASS_TYPE_P (t)) |
2797 return NULL_TREE; | 2814 return NULL_TREE; |
2798 /* Fall through. */ | 2815 /* Fall through. */ |
3166 { | 3183 { |
3167 tree *valp = &ce->value; | 3184 tree *valp = &ce->value; |
3168 tree type = TREE_TYPE (*valp); | 3185 tree type = TREE_TYPE (*valp); |
3169 tree subob = obj; | 3186 tree subob = obj; |
3170 | 3187 |
3188 /* Elements with RANGE_EXPR index shouldn't have any | |
3189 placeholders in them. */ | |
3190 if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR) | |
3191 continue; | |
3192 | |
3171 if (TREE_CODE (*valp) == CONSTRUCTOR | 3193 if (TREE_CODE (*valp) == CONSTRUCTOR |
3172 && AGGREGATE_TYPE_P (type)) | 3194 && AGGREGATE_TYPE_P (type)) |
3173 { | 3195 { |
3174 /* If we're looking at the initializer for OBJ, then build | 3196 /* If we're looking at the initializer for OBJ, then build |
3175 a sub-object reference. If we're looking at an | 3197 a sub-object reference. If we're looking at an |
3341 | 3363 |
3342 if (REFERENCE_REF_P (non_dep)) | 3364 if (REFERENCE_REF_P (non_dep)) |
3343 non_dep = TREE_OPERAND (non_dep, 0); | 3365 non_dep = TREE_OPERAND (non_dep, 0); |
3344 | 3366 |
3345 t = make_node (code); | 3367 t = make_node (code); |
3368 SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep)); | |
3346 length = TREE_CODE_LENGTH (code); | 3369 length = TREE_CODE_LENGTH (code); |
3347 TREE_TYPE (t) = unlowered_expr_type (non_dep); | 3370 TREE_TYPE (t) = unlowered_expr_type (non_dep); |
3348 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep); | 3371 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep); |
3349 | 3372 |
3350 for (i = 0; i < length; i++) | 3373 for (i = 0; i < length; i++) |
3403 tree overload, ...) | 3426 tree overload, ...) |
3404 { | 3427 { |
3405 va_list p; | 3428 va_list p; |
3406 int nargs, expected_nargs; | 3429 int nargs, expected_nargs; |
3407 tree fn, call; | 3430 tree fn, call; |
3408 vec<tree, va_gc> *args; | |
3409 | 3431 |
3410 non_dep = extract_call_expr (non_dep); | 3432 non_dep = extract_call_expr (non_dep); |
3411 | 3433 |
3412 nargs = call_expr_nargs (non_dep); | 3434 nargs = call_expr_nargs (non_dep); |
3413 | 3435 |
3417 /* With -fpermissive non_dep could be operator++(). */ | 3439 /* With -fpermissive non_dep could be operator++(). */ |
3418 && (!flag_permissive || nargs != expected_nargs)) | 3440 && (!flag_permissive || nargs != expected_nargs)) |
3419 expected_nargs += 1; | 3441 expected_nargs += 1; |
3420 gcc_assert (nargs == expected_nargs); | 3442 gcc_assert (nargs == expected_nargs); |
3421 | 3443 |
3422 args = make_tree_vector (); | 3444 releasing_vec args; |
3423 va_start (p, overload); | 3445 va_start (p, overload); |
3424 | 3446 |
3425 if (TREE_CODE (TREE_TYPE (overload)) == FUNCTION_TYPE) | 3447 if (TREE_CODE (TREE_TYPE (overload)) == FUNCTION_TYPE) |
3426 { | 3448 { |
3427 fn = overload; | 3449 fn = overload; |
3447 else | 3469 else |
3448 gcc_unreachable (); | 3470 gcc_unreachable (); |
3449 | 3471 |
3450 va_end (p); | 3472 va_end (p); |
3451 call = build_min_non_dep_call_vec (non_dep, fn, args); | 3473 call = build_min_non_dep_call_vec (non_dep, fn, args); |
3452 release_tree_vector (args); | |
3453 | 3474 |
3454 tree call_expr = extract_call_expr (call); | 3475 tree call_expr = extract_call_expr (call); |
3455 KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep); | 3476 KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep); |
3456 CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true; | 3477 CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true; |
3457 CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep); | 3478 CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep); |
3708 case FIELD_DECL: | 3729 case FIELD_DECL: |
3709 case FUNCTION_DECL: | 3730 case FUNCTION_DECL: |
3710 case TEMPLATE_DECL: | 3731 case TEMPLATE_DECL: |
3711 case IDENTIFIER_NODE: | 3732 case IDENTIFIER_NODE: |
3712 case SSA_NAME: | 3733 case SSA_NAME: |
3734 case USING_DECL: | |
3735 case DEFERRED_PARSE: | |
3713 return false; | 3736 return false; |
3714 | 3737 |
3715 case BASELINK: | 3738 case BASELINK: |
3716 return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2) | 3739 return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2) |
3717 && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2) | 3740 && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2) |
3834 DEFERRED_NOEXCEPT_PATTERN (t2)) | 3857 DEFERRED_NOEXCEPT_PATTERN (t2)) |
3835 && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1), | 3858 && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1), |
3836 DEFERRED_NOEXCEPT_ARGS (t2))); | 3859 DEFERRED_NOEXCEPT_ARGS (t2))); |
3837 break; | 3860 break; |
3838 | 3861 |
3839 case USING_DECL: | 3862 case LAMBDA_EXPR: |
3840 if (DECL_DEPENDENT_P (t1) && DECL_DEPENDENT_P (t2)) | 3863 /* Two lambda-expressions are never considered equivalent. */ |
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; | 3864 return false; |
3846 | 3865 |
3847 default: | 3866 default: |
3848 break; | 3867 break; |
3849 } | 3868 } |
4033 && classtype_has_non_deleted_move_ctor (t)) | 4052 && classtype_has_non_deleted_move_ctor (t)) |
4034 { | 4053 { |
4035 bool w; | 4054 bool w; |
4036 auto_diagnostic_group d; | 4055 auto_diagnostic_group d; |
4037 if (flag_abi_version > 12) | 4056 if (flag_abi_version > 12) |
4038 w = warning_at (loc, OPT_Wabi, "-fabi-version=13 (GCC 8.2) fixes the " | 4057 w = warning_at (loc, OPT_Wabi, "%<-fabi-version=13%> (GCC 8.2) fixes " |
4039 "calling convention for %qT, which was accidentally " | 4058 "the calling convention for %qT, which was " |
4040 "changed in 8.1", t); | 4059 "accidentally changed in 8.1", t); |
4041 else | 4060 else |
4042 w = warning_at (loc, OPT_Wabi, "-fabi-version=12 (GCC 8.1) accident" | 4061 w = warning_at (loc, OPT_Wabi, "%<-fabi-version=12%> (GCC 8.1) accident" |
4043 "ally changes the calling convention for %qT", t); | 4062 "ally changes the calling convention for %qT", t); |
4044 if (w) | 4063 if (w) |
4045 inform (location_of (t), " declared here"); | 4064 inform (location_of (t), " declared here"); |
4046 return; | 4065 return; |
4047 } | 4066 } |
4048 | 4067 |
4049 auto_diagnostic_group d; | 4068 auto_diagnostic_group d; |
4050 if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in " | 4069 if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in " |
4051 "-fabi-version=13 (GCC 8.2)", t)) | 4070 "%<-fabi-version=13%> (GCC 8.2)", t)) |
4052 inform (location_of (t), " because all of its copy and move " | 4071 inform (location_of (t), " because all of its copy and move " |
4053 "constructors are deleted"); | 4072 "constructors are deleted"); |
4054 } | 4073 } |
4055 | 4074 |
4056 /* Returns true iff copying an object of type T (including via move | 4075 /* Returns true iff copying an object of type T (including via move |
4158 && (!TYPE_HAS_COPY_ASSIGN (t) | 4177 && (!TYPE_HAS_COPY_ASSIGN (t) |
4159 || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t)) | 4178 || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t)) |
4160 && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) | 4179 && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |
4161 && TYPE_HAS_TRIVIAL_DESTRUCTOR (t)); | 4180 && TYPE_HAS_TRIVIAL_DESTRUCTOR (t)); |
4162 else | 4181 else |
4163 return !CP_TYPE_VOLATILE_P (t) && scalarish_type_p (t); | 4182 /* CWG 2094 makes volatile-qualified scalars trivially copyable again. */ |
4183 return scalarish_type_p (t); | |
4164 } | 4184 } |
4165 | 4185 |
4166 /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and | 4186 /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and |
4167 [class]. */ | 4187 [class]. */ |
4168 | 4188 |
4405 return 0; | 4425 return 0; |
4406 | 4426 |
4407 return 1; | 4427 return 1; |
4408 } | 4428 } |
4409 | 4429 |
4430 /* True IFF T is a C++20 structural type (P1907R1) that can be used as a | |
4431 non-type template parameter. If EXPLAIN, explain why not. */ | |
4432 | |
4433 bool | |
4434 structural_type_p (tree t, bool explain) | |
4435 { | |
4436 t = strip_array_types (t); | |
4437 if (INTEGRAL_OR_ENUMERATION_TYPE_P (t)) | |
4438 return true; | |
4439 if (NULLPTR_TYPE_P (t)) | |
4440 return true; | |
4441 if (TYPE_PTR_P (t) || TYPE_PTRMEM_P (t)) | |
4442 return true; | |
4443 if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t)) | |
4444 return true; | |
4445 if (!CLASS_TYPE_P (t)) | |
4446 return false; | |
4447 if (TREE_CODE (t) == UNION_TYPE) | |
4448 { | |
4449 if (explain) | |
4450 inform (location_of (t), "%qT is a union", t); | |
4451 return false; | |
4452 } | |
4453 if (!literal_type_p (t)) | |
4454 { | |
4455 if (explain) | |
4456 explain_non_literal_class (t); | |
4457 return false; | |
4458 } | |
4459 if (CLASSTYPE_HAS_MUTABLE (t)) | |
4460 { | |
4461 if (explain) | |
4462 inform (location_of (t), "%qT has a mutable member", t); | |
4463 return false; | |
4464 } | |
4465 for (tree m = next_initializable_field (TYPE_FIELDS (t)); m; | |
4466 m = next_initializable_field (DECL_CHAIN (m))) | |
4467 { | |
4468 if (TREE_PRIVATE (m) || TREE_PROTECTED (m)) | |
4469 { | |
4470 if (explain) | |
4471 { | |
4472 if (DECL_FIELD_IS_BASE (m)) | |
4473 inform (location_of (m), "base class %qT is not public", | |
4474 TREE_TYPE (m)); | |
4475 else | |
4476 inform (location_of (m), "%qD is not public", m); | |
4477 } | |
4478 return false; | |
4479 } | |
4480 if (!structural_type_p (TREE_TYPE (m))) | |
4481 { | |
4482 if (explain) | |
4483 { | |
4484 inform (location_of (m), "%qD has a non-structural type", m); | |
4485 structural_type_p (TREE_TYPE (m), true); | |
4486 } | |
4487 return false; | |
4488 } | |
4489 } | |
4490 return true; | |
4491 } | |
4492 | |
4410 /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU | 4493 /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU |
4411 warn_unused_result attribute. */ | 4494 warn_unused_result attribute. */ |
4412 | 4495 |
4413 static tree | 4496 static tree |
4414 handle_nodiscard_attribute (tree *node, tree name, tree /*args*/, | 4497 handle_nodiscard_attribute (tree *node, tree name, tree args, |
4415 int /*flags*/, bool *no_add_attrs) | 4498 int /*flags*/, bool *no_add_attrs) |
4416 { | 4499 { |
4500 if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST) | |
4501 { | |
4502 error ("%qE attribute argument must be a string constant", name); | |
4503 *no_add_attrs = true; | |
4504 } | |
4417 if (TREE_CODE (*node) == FUNCTION_DECL) | 4505 if (TREE_CODE (*node) == FUNCTION_DECL) |
4418 { | 4506 { |
4419 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))) | 4507 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node))) |
4420 warning (OPT_Wattributes, "%qE attribute applied to %qD with void " | 4508 && !DECL_CONSTRUCTOR_P (*node)) |
4421 "return type", name, *node); | 4509 warning_at (DECL_SOURCE_LOCATION (*node), |
4510 OPT_Wattributes, "%qE attribute applied to %qD with void " | |
4511 "return type", name, *node); | |
4422 } | 4512 } |
4423 else if (OVERLOAD_TYPE_P (*node)) | 4513 else if (OVERLOAD_TYPE_P (*node)) |
4424 /* OK */; | 4514 /* OK */; |
4425 else | 4515 else |
4426 { | 4516 { |
4454 } | 4544 } |
4455 | 4545 |
4456 return NULL_TREE; | 4546 return NULL_TREE; |
4457 } | 4547 } |
4458 | 4548 |
4549 /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU | |
4550 hot/cold attributes. */ | |
4551 | |
4552 static tree | |
4553 handle_likeliness_attribute (tree *node, tree name, tree args, | |
4554 int flags, bool *no_add_attrs) | |
4555 { | |
4556 *no_add_attrs = true; | |
4557 if (TREE_CODE (*node) == LABEL_DECL | |
4558 || TREE_CODE (*node) == FUNCTION_DECL) | |
4559 { | |
4560 if (args) | |
4561 warning (OPT_Wattributes, "%qE attribute takes no arguments", name); | |
4562 tree bname = (is_attribute_p ("likely", name) | |
4563 ? get_identifier ("hot") : get_identifier ("cold")); | |
4564 if (TREE_CODE (*node) == FUNCTION_DECL) | |
4565 warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to " | |
4566 "functions; treating as %<[[gnu::%E]]%>", name, bname); | |
4567 tree battr = build_tree_list (bname, NULL_TREE); | |
4568 decl_attributes (node, battr, flags); | |
4569 return NULL_TREE; | |
4570 } | |
4571 else | |
4572 return error_mark_node; | |
4573 } | |
4574 | |
4459 /* Table of valid C++ attributes. */ | 4575 /* Table of valid C++ attributes. */ |
4460 const struct attribute_spec cxx_attribute_table[] = | 4576 const struct attribute_spec cxx_attribute_table[] = |
4461 { | 4577 { |
4462 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, | 4578 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, |
4463 affects_type_identity, handler, exclude } */ | 4579 affects_type_identity, handler, exclude } */ |
4473 { | 4589 { |
4474 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, | 4590 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, |
4475 affects_type_identity, handler, exclude } */ | 4591 affects_type_identity, handler, exclude } */ |
4476 { "maybe_unused", 0, 0, false, false, false, false, | 4592 { "maybe_unused", 0, 0, false, false, false, false, |
4477 handle_unused_attribute, NULL }, | 4593 handle_unused_attribute, NULL }, |
4478 { "nodiscard", 0, 0, false, false, false, false, | 4594 { "nodiscard", 0, 1, false, false, false, false, |
4479 handle_nodiscard_attribute, NULL }, | 4595 handle_nodiscard_attribute, NULL }, |
4480 { "no_unique_address", 0, 0, true, false, false, false, | 4596 { "no_unique_address", 0, 0, true, false, false, false, |
4481 handle_no_unique_addr_attribute, NULL }, | 4597 handle_no_unique_addr_attribute, NULL }, |
4598 { "likely", 0, 0, false, false, false, false, | |
4599 handle_likeliness_attribute, attr_cold_hot_exclusions }, | |
4600 { "unlikely", 0, 0, false, false, false, false, | |
4601 handle_likeliness_attribute, attr_cold_hot_exclusions }, | |
4602 { "noreturn", 0, 0, true, false, false, false, | |
4603 handle_noreturn_attribute, attr_noreturn_exclusions }, | |
4482 { NULL, 0, 0, false, false, false, false, NULL, NULL } | 4604 { NULL, 0, 0, false, false, false, false, NULL, NULL } |
4483 }; | 4605 }; |
4484 | 4606 |
4485 /* Handle an "init_priority" attribute; arguments as in | 4607 /* Handle an "init_priority" attribute; arguments as in |
4486 struct attribute_spec.handler. */ | 4608 struct attribute_spec.handler. */ |
4501 if (initp_expr) | 4623 if (initp_expr) |
4502 initp_expr = maybe_constant_value (initp_expr); | 4624 initp_expr = maybe_constant_value (initp_expr); |
4503 | 4625 |
4504 if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST) | 4626 if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST) |
4505 { | 4627 { |
4506 error ("requested init_priority is not an integer constant"); | 4628 error ("requested %<init_priority%> is not an integer constant"); |
4507 cxx_constant_value (initp_expr); | 4629 cxx_constant_value (initp_expr); |
4508 *no_add_attrs = true; | 4630 *no_add_attrs = true; |
4509 return NULL_TREE; | 4631 return NULL_TREE; |
4510 } | 4632 } |
4511 | 4633 |
4531 return NULL_TREE; | 4653 return NULL_TREE; |
4532 } | 4654 } |
4533 | 4655 |
4534 if (pri > MAX_INIT_PRIORITY || pri <= 0) | 4656 if (pri > MAX_INIT_PRIORITY || pri <= 0) |
4535 { | 4657 { |
4536 error ("requested init_priority is out of range"); | 4658 error ("requested %<init_priority%> %i is out of range [0, %i]", |
4659 pri, MAX_INIT_PRIORITY); | |
4537 *no_add_attrs = true; | 4660 *no_add_attrs = true; |
4538 return NULL_TREE; | 4661 return NULL_TREE; |
4539 } | 4662 } |
4540 | 4663 |
4541 /* Check for init_priorities that are reserved for | 4664 /* Check for init_priorities that are reserved for |
4542 language and runtime support implementations.*/ | 4665 language and runtime support implementations.*/ |
4543 if (pri <= MAX_RESERVED_INIT_PRIORITY) | 4666 if (pri <= MAX_RESERVED_INIT_PRIORITY) |
4544 { | 4667 { |
4545 warning | 4668 warning |
4546 (0, "requested init_priority is reserved for internal use"); | 4669 (0, "requested %<init_priority%> %i is reserved for internal use", |
4670 pri); | |
4547 } | 4671 } |
4548 | 4672 |
4549 if (SUPPORTS_INIT_PRIORITY) | 4673 if (SUPPORTS_INIT_PRIORITY) |
4550 { | 4674 { |
4551 SET_DECL_INIT_PRIORITY (decl, pri); | 4675 SET_DECL_INIT_PRIORITY (decl, pri); |
4744 cp_build_type_attribute_variant (tree type, tree attributes) | 4868 cp_build_type_attribute_variant (tree type, tree attributes) |
4745 { | 4869 { |
4746 tree new_type; | 4870 tree new_type; |
4747 | 4871 |
4748 new_type = build_type_attribute_variant (type, attributes); | 4872 new_type = build_type_attribute_variant (type, attributes); |
4749 if (TREE_CODE (new_type) == FUNCTION_TYPE | 4873 if (FUNC_OR_METHOD_TYPE_P (new_type)) |
4750 || TREE_CODE (new_type) == METHOD_TYPE) | |
4751 gcc_checking_assert (cxx_type_hash_eq (type, new_type)); | 4874 gcc_checking_assert (cxx_type_hash_eq (type, new_type)); |
4752 | 4875 |
4753 /* Making a new main variant of a class type is broken. */ | 4876 /* Making a new main variant of a class type is broken. */ |
4754 gcc_assert (!CLASS_TYPE_P (type) || new_type == type); | 4877 gcc_assert (!CLASS_TYPE_P (type) || new_type == type); |
4755 | 4878 |
4760 Called only after doing all language independent checks. */ | 4883 Called only after doing all language independent checks. */ |
4761 | 4884 |
4762 bool | 4885 bool |
4763 cxx_type_hash_eq (const_tree typea, const_tree typeb) | 4886 cxx_type_hash_eq (const_tree typea, const_tree typeb) |
4764 { | 4887 { |
4765 gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE | 4888 gcc_assert (FUNC_OR_METHOD_TYPE_P (typea)); |
4766 || TREE_CODE (typea) == METHOD_TYPE); | |
4767 | 4889 |
4768 if (type_memfn_rqual (typea) != type_memfn_rqual (typeb)) | 4890 if (type_memfn_rqual (typea) != type_memfn_rqual (typeb)) |
4769 return false; | 4891 return false; |
4770 if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb)) | 4892 if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb)) |
4771 return false; | 4893 return false; |
4778 | 4900 |
4779 tree | 4901 tree |
4780 cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb) | 4902 cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb) |
4781 { | 4903 { |
4782 tree type = CONST_CAST_TREE (typea); | 4904 tree type = CONST_CAST_TREE (typea); |
4783 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | 4905 if (FUNC_OR_METHOD_TYPE_P (type)) |
4784 type = build_cp_fntype_variant (type, type_memfn_rqual (typeb), | 4906 type = build_cp_fntype_variant (type, type_memfn_rqual (typeb), |
4785 TYPE_RAISES_EXCEPTIONS (typeb), | 4907 TYPE_RAISES_EXCEPTIONS (typeb), |
4786 TYPE_HAS_LATE_RETURN_TYPE (typeb)); | 4908 TYPE_HAS_LATE_RETURN_TYPE (typeb)); |
4787 return type; | 4909 return type; |
4788 } | 4910 } |
4803 result = cp_walk_tree (&(NODE), func, data, pset); \ | 4925 result = cp_walk_tree (&(NODE), func, data, pset); \ |
4804 if (result) goto out; \ | 4926 if (result) goto out; \ |
4805 } \ | 4927 } \ |
4806 while (0) | 4928 while (0) |
4807 | 4929 |
4930 if (TYPE_P (*tp)) | |
4931 /* Walk into template args without looking through typedefs. */ | |
4932 if (tree ti = TYPE_TEMPLATE_INFO_MAYBE_ALIAS (*tp)) | |
4933 WALK_SUBTREE (TI_ARGS (ti)); | |
4934 | |
4808 /* Not one of the easy cases. We must explicitly go through the | 4935 /* Not one of the easy cases. We must explicitly go through the |
4809 children. */ | 4936 children. */ |
4810 result = NULL_TREE; | 4937 result = NULL_TREE; |
4811 switch (code) | 4938 switch (code) |
4812 { | 4939 { |
4813 case DEFAULT_ARG: | 4940 case DEFERRED_PARSE: |
4814 case TEMPLATE_TEMPLATE_PARM: | 4941 case TEMPLATE_TEMPLATE_PARM: |
4815 case BOUND_TEMPLATE_TEMPLATE_PARM: | 4942 case BOUND_TEMPLATE_TEMPLATE_PARM: |
4816 case UNBOUND_CLASS_TEMPLATE: | 4943 case UNBOUND_CLASS_TEMPLATE: |
4817 case TEMPLATE_PARM_INDEX: | 4944 case TEMPLATE_PARM_INDEX: |
4818 case TEMPLATE_TYPE_PARM: | 4945 case TEMPLATE_TYPE_PARM: |
4893 int i; | 5020 int i; |
4894 for (i = 0; i < TREE_CODE_LENGTH (TREE_CODE (*tp)); ++i) | 5021 for (i = 0; i < TREE_CODE_LENGTH (TREE_CODE (*tp)); ++i) |
4895 WALK_SUBTREE (TREE_OPERAND (*tp, i)); | 5022 WALK_SUBTREE (TREE_OPERAND (*tp, i)); |
4896 } | 5023 } |
4897 *walk_subtrees_p = 0; | 5024 *walk_subtrees_p = 0; |
5025 break; | |
5026 | |
5027 case CONSTRUCTOR: | |
5028 if (COMPOUND_LITERAL_P (*tp)) | |
5029 WALK_SUBTREE (TREE_TYPE (*tp)); | |
4898 break; | 5030 break; |
4899 | 5031 |
4900 case TRAIT_EXPR: | 5032 case TRAIT_EXPR: |
4901 WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp)); | 5033 WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp)); |
4902 WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp)); | 5034 WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp)); |
4945 WALK_SUBTREE (DECL_SIZE (decl)); | 5077 WALK_SUBTREE (DECL_SIZE (decl)); |
4946 WALK_SUBTREE (DECL_SIZE_UNIT (decl)); | 5078 WALK_SUBTREE (DECL_SIZE_UNIT (decl)); |
4947 } | 5079 } |
4948 break; | 5080 break; |
4949 | 5081 |
5082 case LAMBDA_EXPR: | |
5083 /* Don't walk into the body of the lambda, but the capture initializers | |
5084 are part of the enclosing context. */ | |
5085 for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (*tp); cap; | |
5086 cap = TREE_CHAIN (cap)) | |
5087 WALK_SUBTREE (TREE_VALUE (cap)); | |
5088 break; | |
5089 | |
5090 case CO_YIELD_EXPR: | |
5091 if (TREE_OPERAND (*tp, 1)) | |
5092 /* Operand 1 is the tree for the relevant co_await which has any | |
5093 interesting sub-trees. */ | |
5094 WALK_SUBTREE (TREE_OPERAND (*tp, 1)); | |
5095 break; | |
5096 | |
5097 case CO_AWAIT_EXPR: | |
5098 if (TREE_OPERAND (*tp, 1)) | |
5099 /* Operand 1 is frame variable. */ | |
5100 WALK_SUBTREE (TREE_OPERAND (*tp, 1)); | |
5101 if (TREE_OPERAND (*tp, 2)) | |
5102 /* Operand 2 has the initialiser, and we need to walk any subtrees | |
5103 there. */ | |
5104 WALK_SUBTREE (TREE_OPERAND (*tp, 2)); | |
5105 break; | |
5106 | |
5107 case CO_RETURN_EXPR: | |
5108 if (TREE_OPERAND (*tp, 0)) | |
5109 { | |
5110 if (VOID_TYPE_P (TREE_OPERAND (*tp, 0))) | |
5111 /* For void expressions, operand 1 is a trivial call, and any | |
5112 interesting subtrees will be part of operand 0. */ | |
5113 WALK_SUBTREE (TREE_OPERAND (*tp, 0)); | |
5114 else if (TREE_OPERAND (*tp, 1)) | |
5115 /* Interesting sub-trees will be in the return_value () call | |
5116 arguments. */ | |
5117 WALK_SUBTREE (TREE_OPERAND (*tp, 1)); | |
5118 } | |
5119 break; | |
5120 | |
4950 default: | 5121 default: |
4951 return NULL_TREE; | 5122 return NULL_TREE; |
4952 } | 5123 } |
4953 | 5124 |
4954 /* We didn't find what we were looking for. */ | 5125 /* We didn't find what we were looking for. */ |
5022 return sfk_deleting_destructor; | 5193 return sfk_deleting_destructor; |
5023 if (DECL_CONV_FN_P (decl)) | 5194 if (DECL_CONV_FN_P (decl)) |
5024 return sfk_conversion; | 5195 return sfk_conversion; |
5025 if (deduction_guide_p (decl)) | 5196 if (deduction_guide_p (decl)) |
5026 return sfk_deduction_guide; | 5197 return sfk_deduction_guide; |
5027 | 5198 if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR |
5199 && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR) | |
5200 return sfk_comparison; | |
5201 | |
5202 return sfk_none; | |
5203 } | |
5204 | |
5205 /* As above, but only if DECL is a special member function as per 11.3.3 | |
5206 [special]: default/copy/move ctor, copy/move assignment, or destructor. */ | |
5207 | |
5208 special_function_kind | |
5209 special_memfn_p (const_tree decl) | |
5210 { | |
5211 switch (special_function_kind sfk = special_function_p (decl)) | |
5212 { | |
5213 case sfk_constructor: | |
5214 if (!default_ctor_p (decl)) | |
5215 break; | |
5216 gcc_fallthrough(); | |
5217 case sfk_copy_constructor: | |
5218 case sfk_copy_assignment: | |
5219 case sfk_move_assignment: | |
5220 case sfk_move_constructor: | |
5221 case sfk_destructor: | |
5222 return sfk; | |
5223 | |
5224 default: | |
5225 break; | |
5226 } | |
5028 return sfk_none; | 5227 return sfk_none; |
5029 } | 5228 } |
5030 | 5229 |
5031 /* Returns nonzero if TYPE is a character type, including wchar_t. */ | 5230 /* Returns nonzero if TYPE is a character type, including wchar_t. */ |
5032 | 5231 |
5034 char_type_p (tree type) | 5233 char_type_p (tree type) |
5035 { | 5234 { |
5036 return (same_type_p (type, char_type_node) | 5235 return (same_type_p (type, char_type_node) |
5037 || same_type_p (type, unsigned_char_type_node) | 5236 || same_type_p (type, unsigned_char_type_node) |
5038 || same_type_p (type, signed_char_type_node) | 5237 || same_type_p (type, signed_char_type_node) |
5238 || same_type_p (type, char8_type_node) | |
5039 || same_type_p (type, char16_type_node) | 5239 || same_type_p (type, char16_type_node) |
5040 || same_type_p (type, char32_type_node) | 5240 || same_type_p (type, char32_type_node) |
5041 || same_type_p (type, wchar_type_node)); | 5241 || same_type_p (type, wchar_type_node)); |
5042 } | 5242 } |
5043 | 5243 |
5381 /* Clean the C++ specific parts of the tree T. */ | 5581 /* Clean the C++ specific parts of the tree T. */ |
5382 | 5582 |
5383 void | 5583 void |
5384 cp_free_lang_data (tree t) | 5584 cp_free_lang_data (tree t) |
5385 { | 5585 { |
5386 if (TREE_CODE (t) == METHOD_TYPE | 5586 if (FUNC_OR_METHOD_TYPE_P (t)) |
5387 || TREE_CODE (t) == FUNCTION_TYPE) | |
5388 { | 5587 { |
5389 /* Default args are not interesting anymore. */ | 5588 /* Default args are not interesting anymore. */ |
5390 tree argtypes = TYPE_ARG_TYPES (t); | 5589 tree argtypes = TYPE_ARG_TYPES (t); |
5391 while (argtypes) | 5590 while (argtypes) |
5392 { | 5591 { |
5401 must exist somewhere else since we have decided to not emit it | 5600 must exist somewhere else since we have decided to not emit it |
5402 in this TU. So make it an external reference. */ | 5601 in this TU. So make it an external reference. */ |
5403 DECL_EXTERNAL (t) = 1; | 5602 DECL_EXTERNAL (t) = 1; |
5404 TREE_STATIC (t) = 0; | 5603 TREE_STATIC (t) = 0; |
5405 } | 5604 } |
5605 if (TREE_CODE (t) == FUNCTION_DECL) | |
5606 discard_operator_bindings (t); | |
5406 if (TREE_CODE (t) == NAMESPACE_DECL) | 5607 if (TREE_CODE (t) == NAMESPACE_DECL) |
5407 /* We do not need the leftover chaining of namespaces from the | 5608 /* We do not need the leftover chaining of namespaces from the |
5408 binding level. */ | 5609 binding level. */ |
5409 DECL_CHAIN (t) = NULL_TREE; | 5610 DECL_CHAIN (t) = NULL_TREE; |
5410 } | 5611 } |
5471 { | 5672 { |
5472 case LAMBDA_EXPR: | 5673 case LAMBDA_EXPR: |
5473 return LAMBDA_EXPR_LOCATION (t); | 5674 return LAMBDA_EXPR_LOCATION (t); |
5474 case STATIC_ASSERT: | 5675 case STATIC_ASSERT: |
5475 return STATIC_ASSERT_SOURCE_LOCATION (t); | 5676 return STATIC_ASSERT_SOURCE_LOCATION (t); |
5677 case TRAIT_EXPR: | |
5678 return TRAIT_EXPR_LOCATION (t); | |
5476 default: | 5679 default: |
5477 return EXPR_LOCATION (t); | 5680 return EXPR_LOCATION (t); |
5478 } | 5681 } |
5479 } | 5682 } |
5480 | 5683 |
5491 return true; | 5694 return true; |
5492 } | 5695 } |
5493 return false; | 5696 return false; |
5494 } | 5697 } |
5495 | 5698 |
5699 /* Given an initializer INIT for a TYPE, return true if INIT is zero | |
5700 so that it can be replaced by value initialization. This function | |
5701 distinguishes betwen empty strings as initializers for arrays and | |
5702 for pointers (which make it return false). */ | |
5703 | |
5704 bool | |
5705 type_initializer_zero_p (tree type, tree init) | |
5706 { | |
5707 if (type == error_mark_node || init == error_mark_node) | |
5708 return false; | |
5709 | |
5710 STRIP_NOPS (init); | |
5711 | |
5712 if (POINTER_TYPE_P (type)) | |
5713 return TREE_CODE (init) != STRING_CST && initializer_zerop (init); | |
5714 | |
5715 if (TREE_CODE (init) != CONSTRUCTOR) | |
5716 return initializer_zerop (init); | |
5717 | |
5718 if (TREE_CODE (type) == ARRAY_TYPE) | |
5719 { | |
5720 tree elt_type = TREE_TYPE (type); | |
5721 elt_type = TYPE_MAIN_VARIANT (elt_type); | |
5722 if (elt_type == char_type_node) | |
5723 return initializer_zerop (init); | |
5724 | |
5725 tree elt_init; | |
5726 unsigned HOST_WIDE_INT i; | |
5727 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), i, elt_init) | |
5728 if (!type_initializer_zero_p (elt_type, elt_init)) | |
5729 return false; | |
5730 return true; | |
5731 } | |
5732 | |
5733 if (TREE_CODE (type) != RECORD_TYPE) | |
5734 return initializer_zerop (init); | |
5735 | |
5736 if (TYPE_NON_AGGREGATE_CLASS (type)) | |
5737 return false; | |
5738 | |
5739 tree fld = TYPE_FIELDS (type); | |
5740 | |
5741 tree fld_init; | |
5742 unsigned HOST_WIDE_INT i; | |
5743 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), i, fld_init) | |
5744 { | |
5745 fld = next_initializable_field (fld); | |
5746 if (!fld) | |
5747 return true; | |
5748 | |
5749 tree fldtype = TREE_TYPE (fld); | |
5750 if (!type_initializer_zero_p (fldtype, fld_init)) | |
5751 return false; | |
5752 | |
5753 fld = DECL_CHAIN (fld); | |
5754 if (!fld) | |
5755 break; | |
5756 } | |
5757 | |
5758 return true; | |
5759 } | |
5760 | |
5496 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) | 5761 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) |
5497 /* Complain that some language-specific thing hanging off a tree | 5762 /* Complain that some language-specific thing hanging off a tree |
5498 node has been accessed improperly. */ | 5763 node has been accessed improperly. */ |
5499 | 5764 |
5500 void | 5765 void |
5501 lang_check_failed (const char* file, int line, const char* function) | 5766 lang_check_failed (const char* file, int line, const char* function) |
5502 { | 5767 { |
5503 internal_error ("lang_* check: failed in %s, at %s:%d", | 5768 internal_error ("%<lang_*%> check: failed in %s, at %s:%d", |
5504 function, trim_filename (file), line); | 5769 function, trim_filename (file), line); |
5505 } | 5770 } |
5506 #endif /* ENABLE_TREE_CHECKING */ | 5771 #endif /* ENABLE_TREE_CHECKING */ |
5507 | 5772 |
5508 #if CHECKING_P | 5773 #if CHECKING_P |
5548 affected by location wrappers. */ | 5813 affected by location wrappers. */ |
5549 tree rvalue_ref_of_parm = move (parm); | 5814 tree rvalue_ref_of_parm = move (parm); |
5550 ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm)); | 5815 ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm)); |
5551 tree rvalue_ref_of_wrapped_parm = move (wrapped_parm); | 5816 tree rvalue_ref_of_wrapped_parm = move (wrapped_parm); |
5552 ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm)); | 5817 ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm)); |
5818 | |
5819 /* Verify lvalue_p. */ | |
5820 ASSERT_FALSE (lvalue_p (int_cst)); | |
5821 ASSERT_FALSE (lvalue_p (wrapped_int_cst)); | |
5822 ASSERT_TRUE (lvalue_p (parm)); | |
5823 ASSERT_TRUE (lvalue_p (wrapped_parm)); | |
5824 ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm)); | |
5825 ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm)); | |
5553 } | 5826 } |
5554 | 5827 |
5555 /* Run all of the selftests within this file. */ | 5828 /* Run all of the selftests within this file. */ |
5556 | 5829 |
5557 void | 5830 void |