[clang] d2eda49 - [clang-format] Mark constexpr lambdas as lambda

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 18 12:42:45 PDT 2022


Author: Björn Schäpers
Date: 2022-07-18T21:42:34+02:00
New Revision: d2eda49202386b222cec763aad9aaecd463ce044

URL: https://github.com/llvm/llvm-project/commit/d2eda49202386b222cec763aad9aaecd463ce044
DIFF: https://github.com/llvm/llvm-project/commit/d2eda49202386b222cec763aad9aaecd463ce044.diff

LOG: [clang-format] Mark constexpr lambdas as lambda

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

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp
    clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index bfacfa3e3595..83b4f1e7991f 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -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:

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ed6fb414d618..bdbfca78a6cb 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -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


        


More information about the cfe-commits mailing list