diff options
| author | Daniel Jasper <djasper@google.com> | 2014-04-29 14:05:20 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-04-29 14:05:20 +0000 |
| commit | 35995679c65c36363e347054c966b6b0ac81f8bd (patch) | |
| tree | 266cf9c9e4487e9f908c4d2ad45a8b895b33f8fd | |
| parent | dd18d5b0f6aea5d13fbe653a1bfa20fa17531add (diff) | |
| download | bcm5719-llvm-35995679c65c36363e347054c966b6b0ac81f8bd.tar.gz bcm5719-llvm-35995679c65c36363e347054c966b6b0ac81f8bd.zip | |
clang-format: Allow single-line function in WebKit style.
Before:
void f() {
return; }
After:
void f() { return; }
llvm-svn: 207527
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Format/Format.cpp | 2 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 3 |
3 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 445fc41ad22..26eb7e1bd4b 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -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; diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 3544cff4ddb..d1a29ff8a06 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -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); } } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 084d1dd33d8..02a77af4f75 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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" |

