PR c++/12816
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 6 Jan 2004 00:52:10 +0000 (00:52 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 6 Jan 2004 00:52:10 +0000 (00:52 +0000)
* class.c (build_vtbl_ref_1): Do not unconditionally mark vtable
references as constant.

PR c++/12815
* g++.dg/rtti/typeid4.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@75457 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 3a6a6ae..b428cee 100644 (file)
@@ -1,5 +1,9 @@
 2004-01-05  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/12816
+       * class.c (build_vtbl_ref_1): Do not unconditionally mark vtable
+       references as constant.
+
        PR c++/12132
        * parser.c (cp_parser_explicit_instantiation): Improve error
        recovery.
index 2928dd3..31c6d22 100644 (file)
@@ -455,7 +455,7 @@ build_vtbl_ref_1 (tree instance, tree idx)
   assemble_external (vtbl);
 
   aref = build_array_ref (vtbl, idx);
-  TREE_CONSTANT (aref) = 1;
+  TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
 
   return aref;
 }
index 3741b3b..d9c5108 100644 (file)
@@ -1,3 +1,8 @@
+2004-01-05  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/12815
+       * g++.dg/rtti/typeid4.C: New test.
+
 2004-01-05  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * gcc.dg/compat/sdata-section.h: Declare 'abort'.
diff --git a/gcc/testsuite/g++.dg/rtti/typeid4.C b/gcc/testsuite/g++.dg/rtti/typeid4.C
new file mode 100644 (file)
index 0000000..e6a1dce
--- /dev/null
@@ -0,0 +1,26 @@
+// { dg-do run }
+// { dg-options "-O2" }
+
+#include <typeinfo>
+#include <iostream>
+
+struct A { virtual ~A () {} };
+
+struct APtr
+{ 
+  APtr (A* p)  : p_ (p) { }
+  A& operator* () const { return *p_; }
+  A* p_;
+};
+
+int main ()
+{ 
+  APtr ap (new A);
+  std::type_info const* const exp = &typeid (*ap);
+  for (bool cont = true; cont; cont = false)
+    { 
+      std::cout << "inner: cont " << cont << std::endl;
+      if (exp) ;
+    }
+}
+