[PATCH] D120902: [clang-format] Fix assertion failure/crash with `AllowShortFunctionsOnASingleLine: Inline/InlineOnly`.

Marek Kurdej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 7 07:54:26 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGd03e342803df: [clang-format] Fix assertion failure/crash with… (authored by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120902

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


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12669,6 +12669,13 @@
                "};",
                MergeInlineOnly);
   verifyFormat("int f() {}", MergeInlineOnly);
+  // https://llvm.org/PR54147
+  verifyFormat("auto lambda = []() {\n"
+               "  // comment\n"
+               "  f();\n"
+               "  g();\n"
+               "};",
+               MergeInlineOnly);
 
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -310,6 +310,8 @@
           for (; J != AnnotatedLines.begin(); --J)
             if ((*J)->Level < TheLine->Level)
               break;
+          if ((*J)->Level >= TheLine->Level)
+            return false;
 
           // Check if the found line starts a record.
           const FormatToken *LastNonComment = (*J)->Last;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120902.413484.patch
Type: text/x-patch
Size: 1218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220307/759a6e4b/attachment-0001.bin>


More information about the cfe-commits mailing list