[PATCH] D129946: [clang-format] Mark constexpr lambdas as lambda

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 16 14:51:40 PDT 2022


HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius, eoanermine.
HazardyKnusperkeks added a project: clang-format.
Herald added a project: All.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129946

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -894,6 +894,13 @@
   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
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2127,6 +2127,7 @@
     case tok::coloncolon:
     case tok::kw_mutable:
     case tok::kw_noexcept:
+    case tok::kw_constexpr:
       nextToken();
       break;
     // Specialization of a template with an integer parameter can contain


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129946.445267.patch
Type: text/x-patch
Size: 1084 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220716/80d0a9cd/attachment-0001.bin>


More information about the cfe-commits mailing list