clang-format: Fix corner case in AllowShortBlocksOnASingleLine.
authorDaniel Jasper <djasper@google.com>
Thu, 22 May 2014 13:25:26 +0000 (13:25 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 22 May 2014 13:25:26 +0000 (13:25 +0000)
Before:
  template <int> struct A4 { A4() { }
  };

After:
  template <int i> struct A4 {
    A4() {}
  };

This fixes llvm.org/PR19813 (at least the part that isn't working as
intended).

llvm-svn: 209438

clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

index 2821e4a..3df1366 100644 (file)
@@ -690,8 +690,7 @@ private:
       if (I[1]->Last->Type == TT_LineComment)
         return 0;
       do {
-        if (Tok->is(tok::l_brace) && Tok->BlockKind != BK_BracedInit &&
-            !Style.AllowShortBlocksOnASingleLine)
+        if (Tok->is(tok::l_brace) && Tok->BlockKind != BK_BracedInit)
           return 0;
         Tok = Tok->Next;
       } while (Tok);
index 729eeaf..b3fb776 100644 (file)
@@ -378,6 +378,11 @@ TEST_F(FormatTest, FormatShortBracedStatements) {
                "}",
                AllowSimpleBracedStatements);
 
+  verifyFormat("template <int> struct A2 {\n"
+               "  struct B {};\n"
+               "};",
+               AllowSimpleBracedStatements);
+
   AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
   verifyFormat("if (true) {\n"
                "  f();\n"