re PR c++/32260 (too many warning: dereferencing type-punned pointer will break stric...
authorJakub Jelinek <jakub@redhat.com>
Thu, 1 Nov 2007 22:50:32 +0000 (23:50 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 1 Nov 2007 22:50:32 +0000 (23:50 +0100)
PR c++/32260
* rtti.c (enum_tinfo_kind): Fix TK_TYPE_INFO_TYPE comment.
(typeid_ok_p): Use the same alias set for abi::__type_info_pseudo
as for std::type_info.

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

From-SVN: r129835

gcc/cp/ChangeLog
gcc/cp/rtti.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/rtti/typeid7.C [new file with mode: 0644]

index 6ea272f33f7106c661716b12c5e00da50c416995..c7946ac94694d54cdd086113242bb5825d05c099 100644 (file)
@@ -1,3 +1,10 @@
+2007-11-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/32260
+       * rtti.c (enum_tinfo_kind): Fix TK_TYPE_INFO_TYPE comment.
+       (typeid_ok_p): Use the same alias set for abi::__type_info_pseudo
+       as for std::type_info.
+
 2007-10-31  Paolo Carlini  <pcarlini@suse.de>
 
        PR c++/33494
index 9d2ffdf28235ee0f29abb1bfa0893eefcf0eb96d..92cddbfb37f28f650658fcde7c2fa5bbd3053708 100644 (file)
@@ -79,7 +79,7 @@ DEF_VEC_ALLOC_O(tinfo_s,gc);
 
 typedef enum tinfo_kind
 {
-  TK_TYPE_INFO_TYPE,    /* std::type_info */
+  TK_TYPE_INFO_TYPE,    /* abi::__type_info_pseudo */
   TK_BASE_TYPE,                /* abi::__base_class_type_info */
   TK_BUILTIN_TYPE,     /* abi::__fundamental_type_info */
   TK_ARRAY_TYPE,       /* abi::__array_type_info */
@@ -264,6 +264,8 @@ get_tinfo_decl_dynamic (tree exp)
 static bool
 typeid_ok_p (void)
 {
+  tree pseudo_type_info, type_info_type;
+
   if (! flag_rtti)
     {
       error ("cannot use typeid with -fno-rtti");
@@ -276,6 +278,18 @@ typeid_ok_p (void)
       return false;
     }
 
+  pseudo_type_info
+    = VEC_index (tinfo_s, tinfo_descs, TK_TYPE_INFO_TYPE)->type;
+  type_info_type = TYPE_MAIN_VARIANT (const_type_info_type_node);
+
+  /* Make sure abi::__type_info_pseudo has the same alias set
+     as std::type_info.  */
+  if (! TYPE_ALIAS_SET_KNOWN_P (pseudo_type_info))
+    TYPE_ALIAS_SET (pseudo_type_info) = get_alias_set (type_info_type);
+  else
+    gcc_assert (TYPE_ALIAS_SET (pseudo_type_info)
+               == get_alias_set (type_info_type));
+
   return true;
 }
 
index 3d35ba060bdb47a2363cf0b6aab5da87d2e07c44..74c72305fa3cd34b62331d337a3b584f69cb351d 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/32260
+       * g++.dg/rtti/typeid7.C: New test.
+
 2007-11-01  Tom Tromey  <tromey@redhat.com>
 
        PR preprocessor/30805:
diff --git a/gcc/testsuite/g++.dg/rtti/typeid7.C b/gcc/testsuite/g++.dg/rtti/typeid7.C
new file mode 100644 (file)
index 0000000..7391405
--- /dev/null
@@ -0,0 +1,61 @@
+// PR c++/32260
+// { dg-do compile }
+// { dg-options "-O2 -W -Wall" }
+
+#include <typeinfo>
+
+const std::type_info &
+f1 (int i)
+{
+  return typeid (i + 1);
+}
+
+const std::type_info &
+f2 ()
+{
+  return typeid (int);
+}
+
+struct A
+{
+  A ();
+  virtual ~A ();
+  void foo ();
+};
+
+const std::type_info &
+f3 ()
+{
+  return typeid (A);
+}
+
+const std::type_info &
+f4 (A *p)
+{
+  return typeid (*p);
+}
+
+const std::type_info &
+f5 ()
+{
+  return typeid (int *);
+}
+
+const std::type_info &
+f6 ()
+{
+  return typeid (int [26][12]);
+}
+
+const std::type_info &
+f7 ()
+{
+  return typeid (int [26][12]);
+}
+
+void (A::*pmr) ();
+const std::type_info &
+f8 ()
+{
+  return typeid (pmr);
+}