[PATCH] D150614: [clang-format] Ignore first token when finding MustBreak
Emilia Kond via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 17 19:52:53 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG06763ea5d8f9: [clang-format] Ignore first token when finding MustBreak (authored by rymiel).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150614/new/
https://reviews.llvm.org/D150614
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
@@ -13832,6 +13832,20 @@
"}",
format("A()\n:b(0)\n{\n}", NoColumnLimit));
+ FormatStyle NoColumnLimitWrapAfterFunction = NoColumnLimit;
+ NoColumnLimitWrapAfterFunction.BreakBeforeBraces = FormatStyle::BS_Custom;
+ NoColumnLimitWrapAfterFunction.BraceWrapping.AfterFunction = true;
+ verifyFormat("class C {\n"
+ "#pragma foo\n"
+ " int foo { return 0; }\n"
+ "};",
+ NoColumnLimitWrapAfterFunction);
+ verifyFormat("class C {\n"
+ "#pragma foo\n"
+ " void foo {}\n"
+ "};",
+ NoColumnLimitWrapAfterFunction);
+
FormatStyle DoNotMergeNoColumnLimit = NoColumnLimit;
DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine =
FormatStyle::SFS_None;
@@ -20120,9 +20134,7 @@
" int i = 5;\n"
" }\n"
"#ifdef _DEBUG\n"
- "void bar()\n"
- " {\n"
- " }\n"
+ "void bar() {}\n"
"#else\n"
"void bar()\n"
" {\n"
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -888,7 +888,10 @@
}
bool containsMustBreak(const AnnotatedLine *Line) {
- for (const FormatToken *Tok = Line->First; Tok; Tok = Tok->Next)
+ assert(Line->First);
+ // Ignore the first token, because in this situation, it applies more to the
+ // last token of the previous line.
+ for (const FormatToken *Tok = Line->First->Next; Tok; Tok = Tok->Next)
if (Tok->MustBreakBefore)
return true;
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150614.523243.patch
Type: text/x-patch
Size: 1980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230518/9825eaba/attachment.bin>
More information about the cfe-commits
mailing list