diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-10-02 15:53:37 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-10-02 15:53:37 +0000 |
commit | 4e0b56c202361f464daadc14e860a7842f7edbb2 (patch) | |
tree | b91f6986432a39bb21275363df8c230899b350be /unittests | |
parent | 316ebefb7fff8ad324a08a694347500b6cd7c95f (diff) |
[clang-format] Fix regression about short functions after #else
Summary:
This patch fixes a regression introduced in r312904, where the formatter confuses
the `else` in `#else` with an `else` of an `if-else` statement.
For example, formatting this code with google style
```
#ifdef A
int f() {}
#else
int f() {}
#endif
```
resulted in
```
#ifdef A
int f() {}
#else
int f() {
}
#endif
```
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D37973
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314683 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 8ef11cb3dd..dadc0254c6 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7102,6 +7102,16 @@ TEST_F(FormatTest, SplitEmptyFunction) { "}", Style); } +TEST_F(FormatTest, KeepShortFunctionAfterPPElse) { + FormatStyle Style = getLLVMStyle(); + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + verifyFormat("#ifdef A\n" + "int f() {}\n" + "#else\n" + "int g() {}\n" + "#endif", + Style); +} TEST_F(FormatTest, SplitEmptyClass) { FormatStyle Style = getLLVMStyle(); |