r237569 - clang-format: Fix another regression caused by r237565.

Daniel Jasper djasper at google.com
Mon May 18 07:49:19 PDT 2015


Author: djasper
Date: Mon May 18 09:49:19 2015
New Revision: 237569

URL: http://llvm.org/viewvc/llvm-project?rev=237569&view=rev
Log:
clang-format: Fix another regression caused by r237565.

Before:
  class C : test {
    class D : test{void f(){int i{2};
  }
  }
  ;
  }
  ;

After:
  class C : test {
    class D : test {
      void f() { int i{2}; }
    };
  };

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/lib/Format/UnwrappedLineParser.h
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=237569&r1=237568&r2=237569&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon May 18 09:49:19 2015
@@ -325,6 +325,7 @@ void UnwrappedLineParser::calculateBrace
 
     switch (Tok->Tok.getKind()) {
     case tok::l_brace:
+      Tok->BlockKind = BK_Unknown;
       LBraceStack.push_back(Tok);
       break;
     case tok::r_brace:
@@ -1017,9 +1018,9 @@ void UnwrappedLineParser::tryToParseJSFu
   parseChildBlock();
 }
 
-bool UnwrappedLineParser::tryToParseBracedList(bool ExpectClassBody) {
+bool UnwrappedLineParser::tryToParseBracedList() {
   if (FormatTok->BlockKind == BK_Unknown)
-    calculateBraceTypes(ExpectClassBody);
+    calculateBraceTypes();
   assert(FormatTok->BlockKind != BK_Unknown);
   if (FormatTok->BlockKind == BK_Block)
     return false;
@@ -1573,9 +1574,11 @@ void UnwrappedLineParser::parseRecord()
   // and class declarations).
   if (FormatTok->isOneOf(tok::colon, tok::less)) {
     while (!eof()) {
-      if (FormatTok->is(tok::l_brace) &&
-          !tryToParseBracedList(/*ExpectClassBody=*/true))
-        break;
+      if (FormatTok->is(tok::l_brace)) {
+        calculateBraceTypes(/*ExpectClassBody=*/true);
+        if (!tryToParseBracedList())
+          break;
+      }
       if (FormatTok->Tok.is(tok::semi))
         return;
       nextToken();

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.h?rev=237569&r1=237568&r2=237569&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.h (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.h Mon May 18 09:49:19 2015
@@ -82,7 +82,7 @@ private:
   void parsePPEndIf();
   void parsePPUnknown();
   void parseStructuralElement();
-  bool tryToParseBracedList(bool ExpectClassBody = false);
+  bool tryToParseBracedList();
   bool parseBracedList(bool ContinueOnSemicolons = false);
   void parseParens();
   void parseSquare();
@@ -113,7 +113,7 @@ private:
   void readToken();
   void flushComments(bool NewlineBeforeNext);
   void pushToken(FormatToken *Tok);
-  void calculateBraceTypes(bool ExpectClassBody);
+  void calculateBraceTypes(bool ExpectClassBody = false);
 
   // Marks a conditional compilation edge (for example, an '#if', '#ifdef',
   // '#else' or merge conflict marker). If 'Unreachable' is true, assumes

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=237569&r1=237568&r2=237569&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon May 18 09:49:19 2015
@@ -6195,6 +6195,11 @@ TEST_F(FormatTest, LayoutCxx11BraceIniti
   verifyFormat("class C : public D {\n"
                "  SomeClass SC{2};\n"
                "};");
+  verifyFormat("class C : public A {\n"
+               "  class D : public B {\n"
+               "    void f() { int i{2}; }\n"
+               "  };\n"
+               "};");
 
   // In combination with BinPackParameters = false.
   FormatStyle NoBinPacking = getLLVMStyle();





More information about the cfe-commits mailing list