diff options
author | Mark Mitchell <mark@codesourcery.com> | 2003-01-10 20:30:56 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2003-01-10 20:30:56 +0000 |
commit | 2050a1bbac14451de357a7d78ffdc6621f49ab30 (patch) | |
tree | 2cea45ec7f50f69c10cd2f4336195b5e297a14be /gcc/cp/rtti.c | |
parent | 0cdca92b467aa92deec2819ff65652b87af6f1ea (diff) | |
download | gcc-2050a1bbac14451de357a7d78ffdc6621f49ab30.zip gcc-2050a1bbac14451de357a7d78ffdc6621f49ab30.tar.gz gcc-2050a1bbac14451de357a7d78ffdc6621f49ab30.tar.bz2 |
re PR c++/9128 (Typeid does not work on polymorphic classes)
PR c++/9128
* g++.dg/rtti/typeid1.C: New file.
PR c++/9153
* g++.dg/parse/lookup1.C: New file.
PR c++/9171
* g++.dg/templ/spec5.C: New file.
* cp-tree.h (reparse_absdcl_as_expr): Remove.
(reparse_absdcl_as_casts): Likewise.
(reparse_decl_as_expr): Likewise.
(finish_decl_parsing): Likewise.
* decl2.c (reparse_absdcl_as_expr): Remove.
(reparse_absdcl_as_casts): Likewise.
(repase_decl_as_expr): Likewise.
(finish_decl_parsing): Likewise.
PR c++/9128
PR c++/9153
PR c++/9171
* parser.c (cp_parser_pre_parsed_nested_name_specifier): New
function.
(cp_parser_nested_name_specifier_opt): Correct the
check_dependency_p false.
(cp_parser_postfix_expression): Fix formatting.
(cp_parser_decl_specifier_seq): Avoid looking for constructor
declarators when possible.
(cp_parser_template_id): Avoid performing name-lookup when
possible.
(cp_parser_class_head): Do not count specializations when counting
levels of templates.
(cp_parser_constructor_declarator_p): Return immediately if
there's no chance that the tokens form a constructor declarator.
* rtti.c (throw_bad_typeid): Add comment. Do not return an
expression with reference type.
(get_tinfo_decl_dynamic): Do not return an expression with
reference type.
(build_typeid): Add comment. Do not return an expression with
reference type.
* typeck.c (build_class_member_access_expr): Improve handling of
conditionals and comma-expressions as objects.
From-SVN: r61166
Diffstat (limited to 'gcc/cp/rtti.c')
-rw-r--r-- | gcc/cp/rtti.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index d89f133..71b8e34 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -174,6 +174,9 @@ throw_bad_cast (void) return build_call (fn, NULL_TREE); } +/* Return an expression for "__cxa_bad_typeid()". The expression + returned is an lvalue of type "const std::type_info". */ + static tree throw_bad_typeid (void) { @@ -187,17 +190,19 @@ throw_bad_typeid (void) fn = push_throw_library_fn (fn, t); } - return build_call (fn, NULL_TREE); + return convert_from_reference (build_call (fn, NULL_TREE)); } -/* Return a pointer to type_info function associated with the expression EXP. - If EXP is a reference to a polymorphic class, return the dynamic type; +/* Return an lvalue expression whose type is "const std::type_info" + and whose value indicates the type of the expression EXP. If EXP + is a reference to a polymorphic class, return the dynamic type; otherwise return the static type of the expression. */ static tree get_tinfo_decl_dynamic (tree exp) { tree type; + tree t; if (exp == error_mark_node) return error_mark_node; @@ -221,18 +226,18 @@ get_tinfo_decl_dynamic (tree exp) if (TYPE_POLYMORPHIC_P (type) && ! resolves_to_fixed_type_p (exp, 0)) { /* build reference to type_info from vtable. */ - tree t; tree index; /* The RTTI information is at index -1. */ index = build_int_2 (-1 * TARGET_VTABLE_DATA_ENTRY_DISTANCE, -1); t = build_vtbl_ref (exp, index); TREE_TYPE (t) = type_info_ptr_type; - return t; } + else + /* Otherwise return the type_info for the static type of the expr. */ + t = get_tinfo_ptr (TYPE_MAIN_VARIANT (type)); - /* Otherwise return the type_info for the static type of the expr. */ - return get_tinfo_ptr (TYPE_MAIN_VARIANT (type)); + return build_indirect_ref (t, NULL); } static bool @@ -253,6 +258,9 @@ typeid_ok_p (void) return true; } +/* Return an expression for "typeid(EXP)". The expression returned is + an lvalue of type "const std::type_info". */ + tree build_typeid (tree exp) { @@ -280,8 +288,6 @@ build_typeid (tree exp) if (exp == error_mark_node) return error_mark_node; - exp = build_indirect_ref (exp, NULL); - if (cond) { tree bad = throw_bad_typeid (); @@ -289,7 +295,7 @@ build_typeid (tree exp) exp = build (COND_EXPR, TREE_TYPE (exp), cond, exp, bad); } - return convert_from_reference (exp); + return exp; } /* Generate the NTBS name of a type. */ |