Bug 55063 - g++ 3.0.1 fails to allow access to member field address
g++ 3.0.1 fails to allow access to member field address
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: gcc3 (Show other bugs)
7.2
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-10-24 20:36 EDT by Calvin Austin
Modified: 2008-05-01 11:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-12-15 12:59:43 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Calvin Austin 2001-10-24 20:36:46 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.77 [en] (X11; U; SunOS 5.8 sun4u)

Description of problem:
Previously valid C++ code for Windows Visual C++ and
                 Solaris Forte workshop is now failing with gcc 3.0.1
                 worked on previous 2.x trains

                 The change occured during a "function rename"

                
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?r1=1.523&r2=1.524&f=h

                 in particular this line

                 TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P (ref) |=
TYPE_BASE_CONVS_MAY_REQUIRE_CODE_P
                 (basetype);

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1.gcc3 test.cpp
2.
3.
	

Additional info:

#include <stdio.h>
#include <malloc.h>
 
#ifndef NULL
#define NULL 0L
#endif

 

class threadshadow {
public:
    int data;
};

class OSThread {
 public:
 OSThread(int width);
 OSThread(int width, int type);
 virtual void print_raw(const char* c);
};
 void OSThread::print_raw(const char* c) {
}

class Thread : public threadshadow {
public:
   Thread();
   virtual void print_raw(const char* c);
protected:
   OSThread* x2;

};

Thread::Thread() {
    x2=NULL;
}

void Thread::print_raw(const char* c) {
}
 
class JavaThread : public Thread {
public:
     JavaThread();
     int calc() {
        printf("offset=%x\n", int((int)(long)&(((JavaThread*)NULL)->x2)));
        return 0;
     }
};
 
JavaThread::JavaThread() : Thread() {
}

main ()
{
    JavaThread* t=new JavaThread();
    t->calc();
}
Comment 1 Jason Merrill 2002-02-01 12:34:26 EST
The C++ standard specifies that offsetof may only be used for non-POD classes.  
Now, since your testcase doesn't actually use the offsetof macro, just its 
common implementation, it's merely dubious, rather than clearly ill-formed.  
I'll change g++ 3.1 to accept this code with a warning, rather than an error.

In any case, you shouldn't be writing code like this.  If you really need the 
offset, you can use ((char *)&x2 - (char *)this), but for most uses you should 
be using a pointer-to-member instead.

Jason
Comment 2 Alan Cox 2002-12-15 12:59:43 EST
Confirmed ok in 3.2

x1.C: In member function `int JavaThread::calc()':
x1.C:44: warning: invalid offsetof from non-POD type `class Thread'; use
   pointer to member instead

Note You need to log in before you can comment on or make changes to this bug.