This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
RE: c++/1841: Incorrect error: invalid use of member '' in static member function
- To: nobody at gcc dot gnu dot org
- Subject: RE: c++/1841: Incorrect error: invalid use of member '' in static member function
- From: Jean-Bernard Delva <JeanBernard dot Delva at trisignal dot com>
- Date: 3 Feb 2001 00:06:00 -0000
- Cc: gcc-prs at gcc dot gnu dot org,
- Reply-To: Jean-Bernard Delva <JeanBernard dot Delva at trisignal dot com>
The following reply was made to PR c++/1841; it has been noted by GNATS.
From: Jean-Bernard Delva <JeanBernard.Delva@trisignal.com>
To: 'Neil Booth' <neil@daikokuya.demon.co.uk>
Cc: gcc-gnats@gcc.gnu.org, Normand Barriere
<Normand.Barriere@trisignal.com>, gcc-bugs@gcc.gnu.org
Subject: RE: c++/1841: Incorrect error: invalid use of member '' in static
member function
Date: Fri, 2 Feb 2001 19:01:53 -0500
> In my experience MSVC compiling something tells you very little about
> its correctness, unless you're talking about -ve correlations :-)
Agreed.
That is why I compiled it with the Diab compiler (a well-repected compiler
for embedded systems) and I get the same results.
> > struct X
> > {
> > static int X::* foo () { return &x; };
> >
> > int x;
> > };
>
> Maybe you could explain what this means? I don't think it has a
> meaning. If a member function is static, it applies to the class as a
> type, and not any specific instance. So the 'x' of which instance are
> you trying to return a pointer to?
I understand that this construct is bordering on the isoteric but we need
code that uses this. And after analysis, it seems correct.
Since the static function foo returns a pointer to the data member x, it is
only an offset into the structure. And this offset cannot be used without a
structure instance. So a 'this' isn't really necessary in this case.
Ex:
int main ()
{
int X::* p, x;
X Object;
p = X::foo ();
x = Object.*p;
return 0;
}
If I understand pointer to members correctly, this is the way to use them
(.* and ->*). That is why I think our construct is ok and safe in a static
function. Other compilers seem to think so.
I hope this makes my case more clear.
Jean-Bernard Delva