summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineFormatter.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2018-03-19 15:33:40 +0000
committerKrasimir Georgiev <krasimir@google.com>2018-03-19 15:33:40 +0000
commit5cca20f825e66eea684d5fb8c8303ee2b32456b4 (patch)
tree17edc810c4d08f68a7459eef60cf0d5a4a435a39 /clang/lib/Format/UnwrappedLineFormatter.cpp
parent0f0fb0a06f3275e2357b5e2cc9d1bd441fe4b0e7 (diff)
downloadbcm5719-llvm-5cca20f825e66eea684d5fb8c8303ee2b32456b4.tar.gz
bcm5719-llvm-5cca20f825e66eea684d5fb8c8303ee2b32456b4.zip
[clang-format] Remove empty lines before }[;] // comment
Summary: This addresses bug 36766 and a FIXME in tests about empty lines before `}[;] // comment` lines. Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44631 llvm-svn: 327861
Diffstat (limited to 'clang/lib/Format/UnwrappedLineFormatter.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 2ce39fb04c6..b0da0028bf3 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1133,8 +1133,12 @@ void UnwrappedLineFormatter::formatFirstToken(const AnnotatedLine &Line,
std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
// Remove empty lines before "}" where applicable.
if (RootToken.is(tok::r_brace) &&
+ // Look for "}", "} // comment", "};" or "}; // comment".
(!RootToken.Next ||
- (RootToken.Next->is(tok::semi) && !RootToken.Next->Next)))
+ (RootToken.Next->is(tok::comment) && !RootToken.Next->Next) ||
+ (RootToken.Next->is(tok::semi) &&
+ (!RootToken.Next->Next || (RootToken.Next->Next->is(tok::comment) &&
+ !RootToken.Next->Next->Next)))))
Newlines = std::min(Newlines, 1u);
// Remove empty lines at the start of nested blocks (lambdas/arrow functions)
if (PreviousLine == nullptr && Line.Level > 0)
OpenPOWER on IntegriCloud