<div>On Thu Jan 16 2014 at 3:49:11 PM, Harald van Dijk <<a href="mailto:harald@gigawatt.nl">harald@gigawatt.nl</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I was playing around with the idea of tracking where 'this' is seen, in<br>
order to properly diagnose it after determining whether the function<br>
definition is static, but it needs some more work, and regardless, it<br>
seems too invasive when the point of my current patch was actually<br>
something else.<br>
<br>
How about just rejecting 'this' in typedefs, then? These don't have the<br>
same problem and so don't need the same special treatment as 'static'.<br>
I've rebased, retested, and all tests pass.<br>
<br>
I've changed the check for typedefs to be performed regardless of<br>
declarator context. What I had, when taking the invalid testcase<br>
<br>
struct Foo { };<br>
namespace Bar { };<br>
typedef auto Foo::f() -> decltype(this);<br>
typedef auto Bar::f() -> decltype(this);<br>
<br>
generated one error on line three, but two on line four:<br>
<br>
test.cc:3:19: error: typedef declarator cannot be qualified<br>
typedef auto Foo::f() -> decltype(this);<br>
             ~~~~~^<br>
test.cc:4:35: error: invalid use of 'this' outside of a non-static<br>
member function<br>
typedef auto Bar::f() -> decltype(this);<br>
                                  ^<br>
test.cc:4:19: error: typedef declarator cannot be qualified<br>
typedef auto Bar::f() -> decltype(this);<br>
             ~~~~~^<br>
<br>
Ideally, the two lines would give the same errors, as they both use<br>
'this' outside of a non-static member function, and that's what I've now<br>
implemented, but I have no strong feelings either way about that.<br></blockquote><div><br></div><div>I think consistently issuing two distinct errors here is a step forward.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Any other thoughts or comments on this patch?<br></blockquote><div><br></div><div>Patch LGTM, thanks! Do you need someone to commit this for you?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Cheers,<br>
Harald van Dijk<br>
<br>
On 16/01/14 07:38, Harald van Dijk wrote:<br>
> Ah, thanks, you're right. If the in-class declaration doesn't use<br>
> 'this', but the definition does, then 'this' would not be diagnosed with<br>
> my approach. Normally, if the definition does, so would the in-class<br>
> declaration, where it would be diagnosed, but an example of where it<br>
> doesn't is<br>
><br>
> struct Foo {<br>
>   static bool f();<br>
> };<br>
><br>
> auto Foo::f() -> decltype(this != 0) {<br>
>   return true;<br>
> }<br>
><br>
> Cheers,<br>
> Harald van Dijk<br>
><br>
> On 16/01/14 01:25, Richard Smith wrote:<br>
>> How does this deal with the case where 'this' appears in a declarator<br>
>> for an out-of-line definition of a static member function? In that case,<br>
>> we don't know we're parsing a static member function declaration until<br>
>> *after* we've already parsed the 'this' expression. I believe the<br>
>> existing complexity was aimed at correctly handling that case; it seems<br>
>> surprising that we don't have any tests for it.<br>
>><br>
>> On Wed Jan 15 2014 at 3:33:07 PM, Harald van Dijk <<a href="mailto:harald@gigawatt.nl" target="_blank">harald@gigawatt.nl</a><br>
>> <mailto:<a href="mailto:harald@gigawatt.nl" target="_blank">harald@gigawatt.nl</a>>> wrote:<br>
>><br>
>>     Hi all,<br>
>><br>
>>     This came up on StackOverflow recently:<br>
>><br>
>>     'this' is rejected by clang in static member functions:<br>
>><br>
>>     error: 'this' cannot be used in a static member function declaration<br>
>>       static auto f() -> decltype(this);<br>
>>                                   ^<br>
>><br>
>>     However, what the standard actually says is that 'this' is not allowed<br>
>>     except in non-static member functions (and some more bits not relevant<br>
>>     here). Declarations that look like member functions but aren't, not even<br>
>>     static ones, shouldn't allow 'this' either.<br>
>><br>
>>       typedef auto f() -> decltype(this);<br>
>><br>
>>     Looking to see what clang implements, I was very surprised. There is<br>
>>     already perfectly functional code that rejects 'this' in 'friend'<br>
>>     functions, and that code is not reused for 'static' functions (and<br>
>>     'typedef's): instead, the checks have effectively been rewritten for<br>
>>     'static'.<br>
>><br>
>>     I'm wondering, why is that? If I do attempt to re-use the existing code,<br>
>>     as in the attached patch, then the only changes in the test results are<br>
>>     actually correct, as references to non-static data members are permitted<br>
>>     even in 'static' functions, so long as they appear in unevaluated<br>
>>     expressions. There is even a FIXME comment about this in the test. But<br>
>>     I'm sure the current checks have been added for a good reason. Am I<br>
>>     overlooking some important details that are not covered by the<br>
>>     testsuite?<br>
>><br>
>>     Cheers,<br>
>>     Harald van Dijk<br>
>>     ______________________________<u></u>___________________<br>
>>     cfe-commits mailing list<br>
>>     <a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a> <mailto:<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.<u></u>edu</a>><br>
>>     <a href="http://lists.cs.uiuc.edu/__mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/__<u></u>mailman/listinfo/cfe-commits</a><br>
>>     <<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-commits</a>><br>
>><br>
><br>
<br>
</blockquote>