comparison gcc/cp/call.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 /* Functions related to invoking -*- C++ -*- methods and overloaded functions. 1 /* Functions related to invoking -*- C++ -*- methods and overloaded functions.
2 Copyright (C) 1987-2017 Free Software Foundation, Inc. 2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com) and 3 Contributed by Michael Tiemann (tiemann@cygnus.com) and
4 modified by Brendan Kehoe (brendan@cygnus.com). 4 modified by Brendan Kehoe (brendan@cygnus.com).
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
39 #include "langhooks.h" 39 #include "langhooks.h"
40 #include "c-family/c-objc.h" 40 #include "c-family/c-objc.h"
41 #include "internal-fn.h" 41 #include "internal-fn.h"
42 #include "stringpool.h" 42 #include "stringpool.h"
43 #include "attribs.h" 43 #include "attribs.h"
44 #include "gcc-rich-location.h"
44 45
45 /* The various kinds of conversion. */ 46 /* The various kinds of conversion. */
46 47
47 enum conversion_kind { 48 enum conversion_kind {
48 ck_identity, 49 ck_identity,
91 language standards, e.g. disregarding pointer qualifiers or 92 language standards, e.g. disregarding pointer qualifiers or
92 converting integers to pointers. */ 93 converting integers to pointers. */
93 BOOL_BITFIELD bad_p : 1; 94 BOOL_BITFIELD bad_p : 1;
94 /* If KIND is ck_ref_bind ck_base_conv, true to indicate that a 95 /* If KIND is ck_ref_bind ck_base_conv, true to indicate that a
95 temporary should be created to hold the result of the 96 temporary should be created to hold the result of the
96 conversion. */ 97 conversion. If KIND is ck_ambig, true if the context is
98 copy-initialization. */
97 BOOL_BITFIELD need_temporary_p : 1; 99 BOOL_BITFIELD need_temporary_p : 1;
98 /* If KIND is ck_ptr or ck_pmem, true to indicate that a conversion 100 /* If KIND is ck_ptr or ck_pmem, true to indicate that a conversion
99 from a pointer-to-derived to pointer-to-base is being performed. */ 101 from a pointer-to-derived to pointer-to-base is being performed. */
100 BOOL_BITFIELD base_p : 1; 102 BOOL_BITFIELD base_p : 1;
101 /* If KIND is ck_ref_bind, true when either an lvalue reference is 103 /* If KIND is ck_ref_bind, true when either an lvalue reference is
102 being bound to an lvalue expression or an rvalue reference is 104 being bound to an lvalue expression or an rvalue reference is
103 being bound to an rvalue expression. If KIND is ck_rvalue, 105 being bound to an rvalue expression. If KIND is ck_rvalue or ck_base,
104 true when we are treating an lvalue as an rvalue (12.8p33). If 106 true when we are treating an lvalue as an rvalue (12.8p33). If
105 KIND is ck_base, always false. */ 107 ck_identity, we will be binding a reference directly or decaying to
108 a pointer. */
106 BOOL_BITFIELD rvaluedness_matches_p: 1; 109 BOOL_BITFIELD rvaluedness_matches_p: 1;
107 BOOL_BITFIELD check_narrowing: 1; 110 BOOL_BITFIELD check_narrowing: 1;
111 /* Whether check_narrowing should only check TREE_CONSTANTs; used
112 in build_converted_constant_expr. */
113 BOOL_BITFIELD check_narrowing_const_only: 1;
108 /* The type of the expression resulting from the conversion. */ 114 /* The type of the expression resulting from the conversion. */
109 tree type; 115 tree type;
110 union { 116 union {
111 /* The next conversion in the chain. Since the conversions are 117 /* The next conversion in the chain. Since the conversions are
112 arranged from outermost to innermost, the NEXT conversion will 118 arranged from outermost to innermost, the NEXT conversion will
145 static struct z_candidate * tourney (struct z_candidate *, tsubst_flags_t); 151 static struct z_candidate * tourney (struct z_candidate *, tsubst_flags_t);
146 static int equal_functions (tree, tree); 152 static int equal_functions (tree, tree);
147 static int joust (struct z_candidate *, struct z_candidate *, bool, 153 static int joust (struct z_candidate *, struct z_candidate *, bool,
148 tsubst_flags_t); 154 tsubst_flags_t);
149 static int compare_ics (conversion *, conversion *); 155 static int compare_ics (conversion *, conversion *);
156 static void maybe_warn_class_memaccess (location_t, tree,
157 const vec<tree, va_gc> *);
150 static tree build_over_call (struct z_candidate *, int, tsubst_flags_t); 158 static tree build_over_call (struct z_candidate *, int, tsubst_flags_t);
151 #define convert_like(CONV, EXPR, COMPLAIN) \ 159 #define convert_like(CONV, EXPR, COMPLAIN) \
152 convert_like_real ((CONV), (EXPR), NULL_TREE, 0, \ 160 convert_like_real ((CONV), (EXPR), NULL_TREE, 0, \
153 /*issue_conversion_warnings=*/true, \ 161 /*issue_conversion_warnings=*/true, \
154 /*c_cast_p=*/false, (COMPLAIN)) 162 /*c_cast_p=*/false, (COMPLAIN))
186 static struct z_candidate *add_conv_candidate 194 static struct z_candidate *add_conv_candidate
187 (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, tree, 195 (struct z_candidate **, tree, tree, const vec<tree, va_gc> *, tree,
188 tree, tsubst_flags_t); 196 tree, tsubst_flags_t);
189 static struct z_candidate *add_function_candidate 197 static struct z_candidate *add_function_candidate
190 (struct z_candidate **, tree, tree, tree, const vec<tree, va_gc> *, tree, 198 (struct z_candidate **, tree, tree, tree, const vec<tree, va_gc> *, tree,
191 tree, int, tsubst_flags_t); 199 tree, int, conversion**, tsubst_flags_t);
192 static conversion *implicit_conversion (tree, tree, tree, bool, int, 200 static conversion *implicit_conversion (tree, tree, tree, bool, int,
193 tsubst_flags_t); 201 tsubst_flags_t);
194 static conversion *reference_binding (tree, tree, tree, bool, int, 202 static conversion *reference_binding (tree, tree, tree, bool, int,
195 tsubst_flags_t); 203 tsubst_flags_t);
196 static conversion *build_conv (conversion_kind, tree, conversion *); 204 static conversion *build_conv (conversion_kind, tree, conversion *);
313 called. Split out of build_call_a so that bot_manip can use it too. */ 321 called. Split out of build_call_a so that bot_manip can use it too. */
314 322
315 void 323 void
316 set_flags_from_callee (tree call) 324 set_flags_from_callee (tree call)
317 { 325 {
318 bool nothrow; 326 /* Handle both CALL_EXPRs and AGGR_INIT_EXPRs. */
319 tree decl = get_callee_fndecl (call); 327 tree decl = cp_get_callee_fndecl_nofold (call);
320 328
321 /* We check both the decl and the type; a function may be known not to 329 /* We check both the decl and the type; a function may be known not to
322 throw without being declared throw(). */ 330 throw without being declared throw(). */
323 nothrow = decl && TREE_NOTHROW (decl); 331 bool nothrow = decl && TREE_NOTHROW (decl);
324 if (CALL_EXPR_FN (call)) 332 tree callee = cp_get_callee (call);
325 nothrow |= TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (call)))); 333 if (callee)
326 else if (internal_fn_flags (CALL_EXPR_IFN (call)) & ECF_NOTHROW) 334 nothrow |= TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (callee)));
335 else if (TREE_CODE (call) == CALL_EXPR
336 && internal_fn_flags (CALL_EXPR_IFN (call)) & ECF_NOTHROW)
327 nothrow = true; 337 nothrow = true;
328 338
329 if (!nothrow && at_function_scope_p () && cfun && cp_function_chain) 339 if (!nothrow && at_function_scope_p () && cfun && cp_function_chain)
330 cp_function_chain->can_throw = 1; 340 cp_function_chain->can_throw = 1;
331 341
374 384
375 require_complete_eh_spec_types (fntype, decl); 385 require_complete_eh_spec_types (fntype, decl);
376 386
377 TREE_HAS_CONSTRUCTOR (function) = (decl && DECL_CONSTRUCTOR_P (decl)); 387 TREE_HAS_CONSTRUCTOR (function) = (decl && DECL_CONSTRUCTOR_P (decl));
378 388
379 if (current_function_decl && decl
380 && flag_new_inheriting_ctors
381 && DECL_INHERITED_CTOR (current_function_decl)
382 && (DECL_INHERITED_CTOR (current_function_decl)
383 == DECL_CLONED_FUNCTION (decl)))
384 /* Pass arguments directly to the inherited constructor. */
385 CALL_FROM_THUNK_P (function) = true;
386
387 /* Don't pass empty class objects by value. This is useful 389 /* Don't pass empty class objects by value. This is useful
388 for tags in STL, which are used to control overload resolution. 390 for tags in STL, which are used to control overload resolution.
389 We don't need to handle other cases of copying empty classes. */ 391 We don't need to handle other cases of copying empty classes. */
390 else if (! decl || ! DECL_BUILT_IN (decl)) 392 if (!decl || !fndecl_built_in_p (decl))
391 for (i = 0; i < n; i++) 393 for (i = 0; i < n; i++)
392 { 394 {
393 tree arg = CALL_EXPR_ARG (function, i); 395 tree arg = CALL_EXPR_ARG (function, i);
394 if (is_empty_class (TREE_TYPE (arg)) 396 if (is_empty_class (TREE_TYPE (arg))
395 && ! TREE_ADDRESSABLE (TREE_TYPE (arg))) 397 && ! TREE_ADDRESSABLE (TREE_TYPE (arg)))
432 int n_arg; 434 int n_arg;
433 /* The actual argument or its type. */ 435 /* The actual argument or its type. */
434 tree from; 436 tree from;
435 /* The type of the parameter. */ 437 /* The type of the parameter. */
436 tree to_type; 438 tree to_type;
439 /* The location of the argument. */
440 location_t loc;
437 }; 441 };
438 442
439 struct rejection_reason { 443 struct rejection_reason {
440 enum rejection_reason_code code; 444 enum rejection_reason_code code;
441 union { 445 union {
532 if (NULLPTR_TYPE_P (type)) 536 if (NULLPTR_TYPE_P (type))
533 return true; 537 return true;
534 538
535 if (cxx_dialect >= cxx11) 539 if (cxx_dialect >= cxx11)
536 { 540 {
541 STRIP_ANY_LOCATION_WRAPPER (t);
542
537 /* Core issue 903 says only literal 0 is a null pointer constant. */ 543 /* Core issue 903 says only literal 0 is a null pointer constant. */
538 if (TREE_CODE (type) == INTEGER_TYPE 544 if (TREE_CODE (type) == INTEGER_TYPE
539 && !char_type_p (type) 545 && !char_type_p (type)
540 && TREE_CODE (t) == INTEGER_CST 546 && TREE_CODE (t) == INTEGER_CST
541 && integer_zerop (t) 547 && integer_zerop (t)
542 && !TREE_OVERFLOW (t)) 548 && !TREE_OVERFLOW (t))
543 return true; 549 return true;
544 } 550 }
545 else if (CP_INTEGRAL_TYPE_P (type)) 551 else if (CP_INTEGRAL_TYPE_P (type))
546 { 552 {
547 t = fold_non_dependent_expr (t); 553 t = fold_non_dependent_expr (t, tf_none);
548 STRIP_NOPS (t); 554 STRIP_NOPS (t);
549 if (integer_zerop (t) && !TREE_OVERFLOW (t)) 555 if (integer_zerop (t) && !TREE_OVERFLOW (t))
550 return true; 556 return true;
551 } 557 }
552 558
621 r->u.arity.actual = actual - adjust; 627 r->u.arity.actual = actual - adjust;
622 return r; 628 return r;
623 } 629 }
624 630
625 static struct rejection_reason * 631 static struct rejection_reason *
626 arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to) 632 arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
633 location_t loc)
627 { 634 {
628 struct rejection_reason *r = alloc_rejection (rr_arg_conversion); 635 struct rejection_reason *r = alloc_rejection (rr_arg_conversion);
629 int adjust = first_arg != NULL_TREE; 636 int adjust = first_arg != NULL_TREE;
630 r->u.conversion.n_arg = n_arg - adjust; 637 r->u.conversion.n_arg = n_arg - adjust;
631 r->u.conversion.from = from; 638 r->u.conversion.from = from;
632 r->u.conversion.to_type = to; 639 r->u.conversion.to_type = to;
640 r->u.conversion.loc = loc;
633 return r; 641 return r;
634 } 642 }
635 643
636 static struct rejection_reason * 644 static struct rejection_reason *
637 bad_arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to) 645 bad_arg_conversion_rejection (tree first_arg, int n_arg, tree from, tree to,
646 location_t loc)
638 { 647 {
639 struct rejection_reason *r = alloc_rejection (rr_bad_arg_conversion); 648 struct rejection_reason *r = alloc_rejection (rr_bad_arg_conversion);
640 int adjust = first_arg != NULL_TREE; 649 int adjust = first_arg != NULL_TREE;
641 r->u.bad_conversion.n_arg = n_arg - adjust; 650 r->u.bad_conversion.n_arg = n_arg - adjust;
642 r->u.bad_conversion.from = from; 651 r->u.bad_conversion.from = from;
643 r->u.bad_conversion.to_type = to; 652 r->u.bad_conversion.to_type = to;
653 r->u.bad_conversion.loc = loc;
644 return r; 654 return r;
645 } 655 }
646 656
647 static struct rejection_reason * 657 static struct rejection_reason *
648 explicit_conversion_rejection (tree from, tree to) 658 explicit_conversion_rejection (tree from, tree to)
649 { 659 {
650 struct rejection_reason *r = alloc_rejection (rr_explicit_conversion); 660 struct rejection_reason *r = alloc_rejection (rr_explicit_conversion);
651 r->u.conversion.n_arg = 0; 661 r->u.conversion.n_arg = 0;
652 r->u.conversion.from = from; 662 r->u.conversion.from = from;
653 r->u.conversion.to_type = to; 663 r->u.conversion.to_type = to;
664 r->u.conversion.loc = UNKNOWN_LOCATION;
654 return r; 665 return r;
655 } 666 }
656 667
657 static struct rejection_reason * 668 static struct rejection_reason *
658 template_conversion_rejection (tree from, tree to) 669 template_conversion_rejection (tree from, tree to)
659 { 670 {
660 struct rejection_reason *r = alloc_rejection (rr_template_conversion); 671 struct rejection_reason *r = alloc_rejection (rr_template_conversion);
661 r->u.conversion.n_arg = 0; 672 r->u.conversion.n_arg = 0;
662 r->u.conversion.from = from; 673 r->u.conversion.from = from;
663 r->u.conversion.to_type = to; 674 r->u.conversion.to_type = to;
675 r->u.conversion.loc = UNKNOWN_LOCATION;
664 return r; 676 return r;
665 } 677 }
666 678
667 static struct rejection_reason * 679 static struct rejection_reason *
668 template_unification_rejection (tree tmpl, tree explicit_targs, tree targs, 680 template_unification_rejection (tree tmpl, tree explicit_targs, tree targs,
814 flags &= ~LOOKUP_NO_CONVERSION; 826 flags &= ~LOOKUP_NO_CONVERSION;
815 /* But no narrowing conversions. */ 827 /* But no narrowing conversions. */
816 flags |= LOOKUP_NO_NARROWING; 828 flags |= LOOKUP_NO_NARROWING;
817 829
818 /* Can't make an array of these types. */ 830 /* Can't make an array of these types. */
819 if (TREE_CODE (elttype) == REFERENCE_TYPE 831 if (TYPE_REF_P (elttype)
820 || TREE_CODE (elttype) == FUNCTION_TYPE 832 || TREE_CODE (elttype) == FUNCTION_TYPE
821 || VOID_TYPE_P (elttype)) 833 || VOID_TYPE_P (elttype))
822 return NULL; 834 return NULL;
823 835
824 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val) 836 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), i, val)
915 927
916 if (i < CONSTRUCTOR_NELTS (ctor)) 928 if (i < CONSTRUCTOR_NELTS (ctor))
917 val = CONSTRUCTOR_ELT (ctor, i)->value; 929 val = CONSTRUCTOR_ELT (ctor, i)->value;
918 else if (DECL_INITIAL (field)) 930 else if (DECL_INITIAL (field))
919 val = get_nsdmi (field, /*ctor*/false, complain); 931 val = get_nsdmi (field, /*ctor*/false, complain);
920 else if (TREE_CODE (ftype) == REFERENCE_TYPE) 932 else if (TYPE_REF_P (ftype))
921 /* Value-initialization of reference is ill-formed. */ 933 /* Value-initialization of reference is ill-formed. */
922 return NULL; 934 return NULL;
923 else 935 else
924 { 936 {
925 if (empty_ctor == NULL_TREE) 937 if (empty_ctor == NULL_TREE)
1105 conversion *conv; 1117 conversion *conv;
1106 bool fromref = false; 1118 bool fromref = false;
1107 tree qualified_to; 1119 tree qualified_to;
1108 1120
1109 to = non_reference (to); 1121 to = non_reference (to);
1110 if (TREE_CODE (from) == REFERENCE_TYPE) 1122 if (TYPE_REF_P (from))
1111 { 1123 {
1112 fromref = true; 1124 fromref = true;
1113 from = TREE_TYPE (from); 1125 from = TREE_TYPE (from);
1114 } 1126 }
1115 qualified_to = to; 1127 qualified_to = to;
1140 conv = build_identity_conv (from, expr); 1152 conv = build_identity_conv (from, expr);
1141 if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE) 1153 if (fcode == FUNCTION_TYPE || fcode == ARRAY_TYPE)
1142 { 1154 {
1143 from = type_decays_to (from); 1155 from = type_decays_to (from);
1144 fcode = TREE_CODE (from); 1156 fcode = TREE_CODE (from);
1157 /* Tell convert_like_real that we're using the address. */
1158 conv->rvaluedness_matches_p = true;
1145 conv = build_conv (ck_lvalue, from, conv); 1159 conv = build_conv (ck_lvalue, from, conv);
1146 } 1160 }
1147 /* Wrapping a ck_rvalue around a class prvalue (as a result of using 1161 /* Wrapping a ck_rvalue around a class prvalue (as a result of using
1148 obvalue_p) seems odd, since it's already a prvalue, but that's how we 1162 obvalue_p) seems odd, since it's already a prvalue, but that's how we
1149 express the copy constructor call required by copy-initialization. */ 1163 express the copy constructor call required by copy-initialization. */
1380 && conv->rank < cr_pbool) 1394 && conv->rank < cr_pbool)
1381 || NULLPTR_TYPE_P (from)) 1395 || NULLPTR_TYPE_P (from))
1382 conv->rank = cr_pbool; 1396 conv->rank = cr_pbool;
1383 if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING)) 1397 if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
1384 conv->bad_p = true; 1398 conv->bad_p = true;
1399 if (flags & LOOKUP_NO_NARROWING)
1400 conv->check_narrowing = true;
1385 return conv; 1401 return conv;
1386 } 1402 }
1387 1403
1388 return NULL; 1404 return NULL;
1389 } 1405 }
1415 /* The derived-to-base conversion indicates the initialization 1431 /* The derived-to-base conversion indicates the initialization
1416 of a parameter with base type from an object of a derived 1432 of a parameter with base type from an object of a derived
1417 type. A temporary object is created to hold the result of 1433 type. A temporary object is created to hold the result of
1418 the conversion unless we're binding directly to a reference. */ 1434 the conversion unless we're binding directly to a reference. */
1419 conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND); 1435 conv->need_temporary_p = !(flags & LOOKUP_NO_TEMP_BIND);
1436 if (flags & LOOKUP_PREFER_RVALUE)
1437 /* Tell convert_like_real to set LOOKUP_PREFER_RVALUE. */
1438 conv->rvaluedness_matches_p = true;
1420 } 1439 }
1421 else 1440 else
1422 return NULL; 1441 return NULL;
1423 1442
1424 if (flags & LOOKUP_NO_NARROWING) 1443 if (flags & LOOKUP_NO_NARROWING)
1473 static conversion * 1492 static conversion *
1474 direct_reference_binding (tree type, conversion *conv) 1493 direct_reference_binding (tree type, conversion *conv)
1475 { 1494 {
1476 tree t; 1495 tree t;
1477 1496
1478 gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); 1497 gcc_assert (TYPE_REF_P (type));
1479 gcc_assert (TREE_CODE (conv->type) != REFERENCE_TYPE); 1498 gcc_assert (!TYPE_REF_P (conv->type));
1480 1499
1481 t = TREE_TYPE (type); 1500 t = TREE_TYPE (type);
1501
1502 if (conv->kind == ck_identity)
1503 /* Mark the identity conv as to not decay to rvalue. */
1504 conv->rvaluedness_matches_p = true;
1482 1505
1483 /* [over.ics.rank] 1506 /* [over.ics.rank]
1484 1507
1485 When a parameter of reference type binds directly 1508 When a parameter of reference type binds directly
1486 (_dcl.init.ref_) to an argument expression, the implicit 1509 (_dcl.init.ref_) to an argument expression, the implicit
1503 /* We will actually be binding to the base-class subobject in 1526 /* We will actually be binding to the base-class subobject in
1504 the derived class, so we mark this conversion appropriately. 1527 the derived class, so we mark this conversion appropriately.
1505 That way, convert_like knows not to generate a temporary. */ 1528 That way, convert_like knows not to generate a temporary. */
1506 conv->need_temporary_p = false; 1529 conv->need_temporary_p = false;
1507 } 1530 }
1531
1508 return build_conv (ck_ref_bind, type, conv); 1532 return build_conv (ck_ref_bind, type, conv);
1509 } 1533 }
1510 1534
1511 /* Returns the conversion path from type FROM to reference type TO for 1535 /* Returns the conversion path from type FROM to reference type TO for
1512 purposes of reference binding. For lvalue binding, either pass a 1536 purposes of reference binding. For lvalue binding, either pass a
1553 expr = elt; 1577 expr = elt;
1554 from = etype; 1578 from = etype;
1555 goto skip; 1579 goto skip;
1556 } 1580 }
1557 } 1581 }
1558 /* Otherwise, if T is a reference type, a prvalue temporary of the 1582 /* Otherwise, if T is a reference type, a prvalue temporary of the type
1559 type referenced by T is copy-list-initialized or 1583 referenced by T is copy-list-initialized, and the reference is bound
1560 direct-list-initialized, depending on the kind of initialization 1584 to that temporary. */
1561 for the reference, and the reference is bound to that temporary. */ 1585 CONSTRUCTOR_IS_DIRECT_INIT (expr) = false;
1562 conv = implicit_conversion (to, from, expr, c_cast_p,
1563 flags|LOOKUP_NO_TEMP_BIND, complain);
1564 skip:; 1586 skip:;
1565 } 1587 }
1566 1588
1567 if (TREE_CODE (from) == REFERENCE_TYPE) 1589 if (TYPE_REF_P (from))
1568 { 1590 {
1569 from = TREE_TYPE (from); 1591 from = TREE_TYPE (from);
1570 if (!TYPE_REF_IS_RVALUE (rfrom) 1592 if (!TYPE_REF_IS_RVALUE (rfrom)
1571 || TREE_CODE (from) == FUNCTION_TYPE) 1593 || TREE_CODE (from) == FUNCTION_TYPE)
1572 gl_kind = clk_ordinary; 1594 gl_kind = clk_ordinary;
1628 within that object. */ 1650 within that object. */
1629 1651
1630 conv = build_identity_conv (tfrom, expr); 1652 conv = build_identity_conv (tfrom, expr);
1631 conv = direct_reference_binding (rto, conv); 1653 conv = direct_reference_binding (rto, conv);
1632 1654
1633 if (TREE_CODE (rfrom) == REFERENCE_TYPE) 1655 if (TYPE_REF_P (rfrom))
1634 /* Handle rvalue reference to function properly. */ 1656 /* Handle rvalue reference to function properly. */
1635 conv->rvaluedness_matches_p 1657 conv->rvaluedness_matches_p
1636 = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom)); 1658 = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
1637 else 1659 else
1638 conv->rvaluedness_matches_p 1660 conv->rvaluedness_matches_p
1830 if (expr == error_mark_node) 1852 if (expr == error_mark_node)
1831 return NULL; 1853 return NULL;
1832 from = TREE_TYPE (expr); 1854 from = TREE_TYPE (expr);
1833 } 1855 }
1834 1856
1835 if (TREE_CODE (to) == REFERENCE_TYPE) 1857 if (TYPE_REF_P (to))
1836 conv = reference_binding (to, from, expr, c_cast_p, flags, complain); 1858 conv = reference_binding (to, from, expr, c_cast_p, flags, complain);
1837 else 1859 else
1838 conv = standard_conversion (to, from, expr, c_cast_p, flags, complain); 1860 conv = standard_conversion (to, from, expr, c_cast_p, flags, complain);
1839 1861
1840 if (conv) 1862 if (conv)
1922 } 1944 }
1923 1945
1924 return NULL; 1946 return NULL;
1925 } 1947 }
1926 1948
1949 /* Like implicit_conversion, but return NULL if the conversion is bad.
1950
1951 This is not static so that check_non_deducible_conversion can call it within
1952 add_template_candidate_real as part of overload resolution; it should not be
1953 called outside of overload resolution. */
1954
1955 conversion *
1956 good_conversion (tree to, tree from, tree expr,
1957 int flags, tsubst_flags_t complain)
1958 {
1959 conversion *c = implicit_conversion (to, from, expr, /*cast*/false,
1960 flags, complain);
1961 if (c && c->bad_p)
1962 c = NULL;
1963 return c;
1964 }
1965
1927 /* Add a new entry to the list of candidates. Used by the add_*_candidate 1966 /* Add a new entry to the list of candidates. Used by the add_*_candidate
1928 functions. ARGS will not be changed until a single candidate is 1967 functions. ARGS will not be changed until a single candidate is
1929 selected. */ 1968 selected. */
1930 1969
1931 static struct z_candidate * 1970 static struct z_candidate *
1968 n++; 2007 n++;
1969 2008
1970 return n; 2009 return n;
1971 } 2010 }
1972 2011
2012 /* [over.match.copy]: When initializing a temporary object (12.2) to be bound
2013 to the first parameter of a constructor where the parameter is of type
2014 "reference to possibly cv-qualified T" and the constructor is called with a
2015 single argument in the context of direct-initialization of an object of type
2016 "cv2 T", explicit conversion functions are also considered.
2017
2018 So set LOOKUP_COPY_PARM to let reference_binding know that
2019 it's being called in that context. */
2020
2021 int
2022 conv_flags (int i, int nargs, tree fn, tree arg, int flags)
2023 {
2024 int lflags = flags;
2025 tree t;
2026 if (i == 0 && nargs == 1 && DECL_CONSTRUCTOR_P (fn)
2027 && (t = FUNCTION_FIRST_USER_PARMTYPE (fn))
2028 && (same_type_ignoring_top_level_qualifiers_p
2029 (non_reference (TREE_VALUE (t)), DECL_CONTEXT (fn))))
2030 {
2031 if (!(flags & LOOKUP_ONLYCONVERTING))
2032 lflags |= LOOKUP_COPY_PARM;
2033 if ((flags & LOOKUP_LIST_INIT_CTOR)
2034 && BRACE_ENCLOSED_INITIALIZER_P (arg))
2035 lflags |= LOOKUP_NO_CONVERSION;
2036 }
2037 else
2038 lflags |= LOOKUP_ONLYCONVERTING;
2039
2040 return lflags;
2041 }
2042
1973 /* Create an overload candidate for the function or method FN called 2043 /* Create an overload candidate for the function or method FN called
1974 with the argument list FIRST_ARG/ARGS and add it to CANDIDATES. 2044 with the argument list FIRST_ARG/ARGS and add it to CANDIDATES.
1975 FLAGS is passed on to implicit_conversion. 2045 FLAGS is passed on to implicit_conversion.
1976 2046
1977 This does not change ARGS. 2047 This does not change ARGS.
1982 static struct z_candidate * 2052 static struct z_candidate *
1983 add_function_candidate (struct z_candidate **candidates, 2053 add_function_candidate (struct z_candidate **candidates,
1984 tree fn, tree ctype, tree first_arg, 2054 tree fn, tree ctype, tree first_arg,
1985 const vec<tree, va_gc> *args, tree access_path, 2055 const vec<tree, va_gc> *args, tree access_path,
1986 tree conversion_path, int flags, 2056 tree conversion_path, int flags,
2057 conversion **convs,
1987 tsubst_flags_t complain) 2058 tsubst_flags_t complain)
1988 { 2059 {
1989 tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn)); 2060 tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
1990 int i, len; 2061 int i, len;
1991 conversion **convs;
1992 tree parmnode; 2062 tree parmnode;
1993 tree orig_first_arg = first_arg; 2063 tree orig_first_arg = first_arg;
1994 int skip; 2064 int skip;
1995 int viable = 1; 2065 int viable = 1;
1996 struct rejection_reason *reason = NULL; 2066 struct rejection_reason *reason = NULL;
2018 } 2088 }
2019 else 2089 else
2020 skip = 0; 2090 skip = 0;
2021 2091
2022 len = vec_safe_length (args) - skip + (first_arg != NULL_TREE ? 1 : 0); 2092 len = vec_safe_length (args) - skip + (first_arg != NULL_TREE ? 1 : 0);
2023 convs = alloc_conversions (len); 2093 if (!convs)
2094 convs = alloc_conversions (len);
2024 2095
2025 /* 13.3.2 - Viable functions [over.match.viable] 2096 /* 13.3.2 - Viable functions [over.match.viable]
2026 First, to be a viable function, a candidate function shall have enough 2097 First, to be a viable function, a candidate function shall have enough
2027 parameters to agree in number with the arguments in the list. 2098 parameters to agree in number with the arguments in the list.
2028 2099
2080 if (viable && parmlist && (flags & LOOKUP_DEFAULTED)) 2151 if (viable && parmlist && (flags & LOOKUP_DEFAULTED))
2081 { 2152 {
2082 if (DECL_CONSTRUCTOR_P (fn)) 2153 if (DECL_CONSTRUCTOR_P (fn))
2083 i = 1; 2154 i = 1;
2084 else if (DECL_ASSIGNMENT_OPERATOR_P (fn) 2155 else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
2085 && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR) 2156 && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
2086 i = 2; 2157 i = 2;
2087 else 2158 else
2088 i = 0; 2159 i = 0;
2089 if (i && len == i) 2160 if (i && len == i)
2090 { 2161 {
2114 conversion *t; 2185 conversion *t;
2115 int is_this; 2186 int is_this;
2116 2187
2117 if (parmnode == void_list_node) 2188 if (parmnode == void_list_node)
2118 break; 2189 break;
2190
2191 if (convs[i])
2192 {
2193 /* Already set during deduction. */
2194 parmnode = TREE_CHAIN (parmnode);
2195 continue;
2196 }
2119 2197
2120 if (i == 0 && first_arg != NULL_TREE) 2198 if (i == 0 && first_arg != NULL_TREE)
2121 arg = first_arg; 2199 arg = first_arg;
2122 else 2200 else
2123 arg = CONST_CAST_TREE ( 2201 arg = CONST_CAST_TREE (
2128 && ! DECL_CONSTRUCTOR_P (fn)); 2206 && ! DECL_CONSTRUCTOR_P (fn));
2129 2207
2130 if (parmnode) 2208 if (parmnode)
2131 { 2209 {
2132 tree parmtype = TREE_VALUE (parmnode); 2210 tree parmtype = TREE_VALUE (parmnode);
2133 int lflags = flags;
2134 2211
2135 parmnode = TREE_CHAIN (parmnode); 2212 parmnode = TREE_CHAIN (parmnode);
2136 2213
2137 /* The type of the implicit object parameter ('this') for 2214 /* The type of the implicit object parameter ('this') for
2138 overload resolution is not always the same as for the 2215 overload resolution is not always the same as for the
2166 arg = build_address (arg); 2243 arg = build_address (arg);
2167 argtype = lvalue_type (arg); 2244 argtype = lvalue_type (arg);
2168 } 2245 }
2169 } 2246 }
2170 2247
2171 /* Core issue 899: When [copy-]initializing a temporary to be bound 2248 int lflags = conv_flags (i, len-skip, fn, arg, flags);
2172 to the first parameter of a copy constructor (12.8) called with
2173 a single argument in the context of direct-initialization,
2174 explicit conversion functions are also considered.
2175
2176 So set LOOKUP_COPY_PARM to let reference_binding know that
2177 it's being called in that context. We generalize the above
2178 to handle move constructors and template constructors as well;
2179 the standardese should soon be updated similarly. */
2180 if (ctype && i == 0 && (len-skip == 1)
2181 && DECL_CONSTRUCTOR_P (fn)
2182 && parmtype != error_mark_node
2183 && (same_type_ignoring_top_level_qualifiers_p
2184 (non_reference (parmtype), ctype)))
2185 {
2186 if (!(flags & LOOKUP_ONLYCONVERTING))
2187 lflags |= LOOKUP_COPY_PARM;
2188 /* We allow user-defined conversions within init-lists, but
2189 don't list-initialize the copy parm, as that would mean
2190 using two levels of braces for the same type. */
2191 if ((flags & LOOKUP_LIST_INIT_CTOR)
2192 && BRACE_ENCLOSED_INITIALIZER_P (arg))
2193 lflags |= LOOKUP_NO_CONVERSION;
2194 }
2195 else
2196 lflags |= LOOKUP_ONLYCONVERTING;
2197 2249
2198 t = implicit_conversion (parmtype, argtype, arg, 2250 t = implicit_conversion (parmtype, argtype, arg,
2199 /*c_cast_p=*/false, lflags, complain); 2251 /*c_cast_p=*/false, lflags, complain);
2200 to_type = parmtype; 2252 to_type = parmtype;
2201 } 2253 }
2211 2263
2212 convs[i] = t; 2264 convs[i] = t;
2213 if (! t) 2265 if (! t)
2214 { 2266 {
2215 viable = 0; 2267 viable = 0;
2216 reason = arg_conversion_rejection (first_arg, i, argtype, to_type); 2268 reason = arg_conversion_rejection (first_arg, i, argtype, to_type,
2269 EXPR_LOCATION (arg));
2217 break; 2270 break;
2218 } 2271 }
2219 2272
2220 if (t->bad_p) 2273 if (t->bad_p)
2221 { 2274 {
2222 viable = -1; 2275 viable = -1;
2223 reason = bad_arg_conversion_rejection (first_arg, i, arg, to_type); 2276 reason = bad_arg_conversion_rejection (first_arg, i, arg, to_type,
2277 EXPR_LOCATION (arg));
2278
2224 } 2279 }
2225 } 2280 }
2226 2281
2227 out: 2282 out:
2228 return add_candidate (candidates, fn, orig_first_arg, args, len, convs, 2283 return add_candidate (candidates, fn, orig_first_arg, args, len, convs,
2307 break; 2362 break;
2308 2363
2309 if (t->bad_p) 2364 if (t->bad_p)
2310 { 2365 {
2311 viable = -1; 2366 viable = -1;
2312 reason = bad_arg_conversion_rejection (NULL_TREE, i, arg, convert_type); 2367 reason = bad_arg_conversion_rejection (NULL_TREE, i, arg, convert_type,
2368 EXPR_LOCATION (arg));
2313 } 2369 }
2314 2370
2315 if (i == 0) 2371 if (i == 0)
2316 continue; 2372 continue;
2317 2373
2368 { 2424 {
2369 viable = 0; 2425 viable = 0;
2370 /* We need something for printing the candidate. */ 2426 /* We need something for printing the candidate. */
2371 t = build_identity_conv (types[i], NULL_TREE); 2427 t = build_identity_conv (types[i], NULL_TREE);
2372 reason = arg_conversion_rejection (NULL_TREE, i, argtypes[i], 2428 reason = arg_conversion_rejection (NULL_TREE, i, argtypes[i],
2373 types[i]); 2429 types[i], EXPR_LOCATION (args[i]));
2374 } 2430 }
2375 else if (t->bad_p) 2431 else if (t->bad_p)
2376 { 2432 {
2377 viable = 0; 2433 viable = 0;
2378 reason = bad_arg_conversion_rejection (NULL_TREE, i, args[i], 2434 reason = bad_arg_conversion_rejection (NULL_TREE, i, args[i],
2379 types[i]); 2435 types[i],
2436 EXPR_LOCATION (args[i]));
2380 } 2437 }
2381 convs[i] = t; 2438 convs[i] = t;
2382 } 2439 }
2383 2440
2384 /* For COND_EXPR we rearranged the arguments; undo that now. */ 2441 /* For COND_EXPR we rearranged the arguments; undo that now. */
2393 convs[0] = t; 2450 convs[0] = t;
2394 else 2451 else
2395 { 2452 {
2396 viable = 0; 2453 viable = 0;
2397 reason = arg_conversion_rejection (NULL_TREE, 0, argtypes[2], 2454 reason = arg_conversion_rejection (NULL_TREE, 0, argtypes[2],
2398 boolean_type_node); 2455 boolean_type_node,
2456 EXPR_LOCATION (args[2]));
2399 } 2457 }
2400 } 2458 }
2401 2459
2402 add_candidate (candidates, fnname, /*first_arg=*/NULL_TREE, /*args=*/NULL, 2460 add_candidate (candidates, fnname, /*first_arg=*/NULL_TREE, /*args=*/NULL,
2403 num_convs, convs, 2461 num_convs, convs,
2840 2898
2841 /* If we're dealing with two pointer types or two enumeral types, 2899 /* If we're dealing with two pointer types or two enumeral types,
2842 we need candidates for both of them. */ 2900 we need candidates for both of them. */
2843 if (type2 && !same_type_p (type1, type2) 2901 if (type2 && !same_type_p (type1, type2)
2844 && TREE_CODE (type1) == TREE_CODE (type2) 2902 && TREE_CODE (type1) == TREE_CODE (type2)
2845 && (TREE_CODE (type1) == REFERENCE_TYPE 2903 && (TYPE_REF_P (type1)
2846 || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2)) 2904 || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
2847 || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2)) 2905 || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
2848 || TYPE_PTRMEMFUNC_P (type1) 2906 || TYPE_PTRMEMFUNC_P (type1)
2849 || MAYBE_CLASS_TYPE_P (type1) 2907 || MAYBE_CLASS_TYPE_P (type1)
2850 || TREE_CODE (type1) == ENUMERAL_TYPE)) 2908 || TREE_CODE (type1) == ENUMERAL_TYPE))
3002 for (; convs; convs = TREE_CHAIN (convs)) 3060 for (; convs; convs = TREE_CHAIN (convs))
3003 { 3061 {
3004 type = TREE_TYPE (convs); 3062 type = TREE_TYPE (convs);
3005 3063
3006 if (i == 0 && ref1 3064 if (i == 0 && ref1
3007 && (TREE_CODE (type) != REFERENCE_TYPE 3065 && (!TYPE_REF_P (type)
3008 || CP_TYPE_CONST_P (TREE_TYPE (type)))) 3066 || CP_TYPE_CONST_P (TREE_TYPE (type))))
3009 continue; 3067 continue;
3010 3068
3011 if (code == COND_EXPR && TREE_CODE (type) == REFERENCE_TYPE) 3069 if (code == COND_EXPR && TYPE_REF_P (type))
3012 vec_safe_push (types[i], type); 3070 vec_safe_push (types[i], type);
3013 3071
3014 type = non_reference (type); 3072 type = non_reference (type);
3015 if (i != 0 || ! ref1) 3073 if (i != 0 || ! ref1)
3016 { 3074 {
3095 tree arg; 3153 tree arg;
3096 struct z_candidate *cand; 3154 struct z_candidate *cand;
3097 tree fn; 3155 tree fn;
3098 struct rejection_reason *reason = NULL; 3156 struct rejection_reason *reason = NULL;
3099 int errs; 3157 int errs;
3158 conversion **convs = NULL;
3100 3159
3101 /* We don't do deduction on the in-charge parameter, the VTT 3160 /* We don't do deduction on the in-charge parameter, the VTT
3102 parameter or 'this'. */ 3161 parameter or 'this'. */
3103 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (tmpl)) 3162 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (tmpl))
3104 { 3163 {
3169 ++ia; 3228 ++ia;
3170 } 3229 }
3171 gcc_assert (ia == nargs_without_in_chrg); 3230 gcc_assert (ia == nargs_without_in_chrg);
3172 3231
3173 errs = errorcount+sorrycount; 3232 errs = errorcount+sorrycount;
3233 if (!obj)
3234 convs = alloc_conversions (nargs);
3174 fn = fn_type_unification (tmpl, explicit_targs, targs, 3235 fn = fn_type_unification (tmpl, explicit_targs, targs,
3175 args_without_in_chrg, 3236 args_without_in_chrg,
3176 nargs_without_in_chrg, 3237 nargs_without_in_chrg,
3177 return_type, strict, flags, false, 3238 return_type, strict, flags, convs,
3178 complain & tf_decltype); 3239 false, complain & tf_decltype);
3179 3240
3180 if (fn == error_mark_node) 3241 if (fn == error_mark_node)
3181 { 3242 {
3182 /* Don't repeat unification later if it already resulted in errors. */ 3243 /* Don't repeat unification later if it already resulted in errors. */
3183 if (errorcount+sorrycount == errs) 3244 if (errorcount+sorrycount == errs)
3209 cand = add_conv_candidate (candidates, fn, obj, arglist, 3270 cand = add_conv_candidate (candidates, fn, obj, arglist,
3210 access_path, conversion_path, complain); 3271 access_path, conversion_path, complain);
3211 else 3272 else
3212 cand = add_function_candidate (candidates, fn, ctype, 3273 cand = add_function_candidate (candidates, fn, ctype,
3213 first_arg, arglist, access_path, 3274 first_arg, arglist, access_path,
3214 conversion_path, flags, complain); 3275 conversion_path, flags, convs, complain);
3215 if (DECL_TI_TEMPLATE (fn) != tmpl) 3276 if (DECL_TI_TEMPLATE (fn) != tmpl)
3216 /* This situation can occur if a member template of a template 3277 /* This situation can occur if a member template of a template
3217 class is specialized. Then, instantiate_template might return 3278 class is specialized. Then, instantiate_template might return
3218 an instantiation of the specialization, in which case the 3279 an instantiation of the specialization, in which case the
3219 DECL_TI_TEMPLATE field will point at the original 3280 DECL_TI_TEMPLATE field will point at the original
3267 tree obj, 3328 tree obj,
3268 const vec<tree, va_gc> *arglist, 3329 const vec<tree, va_gc> *arglist,
3269 tree return_type, tree access_path, 3330 tree return_type, tree access_path,
3270 tree conversion_path, tsubst_flags_t complain) 3331 tree conversion_path, tsubst_flags_t complain)
3271 { 3332 {
3272 /* Making this work broke PR 71117, so until the committee resolves core 3333 /* Making this work broke PR 71117 and 85118, so until the committee resolves
3273 issue 2189, let's disable this candidate if there are any viable call 3334 core issue 2189, let's disable this candidate if there are any call
3274 operators. */ 3335 operators. */
3275 if (any_strictly_viable (*candidates)) 3336 if (*candidates)
3276 return NULL; 3337 return NULL;
3277 3338
3278 return 3339 return
3279 add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE, 3340 add_template_candidate_real (candidates, tmpl, NULL_TREE, NULL_TREE,
3280 NULL_TREE, arglist, return_type, access_path, 3341 NULL_TREE, arglist, return_type, access_path,
3363 static tree 3424 static tree
3364 build_this (tree obj) 3425 build_this (tree obj)
3365 { 3426 {
3366 /* In a template, we are only concerned about the type of the 3427 /* In a template, we are only concerned about the type of the
3367 expression, so we can take a shortcut. */ 3428 expression, so we can take a shortcut. */
3368 if (processing_nonlambda_template ()) 3429 if (processing_template_decl)
3369 return build_address (obj); 3430 return build_address (obj);
3370 3431
3371 return cp_build_addr_expr (obj, tf_warning_or_error); 3432 return cp_build_addr_expr (obj, tf_warning_or_error);
3372 } 3433 }
3373 3434
3386 || DECL_EXTERN_C_FUNCTION_P (fn1)) 3447 || DECL_EXTERN_C_FUNCTION_P (fn1))
3387 return decls_match (fn1, fn2); 3448 return decls_match (fn1, fn2);
3388 return fn1 == fn2; 3449 return fn1 == fn2;
3389 } 3450 }
3390 3451
3391 /* Print information about a candidate being rejected due to INFO. */ 3452 /* Print information about a candidate FN being rejected due to INFO. */
3392 3453
3393 static void 3454 static void
3394 print_conversion_rejection (location_t loc, struct conversion_info *info) 3455 print_conversion_rejection (location_t loc, struct conversion_info *info,
3456 tree fn)
3395 { 3457 {
3396 tree from = info->from; 3458 tree from = info->from;
3397 if (!TYPE_P (from)) 3459 if (!TYPE_P (from))
3398 from = lvalue_type (from); 3460 from = lvalue_type (from);
3399 if (info->n_arg == -1) 3461 if (info->n_arg == -1)
3420 else if (info->n_arg == -2) 3482 else if (info->n_arg == -2)
3421 /* Conversion of conversion function return value failed. */ 3483 /* Conversion of conversion function return value failed. */
3422 inform (loc, " no known conversion from %qH to %qI", 3484 inform (loc, " no known conversion from %qH to %qI",
3423 from, info->to_type); 3485 from, info->to_type);
3424 else 3486 else
3425 inform (loc, " no known conversion for argument %d from %qH to %qI", 3487 {
3426 info->n_arg + 1, from, info->to_type); 3488 if (TREE_CODE (fn) == FUNCTION_DECL)
3489 loc = get_fndecl_argument_location (fn, info->n_arg);
3490 inform (loc, " no known conversion for argument %d from %qH to %qI",
3491 info->n_arg + 1, from, info->to_type);
3492 }
3427 } 3493 }
3428 3494
3429 /* Print information about a candidate with WANT parameters and we found 3495 /* Print information about a candidate with WANT parameters and we found
3430 HAVE. */ 3496 HAVE. */
3431 3497
3496 case rr_arity: 3562 case rr_arity:
3497 print_arity_information (cloc, r->u.arity.actual, 3563 print_arity_information (cloc, r->u.arity.actual,
3498 r->u.arity.expected); 3564 r->u.arity.expected);
3499 break; 3565 break;
3500 case rr_arg_conversion: 3566 case rr_arg_conversion:
3501 print_conversion_rejection (cloc, &r->u.conversion); 3567 print_conversion_rejection (cloc, &r->u.conversion, fn);
3502 break; 3568 break;
3503 case rr_bad_arg_conversion: 3569 case rr_bad_arg_conversion:
3504 print_conversion_rejection (cloc, &r->u.bad_conversion); 3570 print_conversion_rejection (cloc, &r->u.bad_conversion, fn);
3505 break; 3571 break;
3506 case rr_explicit_conversion: 3572 case rr_explicit_conversion:
3507 inform (cloc, " return type %qT of explicit conversion function " 3573 inform (cloc, " return type %qT of explicit conversion function "
3508 "cannot be converted to %qT with a qualification " 3574 "cannot be converted to %qT with a qualification "
3509 "conversion", r->u.conversion.from, 3575 "conversion", r->u.conversion.from,
3534 r->u.template_unification.args, 3600 r->u.template_unification.args,
3535 r->u.template_unification.nargs, 3601 r->u.template_unification.nargs,
3536 r->u.template_unification.return_type, 3602 r->u.template_unification.return_type,
3537 r->u.template_unification.strict, 3603 r->u.template_unification.strict,
3538 r->u.template_unification.flags, 3604 r->u.template_unification.flags,
3539 true, false); 3605 NULL, true, false);
3540 break; 3606 break;
3541 case rr_invalid_copy: 3607 case rr_invalid_copy:
3542 inform (cloc, 3608 inform (cloc,
3543 " a constructor taking a single argument of its own " 3609 " a constructor taking a single argument of its own "
3544 "class type is invalid"); 3610 "class type is invalid");
3635 (*t)->user_conv_p = true; 3701 (*t)->user_conv_p = true;
3636 if (bad) 3702 if (bad)
3637 (*t)->bad_p = true; 3703 (*t)->bad_p = true;
3638 } 3704 }
3639 3705
3706 if ((*t)->rvaluedness_matches_p)
3707 /* We're binding a reference directly to the result of the conversion.
3708 build_user_type_conversion_1 stripped the REFERENCE_TYPE from the return
3709 type, but we want it back. */
3710 user_seq->type = TREE_TYPE (TREE_TYPE (user_seq->cand->fn));
3711
3640 /* Replace the identity conversion with the user conversion 3712 /* Replace the identity conversion with the user conversion
3641 sequence. */ 3713 sequence. */
3642 *t = user_seq; 3714 *t = user_seq;
3643 3715
3644 return std_seq; 3716 return std_seq;
3741 if (CLASS_TYPE_P (totype)) 3813 if (CLASS_TYPE_P (totype))
3742 /* Use lookup_fnfields_slot instead of lookup_fnfields to avoid 3814 /* Use lookup_fnfields_slot instead of lookup_fnfields to avoid
3743 creating a garbage BASELINK; constructors can't be inherited. */ 3815 creating a garbage BASELINK; constructors can't be inherited. */
3744 ctors = get_class_binding (totype, complete_ctor_identifier); 3816 ctors = get_class_binding (totype, complete_ctor_identifier);
3745 3817
3746 /* FIXME P0135 doesn't say what to do in C++17 about list-initialization from
3747 a single element. For now, let's handle constructors as before and also
3748 consider conversion operators from the element. */
3749 if (cxx_dialect >= cxx17
3750 && BRACE_ENCLOSED_INITIALIZER_P (expr)
3751 && CONSTRUCTOR_NELTS (expr) == 1)
3752 fromtype = TREE_TYPE (CONSTRUCTOR_ELT (expr, 0)->value);
3753
3754 if (MAYBE_CLASS_TYPE_P (fromtype)) 3818 if (MAYBE_CLASS_TYPE_P (fromtype))
3755 { 3819 {
3756 tree to_nonref = non_reference (totype); 3820 tree to_nonref = non_reference (totype);
3757 if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) || 3821 if (same_type_ignoring_top_level_qualifiers_p (to_nonref, fromtype) ||
3758 (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype) 3822 (CLASS_TYPE_P (to_nonref) && CLASS_TYPE_P (fromtype)
3815 object that is the destination of the copy-initialization." 3879 object that is the destination of the copy-initialization."
3816 [dcl.init] 3880 [dcl.init]
3817 3881
3818 We represent this in the conversion sequence with an 3882 We represent this in the conversion sequence with an
3819 rvalue conversion, which means a constructor call. */ 3883 rvalue conversion, which means a constructor call. */
3820 if (TREE_CODE (totype) != REFERENCE_TYPE 3884 if (!TYPE_REF_P (totype)
3821 && !(convflags & LOOKUP_NO_TEMP_BIND)) 3885 && !(convflags & LOOKUP_NO_TEMP_BIND))
3822 cand->second_conv 3886 cand->second_conv
3823 = build_conv (ck_rvalue, totype, cand->second_conv); 3887 = build_conv (ck_rvalue, totype, cand->second_conv);
3824 } 3888 }
3825 } 3889 }
3826 3890
3827 if (conv_fns) 3891 if (conv_fns)
3828 { 3892 {
3829 if (BRACE_ENCLOSED_INITIALIZER_P (expr)) 3893 if (BRACE_ENCLOSED_INITIALIZER_P (expr))
3830 /* FIXME see above about C++17. */
3831 first_arg = CONSTRUCTOR_ELT (expr, 0)->value; 3894 first_arg = CONSTRUCTOR_ELT (expr, 0)->value;
3832 else 3895 else
3833 first_arg = expr; 3896 first_arg = expr;
3834 } 3897 }
3835 3898
3840 3903
3841 /* If we are called to convert to a reference type, we are trying to 3904 /* If we are called to convert to a reference type, we are trying to
3842 find a direct binding, so don't even consider temporaries. If 3905 find a direct binding, so don't even consider temporaries. If
3843 we don't find a direct binding, the caller will try again to 3906 we don't find a direct binding, the caller will try again to
3844 look for a temporary binding. */ 3907 look for a temporary binding. */
3845 if (TREE_CODE (totype) == REFERENCE_TYPE) 3908 if (TYPE_REF_P (totype))
3846 convflags |= LOOKUP_NO_TEMP_BIND; 3909 convflags |= LOOKUP_NO_TEMP_BIND;
3847 3910
3848 old_candidates = candidates; 3911 old_candidates = candidates;
3849 add_candidates (TREE_VALUE (conv_fns), first_arg, NULL, totype, 3912 add_candidates (TREE_VALUE (conv_fns), first_arg, NULL, totype,
3850 NULL_TREE, false, 3913 NULL_TREE, false,
3879 3942
3880 if (!ics) 3943 if (!ics)
3881 { 3944 {
3882 cand->viable = 0; 3945 cand->viable = 0;
3883 cand->reason = arg_conversion_rejection (NULL_TREE, -2, 3946 cand->reason = arg_conversion_rejection (NULL_TREE, -2,
3884 rettype, totype); 3947 rettype, totype,
3948 EXPR_LOCATION (expr));
3885 } 3949 }
3886 else if (DECL_NONCONVERTING_P (cand->fn) 3950 else if (DECL_NONCONVERTING_P (cand->fn)
3887 && ics->rank > cr_exact) 3951 && ics->rank > cr_exact)
3888 { 3952 {
3889 /* 13.3.1.5: For direct-initialization, those explicit 3953 /* 13.3.1.5: For direct-initialization, those explicit
3899 else if (cand->viable == 1 && ics->bad_p) 3963 else if (cand->viable == 1 && ics->bad_p)
3900 { 3964 {
3901 cand->viable = -1; 3965 cand->viable = -1;
3902 cand->reason 3966 cand->reason
3903 = bad_arg_conversion_rejection (NULL_TREE, -2, 3967 = bad_arg_conversion_rejection (NULL_TREE, -2,
3904 rettype, totype); 3968 rettype, totype,
3969 EXPR_LOCATION (expr));
3905 } 3970 }
3906 else if (primary_template_instantiation_p (cand->fn) 3971 else if (primary_template_specialization_p (cand->fn)
3907 && ics->rank > cr_exact) 3972 && ics->rank > cr_exact)
3908 { 3973 {
3909 /* 13.3.3.1.2: If the user-defined conversion is specified by 3974 /* 13.3.3.1.2: If the user-defined conversion is specified by
3910 a specialization of a conversion function template, the 3975 a specialization of a conversion function template, the
3911 second standard conversion sequence shall have exact match 3976 second standard conversion sequence shall have exact match
3923 release_tree_vector (args); 3988 release_tree_vector (args);
3924 return NULL; 3989 return NULL;
3925 } 3990 }
3926 3991
3927 cand = tourney (candidates, complain); 3992 cand = tourney (candidates, complain);
3928 if (cand == 0) 3993 if (cand == NULL)
3929 { 3994 {
3930 if (complain & tf_error) 3995 if (complain & tf_error)
3931 { 3996 {
3997 auto_diagnostic_group d;
3932 error ("conversion from %qH to %qI is ambiguous", 3998 error ("conversion from %qH to %qI is ambiguous",
3933 fromtype, totype); 3999 fromtype, totype);
3934 print_z_candidates (location_of (expr), candidates); 4000 print_z_candidates (location_of (expr), candidates);
3935 } 4001 }
3936 4002
3937 cand = candidates; /* any one will do */ 4003 cand = candidates; /* any one will do */
3938 cand->second_conv = build_ambiguous_conv (totype, expr); 4004 cand->second_conv = build_ambiguous_conv (totype, expr);
3939 cand->second_conv->user_conv_p = true; 4005 cand->second_conv->user_conv_p = true;
3940 if (!any_strictly_viable (candidates)) 4006 if (!any_strictly_viable (candidates))
3941 cand->second_conv->bad_p = true; 4007 cand->second_conv->bad_p = true;
4008 if (flags & LOOKUP_ONLYCONVERTING)
4009 cand->second_conv->need_temporary_p = true;
3942 /* If there are viable candidates, don't set ICS_BAD_FLAG; an 4010 /* If there are viable candidates, don't set ICS_BAD_FLAG; an
3943 ambiguous conversion is no worse than another user-defined 4011 ambiguous conversion is no worse than another user-defined
3944 conversion. */ 4012 conversion. */
3945 4013
3946 return cand; 4014 return cand;
3963 build_identity_conv (TREE_TYPE (expr), expr)); 4031 build_identity_conv (TREE_TYPE (expr), expr));
3964 conv->cand = cand; 4032 conv->cand = cand;
3965 if (cand->viable == -1) 4033 if (cand->viable == -1)
3966 conv->bad_p = true; 4034 conv->bad_p = true;
3967 4035
4036 /* We're performing the maybe-rvalue overload resolution and
4037 a conversion function is in play. Reject converting the return
4038 value of the conversion function to a base class. */
4039 if ((flags & LOOKUP_PREFER_RVALUE) && !DECL_CONSTRUCTOR_P (cand->fn))
4040 for (conversion *t = cand->second_conv; t; t = next_conversion (t))
4041 if (t->kind == ck_base)
4042 return NULL;
4043
3968 /* Remember that this was a list-initialization. */ 4044 /* Remember that this was a list-initialization. */
3969 if (flags & LOOKUP_NO_NARROWING) 4045 if (flags & LOOKUP_NO_NARROWING)
3970 conv->check_narrowing = true; 4046 conv->check_narrowing = true;
3971 4047
3972 /* Combine it with the second conversion sequence. */ 4048 /* Combine it with the second conversion sequence. */
4019 build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain) 4095 build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
4020 { 4096 {
4021 conversion *conv; 4097 conversion *conv;
4022 void *p; 4098 void *p;
4023 tree t; 4099 tree t;
4024 location_t loc = EXPR_LOC_OR_LOC (expr, input_location); 4100 location_t loc = cp_expr_loc_or_loc (expr, input_location);
4025 4101
4026 if (error_operand_p (expr)) 4102 if (error_operand_p (expr))
4027 return error_mark_node; 4103 return error_mark_node;
4028 4104
4029 /* Get the high-water mark for the CONVERSION_OBSTACK. */ 4105 /* Get the high-water mark for the CONVERSION_OBSTACK. */
4113 if (same_type_p (type, TREE_TYPE (ref))) 4189 if (same_type_p (type, TREE_TYPE (ref)))
4114 return ref; 4190 return ref;
4115 } 4191 }
4116 4192
4117 if (conv) 4193 if (conv)
4118 expr = convert_like (conv, expr, complain); 4194 {
4195 conv->check_narrowing = true;
4196 conv->check_narrowing_const_only = true;
4197 expr = convert_like (conv, expr, complain);
4198 }
4119 else 4199 else
4120 expr = error_mark_node; 4200 {
4201 if (complain & tf_error)
4202 error_at (loc, "could not convert %qE from %qH to %qI", expr,
4203 TREE_TYPE (expr), type);
4204 expr = error_mark_node;
4205 }
4121 4206
4122 /* Free all the conversions we allocated. */ 4207 /* Free all the conversions we allocated. */
4123 obstack_free (&conversion_obstack, p); 4208 obstack_free (&conversion_obstack, p);
4124 4209
4125 return expr; 4210 return expr;
4141 { 4226 {
4142 if (complain & tf_error) 4227 if (complain & tf_error)
4143 error ("invalid use of void expression"); 4228 error ("invalid use of void expression");
4144 return NULL; 4229 return NULL;
4145 } 4230 }
4146 else if (invalid_nonstatic_memfn_p (input_location, arg, complain)) 4231 else if (invalid_nonstatic_memfn_p (arg->exp.locus, arg, complain))
4147 return NULL; 4232 return NULL;
4148 } 4233 }
4149 return args; 4234 return args;
4150 } 4235 }
4151 4236
4228 tree name = OVL_NAME (fn); 4313 tree name = OVL_NAME (fn);
4229 location_t loc = location_of (name); 4314 location_t loc = location_of (name);
4230 if (targs) 4315 if (targs)
4231 name = lookup_template_function (name, targs); 4316 name = lookup_template_function (name, targs);
4232 4317
4318 auto_diagnostic_group d;
4233 if (!any_strictly_viable (candidates)) 4319 if (!any_strictly_viable (candidates))
4234 error_at (loc, "no matching function for call to %<%D(%A)%>", 4320 error_at (loc, "no matching function for call to %<%D(%A)%>",
4235 name, build_tree_list_vec (args)); 4321 name, build_tree_list_vec (args));
4236 else 4322 else
4237 error_at (loc, "call of overloaded %<%D(%A)%> is ambiguous", 4323 error_at (loc, "call of overloaded %<%D(%A)%> is ambiguous",
4378 { 4464 {
4379 vec<tree, va_gc>* align_args 4465 vec<tree, va_gc>* align_args
4380 = vec_copy_and_insert (*args, align_arg, 1); 4466 = vec_copy_and_insert (*args, align_arg, 1);
4381 cand = perform_overload_resolution (fns, align_args, &candidates, 4467 cand = perform_overload_resolution (fns, align_args, &candidates,
4382 &any_viable_p, tf_none); 4468 &any_viable_p, tf_none);
4469 if (cand)
4470 *args = align_args;
4383 /* If no aligned allocation function matches, try again without the 4471 /* If no aligned allocation function matches, try again without the
4384 alignment. */ 4472 alignment. */
4385 } 4473 }
4386 4474
4387 /* Figure out what function is being called. */ 4475 /* Figure out what function is being called. */
4472 return error_mark_node; 4560 return error_mark_node;
4473 } 4561 }
4474 4562
4475 if (TYPE_BINFO (type)) 4563 if (TYPE_BINFO (type))
4476 { 4564 {
4477 fns = lookup_fnfields (TYPE_BINFO (type), cp_operator_id (CALL_EXPR), 1); 4565 fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1);
4478 if (fns == error_mark_node) 4566 if (fns == error_mark_node)
4479 return error_mark_node; 4567 return error_mark_node;
4480 } 4568 }
4481 else 4569 else
4482 fns = NULL_TREE; 4570 fns = NULL_TREE;
4508 { 4596 {
4509 tree totype = TREE_TYPE (convs); 4597 tree totype = TREE_TYPE (convs);
4510 4598
4511 if (TYPE_PTRFN_P (totype) 4599 if (TYPE_PTRFN_P (totype)
4512 || TYPE_REFFN_P (totype) 4600 || TYPE_REFFN_P (totype)
4513 || (TREE_CODE (totype) == REFERENCE_TYPE 4601 || (TYPE_REF_P (totype)
4514 && TYPE_PTRFN_P (TREE_TYPE (totype)))) 4602 && TYPE_PTRFN_P (TREE_TYPE (totype))))
4515 for (ovl_iterator iter (TREE_VALUE (convs)); iter; ++iter) 4603 for (ovl_iterator iter (TREE_VALUE (convs)); iter; ++iter)
4516 { 4604 {
4517 tree fn = *iter; 4605 tree fn = *iter;
4518 4606
4536 candidates = splice_viable (candidates, true, &any_viable_p); 4624 candidates = splice_viable (candidates, true, &any_viable_p);
4537 if (!any_viable_p) 4625 if (!any_viable_p)
4538 { 4626 {
4539 if (complain & tf_error) 4627 if (complain & tf_error)
4540 { 4628 {
4629 auto_diagnostic_group d;
4541 error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj), 4630 error ("no match for call to %<(%T) (%A)%>", TREE_TYPE (obj),
4542 build_tree_list_vec (*args)); 4631 build_tree_list_vec (*args));
4543 print_z_candidates (location_of (TREE_TYPE (obj)), candidates); 4632 print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
4544 } 4633 }
4545 result = error_mark_node; 4634 result = error_mark_node;
4549 cand = tourney (candidates, complain); 4638 cand = tourney (candidates, complain);
4550 if (cand == 0) 4639 if (cand == 0)
4551 { 4640 {
4552 if (complain & tf_error) 4641 if (complain & tf_error)
4553 { 4642 {
4643 auto_diagnostic_group d;
4554 error ("call of %<(%T) (%A)%> is ambiguous", 4644 error ("call of %<(%T) (%A)%> is ambiguous",
4555 TREE_TYPE (obj), build_tree_list_vec (*args)); 4645 TREE_TYPE (obj), build_tree_list_vec (*args));
4556 print_z_candidates (location_of (TREE_TYPE (obj)), candidates); 4646 print_z_candidates (location_of (TREE_TYPE (obj)), candidates);
4557 } 4647 }
4558 result = error_mark_node; 4648 result = error_mark_node;
4559 } 4649 }
4560 /* Since cand->fn will be a type, not a function, for a conversion
4561 function, we must be careful not to unconditionally look at
4562 DECL_NAME here. */
4563 else if (TREE_CODE (cand->fn) == FUNCTION_DECL 4650 else if (TREE_CODE (cand->fn) == FUNCTION_DECL
4564 && DECL_OVERLOADED_OPERATOR_P (cand->fn) == CALL_EXPR) 4651 && DECL_OVERLOADED_OPERATOR_P (cand->fn)
4652 && DECL_OVERLOADED_OPERATOR_IS (cand->fn, CALL_EXPR))
4565 result = build_over_call (cand, LOOKUP_NORMAL, complain); 4653 result = build_over_call (cand, LOOKUP_NORMAL, complain);
4566 else 4654 else
4567 { 4655 {
4568 if (DECL_P (cand->fn)) 4656 if (TREE_CODE (cand->fn) == FUNCTION_DECL)
4569 obj = convert_like_with_context (cand->convs[0], obj, cand->fn, 4657 obj = convert_like_with_context (cand->convs[0], obj, cand->fn,
4570 -1, complain); 4658 -1, complain);
4571 else 4659 else
4572 obj = convert_like (cand->convs[0], obj, complain); 4660 {
4661 gcc_checking_assert (TYPE_P (cand->fn));
4662 obj = convert_like (cand->convs[0], obj, complain);
4663 }
4573 obj = convert_from_reference (obj); 4664 obj = convert_from_reference (obj);
4574 result = cp_build_function_call_vec (obj, args, complain); 4665 result = cp_build_function_call_vec (obj, args, complain);
4575 } 4666 }
4576 } 4667 }
4577 4668
4617 4708
4618 static void 4709 static void
4619 op_error (location_t loc, enum tree_code code, enum tree_code code2, 4710 op_error (location_t loc, enum tree_code code, enum tree_code code2,
4620 tree arg1, tree arg2, tree arg3, bool match) 4711 tree arg1, tree arg2, tree arg3, bool match)
4621 { 4712 {
4622 const char *opname; 4713 bool assop = code == MODIFY_EXPR;
4623 4714 const char *opname = OVL_OP_INFO (assop, assop ? code2 : code)->name;
4624 if (code == MODIFY_EXPR)
4625 opname = assignment_operator_name_info[code2].name;
4626 else
4627 opname = operator_name_info[code].name;
4628 4715
4629 switch (code) 4716 switch (code)
4630 { 4717 {
4631 case COND_EXPR: 4718 case COND_EXPR:
4632 if (flag_diagnostics_show_caret) 4719 if (flag_diagnostics_show_caret)
4779 { 4866 {
4780 tree arg2_type; 4867 tree arg2_type;
4781 tree arg3_type; 4868 tree arg3_type;
4782 tree result = NULL_TREE; 4869 tree result = NULL_TREE;
4783 tree result_type = NULL_TREE; 4870 tree result_type = NULL_TREE;
4784 bool is_lvalue = true; 4871 bool is_glvalue = true;
4785 struct z_candidate *candidates = 0; 4872 struct z_candidate *candidates = 0;
4786 struct z_candidate *cand; 4873 struct z_candidate *cand;
4787 void *p; 4874 void *p;
4788 tree orig_arg2, orig_arg3; 4875 tree orig_arg2, orig_arg3;
4789 4876
4802 4889
4803 /* Make sure that lvalues remain lvalues. See g++.oliva/ext1.C. */ 4890 /* Make sure that lvalues remain lvalues. See g++.oliva/ext1.C. */
4804 if (lvalue_p (arg1)) 4891 if (lvalue_p (arg1))
4805 arg2 = arg1 = cp_stabilize_reference (arg1); 4892 arg2 = arg1 = cp_stabilize_reference (arg1);
4806 else 4893 else
4807 arg2 = arg1 = save_expr (arg1); 4894 arg2 = arg1 = cp_save_expr (arg1);
4808 } 4895 }
4809 4896
4810 /* If something has already gone wrong, just pass that fact up the 4897 /* If something has already gone wrong, just pass that fact up the
4811 tree. */ 4898 tree. */
4812 if (error_operand_p (arg1) 4899 if (error_operand_p (arg1)
4926 break; 5013 break;
4927 } 5014 }
4928 } 5015 }
4929 5016
4930 if (!same_type_p (arg2_type, arg3_type) 5017 if (!same_type_p (arg2_type, arg3_type)
4931 || TYPE_VECTOR_SUBPARTS (arg1_type) 5018 || maybe_ne (TYPE_VECTOR_SUBPARTS (arg1_type),
4932 != TYPE_VECTOR_SUBPARTS (arg2_type) 5019 TYPE_VECTOR_SUBPARTS (arg2_type))
4933 || TYPE_SIZE (arg1_type) != TYPE_SIZE (arg2_type)) 5020 || TYPE_SIZE (arg1_type) != TYPE_SIZE (arg2_type))
4934 { 5021 {
4935 if (complain & tf_error) 5022 if (complain & tf_error)
4936 error_at (loc, 5023 error_at (loc,
4937 "incompatible vector types in conditional expression: " 5024 "incompatible vector types in conditional expression: "
4966 and third operands. */ 5053 and third operands. */
4967 arg2_type = unlowered_expr_type (arg2); 5054 arg2_type = unlowered_expr_type (arg2);
4968 arg3_type = unlowered_expr_type (arg3); 5055 arg3_type = unlowered_expr_type (arg3);
4969 if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type)) 5056 if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type))
4970 { 5057 {
4971 /* Do the conversions. We don't these for `void' type arguments
4972 since it can't have any effect and since decay_conversion
4973 does not handle that case gracefully. */
4974 if (!VOID_TYPE_P (arg2_type))
4975 arg2 = decay_conversion (arg2, complain);
4976 if (!VOID_TYPE_P (arg3_type))
4977 arg3 = decay_conversion (arg3, complain);
4978 arg2_type = TREE_TYPE (arg2);
4979 arg3_type = TREE_TYPE (arg3);
4980
4981 /* [expr.cond] 5058 /* [expr.cond]
4982 5059
4983 One of the following shall hold: 5060 One of the following shall hold:
4984 5061
4985 --The second or the third operand (but not both) is a 5062 --The second or the third operand (but not both) is a
4986 throw-expression (_except.throw_); the result is of the 5063 throw-expression (_except.throw_); the result is of the type
4987 type of the other and is an rvalue. 5064 and value category of the other.
4988 5065
4989 --Both the second and the third operands have type void; the 5066 --Both the second and the third operands have type void; the
4990 result is of type void and is an rvalue. 5067 result is of type void and is a prvalue. */
4991
4992 We must avoid calling force_rvalue for expressions of type
4993 "void" because it will complain that their value is being
4994 used. */
4995 if (TREE_CODE (arg2) == THROW_EXPR 5068 if (TREE_CODE (arg2) == THROW_EXPR
4996 && TREE_CODE (arg3) != THROW_EXPR) 5069 && TREE_CODE (arg3) != THROW_EXPR)
4997 { 5070 {
4998 if (!VOID_TYPE_P (arg3_type))
4999 {
5000 arg3 = force_rvalue (arg3, complain);
5001 if (arg3 == error_mark_node)
5002 return error_mark_node;
5003 }
5004 arg3_type = TREE_TYPE (arg3);
5005 result_type = arg3_type; 5071 result_type = arg3_type;
5072 is_glvalue = glvalue_p (arg3);
5006 } 5073 }
5007 else if (TREE_CODE (arg2) != THROW_EXPR 5074 else if (TREE_CODE (arg2) != THROW_EXPR
5008 && TREE_CODE (arg3) == THROW_EXPR) 5075 && TREE_CODE (arg3) == THROW_EXPR)
5009 { 5076 {
5010 if (!VOID_TYPE_P (arg2_type))
5011 {
5012 arg2 = force_rvalue (arg2, complain);
5013 if (arg2 == error_mark_node)
5014 return error_mark_node;
5015 }
5016 arg2_type = TREE_TYPE (arg2);
5017 result_type = arg2_type; 5077 result_type = arg2_type;
5078 is_glvalue = glvalue_p (arg2);
5018 } 5079 }
5019 else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type)) 5080 else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
5020 result_type = void_type_node; 5081 {
5082 result_type = void_type_node;
5083 is_glvalue = false;
5084 }
5021 else 5085 else
5022 { 5086 {
5023 if (complain & tf_error) 5087 if (complain & tf_error)
5024 { 5088 {
5025 if (VOID_TYPE_P (arg2_type)) 5089 if (VOID_TYPE_P (arg2_type))
5026 error_at (EXPR_LOC_OR_LOC (arg3, loc), 5090 error_at (cp_expr_loc_or_loc (arg3, loc),
5027 "second operand to the conditional operator " 5091 "second operand to the conditional operator "
5028 "is of type %<void%>, but the third operand is " 5092 "is of type %<void%>, but the third operand is "
5029 "neither a throw-expression nor of type %<void%>"); 5093 "neither a throw-expression nor of type %<void%>");
5030 else 5094 else
5031 error_at (EXPR_LOC_OR_LOC (arg2, loc), 5095 error_at (cp_expr_loc_or_loc (arg2, loc),
5032 "third operand to the conditional operator " 5096 "third operand to the conditional operator "
5033 "is of type %<void%>, but the second operand is " 5097 "is of type %<void%>, but the second operand is "
5034 "neither a throw-expression nor of type %<void%>"); 5098 "neither a throw-expression nor of type %<void%>");
5035 } 5099 }
5036 return error_mark_node; 5100 return error_mark_node;
5037 } 5101 }
5038 5102
5039 is_lvalue = false;
5040 goto valid_operands; 5103 goto valid_operands;
5041 } 5104 }
5042 /* [expr.cond] 5105 /* [expr.cond]
5043 5106
5044 Otherwise, if the second and third operand have different types, 5107 Otherwise, if the second and third operand have different types,
5164 Otherwise, the result is an rvalue. If the second and third 5227 Otherwise, the result is an rvalue. If the second and third
5165 operand do not have the same type, and either has (possibly 5228 operand do not have the same type, and either has (possibly
5166 cv-qualified) class type, overload resolution is used to 5229 cv-qualified) class type, overload resolution is used to
5167 determine the conversions (if any) to be applied to the operands 5230 determine the conversions (if any) to be applied to the operands
5168 (_over.match.oper_, _over.built_). */ 5231 (_over.match.oper_, _over.built_). */
5169 is_lvalue = false; 5232 is_glvalue = false;
5170 if (!same_type_p (arg2_type, arg3_type) 5233 if (!same_type_p (arg2_type, arg3_type)
5171 && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type))) 5234 && (CLASS_TYPE_P (arg2_type) || CLASS_TYPE_P (arg3_type)))
5172 { 5235 {
5173 tree args[3]; 5236 tree args[3];
5174 conversion *conv; 5237 conversion *conv;
5181 args[1] = arg3; 5244 args[1] = arg3;
5182 args[2] = arg1; 5245 args[2] = arg1;
5183 add_builtin_candidates (&candidates, 5246 add_builtin_candidates (&candidates,
5184 COND_EXPR, 5247 COND_EXPR,
5185 NOP_EXPR, 5248 NOP_EXPR,
5186 cp_operator_id (COND_EXPR), 5249 ovl_op_identifier (false, COND_EXPR),
5187 args, 5250 args,
5188 LOOKUP_NORMAL, complain); 5251 LOOKUP_NORMAL, complain);
5189 5252
5190 /* [expr.cond] 5253 /* [expr.cond]
5191 5254
5202 cand = tourney (candidates, complain); 5265 cand = tourney (candidates, complain);
5203 if (!cand) 5266 if (!cand)
5204 { 5267 {
5205 if (complain & tf_error) 5268 if (complain & tf_error)
5206 { 5269 {
5270 auto_diagnostic_group d;
5207 op_error (loc, COND_EXPR, NOP_EXPR, arg1, arg2, arg3, FALSE); 5271 op_error (loc, COND_EXPR, NOP_EXPR, arg1, arg2, arg3, FALSE);
5208 print_z_candidates (loc, candidates); 5272 print_z_candidates (loc, candidates);
5209 } 5273 }
5210 return error_mark_node; 5274 return error_mark_node;
5211 } 5275 }
5345 5409
5346 if (arg2 == error_mark_node || arg3 == error_mark_node) 5410 if (arg2 == error_mark_node || arg3 == error_mark_node)
5347 return error_mark_node; 5411 return error_mark_node;
5348 5412
5349 valid_operands: 5413 valid_operands:
5414 if (processing_template_decl && is_glvalue)
5415 {
5416 /* Let lvalue_kind know this was a glvalue. */
5417 tree arg = (result_type == arg2_type ? arg2 : arg3);
5418 result_type = cp_build_reference_type (result_type, xvalue_p (arg));
5419 }
5420
5350 result = build3_loc (loc, COND_EXPR, result_type, arg1, arg2, arg3); 5421 result = build3_loc (loc, COND_EXPR, result_type, arg1, arg2, arg3);
5351 5422
5352 /* If the ARG2 and ARG3 are the same and don't have side-effects, 5423 /* If the ARG2 and ARG3 are the same and don't have side-effects,
5353 warn here, because the COND_EXPR will be turned into ARG2. */ 5424 warn here, because the COND_EXPR will be turned into ARG2. */
5354 if (warn_duplicated_branches 5425 if (warn_duplicated_branches
5426 && (complain & tf_warning)
5355 && (arg2 == arg3 || operand_equal_p (arg2, arg3, 0))) 5427 && (arg2 == arg3 || operand_equal_p (arg2, arg3, 0)))
5356 warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches, 5428 warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches,
5357 "this condition has identical branches"); 5429 "this condition has identical branches");
5358 5430
5359 /* We can't use result_type below, as fold might have returned a 5431 /* We can't use result_type below, as fold might have returned a
5360 throw_expr. */ 5432 throw_expr. */
5361 5433
5362 if (!is_lvalue) 5434 if (!is_glvalue)
5363 { 5435 {
5364 /* Expand both sides into the same slot, hopefully the target of 5436 /* Expand both sides into the same slot, hopefully the target of
5365 the ?: expression. We used to check for TARGET_EXPRs here, 5437 the ?: expression. We used to check for TARGET_EXPRs here,
5366 but now we sometimes wrap them in NOP_EXPRs so the test would 5438 but now we sometimes wrap them in NOP_EXPRs so the test would
5367 fail. */ 5439 fail. */
5528 fn_first_arg, 5600 fn_first_arg,
5529 fn_args, 5601 fn_args,
5530 access_path, 5602 access_path,
5531 conversion_path, 5603 conversion_path,
5532 flags, 5604 flags,
5605 NULL,
5533 complain); 5606 complain);
5534 } 5607 }
5535 } 5608 }
5536 5609
5537 /* Returns 1 if P0145R2 says that the LHS of operator CODE is evaluated first, 5610 /* Returns 1 if P0145R2 says that the LHS of operator CODE is evaluated first,
5571 build_new_op_1 (location_t loc, enum tree_code code, int flags, tree arg1, 5644 build_new_op_1 (location_t loc, enum tree_code code, int flags, tree arg1,
5572 tree arg2, tree arg3, tree *overload, tsubst_flags_t complain) 5645 tree arg2, tree arg3, tree *overload, tsubst_flags_t complain)
5573 { 5646 {
5574 struct z_candidate *candidates = 0, *cand; 5647 struct z_candidate *candidates = 0, *cand;
5575 vec<tree, va_gc> *arglist; 5648 vec<tree, va_gc> *arglist;
5576 tree fnname;
5577 tree args[3]; 5649 tree args[3];
5578 tree result = NULL_TREE; 5650 tree result = NULL_TREE;
5579 bool result_valid_p = false; 5651 bool result_valid_p = false;
5580 enum tree_code code2 = NOP_EXPR; 5652 enum tree_code code2 = NOP_EXPR;
5581 enum tree_code code_orig_arg1 = ERROR_MARK; 5653 enum tree_code code_orig_arg1 = ERROR_MARK;
5588 if (error_operand_p (arg1) 5660 if (error_operand_p (arg1)
5589 || error_operand_p (arg2) 5661 || error_operand_p (arg2)
5590 || error_operand_p (arg3)) 5662 || error_operand_p (arg3))
5591 return error_mark_node; 5663 return error_mark_node;
5592 5664
5593 if (code == MODIFY_EXPR) 5665 bool ismodop = code == MODIFY_EXPR;
5666 if (ismodop)
5594 { 5667 {
5595 code2 = TREE_CODE (arg3); 5668 code2 = TREE_CODE (arg3);
5596 arg3 = NULL_TREE; 5669 arg3 = NULL_TREE;
5597 fnname = cp_assignment_operator_id (code2); 5670 }
5598 } 5671 tree fnname = ovl_op_identifier (ismodop, ismodop ? code2 : code);
5599 else
5600 fnname = cp_operator_id (code);
5601 5672
5602 arg1 = prep_operand (arg1); 5673 arg1 = prep_operand (arg1);
5603 5674
5604 bool memonly = false; 5675 bool memonly = false;
5605 switch (code) 5676 switch (code)
5727 5798
5728 for (i = 0; i < nargs; ++i) 5799 for (i = 0; i < nargs; ++i)
5729 { 5800 {
5730 parmtype = TREE_VALUE (parmlist); 5801 parmtype = TREE_VALUE (parmlist);
5731 5802
5732 if (TREE_CODE (parmtype) == REFERENCE_TYPE) 5803 if (TYPE_REF_P (parmtype))
5733 parmtype = TREE_TYPE (parmtype); 5804 parmtype = TREE_TYPE (parmtype);
5734 if (TREE_CODE (TREE_TYPE (args[i])) == ENUMERAL_TYPE 5805 if (TREE_CODE (TREE_TYPE (args[i])) == ENUMERAL_TYPE
5735 && (same_type_ignoring_top_level_qualifiers_p 5806 && (same_type_ignoring_top_level_qualifiers_p
5736 (TREE_TYPE (args[i]), parmtype))) 5807 (TREE_TYPE (args[i]), parmtype)))
5737 break; 5808 break;
5790 { 5861 {
5791 const char *msg = (flag_permissive) 5862 const char *msg = (flag_permissive)
5792 ? G_("no %<%D(int)%> declared for postfix %qs," 5863 ? G_("no %<%D(int)%> declared for postfix %qs,"
5793 " trying prefix operator instead") 5864 " trying prefix operator instead")
5794 : G_("no %<%D(int)%> declared for postfix %qs"); 5865 : G_("no %<%D(int)%> declared for postfix %qs");
5795 permerror (loc, msg, fnname, operator_name_info[code].name); 5866 permerror (loc, msg, fnname, OVL_OP_INFO (false, code)->name);
5796 } 5867 }
5797 5868
5798 if (!flag_permissive) 5869 if (!flag_permissive)
5799 return error_mark_node; 5870 return error_mark_node;
5800 5871
5826 /* We displayed the error message. */; 5897 /* We displayed the error message. */;
5827 else 5898 else
5828 { 5899 {
5829 /* ... Otherwise, report the more generic 5900 /* ... Otherwise, report the more generic
5830 "no matching operator found" error */ 5901 "no matching operator found" error */
5902 auto_diagnostic_group d;
5831 op_error (loc, code, code2, arg1, arg2, arg3, FALSE); 5903 op_error (loc, code, code2, arg1, arg2, arg3, FALSE);
5832 print_z_candidates (loc, candidates); 5904 print_z_candidates (loc, candidates);
5833 } 5905 }
5834 } 5906 }
5835 result = error_mark_node; 5907 result = error_mark_node;
5841 cand = tourney (candidates, complain); 5913 cand = tourney (candidates, complain);
5842 if (cand == 0) 5914 if (cand == 0)
5843 { 5915 {
5844 if (complain & tf_error) 5916 if (complain & tf_error)
5845 { 5917 {
5918 auto_diagnostic_group d;
5846 op_error (loc, code, code2, arg1, arg2, arg3, TRUE); 5919 op_error (loc, code, code2, arg1, arg2, arg3, TRUE);
5847 print_z_candidates (loc, candidates); 5920 print_z_candidates (loc, candidates);
5848 } 5921 }
5849 result = error_mark_node; 5922 result = error_mark_node;
5850 } 5923 }
6122 return false; 6195 return false;
6123 6196
6124 /* A template instance is never a usual deallocation function, 6197 /* A template instance is never a usual deallocation function,
6125 regardless of its signature. */ 6198 regardless of its signature. */
6126 if (TREE_CODE (t) == TEMPLATE_DECL 6199 if (TREE_CODE (t) == TEMPLATE_DECL
6127 || primary_template_instantiation_p (t)) 6200 || primary_template_specialization_p (t))
6128 return false; 6201 return false;
6129 6202
6130 tree a = FUNCTION_ARG_CHAIN (t); 6203 tree a = FUNCTION_ARG_CHAIN (t);
6131 if (same_type_p (TREE_VALUE (a), align_type_node) 6204 if (same_type_p (TREE_VALUE (a), align_type_node)
6132 && TREE_CHAIN (a) == void_list_node) 6205 && TREE_CHAIN (a) == void_list_node)
6147 usual_deallocation_fn_p (tree t) 6220 usual_deallocation_fn_p (tree t)
6148 { 6221 {
6149 /* A template instance is never a usual deallocation function, 6222 /* A template instance is never a usual deallocation function,
6150 regardless of its signature. */ 6223 regardless of its signature. */
6151 if (TREE_CODE (t) == TEMPLATE_DECL 6224 if (TREE_CODE (t) == TEMPLATE_DECL
6152 || primary_template_instantiation_p (t)) 6225 || primary_template_specialization_p (t))
6153 return false; 6226 return false;
6154 6227
6155 /* If a class T has a member deallocation function named operator delete 6228 /* If a class T has a member deallocation function named operator delete
6156 with exactly one parameter, then that function is a usual 6229 with exactly one parameter, then that function is a usual
6157 (non-placement) deallocation function. If class T does not declare 6230 (non-placement) deallocation function. If class T does not declare
6202 if (addr == error_mark_node) 6275 if (addr == error_mark_node)
6203 return error_mark_node; 6276 return error_mark_node;
6204 6277
6205 type = strip_array_types (TREE_TYPE (TREE_TYPE (addr))); 6278 type = strip_array_types (TREE_TYPE (TREE_TYPE (addr)));
6206 6279
6207 fnname = cp_operator_id (code); 6280 fnname = ovl_op_identifier (false, code);
6208 6281
6209 if (CLASS_TYPE_P (type) 6282 if (CLASS_TYPE_P (type)
6210 && COMPLETE_TYPE_P (complete_type (type)) 6283 && COMPLETE_TYPE_P (complete_type (type))
6211 && !global_p) 6284 && !global_p)
6212 /* In [class.free] 6285 /* In [class.free]
6277 /* Before C++14 a two-parameter global deallocation function is 6350 /* Before C++14 a two-parameter global deallocation function is
6278 always a placement deallocation function, but warn if 6351 always a placement deallocation function, but warn if
6279 -Wc++14-compat. */ 6352 -Wc++14-compat. */
6280 else if (!flag_sized_deallocation) 6353 else if (!flag_sized_deallocation)
6281 { 6354 {
6282 if ((complain & tf_warning) 6355 if (complain & tf_warning)
6283 && warning (OPT_Wc__14_compat, msg1)) 6356 {
6284 inform (DECL_SOURCE_LOCATION (fn), msg2, fn); 6357 auto_diagnostic_group d;
6358 if (warning (OPT_Wc__14_compat, msg1))
6359 inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
6360 }
6285 goto ok; 6361 goto ok;
6286 } 6362 }
6287 6363
6288 if (complain & tf_warning_or_error) 6364 if (complain & tf_warning_or_error)
6289 { 6365 {
6366 auto_diagnostic_group d;
6290 if (permerror (input_location, msg1)) 6367 if (permerror (input_location, msg1))
6291 { 6368 {
6292 /* Only mention C++14 for namespace-scope delete. */ 6369 /* Only mention C++14 for namespace-scope delete. */
6293 if (DECL_NAMESPACE_SCOPE_P (fn)) 6370 if (DECL_NAMESPACE_SCOPE_P (fn))
6294 inform (DECL_SOURCE_LOCATION (fn), msg2, fn); 6371 inform (DECL_SOURCE_LOCATION (fn), msg2, fn);
6431 return NULL_TREE; 6508 return NULL_TREE;
6432 } 6509 }
6433 6510
6434 if (complain & tf_error) 6511 if (complain & tf_error)
6435 error ("no suitable %<operator %s%> for %qT", 6512 error ("no suitable %<operator %s%> for %qT",
6436 operator_name_info[(int)code].name, type); 6513 OVL_OP_INFO (false, code)->name, type);
6437 return error_mark_node; 6514 return error_mark_node;
6515 }
6516
6517 /* Issue diagnostics about a disallowed access of DECL, using DIAG_DECL
6518 in the diagnostics.
6519
6520 If ISSUE_ERROR is true, then issue an error about the
6521 access, followed by a note showing the declaration.
6522 Otherwise, just show the note. */
6523
6524 void
6525 complain_about_access (tree decl, tree diag_decl, bool issue_error)
6526 {
6527 if (TREE_PRIVATE (decl))
6528 {
6529 if (issue_error)
6530 error ("%q#D is private within this context", diag_decl);
6531 inform (DECL_SOURCE_LOCATION (diag_decl),
6532 "declared private here");
6533 }
6534 else if (TREE_PROTECTED (decl))
6535 {
6536 if (issue_error)
6537 error ("%q#D is protected within this context", diag_decl);
6538 inform (DECL_SOURCE_LOCATION (diag_decl),
6539 "declared protected here");
6540 }
6541 else
6542 {
6543 if (issue_error)
6544 error ("%q#D is inaccessible within this context", diag_decl);
6545 inform (DECL_SOURCE_LOCATION (diag_decl), "declared here");
6546 }
6438 } 6547 }
6439 6548
6440 /* If the current scope isn't allowed to access DECL along 6549 /* If the current scope isn't allowed to access DECL along
6441 BASETYPE_PATH, give an error. The most derived class in 6550 BASETYPE_PATH, give an error. The most derived class in
6442 BASETYPE_PATH is the one used to qualify DECL. DIAG_DECL is 6551 BASETYPE_PATH is the one used to qualify DECL. DIAG_DECL is
6459 ba_any, NULL, complain); 6568 ba_any, NULL, complain);
6460 } 6569 }
6461 6570
6462 if (!accessible_p (basetype_path, decl, true)) 6571 if (!accessible_p (basetype_path, decl, true))
6463 { 6572 {
6573 if (flag_new_inheriting_ctors)
6574 diag_decl = strip_inheriting_ctors (diag_decl);
6464 if (complain & tf_error) 6575 if (complain & tf_error)
6465 { 6576 complain_about_access (decl, diag_decl, true);
6466 if (flag_new_inheriting_ctors) 6577 if (afi)
6467 diag_decl = strip_inheriting_ctors (diag_decl); 6578 afi->record_access_failure (basetype_path, decl, diag_decl);
6468 if (TREE_PRIVATE (decl))
6469 {
6470 error ("%q#D is private within this context", diag_decl);
6471 inform (DECL_SOURCE_LOCATION (diag_decl),
6472 "declared private here");
6473 if (afi)
6474 afi->record_access_failure (basetype_path, diag_decl);
6475 }
6476 else if (TREE_PROTECTED (decl))
6477 {
6478 error ("%q#D is protected within this context", diag_decl);
6479 inform (DECL_SOURCE_LOCATION (diag_decl),
6480 "declared protected here");
6481 if (afi)
6482 afi->record_access_failure (basetype_path, diag_decl);
6483 }
6484 else
6485 {
6486 error ("%q#D is inaccessible within this context", diag_decl);
6487 inform (DECL_SOURCE_LOCATION (diag_decl), "declared here");
6488 if (afi)
6489 afi->record_access_failure (basetype_path, diag_decl);
6490 }
6491 }
6492 return false; 6579 return false;
6493 } 6580 }
6494 6581
6495 return true; 6582 return true;
6496 } 6583 }
6530 *diagnostic_kind = DK_ERROR; 6617 *diagnostic_kind = DK_ERROR;
6531 return expr; 6618 return expr;
6532 } 6619 }
6533 6620
6534 /* Perform warnings about peculiar, but valid, conversions from/to NULL. 6621 /* Perform warnings about peculiar, but valid, conversions from/to NULL.
6622 Also handle a subset of zero as null warnings.
6535 EXPR is implicitly converted to type TOTYPE. 6623 EXPR is implicitly converted to type TOTYPE.
6536 FN and ARGNUM are used for diagnostics. */ 6624 FN and ARGNUM are used for diagnostics. */
6537 6625
6538 static void 6626 static void
6539 conversion_null_warnings (tree totype, tree expr, tree fn, int argnum) 6627 conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
6540 { 6628 {
6541 /* Issue warnings about peculiar, but valid, uses of NULL. */ 6629 /* Issue warnings about peculiar, but valid, uses of NULL. */
6542 if (expr == null_node && TREE_CODE (totype) != BOOLEAN_TYPE 6630 if (null_node_p (expr) && TREE_CODE (totype) != BOOLEAN_TYPE
6543 && ARITHMETIC_TYPE_P (totype)) 6631 && ARITHMETIC_TYPE_P (totype))
6544 { 6632 {
6545 source_location loc = 6633 source_location loc =
6546 expansion_point_location_if_in_system_header (input_location); 6634 expansion_point_location_if_in_system_header (input_location);
6547 6635
6564 "of %qD", argnum, fn); 6652 "of %qD", argnum, fn);
6565 else 6653 else
6566 warning_at (input_location, OPT_Wconversion_null, 6654 warning_at (input_location, OPT_Wconversion_null,
6567 "converting %<false%> to pointer type %qT", totype); 6655 "converting %<false%> to pointer type %qT", totype);
6568 } 6656 }
6657 /* Handle zero as null pointer warnings for cases other
6658 than EQ_EXPR and NE_EXPR */
6659 else if (null_ptr_cst_p (expr) &&
6660 (TYPE_PTR_OR_PTRMEM_P (totype) || NULLPTR_TYPE_P (totype)))
6661 {
6662 source_location loc =
6663 expansion_point_location_if_in_system_header (input_location);
6664 maybe_warn_zero_as_null_pointer_constant (expr, loc);
6665 }
6569 } 6666 }
6570 6667
6571 /* We gave a diagnostic during a conversion. If this was in the second 6668 /* We gave a diagnostic during a conversion. If this was in the second
6572 standard conversion sequence of a user-defined conversion sequence, say 6669 standard conversion sequence of a user-defined conversion sequence, say
6573 which user-defined conversion. */ 6670 which user-defined conversion. */
6587 6684
6588 /* Locate the parameter with the given index within FNDECL. 6685 /* Locate the parameter with the given index within FNDECL.
6589 ARGNUM is zero based, -1 indicates the `this' argument of a method. 6686 ARGNUM is zero based, -1 indicates the `this' argument of a method.
6590 Return the location of the FNDECL itself if there are problems. */ 6687 Return the location of the FNDECL itself if there are problems. */
6591 6688
6592 static location_t 6689 location_t
6593 get_fndecl_argument_location (tree fndecl, int argnum) 6690 get_fndecl_argument_location (tree fndecl, int argnum)
6594 { 6691 {
6595 int i; 6692 int i;
6596 tree param; 6693 tree param;
6597 6694
6625 bool c_cast_p, tsubst_flags_t complain) 6722 bool c_cast_p, tsubst_flags_t complain)
6626 { 6723 {
6627 tree totype = convs->type; 6724 tree totype = convs->type;
6628 diagnostic_t diag_kind; 6725 diagnostic_t diag_kind;
6629 int flags; 6726 int flags;
6630 location_t loc = EXPR_LOC_OR_LOC (expr, input_location); 6727 location_t loc = cp_expr_loc_or_loc (expr, input_location);
6631 6728
6632 if (convs->bad_p && !(complain & tf_error)) 6729 if (convs->bad_p && !(complain & tf_error))
6633 return error_mark_node; 6730 return error_mark_node;
6634 6731
6635 if (convs->bad_p 6732 if (convs->bad_p
6668 6765
6669 for (; t ; t = next_conversion (t)) 6766 for (; t ; t = next_conversion (t))
6670 { 6767 {
6671 if (t->kind == ck_user && t->cand->reason) 6768 if (t->kind == ck_user && t->cand->reason)
6672 { 6769 {
6770 auto_diagnostic_group d;
6673 complained = permerror (loc, "invalid user-defined conversion " 6771 complained = permerror (loc, "invalid user-defined conversion "
6674 "from %qH to %qI", TREE_TYPE (expr), 6772 "from %qH to %qI", TREE_TYPE (expr),
6675 totype); 6773 totype);
6676 if (complained) 6774 if (complained)
6677 print_z_candidate (loc, "candidate is:", t->cand); 6775 print_z_candidate (loc, "candidate is:", t->cand);
6705 complain); 6803 complain);
6706 else if (t->kind == ck_identity) 6804 else if (t->kind == ck_identity)
6707 break; 6805 break;
6708 } 6806 }
6709 if (!complained) 6807 if (!complained)
6710 complained = permerror (loc, "invalid conversion from %qH to %qI", 6808 {
6711 TREE_TYPE (expr), totype); 6809 range_label_for_type_mismatch label (TREE_TYPE (expr), totype);
6810 gcc_rich_location richloc (loc, &label);
6811 complained = permerror (&richloc,
6812 "invalid conversion from %qH to %qI",
6813 TREE_TYPE (expr), totype);
6814 }
6712 if (complained && fn) 6815 if (complained && fn)
6713 inform (get_fndecl_argument_location (fn, argnum), 6816 inform (get_fndecl_argument_location (fn, argnum),
6714 " initializing argument %P of %qD", argnum, fn); 6817 " initializing argument %P of %qD", argnum, fn);
6715 6818
6716 return cp_convert (totype, expr, complain); 6819 return cp_convert (totype, expr, complain);
6746 return error_mark_node; 6849 return error_mark_node;
6747 location_t loc = location_of (expr); 6850 location_t loc = location_of (expr);
6748 if (CONSTRUCTOR_NELTS (expr) == 0 6851 if (CONSTRUCTOR_NELTS (expr) == 0
6749 && FUNCTION_FIRST_USER_PARMTYPE (convfn) != void_list_node) 6852 && FUNCTION_FIRST_USER_PARMTYPE (convfn) != void_list_node)
6750 { 6853 {
6854 auto_diagnostic_group d;
6751 if (pedwarn (loc, 0, "converting to %qT from initializer list " 6855 if (pedwarn (loc, 0, "converting to %qT from initializer list "
6752 "would use explicit constructor %qD", 6856 "would use explicit constructor %qD",
6753 totype, convfn)) 6857 totype, convfn))
6754 inform (loc, "in C++11 and above a default constructor " 6858 inform (loc, "in C++11 and above a default constructor "
6755 "can be explicit"); 6859 "can be explicit");
6763 if (BRACE_ENCLOSED_INITIALIZER_P (expr) 6867 if (BRACE_ENCLOSED_INITIALIZER_P (expr)
6764 && CONSTRUCTOR_NELTS (expr) == 0 6868 && CONSTRUCTOR_NELTS (expr) == 0
6765 && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)) 6869 && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
6766 { 6870 {
6767 bool direct = CONSTRUCTOR_IS_DIRECT_INIT (expr); 6871 bool direct = CONSTRUCTOR_IS_DIRECT_INIT (expr);
6872 if (abstract_virtuals_error_sfinae (NULL_TREE, totype, complain))
6873 return error_mark_node;
6768 expr = build_value_init (totype, complain); 6874 expr = build_value_init (totype, complain);
6769 expr = get_target_expr_sfinae (expr, complain); 6875 expr = get_target_expr_sfinae (expr, complain);
6770 if (expr != error_mark_node) 6876 if (expr != error_mark_node)
6771 { 6877 {
6772 TARGET_EXPR_LIST_INIT_P (expr) = true; 6878 TARGET_EXPR_LIST_INIT_P (expr) = true;
6804 else if (nelts == 1) 6910 else if (nelts == 1)
6805 expr = CONSTRUCTOR_ELT (expr, 0)->value; 6911 expr = CONSTRUCTOR_ELT (expr, 0)->value;
6806 else 6912 else
6807 gcc_unreachable (); 6913 gcc_unreachable ();
6808 } 6914 }
6809 expr = mark_rvalue_use (expr); 6915 expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p,
6916 /*read_p=*/true, UNKNOWN_LOCATION,
6917 /*reject_builtin=*/true);
6810 6918
6811 if (type_unknown_p (expr)) 6919 if (type_unknown_p (expr))
6812 expr = instantiate_type (totype, expr, complain); 6920 expr = instantiate_type (totype, expr, complain);
6921 if (expr == null_node
6922 && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (totype))
6923 /* If __null has been converted to an integer type, we do not want to
6924 continue to warn about uses of EXPR as an integer, rather than as a
6925 pointer. */
6926 expr = build_int_cst (totype, 0);
6813 return expr; 6927 return expr;
6814 case ck_ambig: 6928 case ck_ambig:
6815 /* We leave bad_p off ck_ambig because overload resolution considers 6929 /* We leave bad_p off ck_ambig because overload resolution considers
6816 it valid, it just fails when we try to perform it. So we need to 6930 it valid, it just fails when we try to perform it. So we need to
6817 check complain here, too. */ 6931 check complain here, too. */
6818 if (complain & tf_error) 6932 if (complain & tf_error)
6819 { 6933 {
6820 /* Call build_user_type_conversion again for the error. */ 6934 /* Call build_user_type_conversion again for the error. */
6821 build_user_type_conversion (totype, convs->u.expr, LOOKUP_IMPLICIT, 6935 int flags = (convs->need_temporary_p
6822 complain); 6936 ? LOOKUP_IMPLICIT : LOOKUP_NORMAL);
6937 build_user_type_conversion (totype, convs->u.expr, flags, complain);
6938 gcc_assert (seen_error ());
6823 if (fn) 6939 if (fn)
6824 inform (DECL_SOURCE_LOCATION (fn), 6940 inform (DECL_SOURCE_LOCATION (fn),
6825 " initializing argument %P of %qD", argnum, fn); 6941 " initializing argument %P of %qD", argnum, fn);
6826 } 6942 }
6827 return error_mark_node; 6943 return error_mark_node;
6860 array = cp_build_addr_expr (array, complain); 6976 array = cp_build_addr_expr (array, complain);
6861 array = cp_convert (build_pointer_type (elttype), array, complain); 6977 array = cp_convert (build_pointer_type (elttype), array, complain);
6862 if (array == error_mark_node) 6978 if (array == error_mark_node)
6863 return error_mark_node; 6979 return error_mark_node;
6864 6980
6865 /* Build up the initializer_list object. */ 6981 /* Build up the initializer_list object. Note: fail gracefully
6866 totype = complete_type (totype); 6982 if the object cannot be completed because, for example, no
6983 definition is provided (c++/80956). */
6984 totype = complete_type_or_maybe_complain (totype, NULL_TREE, complain);
6985 if (!totype)
6986 return error_mark_node;
6867 field = next_initializable_field (TYPE_FIELDS (totype)); 6987 field = next_initializable_field (TYPE_FIELDS (totype));
6868 CONSTRUCTOR_APPEND_ELT (vec, field, array); 6988 CONSTRUCTOR_APPEND_ELT (vec, field, array);
6869 field = next_initializable_field (DECL_CHAIN (field)); 6989 field = next_initializable_field (DECL_CHAIN (field));
6870 CONSTRUCTOR_APPEND_ELT (vec, field, size_int (len)); 6990 CONSTRUCTOR_APPEND_ELT (vec, field, size_int (len));
6871 new_ctor = build_constructor (totype, vec); 6991 new_ctor = build_constructor (totype, vec);
6894 default: 7014 default:
6895 break; 7015 break;
6896 }; 7016 };
6897 7017
6898 expr = convert_like_real (next_conversion (convs), expr, fn, argnum, 7018 expr = convert_like_real (next_conversion (convs), expr, fn, argnum,
6899 convs->kind == ck_ref_bind ? issue_conversion_warnings : false, 7019 convs->kind == ck_ref_bind
6900 c_cast_p, 7020 ? issue_conversion_warnings : false,
6901 complain); 7021 c_cast_p, complain);
6902 if (expr == error_mark_node) 7022 if (expr == error_mark_node)
6903 return error_mark_node; 7023 return error_mark_node;
6904 7024
6905 switch (convs->kind) 7025 switch (convs->kind)
6906 { 7026 {
6908 expr = decay_conversion (expr, complain); 7028 expr = decay_conversion (expr, complain);
6909 if (expr == error_mark_node) 7029 if (expr == error_mark_node)
6910 { 7030 {
6911 if (complain & tf_error) 7031 if (complain & tf_error)
6912 { 7032 {
7033 auto_diagnostic_group d;
6913 maybe_print_user_conv_context (convs); 7034 maybe_print_user_conv_context (convs);
6914 if (fn) 7035 if (fn)
6915 inform (DECL_SOURCE_LOCATION (fn), 7036 inform (DECL_SOURCE_LOCATION (fn),
6916 " initializing argument %P of %qD", argnum, fn); 7037 " initializing argument %P of %qD", argnum, fn);
6917 } 7038 }
6924 /* Don't introduce copies when passing arguments along to the inherited 7045 /* Don't introduce copies when passing arguments along to the inherited
6925 constructor. */ 7046 constructor. */
6926 if (current_function_decl 7047 if (current_function_decl
6927 && flag_new_inheriting_ctors 7048 && flag_new_inheriting_ctors
6928 && DECL_INHERITED_CTOR (current_function_decl)) 7049 && DECL_INHERITED_CTOR (current_function_decl))
7050 return expr;
7051
7052 if (TREE_CODE (expr) == TARGET_EXPR
7053 && TARGET_EXPR_LIST_INIT_P (expr))
7054 /* Copy-list-initialization doesn't actually involve a copy. */
6929 return expr; 7055 return expr;
6930 7056
6931 /* Fall through. */ 7057 /* Fall through. */
6932 case ck_base: 7058 case ck_base:
6933 if (convs->kind == ck_base && !convs->need_temporary_p) 7059 if (convs->kind == ck_base && !convs->need_temporary_p)
6952 else 7078 else
6953 flags |= LOOKUP_ONLYCONVERTING; 7079 flags |= LOOKUP_ONLYCONVERTING;
6954 if (convs->rvaluedness_matches_p) 7080 if (convs->rvaluedness_matches_p)
6955 /* standard_conversion got LOOKUP_PREFER_RVALUE. */ 7081 /* standard_conversion got LOOKUP_PREFER_RVALUE. */
6956 flags |= LOOKUP_PREFER_RVALUE; 7082 flags |= LOOKUP_PREFER_RVALUE;
6957 if (TREE_CODE (expr) == TARGET_EXPR
6958 && TARGET_EXPR_LIST_INIT_P (expr))
6959 /* Copy-list-initialization doesn't actually involve a copy. */
6960 return expr;
6961 expr = build_temp (expr, totype, flags, &diag_kind, complain); 7083 expr = build_temp (expr, totype, flags, &diag_kind, complain);
6962 if (diag_kind && complain) 7084 if (diag_kind && complain)
6963 { 7085 {
7086 auto_diagnostic_group d;
6964 maybe_print_user_conv_context (convs); 7087 maybe_print_user_conv_context (convs);
6965 if (fn) 7088 if (fn)
6966 inform (DECL_SOURCE_LOCATION (fn), 7089 inform (DECL_SOURCE_LOCATION (fn),
6967 " initializing argument %P of %qD", argnum, fn); 7090 " initializing argument %P of %qD", argnum, fn);
6968 } 7091 }
6974 tree ref_type = totype; 7097 tree ref_type = totype;
6975 7098
6976 if (convs->bad_p && !next_conversion (convs)->bad_p) 7099 if (convs->bad_p && !next_conversion (convs)->bad_p)
6977 { 7100 {
6978 tree extype = TREE_TYPE (expr); 7101 tree extype = TREE_TYPE (expr);
7102 auto_diagnostic_group d;
6979 if (TYPE_REF_IS_RVALUE (ref_type) 7103 if (TYPE_REF_IS_RVALUE (ref_type)
6980 && lvalue_p (expr)) 7104 && lvalue_p (expr))
6981 error_at (loc, "cannot bind rvalue reference of type %qH to " 7105 error_at (loc, "cannot bind rvalue reference of type %qH to "
6982 "lvalue of type %qI", totype, extype); 7106 "lvalue of type %qI", totype, extype);
6983 else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr) 7107 else if (!TYPE_REF_IS_RVALUE (ref_type) && !lvalue_p (expr)
7094 default: 7218 default:
7095 break; 7219 break;
7096 } 7220 }
7097 7221
7098 if (convs->check_narrowing 7222 if (convs->check_narrowing
7099 && !check_narrowing (totype, expr, complain)) 7223 && !check_narrowing (totype, expr, complain,
7224 convs->check_narrowing_const_only))
7100 return error_mark_node; 7225 return error_mark_node;
7101 7226
7227 warning_sentinel w (warn_zero_as_null_pointer_constant);
7102 if (issue_conversion_warnings) 7228 if (issue_conversion_warnings)
7103 expr = cp_convert_and_check (totype, expr, complain); 7229 expr = cp_convert_and_check (totype, expr, complain);
7104 else 7230 else
7105 expr = cp_convert (totype, expr, complain); 7231 expr = cp_convert (totype, expr, complain);
7106 7232
7112 7238
7113 tree 7239 tree
7114 convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain) 7240 convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
7115 { 7241 {
7116 tree arg_type; 7242 tree arg_type;
7117 location_t loc = EXPR_LOC_OR_LOC (arg, input_location); 7243 location_t loc = cp_expr_loc_or_loc (arg, input_location);
7118 7244
7119 /* [expr.call] 7245 /* [expr.call]
7120 7246
7121 The lvalue-to-rvalue, array-to-pointer, and function-to-pointer 7247 The lvalue-to-rvalue, array-to-pointer, and function-to-pointer
7122 standard conversions are performed. */ 7248 standard conversions are performed. */
7192 if (complain & tf_warning) 7318 if (complain & tf_warning)
7193 warning (OPT_Wconditionally_supported, 7319 warning (OPT_Wconditionally_supported,
7194 "passing objects of non-trivially-copyable " 7320 "passing objects of non-trivially-copyable "
7195 "type %q#T through %<...%> is conditionally supported", 7321 "type %q#T through %<...%> is conditionally supported",
7196 arg_type); 7322 arg_type);
7197 return cp_build_addr_expr (arg, complain); 7323 return build1 (ADDR_EXPR, build_reference_type (arg_type), arg);
7198 } 7324 }
7199 /* Build up a real lvalue-to-rvalue conversion in case the 7325 /* Build up a real lvalue-to-rvalue conversion in case the
7200 copy constructor is trivial but not callable. */ 7326 copy constructor is trivial but not callable. */
7201 else if (CLASS_TYPE_P (arg_type)) 7327 else if (CLASS_TYPE_P (arg_type))
7202 force_rvalue (arg, complain); 7328 force_rvalue (arg, complain);
7223 if (expr == error_mark_node || !type) 7349 if (expr == error_mark_node || !type)
7224 return error_mark_node; 7350 return error_mark_node;
7225 7351
7226 expr = mark_lvalue_use (expr); 7352 expr = mark_lvalue_use (expr);
7227 7353
7228 if (TREE_CODE (type) == REFERENCE_TYPE) 7354 if (TYPE_REF_P (type))
7229 { 7355 {
7230 error ("cannot receive reference type %qT through %<...%>", type); 7356 error ("cannot receive reference type %qT through %<...%>", type);
7231 return error_mark_node; 7357 return error_mark_node;
7232 } 7358 }
7233 7359
7334 7460
7335 we must not perform access checks here. */ 7461 we must not perform access checks here. */
7336 push_deferring_access_checks (dk_no_check); 7462 push_deferring_access_checks (dk_no_check);
7337 /* We must make a copy of ARG, in case subsequent processing 7463 /* We must make a copy of ARG, in case subsequent processing
7338 alters any part of it. */ 7464 alters any part of it. */
7339 arg = break_out_target_exprs (arg); 7465 arg = break_out_target_exprs (arg, /*clear location*/true);
7466
7340 arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT, 7467 arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT,
7341 ICR_DEFAULT_ARGUMENT, fn, parmnum, 7468 ICR_DEFAULT_ARGUMENT, fn, parmnum,
7342 complain); 7469 complain);
7343 arg = convert_for_arg_passing (type, arg, complain); 7470 arg = convert_for_arg_passing (type, arg, complain);
7344 pop_deferring_access_checks(); 7471 pop_deferring_access_checks();
7359 { 7486 {
7360 type = build_reference_type (type); 7487 type = build_reference_type (type);
7361 /* There are no other pointers to this temporary. */ 7488 /* There are no other pointers to this temporary. */
7362 type = cp_build_qualified_type (type, TYPE_QUAL_RESTRICT); 7489 type = cp_build_qualified_type (type, TYPE_QUAL_RESTRICT);
7363 } 7490 }
7364 else if (targetm.calls.promote_prototypes (type) 7491 else if (targetm.calls.promote_prototypes (NULL_TREE)
7365 && INTEGRAL_TYPE_P (type) 7492 && INTEGRAL_TYPE_P (type)
7366 && COMPLETE_TYPE_P (type) 7493 && COMPLETE_TYPE_P (type)
7367 && tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (integer_type_node))) 7494 && tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (integer_type_node)))
7368 type = integer_type_node; 7495 type = integer_type_node;
7369 7496
7399 if (val == error_mark_node) 7526 if (val == error_mark_node)
7400 ; 7527 ;
7401 /* Pass classes with copy ctors by invisible reference. */ 7528 /* Pass classes with copy ctors by invisible reference. */
7402 else if (TREE_ADDRESSABLE (type)) 7529 else if (TREE_ADDRESSABLE (type))
7403 val = build1 (ADDR_EXPR, build_reference_type (type), val); 7530 val = build1 (ADDR_EXPR, build_reference_type (type), val);
7404 else if (targetm.calls.promote_prototypes (type) 7531 else if (targetm.calls.promote_prototypes (NULL_TREE)
7405 && INTEGRAL_TYPE_P (type) 7532 && INTEGRAL_TYPE_P (type)
7406 && COMPLETE_TYPE_P (type) 7533 && COMPLETE_TYPE_P (type)
7407 && tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (integer_type_node))) 7534 && tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (integer_type_node)))
7408 val = cp_perform_integral_promotions (val, complain); 7535 val = cp_perform_integral_promotions (val, complain);
7409 if (complain & tf_warning) 7536 if (complain & tf_warning)
7418 && check_missing_format_attribute (type, rhstype)) 7545 && check_missing_format_attribute (type, rhstype))
7419 warning (OPT_Wsuggest_attribute_format, 7546 warning (OPT_Wsuggest_attribute_format,
7420 "argument of function call might be a candidate " 7547 "argument of function call might be a candidate "
7421 "for a format attribute"); 7548 "for a format attribute");
7422 } 7549 }
7423 maybe_warn_parm_abi (type, EXPR_LOC_OR_LOC (val, input_location)); 7550 maybe_warn_parm_abi (type, cp_expr_loc_or_loc (val, input_location));
7424 } 7551 }
7425 return val; 7552 return val;
7426 } 7553 }
7427 7554
7428 /* Returns non-zero iff FN is a function with magic varargs, i.e. ones for 7555 /* Returns non-zero iff FN is a function with magic varargs, i.e. ones for
7433 for __builtin_*_overflow_p. */ 7560 for __builtin_*_overflow_p. */
7434 7561
7435 int 7562 int
7436 magic_varargs_p (tree fn) 7563 magic_varargs_p (tree fn)
7437 { 7564 {
7438 if (flag_cilkplus && is_cilkplus_reduce_builtin (fn) != BUILT_IN_NONE)
7439 return 2;
7440
7441 if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL) 7565 if (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
7442 switch (DECL_FUNCTION_CODE (fn)) 7566 switch (DECL_FUNCTION_CODE (fn))
7443 { 7567 {
7444 case BUILT_IN_CLASSIFY_TYPE: 7568 case BUILT_IN_CLASSIFY_TYPE:
7445 case BUILT_IN_CONSTANT_P: 7569 case BUILT_IN_CONSTANT_P:
7570 return false; 7694 return false;
7571 tree init = TARGET_EXPR_INITIAL (exp); 7695 tree init = TARGET_EXPR_INITIAL (exp);
7572 /* build_compound_expr pushes COMPOUND_EXPR inside TARGET_EXPR. */ 7696 /* build_compound_expr pushes COMPOUND_EXPR inside TARGET_EXPR. */
7573 while (TREE_CODE (init) == COMPOUND_EXPR) 7697 while (TREE_CODE (init) == COMPOUND_EXPR)
7574 init = TREE_OPERAND (init, 1); 7698 init = TREE_OPERAND (init, 1);
7699 if (TREE_CODE (init) == COND_EXPR)
7700 {
7701 /* We'll end up copying from each of the arms of the COND_EXPR directly
7702 into the target, so look at them. */
7703 if (tree op = TREE_OPERAND (init, 1))
7704 if (unsafe_copy_elision_p (target, op))
7705 return true;
7706 return unsafe_copy_elision_p (target, TREE_OPERAND (init, 2));
7707 }
7575 return (TREE_CODE (init) == AGGR_INIT_EXPR 7708 return (TREE_CODE (init) == AGGR_INIT_EXPR
7576 && !AGGR_INIT_VIA_CTOR_P (init)); 7709 && !AGGR_INIT_VIA_CTOR_P (init));
7710 }
7711
7712 /* True iff C is a conversion that binds a reference to a prvalue. */
7713
7714 static bool
7715 conv_binds_ref_to_prvalue (conversion *c)
7716 {
7717 if (c->kind != ck_ref_bind)
7718 return false;
7719 if (c->need_temporary_p)
7720 return true;
7721
7722 c = next_conversion (c);
7723
7724 if (c->kind == ck_rvalue)
7725 return true;
7726 if (c->kind == ck_user && !TYPE_REF_P (c->type))
7727 return true;
7728 if (c->kind == ck_identity && c->u.expr
7729 && TREE_CODE (c->u.expr) == TARGET_EXPR)
7730 return true;
7731
7732 return false;
7733 }
7734
7735 /* Call the trivial destructor for INSTANCE, which can be either an lvalue of
7736 class type or a pointer to class type. */
7737
7738 tree
7739 build_trivial_dtor_call (tree instance)
7740 {
7741 gcc_assert (!is_dummy_object (instance));
7742
7743 if (!flag_lifetime_dse)
7744 {
7745 no_clobber:
7746 return fold_convert (void_type_node, instance);
7747 }
7748
7749 if (INDIRECT_TYPE_P (TREE_TYPE (instance)))
7750 {
7751 if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
7752 goto no_clobber;
7753 instance = cp_build_fold_indirect_ref (instance);
7754 }
7755
7756 /* A trivial destructor should still clobber the object. */
7757 tree clobber = build_clobber (TREE_TYPE (instance));
7758 return build2 (MODIFY_EXPR, void_type_node,
7759 instance, clobber);
7577 } 7760 }
7578 7761
7579 /* Subroutine of the various build_*_call functions. Overload resolution 7762 /* Subroutine of the various build_*_call functions. Overload resolution
7580 has chosen a winning candidate CAND; build up a CALL_EXPR accordingly. 7763 has chosen a winning candidate CAND; build up a CALL_EXPR accordingly.
7581 ARGS is a TREE_LIST of the unconverted arguments to the call. FLAGS is a 7764 ARGS is a TREE_LIST of the unconverted arguments to the call. FLAGS is a
7611 const tree *argarray; 7794 const tree *argarray;
7612 unsigned int nargs; 7795 unsigned int nargs;
7613 7796
7614 if (undeduced_auto_decl (fn)) 7797 if (undeduced_auto_decl (fn))
7615 mark_used (fn, complain); 7798 mark_used (fn, complain);
7799 else
7800 /* Otherwise set TREE_USED for the benefit of -Wunused-function.
7801 See PR80598. */
7802 TREE_USED (fn) = 1;
7616 7803
7617 return_type = TREE_TYPE (TREE_TYPE (fn)); 7804 return_type = TREE_TYPE (TREE_TYPE (fn));
7618 nargs = vec_safe_length (args); 7805 nargs = vec_safe_length (args);
7619 if (first_arg == NULL_TREE) 7806 if (first_arg == NULL_TREE)
7620 argarray = args->address (); 7807 argarray = args->address ();
7648 struct candidate_warning *w; 7835 struct candidate_warning *w;
7649 for (w = cand->warnings; w; w = w->next) 7836 for (w = cand->warnings; w; w = w->next)
7650 joust (cand, w->loser, 1, complain); 7837 joust (cand, w->loser, 1, complain);
7651 } 7838 }
7652 7839
7840 /* Core issue 2327: P0135 doesn't say how to handle the case where the
7841 argument to the copy constructor ends up being a prvalue after
7842 conversion. Let's do the normal processing, but pretend we aren't
7843 actually using the copy constructor. */
7844 bool force_elide = false;
7845 if (cxx_dialect >= cxx17
7846 && cand->num_convs == 1
7847 && DECL_COMPLETE_CONSTRUCTOR_P (fn)
7848 && (DECL_COPY_CONSTRUCTOR_P (fn)
7849 || DECL_MOVE_CONSTRUCTOR_P (fn))
7850 && conv_binds_ref_to_prvalue (convs[0]))
7851 {
7852 force_elide = true;
7853 goto not_really_used;
7854 }
7855
7653 /* OK, we're actually calling this inherited constructor; set its deletedness 7856 /* OK, we're actually calling this inherited constructor; set its deletedness
7654 appropriately. We can get away with doing this here because calling is 7857 appropriately. We can get away with doing this here because calling is
7655 the only way to refer to a constructor. */ 7858 the only way to refer to a constructor. */
7656 if (DECL_INHERITED_CTOR (fn)) 7859 if (DECL_INHERITED_CTOR (fn))
7657 deduce_inheriting_ctor (fn); 7860 deduce_inheriting_ctor (fn);
7658 7861
7659 /* Make =delete work with SFINAE. */ 7862 /* Make =delete work with SFINAE. */
7660 if (DECL_DELETED_FN (fn) && !(complain & tf_error)) 7863 if (DECL_DELETED_FN (fn))
7661 return error_mark_node; 7864 {
7865 if (complain & tf_error)
7866 mark_used (fn);
7867 return error_mark_node;
7868 }
7662 7869
7663 if (DECL_FUNCTION_MEMBER_P (fn)) 7870 if (DECL_FUNCTION_MEMBER_P (fn))
7664 { 7871 {
7665 tree access_fn; 7872 tree access_fn;
7666 /* If FN is a template function, two cases must be considered. 7873 /* If FN is a template function, two cases must be considered.
7700 7907
7701 /* If we're checking for implicit delete, don't bother with argument 7908 /* If we're checking for implicit delete, don't bother with argument
7702 conversions. */ 7909 conversions. */
7703 if (flags & LOOKUP_SPECULATIVE) 7910 if (flags & LOOKUP_SPECULATIVE)
7704 { 7911 {
7705 if (DECL_DELETED_FN (fn))
7706 {
7707 if (complain & tf_error)
7708 mark_used (fn);
7709 return error_mark_node;
7710 }
7711 if (cand->viable == 1) 7912 if (cand->viable == 1)
7712 return fn; 7913 return fn;
7713 else if (!(complain & tf_error)) 7914 else if (!(complain & tf_error))
7714 /* Reject bad conversions now. */ 7915 /* Reject bad conversions now. */
7715 return error_mark_node; 7916 return error_mark_node;
7716 /* else continue to get conversion error. */ 7917 /* else continue to get conversion error. */
7717 } 7918 }
7718 7919
7920 not_really_used:
7921
7719 /* N3276 magic doesn't apply to nested calls. */ 7922 /* N3276 magic doesn't apply to nested calls. */
7720 tsubst_flags_t decltype_flag = (complain & tf_decltype); 7923 tsubst_flags_t decltype_flag = (complain & tf_decltype);
7721 complain &= ~tf_decltype; 7924 complain &= ~tf_decltype;
7722 /* No-Cleanup doesn't apply to nested calls either. */ 7925 /* No-Cleanup doesn't apply to nested calls either. */
7723 tsubst_flags_t no_cleanup_complain = complain; 7926 tsubst_flags_t no_cleanup_complain = complain;
7759 7962
7760 if (flags & LOOKUP_PREFER_RVALUE) 7963 if (flags & LOOKUP_PREFER_RVALUE)
7761 { 7964 {
7762 /* The implicit move specified in 15.8.3/3 fails "...if the type of 7965 /* The implicit move specified in 15.8.3/3 fails "...if the type of
7763 the first parameter of the selected constructor is not an rvalue 7966 the first parameter of the selected constructor is not an rvalue
7764 reference to the object’s type (possibly cv-qualified)...." */ 7967 reference to the object's type (possibly cv-qualified)...." */
7765 gcc_assert (!(complain & tf_error)); 7968 gcc_assert (!(complain & tf_error));
7766 tree ptype = convs[0]->type; 7969 tree ptype = convs[0]->type;
7767 if (TREE_CODE (ptype) != REFERENCE_TYPE 7970 if (!TYPE_REF_P (ptype)
7768 || !TYPE_REF_IS_RVALUE (ptype) 7971 || !TYPE_REF_IS_RVALUE (ptype)
7769 || CONVERSION_RANK (convs[0]) > cr_exact) 7972 || CONVERSION_RANK (convs[0]) > cr_exact)
7770 return error_mark_node; 7973 return error_mark_node;
7771 } 7974 }
7772 } 7975 }
7786 7989
7787 if (convs[i]->bad_p) 7990 if (convs[i]->bad_p)
7788 { 7991 {
7789 if (complain & tf_error) 7992 if (complain & tf_error)
7790 { 7993 {
7994 auto_diagnostic_group d;
7791 if (permerror (input_location, "passing %qT as %<this%> " 7995 if (permerror (input_location, "passing %qT as %<this%> "
7792 "argument discards qualifiers", 7996 "argument discards qualifiers",
7793 TREE_TYPE (argtype))) 7997 TREE_TYPE (argtype)))
7794 inform (DECL_SOURCE_LOCATION (fn), " in call to %qD", fn); 7998 inform (DECL_SOURCE_LOCATION (fn), " in call to %qD", fn);
7795 } 7999 }
7874 8078
7875 void foo() { 8079 void foo() {
7876 func(NULL); 8080 func(NULL);
7877 } 8081 }
7878 */ 8082 */
7879 if (arg == null_node 8083 if (null_node_p (arg)
7880 && DECL_TEMPLATE_INFO (fn) 8084 && DECL_TEMPLATE_INFO (fn)
7881 && cand->template_decl 8085 && cand->template_decl
7882 && !(flags & LOOKUP_EXPLICIT_TMPL_ARGS)) 8086 && !(flags & LOOKUP_EXPLICIT_TMPL_ARGS))
7883 conversion_warning = false; 8087 conversion_warning = false;
7884 8088
7992 || warn_suggest_attribute_format 8196 || warn_suggest_attribute_format
7993 || warn_restrict) 8197 || warn_restrict)
7994 { 8198 {
7995 tree *fargs = (!nargs ? argarray 8199 tree *fargs = (!nargs ? argarray
7996 : (tree *) alloca (nargs * sizeof (tree))); 8200 : (tree *) alloca (nargs * sizeof (tree)));
8201 auto_vec<location_t> arglocs (nargs);
7997 for (j = 0; j < nargs; j++) 8202 for (j = 0; j < nargs; j++)
7998 fargs[j] = maybe_constant_value (argarray[j]); 8203 {
8204 /* For -Wformat undo the implicit passing by hidden reference
8205 done by convert_arg_to_ellipsis. */
8206 if (TREE_CODE (argarray[j]) == ADDR_EXPR
8207 && TYPE_REF_P (TREE_TYPE (argarray[j])))
8208 fargs[j] = TREE_OPERAND (argarray[j], 0);
8209 else
8210 fargs[j] = maybe_constant_value (argarray[j]);
8211 arglocs.quick_push (EXPR_LOC_OR_LOC (argarray[j], input_location));
8212 }
7999 8213
8000 warned_p = check_function_arguments (input_location, fn, TREE_TYPE (fn), 8214 warned_p = check_function_arguments (input_location, fn, TREE_TYPE (fn),
8001 nargs, fargs, NULL); 8215 nargs, fargs, &arglocs);
8002 } 8216 }
8003 8217
8004 if (DECL_INHERITED_CTOR (fn)) 8218 if (DECL_INHERITED_CTOR (fn))
8005 { 8219 {
8006 /* Check for passing ellipsis arguments to an inherited constructor. We 8220 /* Check for passing ellipsis arguments to an inherited constructor. We
8026 } 8240 }
8027 8241
8028 /* Avoid actually calling copy constructors and copy assignment operators, 8242 /* Avoid actually calling copy constructors and copy assignment operators,
8029 if possible. */ 8243 if possible. */
8030 8244
8031 if (! flag_elide_constructors) 8245 if (! flag_elide_constructors && !force_elide)
8032 /* Do things the hard way. */; 8246 /* Do things the hard way. */;
8033 else if (cand->num_convs == 1 8247 else if (cand->num_convs == 1
8034 && (DECL_COPY_CONSTRUCTOR_P (fn) 8248 && (DECL_COPY_CONSTRUCTOR_P (fn)
8035 || DECL_MOVE_CONSTRUCTOR_P (fn)) 8249 || DECL_MOVE_CONSTRUCTOR_P (fn))
8036 /* It's unsafe to elide the constructor when handling 8250 /* It's unsafe to elide the constructor when handling
8037 a noexcept-expression, it may evaluate to the wrong 8251 a noexcept-expression, it may evaluate to the wrong
8038 value (c++/53025). */ 8252 value (c++/53025). */
8039 && cp_noexcept_operand == 0) 8253 && (force_elide || cp_noexcept_operand == 0))
8040 { 8254 {
8041 tree targ; 8255 tree targ;
8042 tree arg = argarray[num_artificial_parms_for (fn)]; 8256 tree arg = argarray[num_artificial_parms_for (fn)];
8043 tree fa; 8257 tree fa;
8044 bool trivial = trivial_fn_p (fn); 8258 bool trivial = trivial_fn_p (fn);
8045 8259
8046 /* Pull out the real argument, disregarding const-correctness. */ 8260 /* Pull out the real argument, disregarding const-correctness. */
8047 targ = arg; 8261 targ = arg;
8048 /* Strip the reference binding for the constructor parameter. */ 8262 /* Strip the reference binding for the constructor parameter. */
8049 if (CONVERT_EXPR_P (targ) 8263 if (CONVERT_EXPR_P (targ)
8050 && TREE_CODE (TREE_TYPE (targ)) == REFERENCE_TYPE) 8264 && TYPE_REF_P (TREE_TYPE (targ)))
8051 targ = TREE_OPERAND (targ, 0); 8265 targ = TREE_OPERAND (targ, 0);
8052 /* But don't strip any other reference bindings; binding a temporary to a 8266 /* But don't strip any other reference bindings; binding a temporary to a
8053 reference prevents copy elision. */ 8267 reference prevents copy elision. */
8054 while ((CONVERT_EXPR_P (targ) 8268 while ((CONVERT_EXPR_P (targ)
8055 && TREE_CODE (TREE_TYPE (targ)) != REFERENCE_TYPE) 8269 && !TYPE_REF_P (TREE_TYPE (targ)))
8056 || TREE_CODE (targ) == NON_LVALUE_EXPR) 8270 || TREE_CODE (targ) == NON_LVALUE_EXPR)
8057 targ = TREE_OPERAND (targ, 0); 8271 targ = TREE_OPERAND (targ, 0);
8058 if (TREE_CODE (targ) == ADDR_EXPR) 8272 if (TREE_CODE (targ) == ADDR_EXPR)
8059 { 8273 {
8060 targ = TREE_OPERAND (targ, 0); 8274 targ = TREE_OPERAND (targ, 0);
8066 targ = NULL_TREE; 8280 targ = NULL_TREE;
8067 8281
8068 if (targ) 8282 if (targ)
8069 arg = targ; 8283 arg = targ;
8070 else 8284 else
8071 arg = cp_build_indirect_ref (arg, RO_NULL, complain); 8285 arg = cp_build_fold_indirect_ref (arg);
8072 8286
8073 /* In C++17 we shouldn't be copying a TARGET_EXPR except into a base 8287 /* In C++17 we shouldn't be copying a TARGET_EXPR except into a base
8074 subobject. */ 8288 subobject. */
8075 if (CHECKING_P && cxx_dialect >= cxx17) 8289 if (CHECKING_P && cxx_dialect >= cxx17)
8076 gcc_assert (TREE_CODE (arg) != TARGET_EXPR 8290 gcc_assert (TREE_CODE (arg) != TARGET_EXPR
8291 || force_elide
8077 /* It's from binding the ref parm to a packed field. */ 8292 /* It's from binding the ref parm to a packed field. */
8078 || convs[0]->need_temporary_p 8293 || convs[0]->need_temporary_p
8079 || seen_error () 8294 || seen_error ()
8080 /* See unsafe_copy_elision_p. */ 8295 /* See unsafe_copy_elision_p. */
8081 || DECL_BASE_CONSTRUCTOR_P (fn)); 8296 || DECL_BASE_CONSTRUCTOR_P (fn));
8082 8297
8083 /* [class.copy]: the copy constructor is implicitly defined even if 8298 fa = argarray[0];
8084 the implementation elided its use. */ 8299 bool unsafe = unsafe_copy_elision_p (fa, arg);
8085 if (!trivial || DECL_DELETED_FN (fn)) 8300 bool eliding_temp = (TREE_CODE (arg) == TARGET_EXPR && !unsafe);
8301
8302 /* [class.copy]: the copy constructor is implicitly defined even if the
8303 implementation elided its use. But don't warn about deprecation when
8304 eliding a temporary, as then no copy is actually performed. */
8305 warning_sentinel s (warn_deprecated_copy, eliding_temp);
8306 if (force_elide)
8307 /* The language says this isn't called. */;
8308 else if (!trivial)
8086 { 8309 {
8087 if (!mark_used (fn, complain) && !(complain & tf_error)) 8310 if (!mark_used (fn, complain) && !(complain & tf_error))
8088 return error_mark_node; 8311 return error_mark_node;
8089 already_used = true; 8312 already_used = true;
8090 } 8313 }
8314 else
8315 cp_warn_deprecated_use (fn, complain);
8091 8316
8092 /* If we're creating a temp and we already have one, don't create a 8317 /* If we're creating a temp and we already have one, don't create a
8093 new one. If we're not creating a temp but we get one, use 8318 new one. If we're not creating a temp but we get one, use
8094 INIT_EXPR to collapse the temp into our target. Otherwise, if the 8319 INIT_EXPR to collapse the temp into our target. Otherwise, if the
8095 ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a 8320 ctor is trivial, do a bitwise copy with a simple TARGET_EXPR for a
8096 temp or an INIT_EXPR otherwise. */ 8321 temp or an INIT_EXPR otherwise. */
8097 fa = argarray[0];
8098 if (is_dummy_object (fa)) 8322 if (is_dummy_object (fa))
8099 { 8323 {
8100 if (TREE_CODE (arg) == TARGET_EXPR) 8324 if (TREE_CODE (arg) == TARGET_EXPR)
8101 return arg; 8325 return arg;
8102 else if (trivial) 8326 else if (trivial)
8103 return force_target_expr (DECL_CONTEXT (fn), arg, complain); 8327 return force_target_expr (DECL_CONTEXT (fn), arg, complain);
8104 } 8328 }
8105 else if ((trivial || TREE_CODE (arg) == TARGET_EXPR) 8329 else if ((trivial || TREE_CODE (arg) == TARGET_EXPR)
8106 && !unsafe_copy_elision_p (fa, arg)) 8330 && !unsafe)
8107 { 8331 {
8108 tree to = cp_stabilize_reference (cp_build_indirect_ref (fa, 8332 tree to = cp_stabilize_reference (cp_build_fold_indirect_ref (fa));
8109 RO_NULL,
8110 complain));
8111 8333
8112 val = build2 (INIT_EXPR, DECL_CONTEXT (fn), to, arg); 8334 val = build2 (INIT_EXPR, DECL_CONTEXT (fn), to, arg);
8113 return val; 8335 return val;
8114 } 8336 }
8115 } 8337 }
8116 else if (DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR 8338 else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
8117 && trivial_fn_p (fn) 8339 && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR)
8118 && !DECL_DELETED_FN (fn)) 8340 && trivial_fn_p (fn))
8119 { 8341 {
8120 tree to = cp_stabilize_reference 8342 tree to = cp_stabilize_reference
8121 (cp_build_indirect_ref (argarray[0], RO_NULL, complain)); 8343 (cp_build_fold_indirect_ref (argarray[0]));
8122 tree type = TREE_TYPE (to); 8344 tree type = TREE_TYPE (to);
8123 tree as_base = CLASSTYPE_AS_BASE (type); 8345 tree as_base = CLASSTYPE_AS_BASE (type);
8124 tree arg = argarray[1]; 8346 tree arg = argarray[1];
8347 location_t loc = cp_expr_loc_or_loc (arg, input_location);
8125 8348
8126 if (is_really_empty_class (type)) 8349 if (is_really_empty_class (type))
8127 { 8350 {
8128 /* Avoid copying empty classes. */ 8351 /* Avoid copying empty classes. */
8129 val = build2 (COMPOUND_EXPR, type, arg, to); 8352 val = build2 (COMPOUND_EXPR, type, arg, to);
8130 TREE_NO_WARNING (val) = 1; 8353 TREE_NO_WARNING (val) = 1;
8131 } 8354 }
8132 else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base))) 8355 else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base)))
8133 { 8356 {
8134 arg = cp_build_indirect_ref (arg, RO_NULL, complain); 8357 if (is_std_init_list (type)
8358 && conv_binds_ref_to_prvalue (convs[1]))
8359 warning_at (loc, OPT_Winit_list_lifetime,
8360 "assignment from temporary initializer_list does not "
8361 "extend the lifetime of the underlying array");
8362 arg = cp_build_fold_indirect_ref (arg);
8135 val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg); 8363 val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg);
8136 /* Handle NSDMI that refer to the object being initialized. */
8137 replace_placeholders (arg, to);
8138 } 8364 }
8139 else 8365 else
8140 { 8366 {
8141 /* We must only copy the non-tail padding parts. */ 8367 /* We must only copy the non-tail padding parts. */
8142 tree arg0, arg2, t; 8368 tree arg0, arg2, t;
8155 build2 (MEM_REF, array_type, arg, alias_set)); 8381 build2 (MEM_REF, array_type, arg, alias_set));
8156 val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to); 8382 val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to);
8157 TREE_NO_WARNING (val) = 1; 8383 TREE_NO_WARNING (val) = 1;
8158 } 8384 }
8159 8385
8386 cp_warn_deprecated_use (fn, complain);
8387
8160 return val; 8388 return val;
8161 } 8389 }
8162 else if (!DECL_DELETED_FN (fn) 8390 else if (trivial_fn_p (fn))
8163 && trivial_fn_p (fn))
8164 { 8391 {
8165 if (DECL_DESTRUCTOR_P (fn)) 8392 if (DECL_DESTRUCTOR_P (fn))
8166 return fold_convert (void_type_node, argarray[0]); 8393 return build_trivial_dtor_call (argarray[0]);
8167 else if (default_ctor_p (fn)) 8394 else if (default_ctor_p (fn))
8168 { 8395 {
8169 if (is_dummy_object (argarray[0])) 8396 if (is_dummy_object (argarray[0]))
8170 return force_target_expr (DECL_CONTEXT (fn), void_node, 8397 return force_target_expr (DECL_CONTEXT (fn), void_node,
8171 no_cleanup_complain); 8398 no_cleanup_complain);
8172 else 8399 else
8173 return cp_build_indirect_ref (argarray[0], RO_NULL, complain); 8400 return cp_build_fold_indirect_ref (argarray[0]);
8174 } 8401 }
8175 } 8402 }
8176 8403
8177 /* For calls to a multi-versioned function, overload resolution 8404 gcc_assert (!force_elide);
8178 returns the function with the highest target priority, that is,
8179 the version that will checked for dispatching first. If this
8180 version is inlinable, a direct call to this version can be made
8181 otherwise the call should go through the dispatcher. */
8182
8183 if (DECL_FUNCTION_VERSIONED (fn)
8184 && (current_function_decl == NULL
8185 || !targetm.target_option.can_inline_p (current_function_decl, fn)))
8186 {
8187 fn = get_function_version_dispatcher (fn);
8188 if (fn == NULL)
8189 return NULL;
8190 if (!already_used)
8191 mark_versions_used (fn);
8192 }
8193 8405
8194 if (!already_used 8406 if (!already_used
8195 && !mark_used (fn, complain)) 8407 && !mark_used (fn, complain))
8196 return error_mark_node; 8408 return error_mark_node;
8197 8409
8198 if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0 8410 /* Warn if the built-in writes to an object of a non-trivial type. */
8199 /* Don't mess with virtual lookup in instantiate_non_dependent_expr; 8411 if (warn_class_memaccess
8200 virtual functions can't be constexpr. */ 8412 && vec_safe_length (args) >= 2
8201 && !in_template_function ()) 8413 && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
8414 maybe_warn_class_memaccess (input_location, fn, args);
8415
8416 if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
8202 { 8417 {
8203 tree t; 8418 tree t;
8204 tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (argarray[0])), 8419 tree binfo = lookup_base (TREE_TYPE (TREE_TYPE (argarray[0])),
8205 DECL_CONTEXT (fn), 8420 DECL_CONTEXT (fn),
8206 ba_any, NULL, complain); 8421 ba_any, NULL, complain);
8237 TREE_NO_WARNING (c) = 1; 8452 TREE_NO_WARNING (c) = 1;
8238 } 8453 }
8239 return call; 8454 return call;
8240 } 8455 }
8241 8456
8242 /* Return the DECL of the first non-public data member of class TYPE 8457 namespace
8243 or null if none can be found. */ 8458 {
8244 8459
8245 static tree 8460 /* Return the DECL of the first non-static subobject of class TYPE
8246 first_non_public_field (tree type) 8461 that satisfies the predicate PRED or null if none can be found. */
8247 { 8462
8248 if (!CLASS_TYPE_P (type)) 8463 template <class Predicate>
8464 tree
8465 first_non_static_field (tree type, Predicate pred)
8466 {
8467 if (!type || !CLASS_TYPE_P (type))
8249 return NULL_TREE; 8468 return NULL_TREE;
8250 8469
8251 for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) 8470 for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
8252 { 8471 {
8253 if (TREE_CODE (field) != FIELD_DECL) 8472 if (TREE_CODE (field) != FIELD_DECL)
8254 continue; 8473 continue;
8255 if (TREE_STATIC (field)) 8474 if (TREE_STATIC (field))
8256 continue; 8475 continue;
8257 if (TREE_PRIVATE (field) || TREE_PROTECTED (field)) 8476 if (pred (field))
8258 return field; 8477 return field;
8259 } 8478 }
8260 8479
8261 int i = 0; 8480 int i = 0;
8262 8481
8263 for (tree base_binfo, binfo = TYPE_BINFO (type); 8482 for (tree base_binfo, binfo = TYPE_BINFO (type);
8264 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++) 8483 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
8265 { 8484 {
8266 tree base = TREE_TYPE (base_binfo); 8485 tree base = TREE_TYPE (base_binfo);
8267 8486 if (pred (base))
8268 if (tree field = first_non_public_field (base)) 8487 return base;
8488 if (tree field = first_non_static_field (base, pred))
8269 return field; 8489 return field;
8270 } 8490 }
8271 8491
8272 return NULL_TREE; 8492 return NULL_TREE;
8273 } 8493 }
8494
8495 struct NonPublicField
8496 {
8497 bool operator() (const_tree t)
8498 {
8499 return DECL_P (t) && (TREE_PRIVATE (t) || TREE_PROTECTED (t));
8500 }
8501 };
8502
8503 /* Return the DECL of the first non-public subobject of class TYPE
8504 or null if none can be found. */
8505
8506 static inline tree
8507 first_non_public_field (tree type)
8508 {
8509 return first_non_static_field (type, NonPublicField ());
8510 }
8511
8512 struct NonTrivialField
8513 {
8514 bool operator() (const_tree t)
8515 {
8516 return !trivial_type_p (DECL_P (t) ? TREE_TYPE (t) : t);
8517 }
8518 };
8519
8520 /* Return the DECL of the first non-trivial subobject of class TYPE
8521 or null if none can be found. */
8522
8523 static inline tree
8524 first_non_trivial_field (tree type)
8525 {
8526 return first_non_static_field (type, NonTrivialField ());
8527 }
8528
8529 } /* unnamed namespace */
8274 8530
8275 /* Return true if all copy and move assignment operator overloads for 8531 /* Return true if all copy and move assignment operator overloads for
8276 class TYPE are trivial and at least one of them is not deleted and, 8532 class TYPE are trivial and at least one of them is not deleted and,
8277 when ACCESS is set, accessible. Return false otherwise. Set 8533 when ACCESS is set, accessible. Return false otherwise. Set
8278 HASASSIGN to true when the TYPE has a (not necessarily trivial) 8534 HASASSIGN to true when the TYPE has a (not necessarily trivial)
8279 copy or move assignment. */ 8535 copy or move assignment. */
8280 8536
8281 static bool 8537 static bool
8282 has_trivial_copy_assign_p (tree type, bool access, bool *hasassign) 8538 has_trivial_copy_assign_p (tree type, bool access, bool *hasassign)
8283 { 8539 {
8284 tree fns = get_class_binding (type, cp_assignment_operator_id (NOP_EXPR)); 8540 tree fns = get_class_binding (type, assign_op_identifier);
8285 bool all_trivial = true; 8541 bool all_trivial = true;
8286 8542
8287 /* Iterate over overloads of the assignment operator, checking 8543 /* Iterate over overloads of the assignment operator, checking
8288 accessible copy assignments for triviality. */ 8544 accessible copy assignments for triviality. */
8289 8545
8373 and copy ctor. Detects const correctness violations, corrupting 8629 and copy ctor. Detects const correctness violations, corrupting
8374 references, virtual table pointers, and bypassing non-trivial 8630 references, virtual table pointers, and bypassing non-trivial
8375 assignments. */ 8631 assignments. */
8376 8632
8377 static void 8633 static void
8378 maybe_warn_class_memaccess (location_t loc, tree fndecl, tree *args) 8634 maybe_warn_class_memaccess (location_t loc, tree fndecl,
8635 const vec<tree, va_gc> *args)
8379 { 8636 {
8380 /* Except for bcopy where it's second, the destination pointer is 8637 /* Except for bcopy where it's second, the destination pointer is
8381 the first argument for all functions handled here. Compute 8638 the first argument for all functions handled here. Compute
8382 the index of the destination and source arguments. */ 8639 the index of the destination and source arguments. */
8383 unsigned dstidx = DECL_FUNCTION_CODE (fndecl) == BUILT_IN_BCOPY; 8640 unsigned dstidx = DECL_FUNCTION_CODE (fndecl) == BUILT_IN_BCOPY;
8384 unsigned srcidx = !dstidx; 8641 unsigned srcidx = !dstidx;
8385 8642
8386 tree dest = args[dstidx]; 8643 tree dest = (*args)[dstidx];
8387 if (!dest || !TREE_TYPE (dest) || !POINTER_TYPE_P (TREE_TYPE (dest))) 8644 if (!TREE_TYPE (dest) || !INDIRECT_TYPE_P (TREE_TYPE (dest)))
8388 return; 8645 return;
8389
8390 /* Remove the outermost (usually implicit) conversion to the void*
8391 argument type. */
8392 if (TREE_CODE (dest) == NOP_EXPR)
8393 dest = TREE_OPERAND (dest, 0);
8394 8646
8395 tree srctype = NULL_TREE; 8647 tree srctype = NULL_TREE;
8396 8648
8397 /* Determine the type of the pointed-to object and whether it's 8649 /* Determine the type of the pointed-to object and whether it's
8398 a complete class type. */ 8650 a complete class type. */
8399 tree desttype = TREE_TYPE (TREE_TYPE (dest)); 8651 tree desttype = TREE_TYPE (TREE_TYPE (dest));
8400 8652
8401 if (!desttype || !COMPLETE_TYPE_P (desttype) || !CLASS_TYPE_P (desttype)) 8653 if (!desttype || !COMPLETE_TYPE_P (desttype) || !CLASS_TYPE_P (desttype))
8402 return; 8654 return;
8403 8655
8404 /* Check to see if the raw memory call is made by a ctor or dtor 8656 /* Check to see if the raw memory call is made by a non-static member
8405 with this as the destination argument for the destination type. 8657 function with THIS as the destination argument for the destination
8406 If so, be more permissive. */ 8658 type. If so, and if the class has no non-trivial bases or members,
8659 be more permissive. */
8407 if (current_function_decl 8660 if (current_function_decl
8408 && (DECL_CONSTRUCTOR_P (current_function_decl) 8661 && DECL_NONSTATIC_MEMBER_FUNCTION_P (current_function_decl)
8409 || DECL_DESTRUCTOR_P (current_function_decl))
8410 && is_this_parameter (tree_strip_nop_conversions (dest))) 8662 && is_this_parameter (tree_strip_nop_conversions (dest)))
8411 { 8663 {
8412 tree ctx = DECL_CONTEXT (current_function_decl); 8664 tree ctx = DECL_CONTEXT (current_function_decl);
8413 bool special = same_type_ignoring_top_level_qualifiers_p (ctx, desttype); 8665 bool special = same_type_ignoring_top_level_qualifiers_p (ctx, desttype);
8414
8415 tree binfo = TYPE_BINFO (ctx); 8666 tree binfo = TYPE_BINFO (ctx);
8416 8667
8417 /* A ctor and dtor for a class with no bases and no virtual functions 8668 if (special
8418 can do whatever they want. Bail early with no further checking. */ 8669 && !BINFO_VTABLE (binfo)
8419 if (special && !BINFO_VTABLE (binfo) && !BINFO_N_BASE_BINFOS (binfo)) 8670 && !first_non_trivial_field (desttype))
8420 return; 8671 return;
8421 } 8672 }
8422 8673
8423 /* True if the class is trivial. */ 8674 /* True if the class is trivial. */
8424 bool trivial = trivial_type_p (desttype); 8675 bool trivial = trivial_type_p (desttype);
8449 bool warned = false; 8700 bool warned = false;
8450 8701
8451 switch (DECL_FUNCTION_CODE (fndecl)) 8702 switch (DECL_FUNCTION_CODE (fndecl))
8452 { 8703 {
8453 case BUILT_IN_MEMSET: 8704 case BUILT_IN_MEMSET:
8454 if (!integer_zerop (args[1])) 8705 if (!integer_zerop (maybe_constant_value ((*args)[1])))
8455 { 8706 {
8456 /* Diagnose setting non-copy-assignable or non-trivial types, 8707 /* Diagnose setting non-copy-assignable or non-trivial types,
8457 or types with a private member, to (potentially) non-zero 8708 or types with a private member, to (potentially) non-zero
8458 bytes. Since the value of the bytes being written is unknown, 8709 bytes. Since the value of the bytes being written is unknown,
8459 suggest using assignment instead (if one exists). Also warn 8710 suggest using assignment instead (if one exists). Also warn
8510 case BUILT_IN_BCOPY: 8761 case BUILT_IN_BCOPY:
8511 case BUILT_IN_MEMCPY: 8762 case BUILT_IN_MEMCPY:
8512 case BUILT_IN_MEMMOVE: 8763 case BUILT_IN_MEMMOVE:
8513 case BUILT_IN_MEMPCPY: 8764 case BUILT_IN_MEMPCPY:
8514 /* Determine the type of the source object. */ 8765 /* Determine the type of the source object. */
8515 srctype = STRIP_NOPS (args[srcidx]); 8766 srctype = TREE_TYPE ((*args)[srcidx]);
8516 srctype = TREE_TYPE (TREE_TYPE (srctype)); 8767 if (!srctype || !INDIRECT_TYPE_P (srctype))
8768 srctype = void_type_node;
8769 else
8770 srctype = TREE_TYPE (srctype);
8517 8771
8518 /* Since it's impossible to determine wheter the byte copy is 8772 /* Since it's impossible to determine wheter the byte copy is
8519 being used in place of assignment to an existing object or 8773 being used in place of assignment to an existing object or
8520 as a substitute for initialization, assume it's the former. 8774 as a substitute for initialization, assume it's the former.
8521 Determine the best alternative to use instead depending on 8775 Determine the best alternative to use instead depending on
8560 "%qD copying an object of type %#qT with " 8814 "%qD copying an object of type %#qT with "
8561 "%qs member %qD from an array of %#qT; use " 8815 "%qs member %qD from an array of %#qT; use "
8562 "assignment or copy-initialization instead", 8816 "assignment or copy-initialization instead",
8563 fndecl, desttype, access, fld, srctype); 8817 fndecl, desttype, access, fld, srctype);
8564 } 8818 }
8565 else if (!trivial && TREE_CODE (args[2]) == INTEGER_CST) 8819 else if (!trivial && vec_safe_length (args) > 2)
8566 { 8820 {
8821 tree sz = maybe_constant_value ((*args)[2]);
8822 if (!tree_fits_uhwi_p (sz))
8823 break;
8824
8567 /* Finally, warn on partial copies. */ 8825 /* Finally, warn on partial copies. */
8568 unsigned HOST_WIDE_INT typesize 8826 unsigned HOST_WIDE_INT typesize
8569 = tree_to_uhwi (TYPE_SIZE_UNIT (desttype)); 8827 = tree_to_uhwi (TYPE_SIZE_UNIT (desttype));
8570 if (unsigned HOST_WIDE_INT partial 8828 if (unsigned HOST_WIDE_INT partial = tree_to_uhwi (sz) % typesize)
8571 = tree_to_uhwi (args[2]) % typesize)
8572 warned = warning_at (loc, OPT_Wclass_memaccess, 8829 warned = warning_at (loc, OPT_Wclass_memaccess,
8573 (typesize - partial > 1 8830 (typesize - partial > 1
8574 ? G_("%qD writing to an object of " 8831 ? G_("%qD writing to an object of "
8575 "a non-trivial type %#qT leaves %wu " 8832 "a non-trivial type %#qT leaves %wu "
8576 "bytes unchanged") 8833 "bytes unchanged")
8590 warnfmt = G_("%qD moving an object of type %#qT with deleted copy " 8847 warnfmt = G_("%qD moving an object of type %#qT with deleted copy "
8591 "constructor; use %<new%> and %<delete%> instead"); 8848 "constructor; use %<new%> and %<delete%> instead");
8592 else if (!get_dtor (desttype, tf_none)) 8849 else if (!get_dtor (desttype, tf_none))
8593 warnfmt = G_("%qD moving an object of type %#qT with deleted " 8850 warnfmt = G_("%qD moving an object of type %#qT with deleted "
8594 "destructor"); 8851 "destructor");
8595 else if (!trivial 8852 else if (!trivial)
8596 && TREE_CODE (args[1]) == INTEGER_CST 8853 {
8597 && tree_int_cst_lt (args[1], TYPE_SIZE_UNIT (desttype))) 8854 tree sz = maybe_constant_value ((*args)[1]);
8598 { 8855 if (TREE_CODE (sz) == INTEGER_CST
8599 /* Finally, warn on reallocation into insufficient space. */ 8856 && tree_int_cst_lt (sz, TYPE_SIZE_UNIT (desttype)))
8600 warned = warning_at (loc, OPT_Wclass_memaccess, 8857 /* Finally, warn on reallocation into insufficient space. */
8601 "%qD moving an object of non-trivial type " 8858 warned = warning_at (loc, OPT_Wclass_memaccess,
8602 "%#qT and size %E into a region of size %E", 8859 "%qD moving an object of non-trivial type "
8603 fndecl, desttype, TYPE_SIZE_UNIT (desttype), 8860 "%#qT and size %E into a region of size %E",
8604 args[1]); 8861 fndecl, desttype, TYPE_SIZE_UNIT (desttype),
8862 sz);
8605 } 8863 }
8606 break; 8864 break;
8607 8865
8608 default: 8866 default:
8609 return; 8867 return;
8610 } 8868 }
8611
8612 if (!warned && !warnfmt)
8613 return;
8614 8869
8615 if (warnfmt) 8870 if (warnfmt)
8616 { 8871 {
8617 if (suggest) 8872 if (suggest)
8618 warned = warning_at (loc, OPT_Wclass_memaccess, 8873 warned = warning_at (loc, OPT_Wclass_memaccess,
8635 tsubst_flags_t complain) 8890 tsubst_flags_t complain)
8636 { 8891 {
8637 tree fndecl; 8892 tree fndecl;
8638 8893
8639 /* Remember roughly where this call is. */ 8894 /* Remember roughly where this call is. */
8640 location_t loc = EXPR_LOC_OR_LOC (fn, input_location); 8895 location_t loc = cp_expr_loc_or_loc (fn, input_location);
8641 fn = build_call_a (fn, nargs, argarray); 8896 fn = build_call_a (fn, nargs, argarray);
8642 SET_EXPR_LOCATION (fn, loc); 8897 SET_EXPR_LOCATION (fn, loc);
8643 8898
8644 fndecl = get_callee_fndecl (fn); 8899 fndecl = get_callee_fndecl (fn);
8645 8900
8646 /* Check that arguments to builtin functions match the expectations. */ 8901 /* Check that arguments to builtin functions match the expectations. */
8647 if (fndecl 8902 if (fndecl
8648 && DECL_BUILT_IN (fndecl) 8903 && !processing_template_decl
8649 && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) 8904 && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
8650 { 8905 {
8651 int i; 8906 int i;
8652 8907
8653 /* We need to take care that values to BUILT_IN_NORMAL 8908 /* We need to take care that values to BUILT_IN_NORMAL
8654 are reduced. */ 8909 are reduced. */
8655 for (i = 0; i < nargs; i++) 8910 for (i = 0; i < nargs; i++)
8656 argarray[i] = fold_non_dependent_expr (argarray[i]); 8911 argarray[i] = maybe_constant_value (argarray[i]);
8657 8912
8658 if (!check_builtin_function_arguments (EXPR_LOCATION (fn), vNULL, fndecl, 8913 if (!check_builtin_function_arguments (EXPR_LOCATION (fn), vNULL, fndecl,
8659 nargs, argarray)) 8914 nargs, argarray))
8660 return error_mark_node; 8915 return error_mark_node;
8661
8662 /* Warn if the built-in writes to an object of a non-trivial type. */
8663 if (nargs)
8664 maybe_warn_class_memaccess (loc, fndecl, argarray);
8665 }
8666
8667 /* If it is a built-in array notation function, then the return type of
8668 the function is the element type of the array passed in as array
8669 notation (i.e. the first parameter of the function). */
8670 if (flag_cilkplus && TREE_CODE (fn) == CALL_EXPR)
8671 {
8672 enum built_in_function bif =
8673 is_cilkplus_reduce_builtin (CALL_EXPR_FN (fn));
8674 if (bif == BUILT_IN_CILKPLUS_SEC_REDUCE_ADD
8675 || bif == BUILT_IN_CILKPLUS_SEC_REDUCE_MUL
8676 || bif == BUILT_IN_CILKPLUS_SEC_REDUCE_MAX
8677 || bif == BUILT_IN_CILKPLUS_SEC_REDUCE_MIN
8678 || bif == BUILT_IN_CILKPLUS_SEC_REDUCE
8679 || bif == BUILT_IN_CILKPLUS_SEC_REDUCE_MUTATING)
8680 {
8681 if (call_expr_nargs (fn) == 0)
8682 {
8683 error_at (EXPR_LOCATION (fn), "Invalid builtin arguments");
8684 return error_mark_node;
8685 }
8686 /* for bif == BUILT_IN_CILKPLUS_SEC_REDUCE_ALL_ZERO or
8687 BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_ZERO or
8688 BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_NONZERO or
8689 BUILT_IN_CILKPLUS_SEC_REDUCE_ALL_NONZERO or
8690 BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND or
8691 BUILT_IN_CILKPLUS_SEC_REDUCE_MAX_IND
8692 The pre-defined return-type is the correct one. */
8693 tree array_ntn = CALL_EXPR_ARG (fn, 0);
8694 TREE_TYPE (fn) = TREE_TYPE (array_ntn);
8695 return fn;
8696 }
8697 } 8916 }
8698 8917
8699 if (VOID_TYPE_P (TREE_TYPE (fn))) 8918 if (VOID_TYPE_P (TREE_TYPE (fn)))
8700 return fn; 8919 return fn;
8701 8920
8751 static void 8970 static void
8752 check_self_delegation (tree ret) 8971 check_self_delegation (tree ret)
8753 { 8972 {
8754 if (TREE_CODE (ret) == TARGET_EXPR) 8973 if (TREE_CODE (ret) == TARGET_EXPR)
8755 ret = TARGET_EXPR_INITIAL (ret); 8974 ret = TARGET_EXPR_INITIAL (ret);
8756 tree fn = cp_get_callee_fndecl (ret); 8975 tree fn = cp_get_callee_fndecl_nofold (ret);
8757 if (fn && DECL_ABSTRACT_ORIGIN (fn) == current_function_decl) 8976 if (fn && DECL_ABSTRACT_ORIGIN (fn) == current_function_decl)
8758 error ("constructor delegates to itself"); 8977 error ("constructor delegates to itself");
8759 } 8978 }
8760 8979
8761 /* Build a call to a constructor, destructor, or an assignment 8980 /* Build a call to a constructor, destructor, or an assignment
8779 /* The type of the subobject to be constructed or destroyed. */ 8998 /* The type of the subobject to be constructed or destroyed. */
8780 tree class_type; 8999 tree class_type;
8781 vec<tree, va_gc> *allocated = NULL; 9000 vec<tree, va_gc> *allocated = NULL;
8782 tree ret; 9001 tree ret;
8783 9002
8784 gcc_assert (IDENTIFIER_CDTOR_P (name) 9003 gcc_assert (IDENTIFIER_CDTOR_P (name) || name == assign_op_identifier);
8785 || name == cp_assignment_operator_id (NOP_EXPR)); 9004
9005 if (error_operand_p (instance))
9006 return error_mark_node;
9007
9008 if (IDENTIFIER_DTOR_P (name))
9009 {
9010 gcc_assert (args == NULL || vec_safe_is_empty (*args));
9011 if (!type_build_dtor_call (TREE_TYPE (instance)))
9012 /* Shortcut to avoid lazy destructor declaration. */
9013 return build_trivial_dtor_call (instance);
9014 }
9015
8786 if (TYPE_P (binfo)) 9016 if (TYPE_P (binfo))
8787 { 9017 {
8788 /* Resolve the name. */ 9018 /* Resolve the name. */
8789 if (!complete_type_or_maybe_complain (binfo, NULL_TREE, complain)) 9019 if (!complete_type_or_maybe_complain (binfo, NULL_TREE, complain))
8790 return error_mark_node; 9020 return error_mark_node;
8799 /* Handle the special case where INSTANCE is NULL_TREE. */ 9029 /* Handle the special case where INSTANCE is NULL_TREE. */
8800 if (name == complete_ctor_identifier && !instance) 9030 if (name == complete_ctor_identifier && !instance)
8801 instance = build_dummy_object (class_type); 9031 instance = build_dummy_object (class_type);
8802 else 9032 else
8803 { 9033 {
8804 if (IDENTIFIER_DTOR_P (name))
8805 gcc_assert (args == NULL || vec_safe_is_empty (*args));
8806
8807 /* Convert to the base class, if necessary. */ 9034 /* Convert to the base class, if necessary. */
8808 if (!same_type_ignoring_top_level_qualifiers_p 9035 if (!same_type_ignoring_top_level_qualifiers_p
8809 (TREE_TYPE (instance), BINFO_TYPE (binfo))) 9036 (TREE_TYPE (instance), BINFO_TYPE (binfo)))
8810 { 9037 {
8811 if (name != cp_assignment_operator_id (NOP_EXPR)) 9038 if (IDENTIFIER_CDTOR_P (name))
8812 /* For constructors and destructors, either the base is 9039 /* For constructors and destructors, either the base is
8813 non-virtual, or it is virtual but we are doing the 9040 non-virtual, or it is virtual but we are doing the
8814 conversion from a constructor or destructor for the 9041 conversion from a constructor or destructor for the
8815 complete object. In either case, we can convert 9042 complete object. In either case, we can convert
8816 statically. */ 9043 statically. */
8817 instance = convert_to_base_statically (instance, binfo); 9044 instance = convert_to_base_statically (instance, binfo);
8818 else 9045 else
8819 /* However, for assignment operators, we must convert 9046 {
8820 dynamically if the base is virtual. */ 9047 /* However, for assignment operators, we must convert
8821 instance = build_base_path (PLUS_EXPR, instance, 9048 dynamically if the base is virtual. */
8822 binfo, /*nonnull=*/1, complain); 9049 gcc_checking_assert (name == assign_op_identifier);
9050 instance = build_base_path (PLUS_EXPR, instance,
9051 binfo, /*nonnull=*/1, complain);
9052 }
8823 } 9053 }
8824 } 9054 }
8825 9055
8826 gcc_assert (instance != NULL_TREE); 9056 gcc_assert (instance != NULL_TREE);
8827 9057
8834 && args && vec_safe_length (*args) == 1 9064 && args && vec_safe_length (*args) == 1
8835 && name == complete_ctor_identifier) 9065 && name == complete_ctor_identifier)
8836 { 9066 {
8837 tree arg = (**args)[0]; 9067 tree arg = (**args)[0];
8838 9068
8839 /* FIXME P0135 doesn't say how to handle direct initialization from a 9069 if (BRACE_ENCLOSED_INITIALIZER_P (arg)
8840 type with a suitable conversion operator. Let's handle it like 9070 && !TYPE_HAS_LIST_CTOR (class_type)
8841 copy-initialization, but allowing explict conversions. */ 9071 && CONSTRUCTOR_NELTS (arg) == 1)
8842 tsubst_flags_t sub_complain = tf_warning; 9072 arg = CONSTRUCTOR_ELT (arg, 0)->value;
8843 if (!is_dummy_object (instance)) 9073
8844 /* If we're using this to initialize a non-temporary object, don't
8845 require the destructor to be accessible. */
8846 sub_complain |= tf_no_cleanup;
8847 if (!reference_related_p (class_type, TREE_TYPE (arg)))
8848 arg = perform_implicit_conversion_flags (class_type, arg,
8849 sub_complain,
8850 flags);
8851 if ((TREE_CODE (arg) == TARGET_EXPR 9074 if ((TREE_CODE (arg) == TARGET_EXPR
8852 || TREE_CODE (arg) == CONSTRUCTOR) 9075 || TREE_CODE (arg) == CONSTRUCTOR)
8853 && (same_type_ignoring_top_level_qualifiers_p 9076 && (same_type_ignoring_top_level_qualifiers_p
8854 (class_type, TREE_TYPE (arg)))) 9077 (class_type, TREE_TYPE (arg))))
8855 { 9078 {
8856 if (is_dummy_object (instance)) 9079 if (is_dummy_object (instance))
8857 return arg; 9080 return arg;
9081 else if (TREE_CODE (arg) == TARGET_EXPR)
9082 TARGET_EXPR_DIRECT_INIT_P (arg) = true;
9083
8858 if ((complain & tf_error) 9084 if ((complain & tf_error)
8859 && (flags & LOOKUP_DELEGATING_CONS)) 9085 && (flags & LOOKUP_DELEGATING_CONS))
8860 check_self_delegation (arg); 9086 check_self_delegation (arg);
8861 /* Avoid change of behavior on Wunused-var-2.C. */ 9087 /* Avoid change of behavior on Wunused-var-2.C. */
8862 instance = mark_lvalue_use (instance); 9088 instance = mark_lvalue_use (instance);
8953 } 9179 }
8954 else 9180 else
8955 pretty_name = identifier_to_locale (IDENTIFIER_POINTER (name)); 9181 pretty_name = identifier_to_locale (IDENTIFIER_POINTER (name));
8956 9182
8957 return CONST_CAST (char *, pretty_name); 9183 return CONST_CAST (char *, pretty_name);
9184 }
9185
9186 /* If CANDIDATES contains exactly one candidate, return it, otherwise
9187 return NULL. */
9188
9189 static z_candidate *
9190 single_z_candidate (z_candidate *candidates)
9191 {
9192 if (candidates == NULL)
9193 return NULL;
9194
9195 if (candidates->next)
9196 return NULL;
9197
9198 return candidates;
9199 }
9200
9201 /* If CANDIDATE is invalid due to a bad argument type, return the
9202 pertinent conversion_info.
9203
9204 Otherwise, return NULL. */
9205
9206 static const conversion_info *
9207 maybe_get_bad_conversion_for_unmatched_call (const z_candidate *candidate)
9208 {
9209 /* Must be an rr_arg_conversion or rr_bad_arg_conversion. */
9210 rejection_reason *r = candidate->reason;
9211
9212 if (r == NULL)
9213 return NULL;
9214
9215 switch (r->code)
9216 {
9217 default:
9218 return NULL;
9219
9220 case rr_arg_conversion:
9221 return &r->u.conversion;
9222
9223 case rr_bad_arg_conversion:
9224 return &r->u.bad_conversion;
9225 }
9226 }
9227
9228 /* Issue an error and note complaining about a bad argument type at a
9229 callsite with a single candidate FNDECL.
9230
9231 ARG_LOC is the location of the argument (or UNKNOWN_LOCATION, in which
9232 case input_location is used).
9233 FROM_TYPE is the type of the actual argument; TO_TYPE is the type of
9234 the formal parameter. */
9235
9236 void
9237 complain_about_bad_argument (location_t arg_loc,
9238 tree from_type, tree to_type,
9239 tree fndecl, int parmnum)
9240 {
9241 auto_diagnostic_group d;
9242 range_label_for_type_mismatch rhs_label (from_type, to_type);
9243 range_label *label = &rhs_label;
9244 if (arg_loc == UNKNOWN_LOCATION)
9245 {
9246 arg_loc = input_location;
9247 label = NULL;
9248 }
9249 gcc_rich_location richloc (arg_loc, label);
9250 error_at (&richloc,
9251 "cannot convert %qH to %qI",
9252 from_type, to_type);
9253 inform (get_fndecl_argument_location (fndecl, parmnum),
9254 " initializing argument %P of %qD", parmnum, fndecl);
9255 }
9256
9257 /* Subroutine of build_new_method_call_1, for where there are no viable
9258 candidates for the call. */
9259
9260 static void
9261 complain_about_no_candidates_for_method_call (tree instance,
9262 z_candidate *candidates,
9263 tree explicit_targs,
9264 tree basetype,
9265 tree optype, tree name,
9266 bool skip_first_for_error,
9267 vec<tree, va_gc> *user_args)
9268 {
9269 auto_diagnostic_group d;
9270 if (!COMPLETE_OR_OPEN_TYPE_P (basetype))
9271 cxx_incomplete_type_error (instance, basetype);
9272 else if (optype)
9273 error ("no matching function for call to %<%T::operator %T(%A)%#V%>",
9274 basetype, optype, build_tree_list_vec (user_args),
9275 TREE_TYPE (instance));
9276 else
9277 {
9278 /* Special-case for when there's a single candidate that's failing
9279 due to a bad argument type. */
9280 if (z_candidate *candidate = single_z_candidate (candidates))
9281 if (const conversion_info *conv
9282 = maybe_get_bad_conversion_for_unmatched_call (candidate))
9283 {
9284 complain_about_bad_argument (conv->loc,
9285 conv->from, conv->to_type,
9286 candidate->fn, conv->n_arg);
9287 return;
9288 }
9289
9290 tree arglist = build_tree_list_vec (user_args);
9291 tree errname = name;
9292 bool twiddle = false;
9293 if (IDENTIFIER_CDTOR_P (errname))
9294 {
9295 twiddle = IDENTIFIER_DTOR_P (errname);
9296 errname = constructor_name (basetype);
9297 }
9298 if (explicit_targs)
9299 errname = lookup_template_function (errname, explicit_targs);
9300 if (skip_first_for_error)
9301 arglist = TREE_CHAIN (arglist);
9302 error ("no matching function for call to %<%T::%s%E(%A)%#V%>",
9303 basetype, &"~"[!twiddle], errname, arglist,
9304 TREE_TYPE (instance));
9305 }
9306 print_z_candidates (location_of (name), candidates);
8958 } 9307 }
8959 9308
8960 /* Build a call to "INSTANCE.FN (ARGS)". If FN_P is non-NULL, it will 9309 /* Build a call to "INSTANCE.FN (ARGS)". If FN_P is non-NULL, it will
8961 be set, upon return, to the function called. ARGS may be NULL. 9310 be set, upon return, to the function called. ARGS may be NULL.
8962 This may change ARGS. */ 9311 This may change ARGS. */
9024 name = DECL_NAME (fn); 9373 name = DECL_NAME (fn);
9025 9374
9026 basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance)); 9375 basetype = TYPE_MAIN_VARIANT (TREE_TYPE (instance));
9027 gcc_assert (CLASS_TYPE_P (basetype)); 9376 gcc_assert (CLASS_TYPE_P (basetype));
9028 9377
9029 if (processing_template_decl)
9030 {
9031 orig_args = args == NULL ? NULL : make_tree_vector_copy (*args);
9032 instance = build_non_dependent_expr (instance);
9033 if (args != NULL)
9034 make_args_non_dependent (*args);
9035 }
9036
9037 user_args = args == NULL ? NULL : *args; 9378 user_args = args == NULL ? NULL : *args;
9038 /* Under DR 147 A::A() is an invalid constructor call, 9379 /* Under DR 147 A::A() is an invalid constructor call,
9039 not a functional cast. */ 9380 not a functional cast. */
9040 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)) 9381 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
9041 { 9382 {
9042 if (! (complain & tf_error)) 9383 if (! (complain & tf_error))
9043 return error_mark_node; 9384 return error_mark_node;
9044 9385
9045 basetype = DECL_CONTEXT (fn); 9386 basetype = DECL_CONTEXT (fn);
9046 name = constructor_name (basetype); 9387 name = constructor_name (basetype);
9388 auto_diagnostic_group d;
9047 if (permerror (input_location, 9389 if (permerror (input_location,
9048 "cannot call constructor %<%T::%D%> directly", 9390 "cannot call constructor %<%T::%D%> directly",
9049 basetype, name)) 9391 basetype, name))
9050 inform (input_location, "for a function-style cast, remove the " 9392 inform (input_location, "for a function-style cast, remove the "
9051 "redundant %<::%D%>", name); 9393 "redundant %<::%D%>", name);
9052 call = build_functional_cast (basetype, build_tree_list_vec (user_args), 9394 call = build_functional_cast (basetype, build_tree_list_vec (user_args),
9053 complain); 9395 complain);
9054 return call; 9396 return call;
9055 } 9397 }
9056 9398
9399 if (processing_template_decl)
9400 {
9401 orig_args = args == NULL ? NULL : make_tree_vector_copy (*args);
9402 instance = build_non_dependent_expr (instance);
9403 if (args != NULL)
9404 make_args_non_dependent (*args);
9405 }
9406
9057 /* Process the argument list. */ 9407 /* Process the argument list. */
9058 if (args != NULL && *args != NULL) 9408 if (args != NULL && *args != NULL)
9059 { 9409 {
9060 *args = resolve_args (*args, complain); 9410 *args = resolve_args (*args, complain);
9061 if (*args == NULL) 9411 if (*args == NULL)
9062 return error_mark_node; 9412 return error_mark_node;
9413 user_args = *args;
9063 } 9414 }
9064 9415
9065 /* Consider the object argument to be used even if we end up selecting a 9416 /* Consider the object argument to be used even if we end up selecting a
9066 static member function. */ 9417 static member function. */
9067 instance = mark_type_use (instance); 9418 instance = mark_type_use (instance);
9170 candidates = splice_viable (candidates, false, &any_viable_p); 9521 candidates = splice_viable (candidates, false, &any_viable_p);
9171 9522
9172 if (!any_viable_p) 9523 if (!any_viable_p)
9173 { 9524 {
9174 if (complain & tf_error) 9525 if (complain & tf_error)
9175 { 9526 complain_about_no_candidates_for_method_call (instance, candidates,
9176 if (!COMPLETE_OR_OPEN_TYPE_P (basetype)) 9527 explicit_targs, basetype,
9177 cxx_incomplete_type_error (instance, basetype); 9528 optype, name,
9178 else if (optype) 9529 skip_first_for_error,
9179 error ("no matching function for call to %<%T::operator %T(%A)%#V%>", 9530 user_args);
9180 basetype, optype, build_tree_list_vec (user_args),
9181 TREE_TYPE (instance));
9182 else
9183 {
9184 tree arglist = build_tree_list_vec (user_args);
9185 tree errname = name;
9186 bool twiddle = false;
9187 if (IDENTIFIER_CDTOR_P (errname))
9188 {
9189 twiddle = IDENTIFIER_DTOR_P (errname);
9190 errname = constructor_name (basetype);
9191 }
9192 if (explicit_targs)
9193 errname = lookup_template_function (errname, explicit_targs);
9194 if (skip_first_for_error)
9195 arglist = TREE_CHAIN (arglist);
9196 error ("no matching function for call to %<%T::%s%E(%A)%#V%>",
9197 basetype, &"~"[!twiddle], errname, arglist,
9198 TREE_TYPE (instance));
9199 }
9200 print_z_candidates (location_of (name), candidates);
9201 }
9202 call = error_mark_node; 9531 call = error_mark_node;
9203 } 9532 }
9204 else 9533 else
9205 { 9534 {
9206 cand = tourney (candidates, complain); 9535 cand = tourney (candidates, complain);
9214 { 9543 {
9215 pretty_name = name_as_c_string (name, basetype, &free_p); 9544 pretty_name = name_as_c_string (name, basetype, &free_p);
9216 arglist = build_tree_list_vec (user_args); 9545 arglist = build_tree_list_vec (user_args);
9217 if (skip_first_for_error) 9546 if (skip_first_for_error)
9218 arglist = TREE_CHAIN (arglist); 9547 arglist = TREE_CHAIN (arglist);
9548 auto_diagnostic_group d;
9219 if (!any_strictly_viable (candidates)) 9549 if (!any_strictly_viable (candidates))
9220 error ("no matching function for call to %<%s(%A)%>", 9550 error ("no matching function for call to %<%s(%A)%>",
9221 pretty_name, arglist); 9551 pretty_name, arglist);
9222 else 9552 else
9223 error ("call of overloaded %<%s(%A)%> is ambiguous", 9553 error ("call of overloaded %<%s(%A)%> is ambiguous",
9300 out to be a static member function, `a' is 9630 out to be a static member function, `a' is
9301 none-the-less evaluated. */ 9631 none-the-less evaluated. */
9302 if (TREE_CODE (TREE_TYPE (fn)) != METHOD_TYPE 9632 if (TREE_CODE (TREE_TYPE (fn)) != METHOD_TYPE
9303 && !is_dummy_object (instance) 9633 && !is_dummy_object (instance)
9304 && TREE_SIDE_EFFECTS (instance)) 9634 && TREE_SIDE_EFFECTS (instance))
9305 call = build2 (COMPOUND_EXPR, TREE_TYPE (call), 9635 {
9306 instance, call); 9636 /* But avoid the implicit lvalue-rvalue conversion when 'a'
9637 is volatile. */
9638 tree a = instance;
9639 if (TREE_THIS_VOLATILE (a))
9640 a = build_this (a);
9641 call = build2 (COMPOUND_EXPR, TREE_TYPE (call), a, call);
9642 }
9307 else if (call != error_mark_node 9643 else if (call != error_mark_node
9308 && DECL_DESTRUCTOR_P (cand->fn) 9644 && DECL_DESTRUCTOR_P (cand->fn)
9309 && !VOID_TYPE_P (TREE_TYPE (call))) 9645 && !VOID_TYPE_P (TREE_TYPE (call)))
9310 /* An explicit call of the form "x->~X()" has type 9646 /* An explicit call of the form "x->~X()" has type
9311 "void". However, on platforms where destructors 9647 "void". However, on platforms where destructors
10096 && !DECL_CONSTRUCTOR_P (w->fn) && !DECL_CONSTRUCTOR_P (l->fn)) 10432 && !DECL_CONSTRUCTOR_P (w->fn) && !DECL_CONSTRUCTOR_P (l->fn))
10097 { 10433 {
10098 tree t = TREE_TYPE (TREE_TYPE (l->fn)); 10434 tree t = TREE_TYPE (TREE_TYPE (l->fn));
10099 tree f = TREE_TYPE (TREE_TYPE (w->fn)); 10435 tree f = TREE_TYPE (TREE_TYPE (w->fn));
10100 10436
10101 if (TREE_CODE (t) == TREE_CODE (f) && POINTER_TYPE_P (t)) 10437 if (TREE_CODE (t) == TREE_CODE (f) && INDIRECT_TYPE_P (t))
10102 { 10438 {
10103 t = TREE_TYPE (t); 10439 t = TREE_TYPE (t);
10104 f = TREE_TYPE (f); 10440 f = TREE_TYPE (f);
10105 } 10441 }
10106 if (!comp_ptr_ttypes (t, f)) 10442 if (!comp_ptr_ttypes (t, f))
10112 if (!give_warning) 10448 if (!give_warning)
10113 /*NOP*/; 10449 /*NOP*/;
10114 else if (warn) 10450 else if (warn)
10115 { 10451 {
10116 tree source = source_type (w->convs[0]); 10452 tree source = source_type (w->convs[0]);
10117 if (! DECL_CONSTRUCTOR_P (w->fn)) 10453 if (INDIRECT_TYPE_P (source))
10118 source = TREE_TYPE (source); 10454 source = TREE_TYPE (source);
10455 auto_diagnostic_group d;
10119 if (warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn) 10456 if (warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn)
10120 && warning (OPT_Wconversion, " for conversion from %qH to %qI", 10457 && warning (OPT_Wconversion, " for conversion from %qH to %qI",
10121 source, w->second_conv->type)) 10458 source, w->second_conv->type))
10122 { 10459 {
10123 inform (input_location, " because conversion sequence for the argument is better"); 10460 inform (input_location, " because conversion sequence for the argument is better");
10341 { 10678 {
10342 if (warn) 10679 if (warn)
10343 { 10680 {
10344 if (complain & tf_error) 10681 if (complain & tf_error)
10345 { 10682 {
10683 auto_diagnostic_group d;
10346 if (permerror (input_location, 10684 if (permerror (input_location,
10347 "default argument mismatch in " 10685 "default argument mismatch in "
10348 "overload resolution")) 10686 "overload resolution"))
10349 { 10687 {
10350 inform (DECL_SOURCE_LOCATION (cand1->fn), 10688 inform (DECL_SOURCE_LOCATION (cand1->fn),
10392 /* Don't choose a deleted function over ambiguity. */ 10730 /* Don't choose a deleted function over ambiguity. */
10393 if (DECL_P (w->fn) && DECL_DELETED_FN (w->fn)) 10731 if (DECL_P (w->fn) && DECL_DELETED_FN (w->fn))
10394 return 0; 10732 return 0;
10395 if (warn) 10733 if (warn)
10396 { 10734 {
10735 auto_diagnostic_group d;
10397 pedwarn (input_location, 0, 10736 pedwarn (input_location, 0,
10398 "ISO C++ says that these are ambiguous, even " 10737 "ISO C++ says that these are ambiguous, even "
10399 "though the worst conversion for the first is better than " 10738 "though the worst conversion for the first is better than "
10400 "the worst conversion for the second:"); 10739 "the worst conversion for the second:");
10401 print_z_candidate (input_location, _("candidate 1:"), w); 10740 print_z_candidate (input_location, _("candidate 1:"), w);
10548 perform_implicit_conversion_flags (tree type, tree expr, 10887 perform_implicit_conversion_flags (tree type, tree expr,
10549 tsubst_flags_t complain, int flags) 10888 tsubst_flags_t complain, int flags)
10550 { 10889 {
10551 conversion *conv; 10890 conversion *conv;
10552 void *p; 10891 void *p;
10553 location_t loc = EXPR_LOC_OR_LOC (expr, input_location); 10892 location_t loc = cp_expr_loc_or_loc (expr, input_location);
10893
10894 if (TYPE_REF_P (type))
10895 expr = mark_lvalue_use (expr);
10896 else
10897 expr = mark_rvalue_use (expr);
10554 10898
10555 if (error_operand_p (expr)) 10899 if (error_operand_p (expr))
10556 return error_mark_node; 10900 return error_mark_node;
10557 10901
10558 /* Get the high-water mark for the CONVERSION_OBSTACK. */ 10902 /* Get the high-water mark for the CONVERSION_OBSTACK. */
10571 if (TREE_TYPE (expr) == unknown_type_node) 10915 if (TREE_TYPE (expr) == unknown_type_node)
10572 instantiate_type (type, expr, complain); 10916 instantiate_type (type, expr, complain);
10573 else if (invalid_nonstatic_memfn_p (loc, expr, complain)) 10917 else if (invalid_nonstatic_memfn_p (loc, expr, complain))
10574 /* We gave an error. */; 10918 /* We gave an error. */;
10575 else 10919 else
10576 error_at (loc, "could not convert %qE from %qH to %qI", expr, 10920 {
10577 TREE_TYPE (expr), type); 10921 range_label_for_type_mismatch label (TREE_TYPE (expr), type);
10922 gcc_rich_location rich_loc (loc, &label);
10923 error_at (&rich_loc, "could not convert %qE from %qH to %qI",
10924 expr, TREE_TYPE (expr), type);
10925 }
10578 } 10926 }
10579 expr = error_mark_node; 10927 expr = error_mark_node;
10580 } 10928 }
10581 else if (processing_template_decl && conv->kind != ck_identity) 10929 else if (processing_template_decl && conv->kind != ck_identity)
10582 { 10930 {
10647 conv = implicit_conversion (type, TREE_TYPE (expr), expr, 10995 conv = implicit_conversion (type, TREE_TYPE (expr), expr,
10648 c_cast_p, 10996 c_cast_p,
10649 LOOKUP_NORMAL, complain); 10997 LOOKUP_NORMAL, complain);
10650 if (!conv || conv->bad_p) 10998 if (!conv || conv->bad_p)
10651 expr = NULL_TREE; 10999 expr = NULL_TREE;
11000 else if (processing_template_decl && conv->kind != ck_identity)
11001 {
11002 /* In a template, we are only concerned about determining the
11003 type of non-dependent expressions, so we do not have to
11004 perform the actual conversion. But for initializers, we
11005 need to be able to perform it at instantiation
11006 (or instantiate_non_dependent_expr) time. */
11007 expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
11008 IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
11009 }
10652 else 11010 else
10653 expr = convert_like_real (conv, expr, NULL_TREE, 0, 11011 expr = convert_like_real (conv, expr, NULL_TREE, 0,
10654 /*issue_conversion_warnings=*/false, 11012 /*issue_conversion_warnings=*/false,
10655 c_cast_p, 11013 c_cast_p,
10656 complain); 11014 complain);
10778 DECL_NONTRIVIALLY_INITIALIZED_P (var) = true; 11136 DECL_NONTRIVIALLY_INITIALIZED_P (var) = true;
10779 11137
10780 /* If the initializer is constant, put it in DECL_INITIAL so we get 11138 /* If the initializer is constant, put it in DECL_INITIAL so we get
10781 static initialization and use in constant expressions. */ 11139 static initialization and use in constant expressions. */
10782 init = maybe_constant_init (expr); 11140 init = maybe_constant_init (expr);
11141 /* As in store_init_value. */
11142 init = cp_fully_fold (init);
10783 if (TREE_CONSTANT (init)) 11143 if (TREE_CONSTANT (init))
10784 { 11144 {
10785 if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type)) 11145 if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
10786 { 11146 {
10787 /* 5.19 says that a constant expression can include an 11147 /* 5.19 says that a constant expression can include an
10788 lvalue-rvalue conversion applied to "a glvalue of literal type 11148 lvalue-rvalue conversion applied to "a glvalue of literal type
10789 that refers to a non-volatile temporary object initialized 11149 that refers to a non-volatile temporary object initialized
10790 with a constant expression". Rather than try to communicate 11150 with a constant expression". Rather than try to communicate
10791 that this VAR_DECL is a temporary, just mark it constexpr. 11151 that this VAR_DECL is a temporary, just mark it constexpr. */
10792
10793 Currently this is only useful for initializer_list temporaries,
10794 since reference vars can't appear in constant expressions. */
10795 DECL_DECLARED_CONSTEXPR_P (var) = true; 11152 DECL_DECLARED_CONSTEXPR_P (var) = true;
10796 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = true; 11153 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var) = true;
10797 TREE_CONSTANT (var) = true; 11154 TREE_CONSTANT (var) = true;
11155 TREE_READONLY (var) = true;
10798 } 11156 }
10799 DECL_INITIAL (var) = init; 11157 DECL_INITIAL (var) = init;
10800 init = NULL_TREE; 11158 init = NULL_TREE;
10801 } 11159 }
10802 else 11160 else
10867 initialize_reference (tree type, tree expr, 11225 initialize_reference (tree type, tree expr,
10868 int flags, tsubst_flags_t complain) 11226 int flags, tsubst_flags_t complain)
10869 { 11227 {
10870 conversion *conv; 11228 conversion *conv;
10871 void *p; 11229 void *p;
10872 location_t loc = EXPR_LOC_OR_LOC (expr, input_location); 11230 location_t loc = cp_expr_loc_or_loc (expr, input_location);
10873 11231
10874 if (type == error_mark_node || error_operand_p (expr)) 11232 if (type == error_mark_node || error_operand_p (expr))
10875 return error_mark_node; 11233 return error_mark_node;
10876 11234
10877 /* Get the high-water mark for the CONVERSION_OBSTACK. */ 11235 /* Get the high-water mark for the CONVERSION_OBSTACK. */
10930 return init; 11288 return init;
10931 } 11289 }
10932 if (TREE_CODE (sub) != ADDR_EXPR) 11290 if (TREE_CODE (sub) != ADDR_EXPR)
10933 return init; 11291 return init;
10934 /* Deal with binding to a subobject. */ 11292 /* Deal with binding to a subobject. */
10935 for (p = &TREE_OPERAND (sub, 0); TREE_CODE (*p) == COMPONENT_REF; ) 11293 for (p = &TREE_OPERAND (sub, 0);
11294 (TREE_CODE (*p) == COMPONENT_REF
11295 || TREE_CODE (*p) == ARRAY_REF); )
10936 p = &TREE_OPERAND (*p, 0); 11296 p = &TREE_OPERAND (*p, 0);
10937 if (TREE_CODE (*p) == TARGET_EXPR) 11297 if (TREE_CODE (*p) == TARGET_EXPR)
10938 { 11298 {
10939 tree subinit = NULL_TREE; 11299 tree subinit = NULL_TREE;
10940 *p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit); 11300 *p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit);
10955 extend_ref_init_temps (tree decl, tree init, vec<tree, va_gc> **cleanups) 11315 extend_ref_init_temps (tree decl, tree init, vec<tree, va_gc> **cleanups)
10956 { 11316 {
10957 tree type = TREE_TYPE (init); 11317 tree type = TREE_TYPE (init);
10958 if (processing_template_decl) 11318 if (processing_template_decl)
10959 return init; 11319 return init;
10960 if (TREE_CODE (type) == REFERENCE_TYPE) 11320 if (TYPE_REF_P (type))
10961 init = extend_ref_init_temps_1 (decl, init, cleanups); 11321 init = extend_ref_init_temps_1 (decl, init, cleanups);
10962 else 11322 else
10963 { 11323 {
10964 tree ctor = init; 11324 tree ctor = init;
10965 if (TREE_CODE (ctor) == TARGET_EXPR) 11325 if (TREE_CODE (ctor) == TARGET_EXPR)
10997 11357
10998 bool 11358 bool
10999 type_has_extended_temps (tree type) 11359 type_has_extended_temps (tree type)
11000 { 11360 {
11001 type = strip_array_types (type); 11361 type = strip_array_types (type);
11002 if (TREE_CODE (type) == REFERENCE_TYPE) 11362 if (TYPE_REF_P (type))
11003 return true; 11363 return true;
11004 if (CLASS_TYPE_P (type)) 11364 if (CLASS_TYPE_P (type))
11005 { 11365 {
11006 if (is_std_init_list (type)) 11366 if (is_std_init_list (type))
11007 return true; 11367 return true;