clang-format: Quickfix for braced init lists detected as lambdas.
authorDaniel Jasper <djasper@google.com>
Thu, 5 Sep 2013 11:49:39 +0000 (11:49 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 5 Sep 2013 11:49:39 +0000 (11:49 +0000)
Before:
  constexpr char hello [] { "hello" };

After:
  constexpr char hello[]{ "hello" };

llvm-svn: 190046

clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

index 13b9847..5029bd6 100644 (file)
@@ -674,6 +674,12 @@ void UnwrappedLineParser::parseStructuralElement() {
 }
 
 void UnwrappedLineParser::tryToParseLambda() {
+  // FIXME: This is a dirty way to access the previous token. Find a better
+  // solution.
+  if (!Line->Tokens.empty() && Line->Tokens.back().Tok->is(tok::identifier)) {
+    nextToken();
+    return;
+  }
   assert(FormatTok->is(tok::l_square));
   FormatToken &LSquare = *FormatTok;
   if (!tryToParseLambdaIntroducer())
index 5e5a579..4c66ef0 100644 (file)
@@ -6300,6 +6300,9 @@ TEST_F(FormatTest, FormatsLambdas) {
                "        x.end(),   //\n"
                "        [&](int, int) { return 1; });\n"
                "}\n");
+
+  // Not lambdas.
+  verifyFormat("constexpr char hello[]{ \"hello\" };");
 }
 
 TEST_F(FormatTest, FormatsBlocks) {