Thanks! Any thoughts about the assert() calls I suggested on the bug?
On Thu, Jan 10, 2013 at 1:26 AM, Daniel Jasper <[email protected]> wrote: > Author: djasper > Date: Thu Jan 10 03:26:47 2013 > New Revision: 172049 > > URL: http://llvm.org/viewvc/llvm-project?rev=172049&view=rev > Log: > Do more error checking for '{}'. > > This fixes llvm.org/PR14883, where clang-format would run into an > assertion on: > > void f() { return } 42 > > Modified: > cfe/trunk/lib/Format/Format.cpp > cfe/trunk/unittests/Format/FormatTest.cpp > > Modified: cfe/trunk/lib/Format/Format.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172049&r1=172048&r2=172049&view=diff > ============================================================================== > --- cfe/trunk/lib/Format/Format.cpp (original) > +++ cfe/trunk/lib/Format/Format.cpp Thu Jan 10 03:26:47 2013 > @@ -651,6 +651,21 @@ > return false; > } > > + bool parseBrace() { > + while (CurrentToken != NULL) { > + if (CurrentToken->is(tok::r_brace)) { > + next(); > + return true; > + } > + if (CurrentToken->is(tok::r_paren) || > CurrentToken->is(tok::r_square)) > + return false; > + if (!consumeToken()) > + return false; > + } > + // Lines can currently end with '{'. > + return true; > + } > + > bool parseConditional() { > while (CurrentToken != NULL) { > if (CurrentToken->is(tok::colon)) { > @@ -693,6 +708,10 @@ > if (!parseSquare()) > return false; > break; > + case tok::l_brace: > + if (!parseBrace()) > + return false; > + break; > case tok::less: > if (parseAngle()) > Tok->Type = TT_TemplateOpener; > @@ -705,6 +724,11 @@ > case tok::r_paren: > case tok::r_square: > return false; > + case tok::r_brace: > + // Lines can start with '}'. > + if (Tok->Parent != NULL) > + return false; > + break; > case tok::greater: > Tok->Type = TT_BinaryOperator; > break; > > Modified: cfe/trunk/unittests/Format/FormatTest.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172049&r1=172048&r2=172049&view=diff > ============================================================================== > --- cfe/trunk/unittests/Format/FormatTest.cpp (original) > +++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jan 10 03:26:47 2013 > @@ -1036,6 +1036,10 @@ > // Error recovery tests. > > //===----------------------------------------------------------------------===// > > +TEST_F(FormatTest, IncorrectCodeTrailingStuff) { > + verifyFormat("void f() { return } 42"); > +} > + > TEST_F(FormatTest, IndentationWithinColumnLimitNotPossible) { > verifyFormat("int aaaaaaaa =\n" > " // Overly long comment\n" > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
