On 05/15/2013 12:11 PM,
andrew...@gmail.com wrote:
>
>
> On Wednesday, May 15, 2013 8:19:17 AM UTC+2, Jens Maurer wrote:
>
I did not.
> I'm not sure I understand how the note about declaration matching is
> relevant here. Can you provide an example of a situation where the
> note and the type of `this` being defined within a static member
> function is relevant?
I'm thinking about an example where there is a (declaration)
choice between a static and a non-static member function, one of
which is defined out-of-class, similar to the example in the standard
(I've added a missing <class T>):
struct A {
char g();
template<class T> static auto f(T t) -> decltype(t + g())
{ return t + g(); }
};
template<class T> auto A::f(int t) -> decltype(t + g());
I believe you need to have "this" available for the decltype prior to
matching this out-of-line definition with the static declaration.
(At the point where you evaluate the "decltype", you don't know yet
whether you're inside a static member function or not, because you
haven't referred to the declaration inside the class, yet.)
> Is the following what you mean?
>
> struct C { static C* f(); };
>
> auto C::f() -> decltype(this) {}
>
> Is this ill-formed? Is the note saying that in order to match the
> function-definition to the declaration inside the class specifier, it
> is necessary to use the type of `this` to get the signature. After
> the declaration match has been made, the compiler notices that the
> function is static, and then rejects it because `this` can't be used
> inside a static member function declaration?
Yes, I think so. It also occurs with implicit uses of this (9.3.1).
It still a bit strange that you can't use "this" here, though. It's
totally harmless inside decltype.
Jens