Hi,<div><br></div><div>Currently, after a malformed declaration, clang skips until it reaches an unparenthesized '}' or ';'. One fairly common error (especially among vim users) is for the first line of a file to have junk in it. This leads to abysmal error recovery, where we skip all 'namespace { ... }' and 'extern "C" { ... }' blocks and function definitions until we get to a top-level semicolon (which often doesn't arrive until we're past all the #included header files and somewhere in the main source file). We then produce a large pile of incorrect diagnostics, because we have not seen any declarations yet.</div>
<div><br></div><div>The attached patch improves this situation by tweaking the recovery heuristic as follows: we skip the shortest sequence of brace/bracket/paren-balanced tokens which either ends with a semicolon or a close brace[1] (and any following semicolon), or is followed by a namespace definition at the start of a line.</div>
<div><br></div><div>In my testing, this seems to be a strict improvement. Does this seem like a reasonable change? I'm sure there are other places where this style of recovery would be a better option than a simple SkipUntil(tok::r_brace), but I don't have evidence of a specific common pattern of errors leading to poor recovery elsewhere.</div>
<div><br></div><div>Thanks!</div><div>Richard</div><div><br></div><div>[1] If the close brace is followed by ',', '{' or 'try', we could be in the initializer-list for a constructor, so we keep skipping.</div>
<div><br></div><div><br></div>