/* The next conversion in the chain. Since the conversions are
arranged from outermost to innermost, the NEXT conversion will
actually be performed before this conversion. This variant is
- used only when KIND is neither ck_identity nor ck_ambig. */
+ used only when KIND is neither ck_identity, ck_ambig nor
+ ck_list. Please use the next_conversion function instead
+ of using this field directly. */
conversion *next;
/* The expression at the beginning of the conversion chain. This
variant is used only if KIND is ck_identity or ck_ambig. */
tree expr;
- /* The array of conversions for an initializer_list. */
+ /* The array of conversions for an initializer_list, so this
+ variant is used only when KIN D is ck_list. */
conversion **list;
} u;
/* The function candidate corresponding to this conversion
static conversion *reference_binding (tree, tree, tree, bool, int);
static conversion *build_conv (conversion_kind, tree, conversion *);
static conversion *build_list_conv (tree, tree, int);
+static conversion *next_conversion (conversion *);
static bool is_subseq (conversion *, conversion *);
static conversion *maybe_handle_ref_bind (conversion **);
static void maybe_handle_implicit_object (conversion **);
static tree source_type (conversion *);
static void add_warning (struct z_candidate *, struct z_candidate *);
static bool reference_compatible_p (tree, tree);
-static conversion *convert_class_to_reference (tree, tree, tree, int);
static conversion *direct_reference_binding (tree, conversion *);
static bool promoted_arithmetic_type_p (tree);
static conversion *conditional_conversion (tree, tree);
}
}
+/* Update various flags in cfun and the call itself based on what is being
+ called. Split out of build_call_a so that bot_manip can use it too. */
+
+void
+set_flags_from_callee (tree call)
+{
+ int nothrow;
+ tree decl = get_callee_fndecl (call);
+
+ /* We check both the decl and the type; a function may be known not to
+ throw without being declared throw(). */
+ nothrow = ((decl && TREE_NOTHROW (decl))
+ || TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (call)))));
+
+ if (!nothrow && at_function_scope_p () && cfun && cp_function_chain)
+ cp_function_chain->can_throw = 1;
+
+ if (decl && TREE_THIS_VOLATILE (decl) && cfun && cp_function_chain)
+ current_function_returns_abnormally = 1;
+
+ TREE_NOTHROW (call) = nothrow;
+}
+
tree
build_call_a (tree function, int n, tree *argarray)
{
- int is_constructor = 0;
- int nothrow;
tree decl;
tree result_type;
tree fntype;
if (SCALAR_TYPE_P (result_type) || VOID_TYPE_P (result_type))
result_type = cv_unqualified (result_type);
- if (TREE_CODE (function) == ADDR_EXPR
- && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
- {
- decl = TREE_OPERAND (function, 0);
- if (!TREE_USED (decl))
- {
- /* We invoke build_call directly for several library
- functions. These may have been declared normally if
- we're building libgcc, so we can't just check
- DECL_ARTIFICIAL. */
- gcc_assert (DECL_ARTIFICIAL (decl)
- || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
- "__", 2));
- mark_used (decl);
- }
- }
- else
- decl = NULL_TREE;
-
- /* We check both the decl and the type; a function may be known not to
- throw without being declared throw(). */
- nothrow = ((decl && TREE_NOTHROW (decl))
- || TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (function))));
+ function = build_call_array_loc (input_location,
+ result_type, function, n, argarray);
+ set_flags_from_callee (function);
- if (!nothrow && at_function_scope_p () && cfun && cp_function_chain)
- cp_function_chain->can_throw = 1;
+ decl = get_callee_fndecl (function);
- if (decl && TREE_THIS_VOLATILE (decl) && cfun && cp_function_chain)
- current_function_returns_abnormally = 1;
+ if (decl && !TREE_USED (decl))
+ {
+ /* We invoke build_call directly for several library
+ functions. These may have been declared normally if
+ we're building libgcc, so we can't just check
+ DECL_ARTIFICIAL. */
+ gcc_assert (DECL_ARTIFICIAL (decl)
+ || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
+ "__", 2));
+ mark_used (decl);
+ }
if (decl && TREE_DEPRECATED (decl))
warn_deprecated_use (decl, NULL_TREE);
require_complete_eh_spec_types (fntype, decl);
- if (decl && DECL_CONSTRUCTOR_P (decl))
- is_constructor = 1;
+ TREE_HAS_CONSTRUCTOR (function) = (decl && DECL_CONSTRUCTOR_P (decl));
/* Don't pass empty class objects by value. This is useful
for tags in STL, which are used to control overload resolution.
We don't need to handle other cases of copying empty classes. */
if (! decl || ! DECL_BUILT_IN (decl))
for (i = 0; i < n; i++)
- if (is_empty_class (TREE_TYPE (argarray[i]))
- && ! TREE_ADDRESSABLE (TREE_TYPE (argarray[i])))
- {
- tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (argarray[i]));
- argarray[i] = build2 (COMPOUND_EXPR, TREE_TYPE (t),
- argarray[i], t);
- }
-
- function = build_call_array_loc (input_location,
- result_type, function, n, argarray);
- TREE_HAS_CONSTRUCTOR (function) = is_constructor;
- TREE_NOTHROW (function) = nothrow;
+ {
+ tree arg = CALL_EXPR_ARG (function, i);
+ if (is_empty_class (TREE_TYPE (arg))
+ && ! TREE_ADDRESSABLE (TREE_TYPE (arg)))
+ {
+ tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
+ arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
+ CALL_EXPR_ARG (function, i) = arg;
+ }
+ }
return function;
}
rr_none,
rr_arity,
rr_explicit_conversion,
+ rr_template_conversion,
rr_arg_conversion,
rr_bad_arg_conversion,
rr_template_unification,
return true;
if (CP_INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
- if (cxx_dialect >= cxx0x)
- {
- t = fold_non_dependent_expr (t);
- t = maybe_constant_value (t);
- if (TREE_CONSTANT (t) && integer_zerop (t))
- return true;
- }
- else
- {
- t = integral_constant_value (t);
- STRIP_NOPS (t);
- if (integer_zerop (t) && !TREE_OVERFLOW (t))
- return true;
- }
+ /* Core issue 903 says only literal 0 is a null pointer constant. */
+ if (cxx_dialect < cxx0x)
+ t = integral_constant_value (t);
+ STRIP_NOPS (t);
+ if (integer_zerop (t) && !TREE_OVERFLOW (t))
+ return true;
}
return false;
}
+/* Returns true iff T is a null member pointer value (4.11). */
+
+bool
+null_member_pointer_value_p (tree t)
+{
+ tree type = TREE_TYPE (t);
+ if (!type)
+ return false;
+ else if (TYPE_PTRMEMFUNC_P (type))
+ return (TREE_CODE (t) == CONSTRUCTOR
+ && integer_zerop (CONSTRUCTOR_ELT (t, 0)->value));
+ else if (TYPE_PTRMEM_P (type))
+ return integer_all_onesp (t);
+ else
+ return false;
+}
+
/* Returns nonzero if PARMLIST consists of only default parms,
ellipsis, and/or undeduced parameter packs. */
}
static struct rejection_reason *
+template_conversion_rejection (tree from, tree to)
+{
+ struct rejection_reason *r = alloc_rejection (rr_template_conversion);
+ r->u.conversion.n_arg = 0;
+ r->u.conversion.from_type = from;
+ r->u.conversion.to_type = to;
+ return r;
+}
+
+static struct rejection_reason *
template_unification_rejection (tree tmpl, tree explicit_targs, tree targs,
const tree *args, unsigned int nargs,
tree return_type, unification_kind_t strict,
return t;
}
+/* Return the next conversion of the conversion chain (if applicable),
+ or NULL otherwise. Please use this function instead of directly
+ accessing fields of struct conversion. */
+
+static conversion *
+next_conversion (conversion *conv)
+{
+ if (conv == NULL
+ || conv->kind == ck_identity
+ || conv->kind == ck_ambig
+ || conv->kind == ck_list)
+ return NULL;
+ return conv->u.next;
+}
+
/* Subroutine of build_aggr_conv: check whether CTOR, a braced-init-list,
is a valid aggregate initializer for array type ATYPE. */
&& at_least_as_qualified_p (t1, t2));
}
-/* Determine whether or not the EXPR (of class type S) can be
- converted to T as in [over.match.ref]. */
-
-static conversion *
-convert_class_to_reference_1 (tree reference_type, tree s, tree expr, int flags)
-{
- tree conversions;
- tree first_arg;
- conversion *conv;
- tree t;
- struct z_candidate *candidates;
- struct z_candidate *cand;
- bool any_viable_p;
-
- if (!expr)
- return NULL;
-
- conversions = lookup_conversions (s);
- if (!conversions)
- return NULL;
-
- /* [over.match.ref]
-
- Assuming that "cv1 T" is the underlying type of the reference
- being initialized, and "cv S" is the type of the initializer
- expression, with S a class type, the candidate functions are
- selected as follows:
-
- --The conversion functions of S and its base classes are
- considered. Those that are not hidden within S and yield type
- "reference to cv2 T2", where "cv1 T" is reference-compatible
- (_dcl.init.ref_) with "cv2 T2", are candidate functions.
-
- The argument list has one argument, which is the initializer
- expression. */
-
- candidates = 0;
-
- /* Conceptually, we should take the address of EXPR and put it in
- the argument list. Unfortunately, however, that can result in
- error messages, which we should not issue now because we are just
- trying to find a conversion operator. Therefore, we use NULL,
- cast to the appropriate type. */
- first_arg = build_int_cst (build_pointer_type (s), 0);
-
- t = TREE_TYPE (reference_type);
-
- /* We're performing a user-defined conversion to a desired type, so set
- this for the benefit of add_candidates. */
- flags |= LOOKUP_NO_CONVERSION;
-
- for (; conversions; conversions = TREE_CHAIN (conversions))
- {
- tree fns = TREE_VALUE (conversions);
- tree binfo = TREE_PURPOSE (conversions);
- struct z_candidate *old_candidates = candidates;;
-
- add_candidates (fns, first_arg, NULL, reference_type,
- NULL_TREE, false,
- binfo, TYPE_BINFO (s),
- flags, &candidates);
-
- for (cand = candidates; cand != old_candidates; cand = cand->next)
- {
- /* Now, see if the conversion function really returns
- an lvalue of the appropriate type. From the
- point of view of unification, simply returning an
- rvalue of the right type is good enough. */
- tree f = cand->fn;
- tree t2 = TREE_TYPE (TREE_TYPE (f));
- if (cand->viable == 0)
- /* Don't bother looking more closely. */;
- else if (TREE_CODE (t2) != REFERENCE_TYPE
- || !reference_compatible_p (t, TREE_TYPE (t2)))
- {
- /* No need to set cand->reason here; this is most likely
- an ambiguous match. If it's not, either this candidate
- will win, or we will have identified a reason for it
- losing already. */
- cand->viable = 0;
- }
- else
- {
- conversion *identity_conv;
- /* Build a standard conversion sequence indicating the
- binding from the reference type returned by the
- function to the desired REFERENCE_TYPE. */
- identity_conv
- = build_identity_conv (TREE_TYPE (TREE_TYPE
- (TREE_TYPE (cand->fn))),
- NULL_TREE);
- cand->second_conv
- = (direct_reference_binding
- (reference_type, identity_conv));
- cand->second_conv->rvaluedness_matches_p
- = TYPE_REF_IS_RVALUE (TREE_TYPE (TREE_TYPE (cand->fn)))
- == TYPE_REF_IS_RVALUE (reference_type);
- cand->second_conv->bad_p |= cand->convs[0]->bad_p;
-
- /* Don't allow binding of lvalues to rvalue references. */
- if (TYPE_REF_IS_RVALUE (reference_type)
- /* Function lvalues are OK, though. */
- && TREE_CODE (TREE_TYPE (reference_type)) != FUNCTION_TYPE
- && !TYPE_REF_IS_RVALUE (TREE_TYPE (TREE_TYPE (cand->fn))))
- cand->second_conv->bad_p = true;
- }
- }
- }
-
- candidates = splice_viable (candidates, pedantic, &any_viable_p);
- /* If none of the conversion functions worked out, let our caller
- know. */
- if (!any_viable_p)
- return NULL;
-
- cand = tourney (candidates);
- if (!cand)
- return NULL;
-
- /* Now that we know that this is the function we're going to use fix
- the dummy first argument. */
- gcc_assert (cand->first_arg == NULL_TREE
- || integer_zerop (cand->first_arg));
- cand->first_arg = build_this (expr);
-
- /* Build a user-defined conversion sequence representing the
- conversion. */
- conv = build_conv (ck_user,
- TREE_TYPE (TREE_TYPE (cand->fn)),
- build_identity_conv (TREE_TYPE (expr), expr));
- conv->cand = cand;
-
- if (cand->viable == -1)
- conv->bad_p = true;
-
- /* Merge it with the standard conversion sequence from the
- conversion function's return type to the desired type. */
- cand->second_conv = merge_conversion_sequences (conv, cand->second_conv);
-
- return cand->second_conv;
-}
-
-/* Wrapper for above. */
-
-static conversion *
-convert_class_to_reference (tree reference_type, tree s, tree expr, int flags)
-{
- conversion *ret;
- bool subtime = timevar_cond_start (TV_OVERLOAD);
- ret = convert_class_to_reference_1 (reference_type, s, expr, flags);
- timevar_cond_stop (TV_OVERLOAD, subtime);
- return ret;
-}
-
/* A reference of the indicated TYPE is being bound directly to the
expression represented by the implicit conversion sequence CONV.
Return a conversion sequence for this binding. */
tree tfrom;
bool related_p;
bool compatible_p;
- cp_lvalue_kind is_lvalue = clk_none;
+ cp_lvalue_kind gl_kind;
+ bool is_lvalue;
if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
{
from = TREE_TYPE (expr);
}
- if (TREE_CODE (from) == REFERENCE_TYPE)
- {
- /* Anything with reference type is an lvalue. */
- is_lvalue = clk_ordinary;
- from = TREE_TYPE (from);
- }
-
if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
{
maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
}
}
- if (is_lvalue == clk_none && expr)
- is_lvalue = real_lvalue_p (expr);
+ if (TREE_CODE (from) == REFERENCE_TYPE)
+ {
+ from = TREE_TYPE (from);
+ if (!TYPE_REF_IS_RVALUE (rfrom)
+ || TREE_CODE (from) == FUNCTION_TYPE)
+ gl_kind = clk_ordinary;
+ else
+ gl_kind = clk_rvalueref;
+ }
+ else if (expr)
+ {
+ gl_kind = lvalue_kind (expr);
+ if (gl_kind & clk_class)
+ /* A class prvalue is not a glvalue. */
+ gl_kind = clk_none;
+ }
+ else
+ gl_kind = clk_none;
+ is_lvalue = gl_kind && !(gl_kind & clk_rvalueref);
tfrom = from;
- if ((is_lvalue & clk_bitfield) != 0)
+ if ((gl_kind & clk_bitfield) != 0)
tfrom = unlowered_expr_type (expr);
/* Figure out whether or not the types are reference-related and
the reference and expression is an lvalue. In DR391, the wording in
[8.5.3/5 dcl.init.ref] is changed to also require direct bindings for
const and rvalue references to rvalues of compatible class type.
- We should also do direct bindings for non-class "rvalues" derived from
- rvalue references. */
+ We should also do direct bindings for non-class xvalues. */
if (compatible_p
&& (is_lvalue
|| (((CP_TYPE_CONST_NON_VOLATILE_P (to)
- && !(flags & LOOKUP_NO_TEMP_BIND))
+ && !(flags & LOOKUP_NO_RVAL_BIND))
|| TYPE_REF_IS_RVALUE (rto))
- && (CLASS_TYPE_P (from)
- || TREE_CODE (from) == ARRAY_TYPE
- || (expr && lvalue_p (expr))))))
+ && (gl_kind
+ || (!(flags & LOOKUP_NO_TEMP_BIND)
+ && (CLASS_TYPE_P (from)
+ || TREE_CODE (from) == ARRAY_TYPE))))))
{
/* [dcl.init.ref]
/* The top-level caller requested that we pretend that the lvalue
be treated as an rvalue. */
conv->rvaluedness_matches_p = TYPE_REF_IS_RVALUE (rto);
+ else if (TREE_CODE (rfrom) == REFERENCE_TYPE)
+ /* Handle rvalue reference to function properly. */
+ conv->rvaluedness_matches_p
+ = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom));
else
conv->rvaluedness_matches_p
= (TYPE_REF_IS_RVALUE (rto) == !is_lvalue);
- if ((is_lvalue & clk_bitfield) != 0
- || ((is_lvalue & clk_packed) != 0 && !TYPE_PACKED (to)))
+ if ((gl_kind & clk_bitfield) != 0
+ || ((gl_kind & clk_packed) != 0 && !TYPE_PACKED (to)))
/* For the purposes of overload resolution, we ignore the fact
this expression is a bitfield or packed field. (In particular,
[over.ics.ref] says specifically that a function with a
the reference is bound to the lvalue result of the conversion
in the second case. */
- conv = convert_class_to_reference (rto, from, expr, flags);
- if (conv)
- return conv;
+ z_candidate *cand = build_user_type_conversion_1 (rto, expr, flags);
+ if (cand)
+ return cand->second_conv;
}
/* From this point on, we conceptually need temporaries, even if we
|| expr == error_mark_node)
return NULL;
+ /* Other flags only apply to the primary function in overload
+ resolution, or after we've chosen one. */
+ flags &= (LOOKUP_ONLYCONVERTING|LOOKUP_NO_CONVERSION|LOOKUP_COPY_PARM
+ |LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND|LOOKUP_PREFER_RVALUE
+ |LOOKUP_NO_NARROWING|LOOKUP_PROTECT);
+
if (TREE_CODE (to) == REFERENCE_TYPE)
conv = reference_binding (to, from, expr, c_cast_p, flags);
else
&& (flags & LOOKUP_NO_CONVERSION) == 0)
{
struct z_candidate *cand;
- int convflags = (flags & (LOOKUP_NO_TEMP_BIND|LOOKUP_ONLYCONVERTING
- |LOOKUP_NO_NARROWING));
if (CLASS_TYPE_P (to)
- && !CLASSTYPE_NON_AGGREGATE (complete_type (to))
- && BRACE_ENCLOSED_INITIALIZER_P (expr))
+ && BRACE_ENCLOSED_INITIALIZER_P (expr)
+ && !CLASSTYPE_NON_AGGREGATE (complete_type (to)))
return build_aggr_conv (to, expr, flags);
- cand = build_user_type_conversion_1 (to, expr, convflags);
+ cand = build_user_type_conversion_1 (to, expr, flags);
if (cand)
conv = cand->second_conv;
|| MAYBE_CLASS_TYPE_P (type1)
|| TREE_CODE (type1) == ENUMERAL_TYPE))
{
+ if (TYPE_PTR_P (type1) || TYPE_PTR_TO_MEMBER_P (type1))
+ {
+ tree cptype = composite_pointer_type (type1, type2,
+ error_mark_node,
+ error_mark_node,
+ CPO_CONVERSION,
+ tf_none);
+ if (cptype != error_mark_node)
+ {
+ build_builtin_candidate
+ (candidates, fnname, cptype, cptype, args, argtypes, flags);
+ return;
+ }
+ }
+
build_builtin_candidate
(candidates, fnname, type1, type1, args, argtypes, flags);
build_builtin_candidate
"conversion", r->u.conversion.from_type,
r->u.conversion.to_type);
break;
+ case rr_template_conversion:
+ inform (loc, " conversion from return type %qT of template "
+ "conversion function specialization to %qT is not an "
+ "exact match", r->u.conversion.from_type,
+ r->u.conversion.to_type);
+ break;
case rr_template_unification:
/* We use template_unification_error_rejection if unification caused
actual non-SFINAE errors, in which case we don't need to repeat
merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
{
conversion **t;
+ bool bad = user_seq->bad_p;
gcc_assert (user_seq->kind == ck_user);
/* Find the end of the second conversion sequence. */
- t = &(std_seq);
- while ((*t)->kind != ck_identity)
- t = &((*t)->u.next);
+ for (t = &std_seq; (*t)->kind != ck_identity; t = &((*t)->u.next))
+ {
+ /* The entire sequence is a user-conversion sequence. */
+ (*t)->user_conv_p = true;
+ if (bad)
+ (*t)->bad_p = true;
+ }
/* Replace the identity conversion with the user conversion
sequence. */
*t = user_seq;
- /* The entire sequence is a user-conversion sequence. */
- std_seq->user_conv_p = true;
-
return std_seq;
}
/* Returns the best overload candidate to perform the requested
conversion. This function is used for three the overloading situations
described in [over.match.copy], [over.match.conv], and [over.match.ref].
- If TOTYPE is a REFERENCE_TYPE, we're trying to find an lvalue binding as
+ If TOTYPE is a REFERENCE_TYPE, we're trying to find a direct binding as
per [dcl.init.ref], so we ignore temporary bindings. */
static struct z_candidate *
build_user_type_conversion_1 (tree totype, tree expr, int flags)
{
struct z_candidate *candidates, *cand;
- tree fromtype = TREE_TYPE (expr);
+ tree fromtype;
tree ctors = NULL_TREE;
tree conv_fns = NULL_TREE;
conversion *conv = NULL;
bool any_viable_p;
int convflags;
+ if (!expr)
+ return NULL;
+
+ fromtype = TREE_TYPE (expr);
+
/* We represent conversion within a hierarchy using RVALUE_CONV and
BASE_CONV, as specified by [over.best.ics]; these become plain
constructor calls, as specified in [dcl.init]. */
struct z_candidate *old_candidates;
/* If we are called to convert to a reference type, we are trying to
- find an lvalue binding, so don't even consider temporaries. If
- we don't find an lvalue binding, the caller will try again to
+ find a direct binding, so don't even consider temporaries. If
+ we don't find a direct binding, the caller will try again to
look for a temporary binding. */
if (TREE_CODE (totype) == REFERENCE_TYPE)
convflags |= LOOKUP_NO_TEMP_BIND;
yield type T or a type that can be converted to type T
with a qualification conversion (4.4) are also candidate
functions. */
+ /* 13.3.1.6 doesn't have a parallel restriction, but it should;
+ I've raised this issue with the committee. --jason 9/2011 */
cand->viable = -1;
cand->reason = explicit_conversion_rejection (rettype, totype);
}
= bad_arg_conversion_rejection (NULL_TREE, -1,
rettype, totype);
}
+ else if (primary_template_instantiation_p (cand->fn)
+ && ics->rank > cr_exact)
+ {
+ /* 13.3.3.1.2: If the user-defined conversion is specified by
+ a specialization of a conversion function template, the
+ second standard conversion sequence shall have exact match
+ rank. */
+ cand->viable = -1;
+ cand->reason = template_conversion_rejection (rettype, totype);
+ }
}
}
? totype : non_reference (TREE_TYPE (TREE_TYPE (cand->fn)))),
build_identity_conv (TREE_TYPE (expr), expr));
conv->cand = cand;
+ if (cand->viable == -1)
+ conv->bad_p = true;
/* Remember that this was a list-initialization. */
if (flags & LOOKUP_NO_NARROWING)
cand->second_conv = merge_conversion_sequences (conv,
cand->second_conv);
- if (cand->viable == -1)
- cand->second_conv->bad_p = true;
-
return cand;
}
return error_mark_node;
}
+ if (flag_tm)
+ tm_malloc_replacement (fn);
+
/* If this function was found without using argument dependent
lookup, then we want to ignore any undeclared friend
functions. */
/* [expr.cond]
If E2 is an lvalue: E1 can be converted to match E2 if E1 can be
- implicitly converted (clause _conv_) to the type "reference to
+ implicitly converted (clause _conv_) to the type "lvalue reference to
T2", subject to the constraint that in the conversion the
- reference must bind directly (_dcl.init.ref_) to E1. */
+ reference must bind directly (_dcl.init.ref_) to an lvalue. */
if (real_lvalue_p (e2))
{
conv = implicit_conversion (build_reference_type (t2),
t1,
e1,
/*c_cast_p=*/false,
- LOOKUP_NO_TEMP_BIND|LOOKUP_ONLYCONVERTING);
+ LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND
+ |LOOKUP_ONLYCONVERTING);
if (conv)
return conv;
}
case POSTDECREMENT_EXPR:
case REALPART_EXPR:
case IMAGPART_EXPR:
+ case ABS_EXPR:
return cp_build_unary_op (code, arg1, candidates != 0, complain);
case ARRAY_REF:
static void
conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
{
- tree t = non_reference (totype);
-
/* Issue warnings about peculiar, but valid, uses of NULL. */
- if (expr == null_node && TREE_CODE (t) != BOOLEAN_TYPE && ARITHMETIC_TYPE_P (t))
+ if (expr == null_node && TREE_CODE (totype) != BOOLEAN_TYPE
+ && ARITHMETIC_TYPE_P (totype))
{
if (fn)
warning_at (input_location, OPT_Wconversion_null,
argnum, fn);
else
warning_at (input_location, OPT_Wconversion_null,
- "converting to non-pointer type %qT from NULL", t);
+ "converting to non-pointer type %qT from NULL", totype);
}
/* Issue warnings if "false" is converted to a NULL pointer */
- else if (expr == boolean_false_node && POINTER_TYPE_P (t))
+ else if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE
+ && TYPE_PTR_P (totype))
{
if (fn)
warning_at (input_location, OPT_Wconversion_null,
"of %qD", argnum, fn);
else
warning_at (input_location, OPT_Wconversion_null,
- "converting %<false%> to pointer type %qT", t);
+ "converting %<false%> to pointer type %qT", totype);
}
}
diagnostic_t diag_kind;
int flags;
+ if (convs->bad_p && !(complain & tf_error))
+ return error_mark_node;
+
if (convs->bad_p
&& convs->kind != ck_user
&& convs->kind != ck_list
&& convs->kind != ck_ambig
- && convs->kind != ck_ref_bind
+ && (convs->kind != ck_ref_bind
+ || convs->user_conv_p)
&& convs->kind != ck_rvalue
&& convs->kind != ck_base)
{
&& BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value))
permerror (input_location, "too many braces around initializer for %qT", totype);
- for (; t; t = convs->u.next)
+ for (; t ; t = next_conversion (t))
{
if (t->kind == ck_user && t->cand->reason)
{
/*issue_conversion_warnings=*/false,
/*c_cast_p=*/false,
complain);
- return cp_convert (totype, expr);
+ if (convs->kind == ck_ref_bind)
+ return convert_to_reference (totype, expr, CONV_IMPLICIT,
+ LOOKUP_NORMAL, NULL_TREE);
+ else
+ return cp_convert (totype, expr);
}
else if (t->kind == ck_user || !t->bad_p)
{
else if (t->kind == ck_identity)
break;
}
- if (complain & tf_error)
- {
- permerror (input_location, "invalid conversion from %qT to %qT", TREE_TYPE (expr), totype);
- if (fn)
- permerror (DECL_SOURCE_LOCATION (fn),
- " initializing argument %P of %qD", argnum, fn);
- }
- else
- return error_mark_node;
+
+ permerror (input_location, "invalid conversion from %qT to %qT",
+ TREE_TYPE (expr), totype);
+ if (fn)
+ permerror (DECL_SOURCE_LOCATION (fn),
+ " initializing argument %P of %qD", argnum, fn);
return cp_convert (totype, expr);
}
&& CONSTRUCTOR_NELTS (expr) == 0
&& TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
{
+ bool direct = CONSTRUCTOR_IS_DIRECT_INIT (expr);
expr = build_value_init (totype, complain);
expr = get_target_expr_sfinae (expr, complain);
if (expr != error_mark_node)
- TARGET_EXPR_LIST_INIT_P (expr) = true;
+ {
+ TARGET_EXPR_LIST_INIT_P (expr) = true;
+ TARGET_EXPR_DIRECT_INIT_P (expr) = direct;
+ }
return expr;
}
/* When converting from an init list we consider explicit
constructors, but actually trying to call one is an error. */
if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
+ /* Unless this is for direct-list-initialization. */
+ && !(BRACE_ENCLOSED_INITIALIZER_P (expr)
+ && CONSTRUCTOR_IS_DIRECT_INIT (expr))
/* Unless we're calling it for value-initialization from an
empty list, since that is handled separately in 8.5.4. */
&& cand->num_convs > 0)
{
- if (complain & tf_error)
- error ("converting to %qT from initializer list would use "
- "explicit constructor %qD", totype, convfn);
- else
- return error_mark_node;
+ error ("converting to %qT from initializer list would use "
+ "explicit constructor %qD", totype, convfn);
}
/* Set user_conv_p on the argument conversions, so rvalue/base
leave it as an lvalue. */
if (inner >= 0)
{
- expr = decl_constant_value (expr);
+ expr = decl_constant_value_safe (expr);
if (expr == null_node && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (totype))
/* If __null has been converted to an integer type, we do not
want to warn about uses of EXPR as an integer, rather than
}
return expr;
case ck_ambig:
+ /* We leave bad_p off ck_ambig because overload resolution considers
+ it valid, it just fails when we try to perform it. So we need to
+ check complain here, too. */
if (complain & tf_error)
{
/* Call build_user_type_conversion again for the error. */
/* Copy-list-initialization doesn't actually involve a copy. */
return expr;
expr = build_temp (expr, totype, flags, &diag_kind, complain);
- if (diag_kind && fn)
- {
- if ((complain & tf_error))
- emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION (fn), 0,
- " initializing argument %P of %qD", argnum, fn);
- else if (diag_kind == DK_ERROR)
- return error_mark_node;
- }
+ if (diag_kind && fn && complain)
+ emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION (fn), 0,
+ " initializing argument %P of %qD", argnum, fn);
return build_cplus_new (totype, expr, complain);
case ck_ref_bind:
{
tree ref_type = totype;
- if (convs->bad_p && TYPE_REF_IS_RVALUE (ref_type)
- && real_lvalue_p (expr))
+ if (convs->bad_p && !convs->u.next->bad_p)
{
- if (complain & tf_error)
- {
- error ("cannot bind %qT lvalue to %qT",
- TREE_TYPE (expr), totype);
- if (fn)
- error (" initializing argument %P of %q+D", argnum, fn);
- }
+ gcc_assert (TYPE_REF_IS_RVALUE (ref_type)
+ && real_lvalue_p (expr));
+
+ error ("cannot bind %qT lvalue to %qT",
+ TREE_TYPE (expr), totype);
+ if (fn)
+ error (" initializing argument %P of %q+D", argnum, fn);
return error_mark_node;
}
if (!CP_TYPE_CONST_NON_VOLATILE_P (type)
&& !TYPE_REF_IS_RVALUE (ref_type))
{
- if (complain & tf_error)
- {
- /* If the reference is volatile or non-const, we
- cannot create a temporary. */
- if (lvalue & clk_bitfield)
- error ("cannot bind bitfield %qE to %qT",
- expr, ref_type);
- else if (lvalue & clk_packed)
- error ("cannot bind packed field %qE to %qT",
- expr, ref_type);
- else
- error ("cannot bind rvalue %qE to %qT", expr, ref_type);
- }
+ /* If the reference is volatile or non-const, we
+ cannot create a temporary. */
+ if (lvalue & clk_bitfield)
+ error ("cannot bind bitfield %qE to %qT",
+ expr, ref_type);
+ else if (lvalue & clk_packed)
+ error ("cannot bind packed field %qE to %qT",
+ expr, ref_type);
+ else
+ error ("cannot bind rvalue %qE to %qT", expr, ref_type);
return error_mark_node;
}
/* If the source is a packed field, and we must use a copy
&& CLASS_TYPE_P (type)
&& type_has_nontrivial_copy_init (type))
{
- if (complain & tf_error)
- error ("cannot bind packed field %qE to %qT",
- expr, ref_type);
+ error ("cannot bind packed field %qE to %qT",
+ expr, ref_type);
return error_mark_node;
}
if (lvalue & clk_bitfield)
we must not perform access checks here. */
push_deferring_access_checks (dk_no_check);
+ /* We must make a copy of ARG, in case subsequent processing
+ alters any part of it. */
arg = break_out_target_exprs (arg);
if (TREE_CODE (arg) == CONSTRUCTOR)
{
}
else
{
- /* We must make a copy of ARG, in case subsequent processing
- alters any part of it. For example, during gimplification a
- cast of the form (T) &X::f (where "f" is a member function)
- will lead to replacing the PTRMEM_CST for &X::f with a
- VAR_DECL. We can avoid the copy for constants, since they
- are never modified in place. */
- if (!CONSTANT_CLASS_P (arg))
- arg = unshare_expr (arg);
arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT,
ICR_DEFAULT_ARGUMENT, fn, parmnum,
tf_warning_or_error);
converted_arg = build_base_path (PLUS_EXPR,
arg,
cand->conversion_path,
- 1);
+ 1, complain);
/* Check that the base class is accessible. */
if (!accessible_base_p (TREE_TYPE (argtype),
BINFO_TYPE (cand->conversion_path), true))
base_binfo = lookup_base (TREE_TYPE (TREE_TYPE (converted_arg)),
TREE_TYPE (parmtype), ba_unique, NULL);
converted_arg = build_base_path (PLUS_EXPR, converted_arg,
- base_binfo, 1);
+ base_binfo, 1, complain);
argarray[j++] = converted_arg;
parm = TREE_CHAIN (parm);
if (TREE_DEPRECATED (fn))
warn_deprecated_use (fn, NULL_TREE);
- argarray[0] = build_base_path (PLUS_EXPR, argarray[0], binfo, 1);
+ argarray[0] = build_base_path (PLUS_EXPR, argarray[0], binfo, 1,
+ complain);
if (TREE_SIDE_EFFECTS (argarray[0]))
argarray[0] = save_expr (argarray[0]);
t = build_pointer_type (TREE_TYPE (fn));
fn = build_call_a (fn, nargs, argarray);
SET_EXPR_LOCATION (fn, loc);
- /* If this call might throw an exception, note that fact. */
fndecl = get_callee_fndecl (fn);
/* Check that arguments to builtin functions match the expectations. */
/* However, for assignment operators, we must convert
dynamically if the base is virtual. */
instance = build_base_path (PLUS_EXPR, instance,
- binfo, /*nonnull=*/1);
+ binfo, /*nonnull=*/1, complain);
}
}
current_in_charge_parm, integer_zero_node),
current_vtt_parm,
vtt);
- gcc_assert (BINFO_SUBVTT_INDEX (binfo));
- sub_vtt = fold_build_pointer_plus (vtt, BINFO_SUBVTT_INDEX (binfo));
+ if (BINFO_SUBVTT_INDEX (binfo))
+ sub_vtt = fold_build_pointer_plus (vtt, BINFO_SUBVTT_INDEX (binfo));
+ else
+ sub_vtt = vtt;
if (args == NULL)
{
&& CONSTRUCTOR_IS_DIRECT_INIT (VEC_index (tree, *args, 0)))
{
tree init_list = VEC_index (tree, *args, 0);
+ tree init = NULL_TREE;
gcc_assert (VEC_length (tree, *args) == 1
&& !(flags & LOOKUP_ONLYCONVERTING));
if (CONSTRUCTOR_NELTS (init_list) == 0
&& TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
&& !processing_template_decl)
+ init = build_value_init (basetype, complain);
+
+ /* If BASETYPE is an aggregate, we need to do aggregate
+ initialization. */
+ else if (CP_AGGREGATE_TYPE_P (basetype))
+ init = digest_init (basetype, init_list, complain);
+
+ if (init)
{
- tree ob, init = build_value_init (basetype, complain);
+ tree ob;
if (integer_zerop (instance_ptr))
return get_target_expr_sfinae (init, complain);
ob = build_fold_indirect_ref (instance_ptr);
return init;
}
+ /* Otherwise go ahead with overload resolution. */
add_list_candidates (fns, first_mem_arg, init_list,
basetype, explicit_targs, template_only,
conversion_path, access_binfo, flags, &candidates);
}
else
{
+ /* Optimize away vtable lookup if we know that this function
+ can't be overridden. */
if (DECL_VINDEX (fn) && ! (flags & LOOKUP_NONVIRTUAL)
- && resolves_to_fixed_type_p (instance, 0))
+ && (resolves_to_fixed_type_p (instance, 0)
+ || DECL_FINAL_P (fn) || CLASSTYPE_FINAL (basetype)))
flags |= LOOKUP_NONVIRTUAL;
if (explicit_targs)
flags |= LOOKUP_EXPLICIT_TMPL_ARGS;
types to which the references refer are the same type except for
top-level cv-qualifiers, and the type to which the reference
initialized by S2 refers is more cv-qualified than the type to
- which the reference initialized by S1 refers */
+ which the reference initialized by S1 refers.
+
+ DR 1328 [over.match.best]: the context is an initialization by
+ conversion function for direct reference binding (13.3.1.6) of a
+ reference to function type, the return type of F1 is the same kind of
+ reference (i.e. lvalue or rvalue) as the reference being initialized,
+ and the return type of F2 is not. */
if (ref_conv1 && ref_conv2)
{
if (!ref_conv1->this_p && !ref_conv2->this_p
- && (TYPE_REF_IS_RVALUE (ref_conv1->type)
- != TYPE_REF_IS_RVALUE (ref_conv2->type)))
+ && (ref_conv1->rvaluedness_matches_p
+ != ref_conv2->rvaluedness_matches_p)
+ && (same_type_p (ref_conv1->type, ref_conv2->type)
+ || (TYPE_REF_IS_RVALUE (ref_conv1->type)
+ != TYPE_REF_IS_RVALUE (ref_conv2->type))))
{
- if (ref_conv1->rvaluedness_matches_p)
- return 1;
- if (ref_conv2->rvaluedness_matches_p)
- return -1;
+ return (ref_conv1->rvaluedness_matches_p
+ - ref_conv2->rvaluedness_matches_p);
}
if (same_type_ignoring_top_level_qualifiers_p (to_type1, to_type2))
if (winner)
return winner;
+ /* DR 495 moved this tiebreaker above the template ones. */
+ /* or, if not that,
+ the context is an initialization by user-defined conversion (see
+ _dcl.init_ and _over.match.user_) and the standard conversion
+ sequence from the return type of F1 to the destination type (i.e.,
+ the type of the entity being initialized) is a better conversion
+ sequence than the standard conversion sequence from the return type
+ of F2 to the destination type. */
+
+ if (cand1->second_conv)
+ {
+ winner = compare_ics (cand1->second_conv, cand2->second_conv);
+ if (winner)
+ return winner;
+ }
+
/* or, if not that,
F1 is a non-template function and F2 is a template function
specialization. */
return winner;
}
- /* or, if not that,
- the context is an initialization by user-defined conversion (see
- _dcl.init_ and _over.match.user_) and the standard conversion
- sequence from the return type of F1 to the destination type (i.e.,
- the type of the entity being initialized) is a better conversion
- sequence than the standard conversion sequence from the return type
- of F2 to the destination type. */
-
- if (cand1->second_conv)
- {
- winner = compare_ics (cand1->second_conv, cand2->second_conv);
- if (winner)
- return winner;
- }
-
/* Check whether we can discard a builtin candidate, either because we
have two identical ones or matching builtin and non-builtin candidates.
}
expr = error_mark_node;
}
- else if (processing_template_decl)
+ else if (processing_template_decl && conv->kind != ck_identity)
{
/* In a template, we are only concerned about determining the
type of non-dependent expressions, so we do not have to
- perform the actual conversion. */
- if (TREE_TYPE (expr) != type)
- expr = build_nop (type, expr);
+ perform the actual conversion. But for initializers, we
+ need to be able to perform it at instantiation
+ (or fold_non_dependent_expr) time. */
+ expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
+ if (!(flags & LOOKUP_ONLYCONVERTING))
+ IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true;
}
else
expr = convert_like (conv, expr, complain);
return expr;
}
+/* When initializing a reference that lasts longer than a full-expression,
+ this special rule applies:
+
+ [class.temporary]
+
+ The temporary to which the reference is bound or the temporary
+ that is the complete object to which the reference is bound
+ persists for the lifetime of the reference.
+
+ The temporaries created during the evaluation of the expression
+ initializing the reference, except the temporary to which the
+ reference is bound, are destroyed at the end of the
+ full-expression in which they are created.
+
+ In that case, we store the converted expression into a new
+ VAR_DECL in a new scope.
+
+ However, we want to be careful not to create temporaries when
+ they are not required. For example, given:
+
+ struct B {};
+ struct D : public B {};
+ D f();
+ const B& b = f();
+
+ there is no need to copy the return value from "f"; we can just
+ extend its lifetime. Similarly, given:
+
+ struct S {};
+ struct T { operator S(); };
+ T t;
+ const S& s = t;
+
+ we can extend the lifetime of the return value of the conversion
+ operator.
+
+ The next several functions are involved in this lifetime extension. */
+
/* DECL is a VAR_DECL whose type is a REFERENCE_TYPE. The reference
is being bound to a temporary. Create and return a new VAR_DECL
with the indicated TYPE; this variable will store the value to
if (TREE_STATIC (decl))
{
/* Namespace-scope or local static; give it a mangled name. */
+ /* FIXME share comdat with decl? */
tree name;
TREE_STATIC (var) = 1;
cleanup for the new variable is returned through CLEANUP, and the
code to initialize the new variable is returned through INITP. */
-tree
-set_up_extended_ref_temp (tree decl, tree expr, tree *cleanup, tree *initp)
+static tree
+set_up_extended_ref_temp (tree decl, tree expr, VEC(tree,gc) **cleanups,
+ tree *initp)
{
tree init;
tree type;
if (TREE_CODE (expr) != TARGET_EXPR)
expr = get_target_expr (expr);
+ if (TREE_CODE (decl) == FIELD_DECL
+ && extra_warnings && !TREE_NO_WARNING (decl))
+ {
+ warning (OPT_Wextra, "a temporary bound to %qD only persists "
+ "until the constructor exits", decl);
+ TREE_NO_WARNING (decl) = true;
+ }
+
+ /* Recursively extend temps in this initializer. */
+ TARGET_EXPR_INITIAL (expr)
+ = extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups);
+
/* If the initializer is constant, put it in DECL_INITIAL so we get
static initialization and use in constant expressions. */
init = maybe_constant_init (expr);
if (TREE_STATIC (var))
init = add_stmt_to_compound (init, register_dtor_fn (var));
else
- *cleanup = cxx_maybe_build_cleanup (var, tf_warning_or_error);
+ {
+ tree cleanup = cxx_maybe_build_cleanup (var, tf_warning_or_error);
+ if (cleanup)
+ VEC_safe_push (tree, gc, *cleanups, cleanup);
+ }
/* We must be careful to destroy the temporary only
after its initialization has taken place. If the
}
/* Convert EXPR to the indicated reference TYPE, in a way suitable for
- initializing a variable of that TYPE. If DECL is non-NULL, it is
- the VAR_DECL being initialized with the EXPR. (In that case, the
- type of DECL will be TYPE.) If DECL is non-NULL, then CLEANUP must
- also be non-NULL, and with *CLEANUP initialized to NULL. Upon
- return, if *CLEANUP is no longer NULL, it will be an expression
- that should be pushed as a cleanup after the returned expression
- is used to initialize DECL.
-
- Return the converted expression. */
+ initializing a variable of that TYPE. */
tree
-initialize_reference (tree type, tree expr, tree decl, tree *cleanup,
- tsubst_flags_t complain)
+initialize_reference (tree type, tree expr,
+ int flags, tsubst_flags_t complain)
{
conversion *conv;
void *p;
p = conversion_obstack_alloc (0);
conv = reference_binding (type, TREE_TYPE (expr), expr, /*c_cast_p=*/false,
- LOOKUP_NORMAL);
+ flags);
if (!conv || conv->bad_p)
{
if (complain & tf_error)
{
- if (!CP_TYPE_CONST_P (TREE_TYPE (type))
- && !TYPE_REF_IS_RVALUE (type)
- && !real_lvalue_p (expr))
+ if (conv)
+ convert_like (conv, expr, complain);
+ else if (!CP_TYPE_CONST_P (TREE_TYPE (type))
+ && !TYPE_REF_IS_RVALUE (type)
+ && !real_lvalue_p (expr))
error ("invalid initialization of non-const reference of "
"type %qT from an rvalue of type %qT",
type, TREE_TYPE (expr));
return error_mark_node;
}
- /* If DECL is non-NULL, then this special rule applies:
-
- [class.temporary]
-
- The temporary to which the reference is bound or the temporary
- that is the complete object to which the reference is bound
- persists for the lifetime of the reference.
+ gcc_assert (conv->kind == ck_ref_bind);
- The temporaries created during the evaluation of the expression
- initializing the reference, except the temporary to which the
- reference is bound, are destroyed at the end of the
- full-expression in which they are created.
+ /* Perform the conversion. */
+ expr = convert_like (conv, expr, complain);
- In that case, we store the converted expression into a new
- VAR_DECL in a new scope.
+ /* Free all the conversions we allocated. */
+ obstack_free (&conversion_obstack, p);
- However, we want to be careful not to create temporaries when
- they are not required. For example, given:
+ return expr;
+}
- struct B {};
- struct D : public B {};
- D f();
- const B& b = f();
+/* Subroutine of extend_ref_init_temps. Possibly extend one initializer,
+ which is bound either to a reference or a std::initializer_list. */
- there is no need to copy the return value from "f"; we can just
- extend its lifetime. Similarly, given:
+static tree
+extend_ref_init_temps_1 (tree decl, tree init, VEC(tree,gc) **cleanups)
+{
+ tree sub = init;
+ tree *p;
+ STRIP_NOPS (sub);
+ if (TREE_CODE (sub) != ADDR_EXPR)
+ return init;
+ /* Deal with binding to a subobject. */
+ for (p = &TREE_OPERAND (sub, 0); TREE_CODE (*p) == COMPONENT_REF; )
+ p = &TREE_OPERAND (*p, 0);
+ if (TREE_CODE (*p) == TARGET_EXPR)
+ {
+ tree subinit = NULL_TREE;
+ *p = set_up_extended_ref_temp (decl, *p, cleanups, &subinit);
+ if (subinit)
+ init = build2 (COMPOUND_EXPR, TREE_TYPE (init), subinit, init);
+ }
+ return init;
+}
- struct S {};
- struct T { operator S(); };
- T t;
- const S& s = t;
+/* INIT is part of the initializer for DECL. If there are any
+ reference or initializer lists being initialized, extend their
+ lifetime to match that of DECL. */
- we can extend the lifetime of the return value of the conversion
- operator. */
- gcc_assert (conv->kind == ck_ref_bind);
- if (decl)
+tree
+extend_ref_init_temps (tree decl, tree init, VEC(tree,gc) **cleanups)
+{
+ tree type = TREE_TYPE (init);
+ if (processing_template_decl)
+ return init;
+ if (TREE_CODE (type) == REFERENCE_TYPE)
+ init = extend_ref_init_temps_1 (decl, init, cleanups);
+ else if (is_std_init_list (type))
{
- tree var;
- tree base_conv_type;
-
- gcc_assert (complain == tf_warning_or_error);
-
- /* Skip over the REF_BIND. */
- conv = conv->u.next;
- /* If the next conversion is a BASE_CONV, skip that too -- but
- remember that the conversion was required. */
- if (conv->kind == ck_base)
- {
- base_conv_type = conv->type;
- conv = conv->u.next;
- }
- else
- base_conv_type = NULL_TREE;
- /* Perform the remainder of the conversion. */
- expr = convert_like_real (conv, expr,
- /*fn=*/NULL_TREE, /*argnum=*/0,
- /*inner=*/-1,
- /*issue_conversion_warnings=*/true,
- /*c_cast_p=*/false,
- complain);
- if (error_operand_p (expr))
- expr = error_mark_node;
- else
+ /* The temporary array underlying a std::initializer_list
+ is handled like a reference temporary. */
+ tree ctor = init;
+ if (TREE_CODE (ctor) == TARGET_EXPR)
+ ctor = TARGET_EXPR_INITIAL (ctor);
+ if (TREE_CODE (ctor) == CONSTRUCTOR)
{
- if (!lvalue_or_rvalue_with_address_p (expr))
- {
- tree init;
- var = set_up_extended_ref_temp (decl, expr, cleanup, &init);
- /* Use its address to initialize the reference variable. */
- expr = build_address (var);
- if (base_conv_type)
- expr = convert_to_base (expr,
- build_pointer_type (base_conv_type),
- /*check_access=*/true,
- /*nonnull=*/true, complain);
- if (init)
- expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), init, expr);
- }
- else
- /* Take the address of EXPR. */
- expr = cp_build_addr_expr (expr, complain);
- /* If a BASE_CONV was required, perform it now. */
- if (base_conv_type)
- expr = (perform_implicit_conversion
- (build_pointer_type (base_conv_type), expr,
- complain));
- expr = build_nop (type, expr);
- if (DECL_DECLARED_CONSTEXPR_P (decl))
- {
- expr = cxx_constant_value (expr);
- DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
- = reduced_constant_expression_p (expr);
- }
+ tree array = CONSTRUCTOR_ELT (ctor, 0)->value;
+ array = extend_ref_init_temps_1 (decl, array, cleanups);
+ CONSTRUCTOR_ELT (ctor, 0)->value = array;
}
}
- else
- /* Perform the conversion. */
- expr = convert_like (conv, expr, complain);
-
- /* Free all the conversions we allocated. */
- obstack_free (&conversion_obstack, p);
+ else if (TREE_CODE (init) == CONSTRUCTOR)
+ {
+ unsigned i;
+ constructor_elt *p;
+ VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
+ FOR_EACH_VEC_ELT (constructor_elt, elts, i, p)
+ p->value = extend_ref_init_temps (decl, p->value, cleanups);
+ }
- return expr;
+ return init;
}
/* Returns true iff TYPE is some variant of std::initializer_list. */