public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Reference to pointer and cast - is this a bug ?
@ 2006-11-28 10:15 Philippe Combes
  0 siblings, 0 replies; only message in thread
From: Philippe Combes @ 2006-11-28 10:15 UTC (permalink / raw)
  To: gcc-bugs


Hi all,

Here is code that works exactly as I think it should with g++-2.95, but 
not with
g++-4.0/4.1

#include <iostream>
using namespace std;

class parent
{
public:
         parent():i(0){}
         parent(int i_):i(i_){}
private:
         int i;
};

class child : public parent
{
public:
         child():parent() {}
         child(int i_):parent(i_){}
};

void trace( const parent* const& p_ptr )
{
         cout << "trace called on a reference tp pointer @"
              << (void*)&p_ptr << ": pointer = " << (void*)p_ptr << endl;
}

int main( int argc, char** argv )
{
         const child c(4);
         const child* c_ptr = &c;
         const child* const& c_ptr_r = c_ptr;
         cout << "Call trace on a reference to pointer @"
              << (void*)&c_ptr_r << ": pointer = " << (void*)c_ptr_r << 
endl;
         trace( c_ptr_r );
         return 0;
}


Output with g++-2.95 (which I think is right)
Call trace on a reference to pointer @0xbfb43a40: pointer = 0xbfb43a44
trace called on a reference tp pointer @0xbfb43a40: pointer = 0xbfb43a44

Output with g++-4.0 or 4.1
Call trace on a reference to pointer @0xbfac899c: pointer = 0xbfac89a0
trace called on a reference tp pointer @0xbfac89a4: pointer = 0xbfac89a0

which means that the pointer passed by reference to trace has been 
copied, just
as if it was passed by value.

If this is a bug, I did not find it in the bug database.
If not, can anybody tell me why ?


Thanks in advance,

Philippe



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-11-28 10:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-28 10:15 Reference to pointer and cast - is this a bug ? Philippe Combes

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).