<div dir="ltr">On Thu, Nov 7, 2013 at 2:15 PM, Kaelyn Uhrain <span dir="ltr"><<a href="mailto:rikka@google.com" target="_blank">rikka@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Richard,</div><div><br></div><div>Thanks for the review feedback!</div>
<div><br></div>Here's an alternate version that better handles cases (such as the example you gave) where the code is actually valid without the "-" or ">" being changed to "->", by only trying the correction if an error diagnostic would have been emitted. It is similar to what I had mentioned doing, except that if the correction fails, ParseRHSOfBinaryExpr is called a second time to emit the original diagnostic messages. I ended up doing it this way because I encountered a problem with my previous idea: how to get the token stream in the right state if the correction fails and the original errors should be emitted. Preprocessor::EnableBacktrackAtThisPos() and friends work for resetting the token stream after the call to ParseRHSOfBinaryExpr but don't quite work for setting the token stream back to the state after the (first) call to ParseRHSOfBinaryExpr after trying the correction and having it fail (emitting the stored diagnostics from the call to ParseRHSOfBinaryExpr to avoid having to call it a second time only works if the token stream can also be restored to the correct state).</div>
</blockquote><div><br></div><div>This looks a lot cleaner, thanks. I have a handful of somewhat minor concerns:</div><div><br></div><div><br></div><div>DelayingDiagnosticConsumer doesn't appropriately handle DiagnosticConsumer::IncludeInDiagnosticCounts. "clang-check -fixit" is supposed to return 0 if it fixes all errors; it looks like it won't if it fixes this error, for this reason. This is a bit tricky: you don't know whether to include the diagnostic in diagnostic counts until you know whether you're emitting it, and you don't know that until you know whether you can recover.  </div>
<div><br></div><div>You're suppressing diagnostics that come from outside the immediate context of the error (for instance, if the RHS triggers a template instantiation, you shouldn't suppress diagnostics from there, because they won't be emitted if the code later uses the same template specialization again). That means that you can get a --fixit run that fixes all errors, and yet rebuilding the code still produces errors; that's not really supposed to happen.</div>
<div><br></div><div>I'm also a little concerned about the cost of turning on tentative parsing/backtracking here. Enabling tentative parsing (allegedly!) has a nontrivial cost, but I suppose we won't see pointers to class types on the LHS of '-' or '>' very frequently.</div>
<div><br></div><div><br></div><div>I don't really have good suggestions for the above -- this is a really tricky issue to recover from, and we're not really set up for tentatively performing arbitrary parsing actions.</div>
<div><br></div><div><br></div><div>Tiny things:</div><div> * You should use getAs<RecordType>, not getAsStructureType() -- this should work for classes and unions, too.</div><div> * Use TentativeParsingAction rather than using PP.*Backtrack* directly -- this will fix a minor bug where you get the source location of the '->' token wrong.</div>
<div> * Can you add an RAII object for registering and unregistering the DelayingDiagnosticConsumer?</div></div></div></div>