This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Follow up on static bug (is it a bug?)
- To: David Durham <david dot durham at wcom dot com>
- Subject: Re: Follow up on static bug (is it a bug?)
- From: Martin Sebor <sebor at roguewave dot com>
- Date: Tue, 24 Jul 2001 11:19:38 -0600
- CC: gcc-bugs at gcc dot gnu dot org
- Organization: Rogue Wave Software, Inc.
- References: <995994184.15203.6.camel@yardath.jxn.wcom.com>
David Durham wrote:
>
> To repeat...
>
> I believe this is a bug in gcc 3.0
No, it isn't. 9.2, p9:
Except when used to form a pointer to member (5.3.1), when used
in the body of a nonstatic member function of its class or of
a class derived from its class (9.3.1), or when used in
a mem-initializer for a constructor for its class or for a class
derived from its class (12.6.2), a nonstatic data or function member
of a class shall only be referred to with the class member access
syntax (5.2.5).
Regards
Martin
> Forgive me if it's already known about...
>
> The following code used to be valid ( <=2.95.3 ):
>
> struct foo
> {
> char field[25];
>
> static int getSize()
> {
> return(sizeof(field));
^^^^^^^^^^^^^
This will work since the argument of sizeof isn't evaluated:
return sizeof ((foo*)0)->field;
> }
> };
>
>
> Here it reports that in foo::getSize, foo::field cannot be referenced
> since it is non-static and foo::getSize is static, however the used of
> sizeof/typeof/etc should make it valid. Is there something about ANSI
> C99 and the fact that arrays can have non-constant sizes or something?
>
> ...
>
> Also, since then I've discovered that the following is also invalid
>
> sizeof(foo::field)
>
> ... or ...
>
> (&foo::field) <- which should give the offset of the field
>
> This is invalid in any ole non-member function
>
> Thanks,
> -- Davy