Skip to content

Commit

Permalink
clang-format: Allow single-line function in WebKit style.
Browse files Browse the repository at this point in the history
Before:
  void f() {
      return; }

After:
  void f() { return; }

llvm-svn: 207527
  • Loading branch information
djasper committed Apr 29, 2014
1 parent dd18d5b commit 3599567
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clang/lib/Format/ContinuationIndenter.cpp
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Format/Format.cpp
Expand Up @@ -499,6 +499,8 @@ class NoColumnLimitFormatter {
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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Expand Up @@ -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"
Expand Down

0 comments on commit 3599567

Please sign in to comment.