[PATCH] D116806: [clang-format] Ensure we can correctly parse lambda in the template argument list

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 10 00:29:54 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG5c2e7c9ca043: [clang-format] Ensure we can correctly parse lambda in the template argument… (authored by MyDeveloperDay).

Changed prior to commit:
  https://reviews.llvm.org/D116806?vs=398124&id=398521#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116806/new/

https://reviews.llvm.org/D116806

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


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23212,6 +23212,15 @@
                Style);
 }
 
+TEST_F(FormatTest, ShortTemplatedArgumentLists) {
+  auto Style = getLLVMStyle();
+
+  verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
+  verifyFormat("struct Y<[] { return 0; }> {};", Style);
+
+  verifyFormat("struct Z : X<decltype([] { return 0; }){}> {};", Style);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2874,6 +2874,8 @@
         if (!tryToParseBracedList())
           break;
       }
+      if (FormatTok->is(tok::l_square) && !tryToParseLambda())
+        break;
       if (FormatTok->Tok.is(tok::semi))
         return;
       if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116806.398521.patch
Type: text/x-patch
Size: 1096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220110/0b2bc642/attachment-0001.bin>


More information about the cfe-commits mailing list