瀏覽代碼

clang-format: Quickfix for braced init lists detected as lambdas.

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

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190046 91177308-0d34-0410-b5e6-96231b3b80d8
Daniel Jasper 12 年之前
父節點
當前提交
2d65705ed0
共有 2 個文件被更改,包括 9 次插入0 次删除
  1. 6 0
      lib/Format/UnwrappedLineParser.cpp
  2. 3 0
      unittests/Format/FormatTest.cpp

+ 6 - 0
lib/Format/UnwrappedLineParser.cpp

@@ -674,6 +674,12 @@ void UnwrappedLineParser::parseStructuralElement() {
 }
 }
 
 
 void UnwrappedLineParser::tryToParseLambda() {
 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));
   assert(FormatTok->is(tok::l_square));
   FormatToken &LSquare = *FormatTok;
   FormatToken &LSquare = *FormatTok;
   if (!tryToParseLambdaIntroducer())
   if (!tryToParseLambdaIntroducer())

+ 3 - 0
unittests/Format/FormatTest.cpp

@@ -6300,6 +6300,9 @@ TEST_F(FormatTest, FormatsLambdas) {
                "        x.end(),   //\n"
                "        x.end(),   //\n"
                "        [&](int, int) { return 1; });\n"
                "        [&](int, int) { return 1; });\n"
                "}\n");
                "}\n");
+
+  // Not lambdas.
+  verifyFormat("constexpr char hello[]{ \"hello\" };");
 }
 }
 
 
 TEST_F(FormatTest, FormatsBlocks) {
 TEST_F(FormatTest, FormatsBlocks) {