]> granicus.if.org Git - clang/commitdiff
clang-format: Fix another regression caused by r237565.
authorDaniel Jasper <djasper@google.com>
Mon, 18 May 2015 14:49:19 +0000 (14:49 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 18 May 2015 14:49:19 +0000 (14:49 +0000)
Before:
  class C : test {
    class D : test{void f(){int i{2};
  }
  }
  ;
  }
  ;

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237569 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
lib/Format/UnwrappedLineParser.h
unittests/Format/FormatTest.cpp

index 2331305cc5397715f46f240971cbe5eae903a183..5b1a448567363a0a47d9715583b99aeb3b3d6fe1 100644 (file)
@@ -325,6 +325,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
 
     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::tryToParseJSFunction() {
   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();
index a75845f5d837996c12c317e871ee9f0cb44eda2c..c2fa02957685a760aae8f3710dd065aa24f5ccbd 100644 (file)
@@ -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
index 0bb1bc151a0b12514f08be0a7b91e57202183fce..ab09e0075d646fbe205a2cd3b0f192e8dbe7aae3 100644 (file)
@@ -6195,6 +6195,11 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   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();