summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp5
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp3
-rw-r--r--clang/unittests/Format/FormatTest.cpp3
3 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index b376ec95c1b..c4d443b2ca0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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))
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index af1e94cfe84..2c6a4fb2540 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -867,6 +867,9 @@ bool UnwrappedLineParser::tryToParseLambda() {
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:
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 479919e9cfe..fceebfadea7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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"
OpenPOWER on IntegriCloud