------- Additional Comments From squell at alumina dot nl  2005-07-23 03:22 
-------
ptr->f is a constant expression, I believe, since it doesn't access any
object (see 5.19/4, C++ Std), because the expression will resolve to a
static member. But whether I am right or not:

I got to this testcase because I was reading C++'s 9.3.1/2 to decipher g++3.3's
error message. This paragraph reads (relevant text shown);

"When an id-expression [..] not used to form a pointer to member is used 
in the body of a non-static member function [..], if name lookup resolves
the name in the id-expression to a non-static non-type member [..],
the id-expression is transformed into a class member access expression
using (*this) as the postfix-expression to the left of the . operator.
The member name then  refers to the member of the object for which the
function is called." 

Since 'f' and 'foo::f' resolve to a non-static member (name lookup
is performed before overload resolution, after all), this applies.

So, the original code snippet:

f_obj<&foo::f>     (g++ accepted this one)
-- &foo::f is pointer to member syntax, do nothing!

f_obj<foo::f>    
-- transforms to f_obj<this->foo::f>

f_obj<f>
-- transforms to f_obj<this->foo::f>

f_obj<&f>
-- transforms to f_obj<&this->foo::f>

Which seams to rather nicely match the results! :) This also explains why
f_obj<foo::f> is OK outside the member function (no transformation done), but
an error inside of it. 

If you are correct about the constant expression, then the original
behaviour I reported is absolutely correct. Surprisingly. 

But I think ptr->f is a constant expression, because in this expression,
the expression 'ptr' (just an lvalue) is evaluated, not (*ptr). This still
leaves the problem that 9.3.1/2 defines operations in terms of "(*this)",
not "this->", but then again, "this" isn't an object, right?



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22621

Reply via email to