diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2018-09-17 07:46:20 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2018-09-17 07:46:20 +0000 |
commit | d046e91f17b5336a9c603c142613f2b80a8ff888 (patch) | |
tree | b9142cd315c6e375a714073c0a729ccc8e54d947 /lib/Format | |
parent | ce5ca6bcf2d662186c486961b1ff2a4ce8356529 (diff) |
[clang-Format] Fix indentation of member call after block
Summary:
before patch:
> echo "test() {([]() -> {int b = 32;return 3;}).as("");});" | clang-format -style=Google
```
test() {
([]() -> {
int b = 32;
return 3;
})
.as();
});
```
after patch:
> echo "test() {([]() -> {int b = 32;return 3;}).as("");});" | clang-format -style=Google
```
test() {
([]() -> {
int b = 32;
return 3;
}).as();
});
```
Patch by Anders Karlsson (ank)!
Reviewers: klimek
Reviewed By: klimek
Subscribers: danilaml, acoomans, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D45719
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342363 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/ContinuationIndenter.cpp | 4 | ||||
-rw-r--r-- | lib/Format/FormatToken.h | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index f035aa71e5..c9c96456f4 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -403,7 +403,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { // }.bind(...)); // FIXME: We should find a more generic solution to this problem. !(State.Column <= NewLineColumn && - Style.Language == FormatStyle::LK_JavaScript)) + Style.Language == FormatStyle::LK_JavaScript) && + !(Previous.closesScopeAfterBlock() && + State.Column <= NewLineColumn)) return true; // If the template declaration spans multiple lines, force wrap before the diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index d9bff0112c..e3b31f9244 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -325,6 +325,14 @@ struct FormatToken { } template <typename T> bool isNot(T Kind) const { return !is(Kind); } + bool closesScopeAfterBlock() const { + if (BlockKind == BK_Block) + return true; + if (closesScope()) + return Previous->closesScopeAfterBlock(); + return false; + } + /// \c true if this token starts a sequence with the given tokens in order, /// following the ``Next`` pointers, ignoring comments. template <typename A, typename... Ts> |