diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-03 21:55:25 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-03 21:55:25 +0000 |
commit | 8999978b6a17d2995fed9ceb36899af63bd24fcf (patch) | |
tree | 843f3d43d5b4320d2aeb9c7f379499f22788a521 /gcc/cp/cvt.c | |
parent | 449db73101208a47b64fc3f0d919b9fec4a5a796 (diff) | |
download | gcc-8999978b6a17d2995fed9ceb36899af63bd24fcf.tar.gz |
PR c++/9878
* call.c (convert_class_to_reference): Correct conversion
sequences.
(reference_binding): Add ref_bound_directly_to_rvalue_p parameter.
(implicit_conversion): Adjust call to reference_binding.
(add_candidate): Change type of candidates parameter.
(add_function_candidate): Likewise.
(add_conv_candidate): Likewise.
(build_builtin_candidate): Likewise.
(add_builtin_candidate): Likewise.
(add_builtin_candidates): Likewise.
(add_template_candidate_real): Likewise.
(add_template_candidate): Likewise.
(add_template_conv_candidate): Likewise.
(build_user_type_conversion_1): Adjust accordingly.
(build_object_call): Likewise.
(build_conditional_expr): Likewise.
(add_candidates): Likewise.
(build_new_op): Likewise.
(convert_like_real): Use USER_CONV_CAND. Use build_nop.
(build_new_method_call): Adjust calls to add_function_candidate.
(make_temporary_var_for_ref_to_temp): New function.
(initialize_reference): Add decl parameter.
* class.c (build_rtti_vtbl_entries): Use build_address and
build_nop.
* cp-tree.h (initialize_reference): Change prototype.
(make_temporary_var_for_ref_to_temp): New function.
(build_type_conversion): Change prototype.
(build_address): New function.
(build_nop): Likewise.
* cvt.c (cp_convert_to_pointer): Adjust call to
build_type_conversion. Avoid indicating redundant NOP_EXPRs.
Use build_nop.
(convert_to_pointer_force): Use build_nop.
(build_up_reference): Use make_temporary_var_for_ref_to_temp.
(convert_to_reference): Adjust call to build_type_conversion.
(ocp_convert): Likewise.
(build_type_conversion): Remove for_sure parameter.
* decl.c (grok_reference_init): Use initialize_reference.
* typeck.c (build_address): New function.
(build_nop): Likewise.
(build_unary_op): Use them.
(build_ptrmemfunc): Tidy slightly.
(convert_for_initialization): Adjust call to
initialize_reference.
* typeck2.c (store_init_value): Remove #if 0'd code.
PR c++/9878
* g++.dg/init/ref1.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@63735 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/cvt.c')
-rw-r--r-- | gcc/cp/cvt.c | 95 |
1 files changed, 27 insertions, 68 deletions
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 73b17e8f054..ba5fbba1a16 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -90,7 +90,7 @@ cp_convert_to_pointer (tree type, tree expr, bool force) return error_mark_node; } - rval = build_type_conversion (type, expr, true); + rval = build_type_conversion (type, expr); if (rval) { if (rval == error_mark_node) @@ -148,31 +148,33 @@ cp_convert_to_pointer (tree type, tree expr, bool force) { enum tree_code code = PLUS_EXPR; tree binfo; + tree intype_class; + tree type_class; + bool same_p; + intype_class = TREE_TYPE (intype); + type_class = TREE_TYPE (type); + + same_p = same_type_p (TYPE_MAIN_VARIANT (intype_class), + TYPE_MAIN_VARIANT (type_class)); + binfo = NULL_TREE; /* Try derived to base conversion. */ - binfo = lookup_base (TREE_TYPE (intype), TREE_TYPE (type), - ba_check, NULL); - if (!binfo) + if (!same_p) + binfo = lookup_base (intype_class, type_class, ba_check, NULL); + if (!same_p && !binfo) { /* Try base to derived conversion. */ - binfo = lookup_base (TREE_TYPE (type), TREE_TYPE (intype), - ba_check, NULL); + binfo = lookup_base (type_class, intype_class, ba_check, NULL); code = MINUS_EXPR; } if (binfo == error_mark_node) return error_mark_node; - if (binfo) + if (binfo || same_p) { - expr = build_base_path (code, expr, binfo, 0); + if (binfo) + expr = build_base_path (code, expr, binfo, 0); /* Add any qualifier conversions. */ - if (!same_type_p (TREE_TYPE (TREE_TYPE (expr)), - TREE_TYPE (type))) - { - expr = build1 (NOP_EXPR, type, expr); - TREE_CONSTANT (expr) = - TREE_CONSTANT (TREE_OPERAND (expr, 0)); - } - return expr; + return build_nop (type, expr); } } @@ -225,9 +227,7 @@ cp_convert_to_pointer (tree type, tree expr, bool force) return error_mark_node; } - rval = build1 (NOP_EXPR, type, expr); - TREE_CONSTANT (rval) = TREE_CONSTANT (expr); - return rval; + return build_nop (type, expr); } else if (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)) return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0); @@ -326,14 +326,9 @@ convert_to_pointer_force (tree type, tree expr) /* Add any qualifier conversions. */ if (!same_type_p (TREE_TYPE (TREE_TYPE (expr)), TREE_TYPE (type))) - { - expr = build1 (NOP_EXPR, type, expr); - TREE_CONSTANT (expr) = - TREE_CONSTANT (TREE_OPERAND (expr, 0)); - } + expr = build_nop (type, expr); return expr; } - } } @@ -354,7 +349,6 @@ build_up_reference (tree type, tree arg, int flags, tree decl) tree rval; tree argtype = TREE_TYPE (arg); tree target_type = TREE_TYPE (type); - tree stmt_expr = NULL_TREE; my_friendly_assert (TREE_CODE (type) == REFERENCE_TYPE, 187); @@ -364,26 +358,7 @@ build_up_reference (tree type, tree arg, int flags, tree decl) here because it needs to live as long as DECL. */ tree targ = arg; - arg = build_decl (VAR_DECL, NULL_TREE, argtype); - DECL_ARTIFICIAL (arg) = 1; - TREE_USED (arg) = 1; - TREE_STATIC (arg) = TREE_STATIC (decl); - - if (TREE_STATIC (decl)) - { - /* Namespace-scope or local static; give it a mangled name. */ - tree name = mangle_ref_init_variable (decl); - DECL_NAME (arg) = name; - SET_DECL_ASSEMBLER_NAME (arg, name); - arg = pushdecl_top_level (arg); - } - else - { - /* Automatic; make sure we handle the cleanup properly. */ - maybe_push_cleanup_level (argtype); - /* Don't push unnamed temps. Do set DECL_CONTEXT, though. */ - DECL_CONTEXT (arg) = current_function_decl; - } + arg = make_temporary_var_for_ref_to_temp (decl); /* Process the initializer for the declaration. */ DECL_INITIAL (arg) = targ; @@ -416,16 +391,7 @@ build_up_reference (tree type, tree arg, int flags, tree decl) else rval = convert_to_pointer_force (build_pointer_type (target_type), rval); - rval = build1 (NOP_EXPR, type, rval); - TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0)); - - /* If we created and initialized a new temporary variable, add the - representation of that initialization to the RVAL. */ - if (stmt_expr) - rval = build (COMPOUND_EXPR, TREE_TYPE (rval), stmt_expr, rval); - - /* And return the result. */ - return rval; + return build_nop (type, rval); } /* Subroutine of convert_to_reference. REFTYPE is the target reference type. @@ -500,7 +466,7 @@ convert_to_reference (tree reftype, tree expr, int convtype, /* Look for a user-defined conversion to lvalue that we can use. */ rval_as_conversion - = build_type_conversion (reftype, expr, 1); + = build_type_conversion (reftype, expr); if (rval_as_conversion && rval_as_conversion != error_mark_node && real_lvalue_p (rval_as_conversion)) @@ -705,7 +671,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags) if (IS_AGGR_TYPE (intype)) { tree rval; - rval = build_type_conversion (type, e, 1); + rval = build_type_conversion (type, e); if (rval) return rval; if (flags & LOOKUP_COMPLAIN) @@ -741,7 +707,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags) if (IS_AGGR_TYPE (TREE_TYPE (e))) { tree rval; - rval = build_type_conversion (type, e, 1); + rval = build_type_conversion (type, e); if (rval) return rval; else @@ -1015,24 +981,17 @@ convert_force (tree type, tree expr, int convtype) allowed (references private members, etc). If no conversion exists, NULL_TREE is returned. - If (FOR_SURE & 1) is nonzero, then we allow this type conversion - to take place immediately. Otherwise, we build a SAVE_EXPR - which can be evaluated if the results are ever needed. - - Changes to this functions should be mirrored in user_harshness. - FIXME: Ambiguity checking is wrong. Should choose one by the implicit object parameter, or by the second standard conversion sequence if that doesn't do it. This will probably wait for an overloading rewrite. (jason 8/9/95) */ tree -build_type_conversion (tree xtype, tree expr, int for_sure) +build_type_conversion (tree xtype, tree expr) { /* C++: check to see if we can convert this aggregate type into the required type. */ - return build_user_type_conversion - (xtype, expr, for_sure ? LOOKUP_NORMAL : 0); + return build_user_type_conversion (xtype, expr, LOOKUP_NORMAL); } /* Convert the given EXPR to one of a group of types suitable for use in an |