]> granicus.if.org Git - clang/commitdiff
clang-format: Allow single-line function in WebKit style.
authorDaniel Jasper <djasper@google.com>
Tue, 29 Apr 2014 14:05:20 +0000 (14:05 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 29 Apr 2014 14:05:20 +0000 (14:05 +0000)
Before:
  void f() {
      return; }

After:
  void f() { return; }

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

lib/Format/ContinuationIndenter.cpp
lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 445fc41ad22dffcc8a7d5e0211674a690f4de8dd..26eb7e1bd4b5ad0ac1952c0bfc2fb7c97da6d96f 100644 (file)
@@ -207,8 +207,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
   // The following could be precomputed as they do not depend on the state.
   // However, as they should take effect only if the UnwrappedLine does not fit
   // into the ColumnLimit, they are checked here in the ContinuationIndenter.
-  if (Previous.BlockKind == BK_Block && Previous.is(tok::l_brace) &&
-      !Current.isOneOf(tok::r_brace, tok::comment))
+  if (Style.ColumnLimit != 0 && Previous.BlockKind == BK_Block &&
+      Previous.is(tok::l_brace) && !Current.isOneOf(tok::r_brace, tok::comment))
     return true;
 
   return false;
index 3544cff4ddbeb4057cfb1bf657527399156a44ce..d1a29ff8a065c16434c106e1edb77aa581206922 100644 (file)
@@ -499,6 +499,8 @@ public:
       bool Newline =
           Indenter->mustBreak(State) ||
           (Indenter->canBreak(State) && State.NextToken->NewlinesBefore > 0);
+      llvm::errs() << State.NextToken->Tok.getName() << " "
+                   << Indenter->mustBreak(State) << "\n";
       Indenter->addTokenToState(State, Newline, /*DryRun=*/false);
     }
   }
index 084d1dd33d8e8cf82c4626bf092883eefc37e054..02a77af4f7500f00c6e2772d8dfe79b7837ac11a 100644 (file)
@@ -8198,6 +8198,9 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) {
           "}",
           Style));
 
+  // Allow functions on a single line.
+  verifyFormat("void f() { return; }", Style);
+
   // Constructor initializers are formatted one per line with the "," on the
   // new line.
   verifyFormat("Constructor()\n"