public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8378] c++: typeid and instantiation [PR102651] Date: Sun, 15 May 2022 16:29:28 +0000 (GMT) [thread overview] Message-ID: <20220515162928.111D33857356@sourceware.org> (raw) https://gcc.gnu.org/g:5237059e04d105fe5441fa7434699eea9a34bf1b commit r12-8378-g5237059e04d105fe5441fa7434699eea9a34bf1b Author: Jason Merrill <jason@redhat.com> Date: Fri Apr 15 00:11:00 2022 -0400 c++: typeid and instantiation [PR102651] PR49387 was a problem with initially asking for a typeid for a class template specialization before it was complete, and later actually filling in the descriptor when the class was complete, and thus disagreeing on the form of the descriptor. I fixed that by forcing the class to be complete, but this testcase shows why that approach is problematic. So instead let's adjust the type of the descriptor later if needed. PR c++/102651 PR c++/49387 gcc/cp/ChangeLog: * rtti.cc (get_tinfo_decl_direct): Don't complete_type. (emit_tinfo_decl): Update tdesc type if needed. gcc/testsuite/ChangeLog: * g++.dg/rtti/typeid-complete1.C: New test. Diff: --- gcc/cp/rtti.cc | 15 +++++++++++---- gcc/testsuite/g++.dg/rtti/typeid-complete1.C | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/gcc/cp/rtti.cc b/gcc/cp/rtti.cc index a4dedc31f0a..f5b43ec0fb2 100644 --- a/gcc/cp/rtti.cc +++ b/gcc/cp/rtti.cc @@ -446,9 +446,6 @@ get_tinfo_decl_direct (tree type, tree name, int pseudo_ix) gcc_checking_assert (TREE_CODE (type) != METHOD_TYPE); - if (pseudo_ix < 0) - type = complete_type (type); - if (CLASS_TYPE_P (type)) d = CLASSTYPE_TYPEINFO_VAR (TYPE_MAIN_VARIANT (type)); @@ -1693,7 +1690,17 @@ emit_tinfo_decl (tree decl) tree init; DECL_EXTERNAL (decl) = 0; - init = get_pseudo_ti_init (type, get_pseudo_ti_index (type)); + int pseudo_ix = get_pseudo_ti_index (type); + const tinfo_s *ti = get_tinfo_desc (pseudo_ix); + if (TREE_TYPE (decl) != ti->type) + { + /* If the class became complete since we first called get_tinfo_decl, + its type_info descriptor may have switched from __class_type_info + to e.g. __si_class_type_info. */ + TREE_TYPE (decl) = ti->type; + relayout_decl (decl); + } + init = get_pseudo_ti_init (type, pseudo_ix); DECL_INITIAL (decl) = init; mark_used (decl); cp_finish_decl (decl, init, false, NULL_TREE, 0); diff --git a/gcc/testsuite/g++.dg/rtti/typeid-complete1.C b/gcc/testsuite/g++.dg/rtti/typeid-complete1.C new file mode 100644 index 00000000000..8d3fec46801 --- /dev/null +++ b/gcc/testsuite/g++.dg/rtti/typeid-complete1.C @@ -0,0 +1,14 @@ +// PR c++/102651 + +#include <typeinfo> + +template <typename T> +struct S : T{ + T x; +}; + +const void *p; +int main() +{ + p = &typeid( S<void>** ); +}
reply other threads:[~2022-05-15 16:29 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220515162928.111D33857356@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).