diff options
author | Jason Merrill <jason@redhat.com> | 2011-06-29 10:08:55 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2011-06-29 10:08:55 -0400 |
commit | 2061820e0d4998d1792021cfa7283c2ce345b093 (patch) | |
tree | d366c391a4221521f9154a0ece1a5d527bf85bfd /gcc/cp/call.c | |
parent | 902233e09cf56332a7823aaf4e28807d73229599 (diff) | |
download | gcc-2061820e0d4998d1792021cfa7283c2ce345b093.zip gcc-2061820e0d4998d1792021cfa7283c2ce345b093.tar.gz gcc-2061820e0d4998d1792021cfa7283c2ce345b093.tar.bz2 |
DR 990
DR 990
* call.c (convert_like_real) [ck_user]: Handle value-initialization.
(build_new_method_call_1): Likewise.
* init.c (expand_default_init): Handle direct list-initialization
of aggregates.
From-SVN: r175639
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r-- | gcc/cp/call.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index cfaef7d8..e2d455a 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5592,6 +5592,18 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, tree convfn = cand->fn; unsigned i; + /* If we're initializing from {}, it's value-initialization. */ + if (BRACE_ENCLOSED_INITIALIZER_P (expr) + && CONSTRUCTOR_NELTS (expr) == 0 + && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)) + { + 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; + return expr; + } + expr = mark_rvalue_use (expr); /* When converting from an init list we consider explicit @@ -5634,7 +5646,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, { int nelts = CONSTRUCTOR_NELTS (expr); if (nelts == 0) - expr = build_value_init (totype, tf_warning_or_error); + expr = build_value_init (totype, complain); else if (nelts == 1) expr = CONSTRUCTOR_ELT (expr, 0)->value; else @@ -7138,10 +7150,29 @@ build_new_method_call_1 (tree instance, tree fns, VEC(tree,gc) **args, && BRACE_ENCLOSED_INITIALIZER_P (VEC_index (tree, *args, 0)) && CONSTRUCTOR_IS_DIRECT_INIT (VEC_index (tree, *args, 0))) { + tree init_list = VEC_index (tree, *args, 0); + gcc_assert (VEC_length (tree, *args) == 1 && !(flags & LOOKUP_ONLYCONVERTING)); - add_list_candidates (fns, first_mem_arg, VEC_index (tree, *args, 0), + /* If the initializer list has no elements and T is a class type with + a default constructor, the object is value-initialized. Handle + this here so we don't need to handle it wherever we use + build_special_member_call. */ + if (CONSTRUCTOR_NELTS (init_list) == 0 + && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype) + && !processing_template_decl) + { + tree ob, init = build_value_init (basetype, complain); + if (integer_zerop (instance_ptr)) + return get_target_expr_sfinae (init, complain); + ob = build_fold_indirect_ref (instance_ptr); + init = build2 (INIT_EXPR, TREE_TYPE (ob), ob, init); + TREE_SIDE_EFFECTS (init) = true; + return init; + } + + add_list_candidates (fns, first_mem_arg, init_list, basetype, explicit_targs, template_only, conversion_path, access_binfo, flags, &candidates); } @@ -8365,7 +8396,7 @@ perform_implicit_conversion (tree type, tree expr, tsubst_flags_t complain) permitted. If the conversion is valid, the converted expression is returned. Otherwise, NULL_TREE is returned, except in the case that TYPE is a class type; in that case, an error is issued. If - C_CAST_P is true, then this direction initialization is taking + C_CAST_P is true, then this direct-initialization is taking place as part of a static_cast being attempted as part of a C-style cast. */ |