return error_mark_node;
}
- if (! flag_rtti)
- error ("requesting typeid with -fno-rtti");
-
if (processing_template_decl)
return build_min_nt (TYPEID_EXPR, type);
{
tree retval;
tree result, td1, td2, td3, elems, expr2;
+ tree static_type, target_type, boff;
/* If we got here, we can't convert statically. Therefore,
dynamic_cast<D&>(b) (b an object) cannot succeed. */
td1 = get_tinfo_fn_dynamic (expr);
td1 = decay_conversion (td1);
- td2 = decay_conversion
- (get_tinfo_fn (TYPE_MAIN_VARIANT (TREE_TYPE (type))));
- td3 = decay_conversion
- (get_tinfo_fn (TYPE_MAIN_VARIANT (TREE_TYPE (exprtype))));
+ target_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
+ static_type = TYPE_MAIN_VARIANT (TREE_TYPE (exprtype));
+ td2 = decay_conversion (get_tinfo_fn (target_type));
+ td3 = decay_conversion (get_tinfo_fn (static_type));
+
+ /* Determine how T and V are related. */
+ boff = get_dynamic_cast_base_type (static_type, target_type);
elems = tree_cons
(NULL_TREE, td1, tree_cons
(NULL_TREE, td2, tree_cons
- (NULL_TREE, build_int_2 (1, 0), tree_cons
+ (NULL_TREE, boff, tree_cons
(NULL_TREE, expr2, tree_cons
- (NULL_TREE, td3, tree_cons
+ (NULL_TREE, td3, tree_cons
(NULL_TREE, expr1, NULL_TREE))))));
- dcast_fn = get_identifier ("__dynamic_cast");
+ dcast_fn = get_identifier ("__dynamic_cast_2");
if (IDENTIFIER_GLOBAL_VALUE (dcast_fn))
dcast_fn = IDENTIFIER_GLOBAL_VALUE (dcast_fn);
else
tmp = tree_cons
(NULL_TREE, TREE_TYPE (td1), tree_cons
(NULL_TREE, TREE_TYPE (td1), tree_cons
- (NULL_TREE, integer_type_node, tree_cons
+ (NULL_TREE, integer_type_node, tree_cons
(NULL_TREE, ptr_type_node, tree_cons
(NULL_TREE, TREE_TYPE (td1), tree_cons
(NULL_TREE, ptr_type_node, void_list_node))))));
}
}
+ cp_error ("dynamic_cast from non-polymorphic type `%#T'", exprtype);
+ return error_mark_node;
+
fail:
cp_error ("cannot dynamic_cast `%E' (of type `%#T') to type `%#T'",
expr, exprtype, type);
/* Begin processing the function. */
start_function (NULL_TREE, fndecl, NULL_TREE,
SF_DEFAULT | SF_PRE_PARSED);
+ DECL_DEFER_OUTPUT (fndecl) = 1;
store_parm_decls ();
clear_last_expr ();
compound_stmt = begin_compound_stmt (/*has_no_scope=*/0);
/* For convenience, we save away the address of the static
- variable. Since we will process expression-statements between
- here and the end of the function, we must call push_momentary to
- keep ADDR from being overwritten. */
+ variable. */
addr = decay_conversion (tdecl);
- push_momentary ();
/* If the first word of the array (the vtable) is non-zero, we've already
initialized the object, so don't do it again. */
tmp = cp_convert (build_pointer_type (type_info_type_node), addr);
tmp = build_indirect_ref (tmp, 0);
finish_return_stmt (tmp);
- /* Undo the call to push_momentary above. */
- pop_momentary ();
/* Finish the function body. */
finish_compound_stmt (/*has_no_scope=*/0, compound_stmt);
expand_body (finish_function (lineno, 0));