diff options
| author | Manuel Klimek <klimek@google.com> | 2017-09-20 09:29:37 +0000 |
|---|---|---|
| committer | Manuel Klimek <klimek@google.com> | 2017-09-20 09:29:37 +0000 |
| commit | e411aa85acffbd8da2ea332e6acf86b7f6804192 (patch) | |
| tree | c3fb11d551dc4c654c67bb3ed179c8a59934e6e7 /clang/unittests | |
| parent | 94444b9a0778d076a73bd430f69ea84aff7185d5 (diff) | |
| download | bcm5719-llvm-e411aa85acffbd8da2ea332e6acf86b7f6804192.tar.gz bcm5719-llvm-e411aa85acffbd8da2ea332e6acf86b7f6804192.zip | |
Fix clang-format's detection of structured bindings.
Correctly determine when [ is part of a structured binding instead of a
lambda.
To be able to reuse the implementation already available, this patch also:
- sets the Previous link of FormatTokens in the UnwrappedLineParser
- moves the isCppStructuredBinding function into FormatToken
Before:
auto const const &&[x, y] { A *i };
After:
auto const const && [x, y]{A * i};
Fixing formatting of the type of the structured binding is still missing.
llvm-svn: 313742
Diffstat (limited to 'clang/unittests')
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 34206e9e418..a1b0e5fee74 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -11588,6 +11588,11 @@ TEST_F(FormatTest, StructuredBindings) { format("auto const volatile &&[a, b] = f();")); EXPECT_EQ("auto && [a, b] = f();", format("auto &&[a, b] = f();")); + // Make sure we don't mistake structured bindings for lambdas. + verifyFormat("auto [a, b]{A * i};"); + verifyFormat("auto const [a, b]{A * i};"); + verifyFormat("auto const && [a, b]{A * i};"); + format::FormatStyle Spaces = format::getLLVMStyle(); Spaces.SpacesInSquareBrackets = true; verifyFormat("auto [ a, b ] = f();", Spaces); |

