diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1840,16 +1840,27 @@ --Line->Level; } while (1) { - if (FormatTok->is(tok::at)) - nextToken(); + unsigned StoredPosition = Tokens->getPosition(); + if (FormatTok->is(tok::at)) { + // Get next non-comment token. + do { + FormatTok = Tokens->getNextToken(); + } while (FormatTok->is(tok::comment)); + } if (!(FormatTok->isOneOf(tok::kw_catch, Keywords.kw___except, tok::kw___finally) || ((Style.Language == FormatStyle::LK_Java || Style.Language == FormatStyle::LK_JavaScript) && FormatTok->is(Keywords.kw_finally)) || (FormatTok->Tok.isObjCAtKeyword(tok::objc_catch) || - FormatTok->Tok.isObjCAtKeyword(tok::objc_finally)))) + FormatTok->Tok.isObjCAtKeyword(tok::objc_finally)))) { + // Go back to before the (optional) @. + FormatTok = Tokens->setPosition(StoredPosition); break; + } + FormatTok = Tokens->setPosition(StoredPosition); + if (FormatTok->is(tok::at)) + nextToken(); nextToken(); while (FormatTok->isNot(tok::l_brace)) { if (FormatTok->is(tok::l_paren)) { diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -191,7 +191,13 @@ " @throw;\n" "} @finally {\n" " exit(42);\n" - "}"); + "}\n" + "@try {\n" + "} @catch (NSException *e) {\n" + "}\n" + "@ /* adena */ try {\n" + "} @catch (NSException *e) {\n" + "}\n"); verifyFormat("DEBUG({\n" " @try {\n" " } @finally {\n"