<div class="gmail_quote">On Tue, Feb 14, 2012 at 12:39 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The patch/example is easier to understand than the description, perhaps.<br>
<br>
struct foo {<br>
operator int[](){};<br></blockquote><div><br></div><div>Playing with lambdas, hmm? ;-)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
};<br>
<br>
crashes - clang seems to be parsing 'operator int' as a member<br>
variable name (? why is that? no type was provided before the name,<br>
and it seems hardly likely a user would've mistakenly tried to name<br>
their variable 'operator int' & much more likely they've messed up a<br>
member function definition), sees the {} thinking its an in-class<br>
initializer and the [] a deduced array bound. At this point the parser<br>
tries to invalidate the declaration which is non-existent because of<br>
the bogus name, and dereferences null.<br>
<br>
Add the null check (there's a smattering of similar checks littered<br>
around this area, so that seems like a reasonable solution - the<br>
erroneous error recovery highlighted above not withstanding).<br></blockquote><div><br></div><div>LGTM</div><div><br></div><div>That said, I think we should be able to do a lot better on this case. We give a terrible diagnostic even in cases which are much more plausible:</div>
<div><br></div><div><div><stdin>:1:26: error: C++ requires a type specifier for all declarations</div><div>struct S { operator int(&)[4](); };</div><div> ~^</div><div><stdin>:1:27: error: 'type name' declared as array of functions of type 'int ()'</div>
<div>struct S { operator int(&)[4](); };</div><div> ^</div><div><stdin>:1:12: error: conversion function cannot have any parameters</div><div>struct S { operator int(&)[4](); };</div>
<div> ^</div></div><div><br></div><div>- Richard</div></div>