summaryrefslogtreecommitdiffstats
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2017-09-20 09:29:37 +0000
committerManuel Klimek <klimek@google.com>2017-09-20 09:29:37 +0000
commit9c03e2cb50ceeee1d3c8a02b6599dd3ea1281915 (patch)
treec7713e01139a949075ee364bb23f78b2618872fa /unittests/Format/FormatTest.cpp
parent4e8386f480e758e0e5e9c26c7439ac7bf9a71d23 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313742 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 34206e9e41..a1b0e5fee7 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/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);