I have reworked the program flow. Instead of tentative parsing, the already parsed expression is reused within the case statement parsing following colon detection.<br><br><div class="gmail_quote">On Fri, Apr 15, 2011 at 2:03 PM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5"><br>
On Apr 15, 2011, at 11:58 AM, Richard Trieu wrote:<br>
<br>
> When a valid expression is followed by a colon inside a switch scope, suggest a fix-it hint to insert a case before the expression.<br>
><br>
> int f1(int i) {<br>
> switch (i) {<br>
> 0: return 1;<br>
> default: return 0;<br>
> }<br>
> }<br>
><br>
> case.cc:3:4: error: expected 'case' keyword before expression<br>
> 0: return 1;<br>
> ^<br>
> case<br>
<br>
</div></div>Cool idea, but this...<br>
<br>
+ // If a case statement is missing, then back-track to this point and<br>
+ // insert case keyword.<br>
+ Token OldToken = Tok;<br>
+ TentativeParsingAction TPA(*this);<br>
<br>
is a huge performance problem, since tentative parsing is expensive and should be avoided except after an error occurs or when required by the language.<br>
<br>
Is there a way to make this diagnostic kick in only when an error is imminent, e.g., because we've seen <expression> ':' somewhere within a switch statement?<br>
<br>
- Doug<br>
</blockquote></div><br>