invalid offsetof from non-POD type
John Quigley
johnw@lowestplane.org
Tue Apr 22 02:40:00 GMT 2003
While it is not standards compliant code, gcc still provides the correct
result. My question is: will gcc continue to provide the correct result in
all cases for the foreseeable future? If so, why not add a flag to disable
this warning and treat this as a "vendor extension" in gcc?
It would make porting to gcc easier. In my case I'm porting a large
application that uses this construct throughout. It will be quite difficult
to make this change and will potentially introduce a lot of bugs. So I would
prefer to avoid it if possible.
On Monday 21 April 2003 6:39 am, Gabriel Dos Reis wrote:
> John Quigley <johnw@lowestplane.org> writes:
> | The code below triggers an "invalid offsetof from non-POD type" warning:
>
> The compiler is right.
>
> | In this case, and in every case I've seen, the warning is a false alarm
> | and
>
> No, that is not false alarm. Your class Foo is *not* a POD, and as
> such your program, technically, invokes undefined behaviour.
>
> [...]
>
> | class Foo
> | {
> | public:
> | int x;
> | char fillerdata[256];
> | int y;
> |
> | Foo()
>
> ^^^^^
>
> Your class has a user-defined constructor, therefore it certainly
> cannot not be a POD. Hence the warning.
>
>
> (if it were only me, I would issue a hard error and halt translation.)
>
> -- Gaby
More information about the Gcc
mailing list