This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/21407] [4.1 Regression] wrong code with upcast in C++
- From: "giovannibajo at libero dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 May 2005 15:48:50 -0000
- Subject: [Bug tree-optimization/21407] [4.1 Regression] wrong code with upcast in C++
- References: <20050506002331.21407.pinskia@gcc.gnu.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From giovannibajo at libero dot it 2005-05-10 15:48 -------
In my example, B is a (sort-of) derived class and A is a (sort-of) base class.
The C++ frontend should use a subobject at offset 0 to represent the base
class. When you downcast through dynamic_cast, you are not doing anything
different from what foo2() is doing, when called with &sb.sa (read: base class).
So what am I missing? What's the difference between:
----------------------------------
/* C code */
struct A { int a; };
struct B { struct A sa; int b; }
void foo(struct A* pa)
{
((struct B*)pa)->b = 0;
}
void bar(void)
{
struct B sb;
foo(&sb.sa);
}
----------------------------------
and
----------------------------------
/* C++ code */
struct A { int a; };
struct B : struct A { int b; }
void foo(struct A* pa)
{
static_cast<B*>(pa)->b = 0;
}
void bar(void)
{
struct B sb;
foo(&sb);
}
----------------------------------
?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21407