This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: c++/1841: Incorrect error: invalid use of member '' in staticmember function


'Neil Booth' wrote:
> 
> Martin Sebor wrote:-
> 
> > > > > struct X
> > > > > {
> > > > >     static int X::* foo () { return &x; };
> > > > >
> > > > >     int x;
> > > > > };
> 
> > The code is incorrect, the type of the result is int*, the type
> > returned from the function is int X::*. Here's the relevant text:
> >
> > 5.3.1, p2: "The result of the unary & operator is a pointer to its
> > operand. The operand shall be an lvalue or a qualified-id. In the
> > first case, if the type of the expression is ``T,'' the type of the
> > result is ``pointer to T.''  In particular, the address of an object
> > of type ``cv T'' is ``pointer to cv T,'' with the same
> > cv-qualifiers. For a qualified-id, if the member is a static member
> > of type ``T'', the type of the result is plain ``pointer to T.'' If
> > the member is a nonstatic member of class C of type T, the type of
> > the result is ``pointer to member of class C of type T.'
> 
> Hi Martin,
> 
> You've confused me now.  According to the last few words of what you
> quoted, I read that the type of "&x" is int X::*.  That is the type
> being returned in the function prototype.  So what's wrong?

Sorry, didn't mean to :) The member is non-static and is not a qualified-id, so
the type is int*. The last two sentences belong together (i.e., the last one
doesn't apply to this case).

Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]