[C++ PATCH] Fix ICE on invalid typeid argument (PR c++/36405)

Jakub Jelinek jakub@redhat.com
Thu Jun 12 10:12:00 GMT 2008


Hi!

PR29928 stopped requiring complete type for typeid for everything but
class types.  This causes ICEs with invalid arguments like non-static member
functions, which have UNKNOWN_TYPE.  I believe the PR29928 change was
because of typeid (void) and typeid (int []) and IMHO we should just special
case those 2 cases - for arrays just require the element type is complete
and allow typeid (void).

Ok for trunk/4.3?

2008-06-12  Jakub Jelinek  <jakub@redhat.com>

	PR c++/36405
	* rtti.c (get_tinfo_decl_dynamic): For array type ensure element type
	is complete, otherwise call complete_type_or_else on all types but
	VOID_TYPE.

	* g++.dg/rtti/typeid8.C: New test.

--- gcc/cp/rtti.c.jj	2008-05-08 01:06:18.000000000 +0200
+++ gcc/cp/rtti.c	2008-06-12 12:00:54.000000000 +0200
@@ -252,7 +252,14 @@ get_tinfo_decl_dynamic (tree exp)
   /* Peel off cv qualifiers.  */
   type = TYPE_MAIN_VARIANT (type);
 
-  if (CLASS_TYPE_P (type))
+  if (TREE_CODE (type) == ARRAY_TYPE)
+    {
+      tree etype = complete_type_or_else (TREE_TYPE (type), exp);
+      if (!etype)
+	return error_mark_node;
+      TREE_TYPE (type) = etype;
+    }
+  else if (TREE_CODE (type) != VOID_TYPE)
     type = complete_type_or_else (type, exp);
 
   if (!type)
--- gcc/testsuite/g++.dg/rtti/typeid8.C.jj	2008-06-12 11:54:40.000000000 +0200
+++ gcc/testsuite/g++.dg/rtti/typeid8.C	2008-06-12 11:57:27.000000000 +0200
@@ -0,0 +1,26 @@
+// PR c++/36405
+// { dg-do compile }
+
+#include <typeinfo>
+
+struct A
+{
+  void foo ()
+  {
+    typeid (foo).name ();	// { dg-error "invalid use of member" }
+    typeid (A::foo).name ();	// { dg-error "invalid use of member" }
+  }
+  void bar ()
+  {
+    typeid (foo).name ();	// { dg-error "invalid use of member" }
+    typeid (A::foo).name ();	// { dg-error "invalid use of member" }
+  }
+  static void baz ()
+  {
+    typeid (baz).name ();
+    typeid (A::baz).name ();
+  }
+};
+
+const char *p1 = typeid (A::foo).name ();	// { dg-error "invalid use of non-static member" }
+const char *p2 = typeid (A::baz).name ();

	Jakub



More information about the Gcc-patches mailing list