From: Daniel Jasper Date: Mon, 10 Mar 2014 10:02:02 +0000 (+0000) Subject: clang-format: Add spaces around trailing/lambda return types. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2d2d02c15b4e7afb5c129f50b844ae3fe8e1ead;p=clang clang-format: Add spaces around trailing/lambda return types. 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 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index b7eb3bfdb4..7efeaffc78 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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); diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index b7de63fd0f..6930bd22bc 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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: diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 341fb3589a..6690103dc1 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7956,9 +7956,9 @@ TEST_F(FormatTest, FormatsLambdas) { "}\n"); // Lambdas with return types. - verifyFormat("int c = []()->int { return 2; }();\n"); - verifyFormat("int c = []()->vector { return {2}; }();\n"); - verifyFormat("Foo([]()->std::vector { return {2}; }());"); + verifyFormat("int c = []() -> int { return 2; }();\n"); + verifyFormat("int c = []() -> vector { return {2}; }();\n"); + verifyFormat("Foo([]() -> std::vector { return {2}; }());"); // Not lambdas. verifyFormat("constexpr char hello[]{\"hello\"};");