]> granicus.if.org Git - clang/commitdiff
clang-format: Add spaces around trailing/lambda return types.
authorDaniel Jasper <djasper@google.com>
Mon, 10 Mar 2014 10:02:02 +0000 (10:02 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 10 Mar 2014 10:02:02 +0000 (10:02 +0000)
Before:
  int c = []()->int { return 2; }();

After:
  int c = []() -> int { return 2; }();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203452 91177308-0d34-0410-b5e6-96231b3b80d8

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

index b7eb3bfdb4d1798338de15f2515d6cb8b028306c..7efeaffc78db9875490bf3d9a04c13fadc59e52f 100644 (file)
@@ -583,7 +583,8 @@ private:
       // recovered from an error (e.g. failure to find the matching >).
       if (CurrentToken->Type != TT_LambdaLSquare &&
           CurrentToken->Type != TT_FunctionLBrace &&
-          CurrentToken->Type != TT_ImplicitStringLiteral)
+          CurrentToken->Type != TT_ImplicitStringLiteral &&
+          CurrentToken->Type != TT_TrailingReturnArrow)
         CurrentToken->Type = TT_Unknown;
       if (CurrentToken->Role)
         CurrentToken->Role.reset(NULL);
index b7de63fd0fc707995aa404f7819f1ee43bc17db5..6930bd22bc97f527e5780b8896080dae09cc77bd 100644 (file)
@@ -784,7 +784,10 @@ bool UnwrappedLineParser::tryToParseLambda() {
     case tok::identifier:
     case tok::coloncolon:
     case tok::kw_mutable:
+      nextToken();
+      break;
     case tok::arrow:
+      FormatTok->Type = TT_TrailingReturnArrow;
       nextToken();
       break;
     default:
index 341fb3589a3eff73c975358ef3e33d1a3e930cdc..6690103dc1b7a720aa7ca6e595a7904cacc98216 100644 (file)
@@ -7956,9 +7956,9 @@ TEST_F(FormatTest, FormatsLambdas) {
                "}\n");
 
   // Lambdas with return types.
-  verifyFormat("int c = []()->int { return 2; }();\n");
-  verifyFormat("int c = []()->vector<int> { return {2}; }();\n");
-  verifyFormat("Foo([]()->std::vector<int> { return {2}; }());");
+  verifyFormat("int c = []() -> int { return 2; }();\n");
+  verifyFormat("int c = []() -> vector<int> { return {2}; }();\n");
+  verifyFormat("Foo([]() -> std::vector<int> { return {2}; }());");
 
   // Not lambdas.
   verifyFormat("constexpr char hello[]{\"hello\"};");