[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 01:49:51 PST 2022
curdeius updated this revision to Diff 413380.
curdeius added a comment.
Safer condition.
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
@@ -12639,6 +12639,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.413380.patch
Type: text/x-patch
Size: 1218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220307/50b4c28f/attachment-0001.bin>
More information about the cfe-commits
mailing list