diff options
author | Martin Probst <martin@probst.io> | 2017-11-17 18:06:33 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-11-17 18:06:33 +0000 |
commit | a004b3f50f3e8fd097f481f531439e783d8b54d6 (patch) | |
tree | 937fe6299739105ee23e80cf157a5ddfd4e83e47 /clang/lib/Format/UnwrappedLineFormatter.cpp | |
parent | f836537516801d2f3f9c103182348c95d4f98d3b (diff) | |
download | bcm5719-llvm-a004b3f50f3e8fd097f481f531439e783d8b54d6.tar.gz bcm5719-llvm-a004b3f50f3e8fd097f481f531439e783d8b54d6.zip |
clang-format: remove trailing lines in lamdas and arrow functions.
Summary:
clang-format already removes empty lines at the beginning & end of
blocks:
int x() {
foo(); // lines before and after will be removed.
}
However because lamdas and arrow functions are parsed as expressions,
the existing logic to remove empty lines in UnwrappedLineFormatter
doesn't handle them.
This change special cases arrow functions in ContinuationIndenter to
remove empty lines:
x = []() {
foo(); // lines before and after will now be removed.
};
Reviewers: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D40178
llvm-svn: 318537
Diffstat (limited to 'clang/lib/Format/UnwrappedLineFormatter.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineFormatter.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index a82cd5abe27..2e9d803a191 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1117,6 +1117,9 @@ void UnwrappedLineFormatter::formatFirstToken(const AnnotatedLine &Line, (!RootToken.Next || (RootToken.Next->is(tok::semi) && !RootToken.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) + Newlines = std::min(Newlines, 1u); if (Newlines == 0 && !RootToken.IsFirst) Newlines = 1; if (RootToken.IsFirst && !RootToken.HasUnescapedNewline) |