public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/7288: Base and derived class don't agree on base class variables
@ 2002-07-12 12:55 nathan
  0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-07-12 12:55 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, jolley, nobody

Synopsis: Base and derived class don't agree on base class variables

State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Fri Jul 12 12:55:21 2002
State-Changed-Why:
    not a bug. You are assuming that the shm_object base class
    lives at the start of the derived object. In general,
    that is untrue. In particular it is untrue in the 3.0 ABI
    for the non-polymorphic bases of a polymorphic class.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7288


^ permalink raw reply	[flat|nested] 2+ messages in thread

* c++/7288: Base and derived class don't agree on base class variables
@ 2002-07-12 12:46 jolley
  0 siblings, 0 replies; 2+ messages in thread
From: jolley @ 2002-07-12 12:46 UTC (permalink / raw)
  To: gcc-gnats


>Number:         7288
>Category:       c++
>Synopsis:       Base and derived class don't agree on base class variables
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 12 12:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Tom Jolley
>Release:        gcc version 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3)
>Organization:
>Environment:
Red Hat 7.2 with dual Pentium III processors.
>Description:
The derived class, with a virtual function, is derived
from shm_object.  The shm_object class overrides the new
operator.  One of the arguments in the overriden new
operator function is stored in the shm_object.arena
variable.  The debugger shows that the value stored is
showing up in another variable of the derived class,
_vptr.derived.  Here is what the debugger says when in the
derived constructor:
(gdb) print *this
$8 = {<shm_object> = {arena = 0x0}, _vptr.derived = 0x1, derived_variable = 0}
>How-To-Repeat:
#include        <iostream>

using namespace std;

class shm_object {
public:
   void* operator new( size_t size, void *mem_arena ) {
      void*ptr;
      ptr = (void*)new char[size];
      if( ptr ) ((shm_object*)ptr)->arena = mem_arena;
      return ptr;
   }

   void* operator new( size_t size ) {
      void*ptr;
      ptr = (void*)new char[size];
      if( ptr ) ((shm_object*)ptr)->arena = NULL;
      return ptr;
   }

   void operator delete( void *v_ptr ) {
      delete [] (char*)v_ptr;
   }

   void*        arena;
};

class derived : public shm_object {
public:
   derived() {}
   virtual ~derived() {}

   virtual int dummy() { return 0; };

   int derived_variable;
};

int main( int argc, char* argv[] )
{

   derived*     d;

   d = new( (void*)1 ) derived;

   if( d->arena != (void*)1 ) {
      cout << "Arena is invalid" << endl;
   } else {
      cout << "Arena worked" << endl;
   }

   delete d;

   return 0;
}
>Fix:
Unknown
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-07-12 19:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-12 12:55 c++/7288: Base and derived class don't agree on base class variables nathan
  -- strict thread matches above, loose matches on Subject: below --
2002-07-12 12:46 jolley

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