[cfe-commits] r172049 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Thu Jan 10 13:57:46 PST 2013


You already added them in r172023. I think they are a good addition.


On Thu, Jan 10, 2013 at 10:51 PM, Nico Weber <thakis at chromium.org> wrote:

> Thanks!
>
> Any thoughts about the assert() calls I suggested on the bug?
>
> On Thu, Jan 10, 2013 at 1:26 AM, Daniel Jasper <djasper at google.com> 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
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130110/04726855/attachment.html>


More information about the cfe-commits mailing list