From: Mark Mitchell Date: Tue, 6 Jan 2004 00:52:10 +0000 (+0000) Subject: re PR c++/12815 (Code compiled with optimization behaves unexpectedly) X-Git-Tag: releases/gcc-3.4.0~1257 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=962c0823997cba18cca85efec200b19fac8e2c87;p=thirdparty%2Fgcc.git re PR c++/12815 (Code compiled with optimization behaves unexpectedly) PR c++/12816 * class.c (build_vtbl_ref_1): Do not unconditionally mark vtable references as constant. PR c++/12815 * g++.dg/rtti/typeid4.C: New test. From-SVN: r75457 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3a6a6ae44b58..b428cee8b4c4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2004-01-05 Mark Mitchell + 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. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 2928dd330710..31c6d2291d99 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3741b3bce481..d9c510868de3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-01-05 Mark Mitchell + + PR c++/12815 + * g++.dg/rtti/typeid4.C: New test. + 2004-01-05 Eric Botcazou * 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 index 000000000000..e6a1dce16f0e --- /dev/null +++ b/gcc/testsuite/g++.dg/rtti/typeid4.C @@ -0,0 +1,26 @@ +// { dg-do run } +// { dg-options "-O2" } + +#include +#include + +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) ; + } +} +