r222534 - clang-format: Understand more lambda return types.
Daniel Jasper
djasper at google.com
Fri Nov 21 06:08:38 PST 2014
Author: djasper
Date: Fri Nov 21 08:08:38 2014
New Revision: 222534
URL: http://llvm.org/viewvc/llvm-project?rev=222534&view=rev
Log:
clang-format: Understand more lambda return types.
Before:
auto a = [&b, c ](D * d) -> D * {}
After:
auto a = [&b, c](D* d) -> D* {}
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=222534&r1=222533&r2=222534&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Nov 21 08:08:38 2014
@@ -747,6 +747,8 @@ private:
}
} else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) {
Contexts.back().IsExpression = true;
+ } else if (Current.is(TT_TrailingReturnArrow)) {
+ Contexts.back().IsExpression = false;
} else if (Current.is(tok::l_paren) && !Line.MustBeDeclaration &&
!Line.InPPDirective &&
(!Current.Previous ||
@@ -973,7 +975,8 @@ private:
return TT_UnaryOperator;
const FormatToken *NextToken = Tok.getNextNonComment();
- if (!NextToken || NextToken->is(tok::l_brace))
+ if (!NextToken ||
+ (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
return TT_Unknown;
if (PrevToken->is(tok::coloncolon))
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=222534&r1=222533&r2=222534&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Nov 21 08:08:38 2014
@@ -867,6 +867,9 @@ bool UnwrappedLineParser::tryToParseLamb
case tok::l_paren:
parseParens();
break;
+ case tok::amp:
+ case tok::star:
+ case tok::kw_const:
case tok::less:
case tok::greater:
case tok::identifier:
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=222534&r1=222533&r2=222534&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Nov 21 08:08:38 2014
@@ -9279,6 +9279,9 @@ TEST_F(FormatTest, FormatsLambdas) {
verifyFormat("int c = []() -> int { return 2; }();\n");
verifyFormat("int c = []() -> vector<int> { return {2}; }();\n");
verifyFormat("Foo([]() -> std::vector<int> { return {2}; }());");
+ verifyGoogleFormat("auto a = [&b, c](D* d) -> D* {};");
+ verifyGoogleFormat("auto a = [&b, c](D* d) -> D& {};");
+ verifyGoogleFormat("auto a = [&b, c](D* d) -> const D* {};");
verifyFormat("auto aaaaaaaa = [](int i, // break for some reason\n"
" int j) -> int {\n"
" return ffffffffffffffffffffffffffffffffffffffffffff(i * j);\n"
More information about the cfe-commits
mailing list