From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7866 invoked by alias); 12 Jul 2002 19:46:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 7844 invoked by uid 71); 12 Jul 2002 19:46:01 -0000 Resent-Date: 12 Jul 2002 19:46:01 -0000 Resent-Message-ID: <20020712194601.7842.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, jolley@fltsim.stl.mo.boeing.com Received: (qmail 5663 invoked by uid 61); 12 Jul 2002 19:41:22 -0000 Message-Id: <20020712194122.5662.qmail@sources.redhat.com> Date: Fri, 12 Jul 2002 12:46:00 -0000 From: jolley@fltsim.stl.mo.boeing.com Reply-To: jolley@fltsim.stl.mo.boeing.com To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/7288: Base and derived class don't agree on base class variables X-SW-Source: 2002-07/txt/msg00387.txt.bz2 List-Id: >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 = { = {arena = 0x0}, _vptr.derived = 0x1, derived_variable = 0} >How-To-Repeat: #include 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: