Skip to content

Commit

Permalink
[clang-format] Mark constexpr lambdas as lambda
Browse files Browse the repository at this point in the history
Otherwise the brace was detected as a function brace, not wrong per se,
but when directly calling the lambda the calling parens were put on the
next line.

Differential Revision: https://reviews.llvm.org/D129946
  • Loading branch information
HazardyKnusperkeks committed Jul 18, 2022
1 parent 3c18a8b commit d2eda49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
case tok::amp:
case tok::star:
case tok::kw_const:
case tok::kw_constexpr:
case tok::comma:
case tok::less:
case tok::greater:
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsObjCBlock) {
EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_ObjCBlockLBrace);
}

TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
auto Tokens = annotate("[]() constexpr {}");
ASSERT_EQ(Tokens.size(), 8u) << Tokens;
EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
}

} // namespace
} // namespace format
} // namespace clang

0 comments on commit d2eda49

Please sign in to comment.