public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44733] New: a bug with virtual base class (?)
@ 2010-06-30 21:17 mikeus at hotmail dot ru
2010-06-30 22:28 ` [Bug c++/44733] " redi at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: mikeus at hotmail dot ru @ 2010-06-30 21:17 UTC (permalink / raw)
To: gcc-bugs
Compiling and executing this code:
---------------------------------
#include <iostream>
using namespace std;
void *p;
struct vbase
{
int a;
virtual vbase* me() = 0;
void set_p() { p = me(); };
};
struct derived : virtual vbase
{
int b;
derived* me()
{
cout << "derived::me() = " << this << endl;
return this;
};
};
int main()
{
derived t;
t.set_p();
cout << "p = " << p << endl;
};
---------------------------------
produce the strange results, the output is:
---------------------------------
derived::me() = 0xbff41ab0
p = 0xbff41ab8
---------------------------------
It doesn't metter is me() a pure virtual function or has a body in 'vbase'
class.
Small changes in code, any of these:
1) declaring the return type of me() as void*
2) commenting data member 'int a' in 'vbase' class
3) making 'vbase' non virtual base of 'derived'
give the right result: saved 'this' in 'p' is equal to 'this' of derived class.
Sorry, don't know how to summarize the problem, is it a bug or I misunderstood
some c++ subtle points...
--
Summary: a bug with virtual base class (?)
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mikeus at hotmail dot ru
GCC host triplet: i686-pc-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44733
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/44733] a bug with virtual base class (?)
2010-06-30 21:17 [Bug c++/44733] New: a bug with virtual base class (?) mikeus at hotmail dot ru
@ 2010-06-30 22:28 ` redi at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-06-30 22:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from redi at gcc dot gnu dot org 2010-06-30 22:28 -------
conversion from derived* to vbase* involves adjusting a pointer
in the context of vbase::set_p the value returned from me() is converted to
vbase* so the pointer is adjusted
try changing derived::me() to this:
int b;
derived* me()
{
cout << "derived::me() = " << this << endl;
cout << "derived::me() as vbase = " << (vbase*)this << endl;
return this;
};
you will see that the value is different, and the second value is the one
assigned to ::p
--
redi at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44733
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-06-30 22:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-30 21:17 [Bug c++/44733] New: a bug with virtual base class (?) mikeus at hotmail dot ru
2010-06-30 22:28 ` [Bug c++/44733] " redi at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).