diff options
author | Krasimir Georgiev <krasimir@google.com> | 2018-01-19 16:12:37 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2018-01-19 16:12:37 +0000 |
commit | bf4cddaafb1e0f730509ff13883f22fb4620b304 (patch) | |
tree | fe2448f38c3b940ea1cc025f7ef870642b9c9884 /clang/lib/Format | |
parent | 72d32f24f5f02e4e8d3ab2fad3f6ed2b109a74c1 (diff) | |
download | bcm5719-llvm-bf4cddaafb1e0f730509ff13883f22fb4620b304.tar.gz bcm5719-llvm-bf4cddaafb1e0f730509ff13883f22fb4620b304.zip |
[clang-format] Fix shortening blocks in macros causing merged next line
Summary:
This patch addresses bug 36002, where a combination of options causes the line
following a short block in macro to be merged with that macro.
Reviewers: bkramer
Reviewed By: bkramer
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D42298
llvm-svn: 322954
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/UnwrappedLineFormatter.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 60dc1a7169d..253f89da9d1 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -304,9 +304,15 @@ private: if (TheLine->First->is(tok::l_brace) && TheLine->First == TheLine->Last && I != AnnotatedLines.begin() && I[-1]->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) { - return Style.AllowShortBlocksOnASingleLine - ? tryMergeSimpleBlock(I - 1, E, Limit) - : 0; + unsigned MergedLines = 0; + if (Style.AllowShortBlocksOnASingleLine) { + MergedLines = tryMergeSimpleBlock(I - 1, E, Limit); + // If we managed to merge the block, discard the first merged line + // since we are merging starting from I. + if (MergedLines > 0) + --MergedLines; + } + return MergedLines; } // Try to merge a block with left brace wrapped that wasn't yet covered if (TheLine->Last->is(tok::l_brace)) { |