Patchwork C++ PATCH for c++/49387 (strange error with typeid)

login
register
mail settings
Submitter Jason Merrill
Date July 1, 2011, 12:53 a.m.
Message ID <4E0D1A6C.5050904@redhat.com>
Download mbox | patch
Permalink /patch/102848/
State New
Headers show

Comments

Jason Merrill - July 1, 2011, 12:53 a.m.
Here we were winding up in get_tinfo_decl with a template type that was 
still incomplete because nothing else had required it to be complete. 
So we initially decide to treat it as a class with no bases.  But then 
the process of creating the initializer for the type_info node causes 
the type to be complete, so we generate an initializer for a class with 
bases, which doesn't match the type we already gave it.

Fixed by instantiating the type in get_tinfo_decl.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 9e18be69b4b6177e94597a20b43ff42f8e8f33bb
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jun 30 18:52:18 2011 -0400

    	PR c++/49387
    	* rtti.c (get_pseudo_ti_index): Call complete_type.

diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index 0feaf07..53404b4 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -406,6 +406,8 @@  get_tinfo_decl (tree type)
     type = build_function_type (TREE_TYPE (type),
 				TREE_CHAIN (TYPE_ARG_TYPES (type)));
 
+  type = complete_type (type);
+
   /* For a class type, the variable is cached in the type node
      itself.  */
   if (CLASS_TYPE_P (type))
diff --git a/gcc/testsuite/g++.dg/rtti/template1.C b/gcc/testsuite/g++.dg/rtti/template1.C
new file mode 100644
index 0000000..e2a0376
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/template1.C
@@ -0,0 +1,23 @@ 
+// PR c++/49387
+
+#include <typeinfo>
+
+struct ResourceMonitorClient { };
+
+template <typename T> struct ResourcePool : public ResourceMonitorClient {
+  virtual ~ResourcePool() { }
+};
+
+template <typename T> struct BaseWriter {
+
+  BaseWriter() {
+    typeid(ResourcePool<int>*);
+  }
+
+  virtual void run() {
+    ResourcePool<int> pool;
+  }
+
+};
+
+BaseWriter<void> b;