r203452 - clang-format: Add spaces around trailing/lambda return types.
Daniel Jasper
djasper at google.com
Mon Mar 10 03:02:03 PDT 2014
Author: djasper
Date: Mon Mar 10 05:02:02 2014
New Revision: 203452
URL: http://llvm.org/viewvc/llvm-project?rev=203452&view=rev
Log:
clang-format: Add spaces around trailing/lambda return types.
Before:
int c = []()->int { return 2; }();
After:
int c = []() -> int { return 2; }();
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=203452&r1=203451&r2=203452&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Mar 10 05:02:02 2014
@@ -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);
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=203452&r1=203451&r2=203452&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Mar 10 05:02:02 2014
@@ -784,7 +784,10 @@ bool UnwrappedLineParser::tryToParseLamb
case tok::identifier:
case tok::coloncolon:
case tok::kw_mutable:
+ nextToken();
+ break;
case tok::arrow:
+ FormatTok->Type = TT_TrailingReturnArrow;
nextToken();
break;
default:
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=203452&r1=203451&r2=203452&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Mar 10 05:02:02 2014
@@ -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\"};");
More information about the cfe-commits
mailing list