diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-07-04 05:05:19 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-07-04 05:05:19 +0000 |
commit | a63bc44c929fedcaa9e37ca282aad20d62d8827f (patch) | |
tree | 613039e905b0fbc1fe50e07889b99fdc172e8d14 /gcc/cp/init.c | |
parent | 695790443d9086ea902babc63b12e29e306bd0e6 (diff) | |
download | gcc-a63bc44c929fedcaa9e37ca282aad20d62d8827f.tar.gz |
* call.c (build_addr_func): Handle bound pointers-to-members.
(build_method_call): Do not call resolve_offset_ref.
(implicit_conversion): Likewise.
(resolve_scoped_fn_name): Use finish_non_static_data_member, not
resolve_offset_ref.
(resolve_args): Do not call resolve_offset_ref.
(build_conditional_expr): Likewise.
(build_new_method_call): Likewise.
* cp-tree.def (OFFSET_REF): Update documentation.
(cp_convert_to_pointer): Update handling of conversions from
pointers to members to pointers.
(ocp_convert): Do not call resolve_offset_ref.
(convert_to_void): Likewise.
(build_expr_type_conversion): Likewise.
(delete_sanity): Likewise.
(resolve_offset_ref): Simplify greatly.
(build_vec_delete): Do not call resolve_offset_ref.
* parser.c (cp_parser_postfix_expression): Call resolve_offset_ref
if appropriate.
(cp_parser_unary_expression): Use
cp_parser_simple_cast_expression.
(cp_parser_delete_expression): Likewise.
(cp_parser_cast_expression): Likewise.
(cp_parser_pm_expression): Use cp_parser_binary_op.
(cp_parser_simple_cast_expression): New function.
* rtti.c (build_dynamic_cast_1): Do not call resolve_offset_ref.
* semantics.c (finish_increment_expr): Likewise.
(finish_typeof): Likewise.
* tree.c (lvalue_p_1): Do not handle OFFSET_REF.
* typeck.c (require_complete_type): Do not handle OFFSET_REFs.
(decay_conversion): Do not call resolve_offset_ref.
(finish_class_member_access_expr): Likewise.
(convert_arguments): Likewise.
(build_x_binary_op): Handle DOTSTAR_EXPR.
(condition_conversion): Do not call resolve_offset_ref.
(unary_complex_lvalue): Likewise.
(build_static_cast): Likewise.
(build_reinterpret_cast): Likewise.
(build_const_cast): Likewise.
(build_c_cast): Likewise.
(build_modify_expr): Likewise.
(convert_for_assignment): Likewise.
(convert_for_initialization): Likewise.
* typeck2.c (build_x_arrow): Likewise.
(build_m_component_ref): Simplify.
* g++.old-deja/g++.jason/typeid1.C: Add dg-error marker.
* g++.old-deja/g++.mike/net36.C: Tweak error messages.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@68911 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r-- | gcc/cp/init.c | 131 |
1 files changed, 26 insertions, 105 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c index b88f1f24243..e1a19b1aedc 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1689,121 +1689,45 @@ build_offset_ref (tree type, tree name) tree resolve_offset_ref (tree exp) { - tree type = TREE_TYPE (exp); - tree base = NULL_TREE; tree member; - tree basetype, addr; - - if (TREE_CODE (exp) == OFFSET_REF) - { - member = TREE_OPERAND (exp, 1); - base = TREE_OPERAND (exp, 0); - } - else - { - my_friendly_assert (TREE_CODE (type) == OFFSET_TYPE, 214); - if (TYPE_OFFSET_BASETYPE (type) != current_class_type) - { - error ("object missing in use of pointer-to-member construct"); - return error_mark_node; - } - member = exp; - type = TREE_TYPE (type); - base = current_class_ref; - } - - if (BASELINK_P (member) || TREE_CODE (member) == TEMPLATE_ID_EXPR) - return build_unary_op (ADDR_EXPR, exp, 0); - - if (TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE) - { - if (!flag_ms_extensions) - /* A single non-static member, make sure we don't allow a - pointer-to-member. */ - exp = ovl_cons (member, NULL_TREE); - - return build_unary_op (ADDR_EXPR, exp, 0); - } - - if ((TREE_CODE (member) == VAR_DECL - && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (member)) - && ! TYPE_PTRMEM_P (TREE_TYPE (member))) - || TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE) - { - /* These were static members. */ - if (!cxx_mark_addressable (member)) - return error_mark_node; - return member; - } - if (TREE_CODE (TREE_TYPE (member)) == POINTER_TYPE - && TREE_CODE (TREE_TYPE (TREE_TYPE (member))) == METHOD_TYPE) - return member; + my_friendly_assert (TREE_CODE (exp) == OFFSET_REF, 20030703); - /* Syntax error can cause a member which should - have been seen as static to be grok'd as non-static. */ - if (TREE_CODE (member) == FIELD_DECL && current_class_ref == NULL_TREE) - { - cp_error_at ("member `%D' is non-static but referenced as a static member", - member); - error ("at this point in file"); - return error_mark_node; - } + member = TREE_OPERAND (exp, 1); - /* The first case is really just a reference to a member of `this'. */ - if (TREE_CODE (member) == FIELD_DECL - && (base == current_class_ref || is_dummy_object (base))) - { - tree binfo = NULL_TREE; + /* If MEMBER is non-static, then the program has fallen afoul of + [expr.prim]: - /* Try to get to basetype from 'this'; if that doesn't work, - nothing will. */ - base = current_class_ref; + An id-expression that denotes a nonstatic data member or + nonstatic member function of a class can only be used: - /* First convert to the intermediate base specified, if appropriate. */ - if (TREE_CODE (exp) == OFFSET_REF && TREE_CODE (type) == OFFSET_TYPE) - base = build_scoped_ref (base, TYPE_OFFSET_BASETYPE (type), &binfo); + -- as part of a class member access (_expr.ref_) in which the + object-expression refers to the member's class or a class + derived from that class, or - return build_class_member_access_expr (base, member, - /*access_path=*/NULL_TREE, - /*preserve_reference=*/false); - } + -- to form a pointer to member (_expr.unary.op_), or - /* Ensure that we have an object. */ - if (is_dummy_object (base)) - addr = error_mark_node; - else - /* If this is a reference to a member function, then return the - address of the member function (which may involve going - through the object's vtable), otherwise, return an expression - for the dereferenced pointer-to-member construct. */ - addr = build_unary_op (ADDR_EXPR, base, 0); + -- in the body of a nonstatic member function of that class or + of a class derived from that class (_class.mfct.nonstatic_), or - if (TYPE_PTRMEM_P (TREE_TYPE (member))) + -- in a mem-initializer for a constructor for that class or for + a class derived from that class (_class.base.init_). */ + if (DECL_NONSTATIC_MEMBER_FUNCTION_P (member)) { - if (addr == error_mark_node) - { - error ("object missing in `%E'", exp); - return error_mark_node; - } - - basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (TREE_TYPE (member))); - basetype = lookup_base (TREE_TYPE (TREE_TYPE (addr)), - basetype, ba_check, NULL); - addr = build_base_path (PLUS_EXPR, addr, basetype, 1); - - member = cp_convert (ptrdiff_type_node, member); - - addr = build (PLUS_EXPR, build_pointer_type (type), addr, member); - return build_indirect_ref (addr, 0); + /* In Microsoft mode, treat a non-static member function as if + it were a pointer-to-member. */ + if (flag_ms_extensions) + return build_unary_op (ADDR_EXPR, exp, 0); + error ("invalid use of non-static member function `%D'", member); + return error_mark_node; } - else if (TYPE_PTRMEMFUNC_P (TREE_TYPE (member))) + else if (TREE_CODE (member) == FIELD_DECL) { - return get_member_function_from_ptrfunc (&addr, member); + error ("invalid use of non-static data member `%D'", member); + return error_mark_node; } - abort (); - /* NOTREACHED */ - return NULL_TREE; + + return member; } /* If DECL is a `const' declaration, and its value is a known @@ -3300,9 +3224,6 @@ build_vec_delete (tree base, tree maxindex, tree rval; tree base_init = NULL_TREE; - if (TREE_CODE (base) == OFFSET_REF) - base = resolve_offset_ref (base); - type = TREE_TYPE (base); if (TREE_CODE (type) == POINTER_TYPE) |