[clang] [clang-format] Add KwBreakBeforeCaseLabel (PR #227668)
Anan Yablonko via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 3 07:36:50 PDT 2026
================
@@ -2833,6 +2833,42 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
Style);
}
+TEST_F(FormatTest, FormatsSwitchStatementCompactCaseLabels) {
----------------
ananski-the-3rd wrote:
[[fallthrough]] is now handled.
I added a couple of tests that check interaction with options that appear in UnwrappedLineParser::parseLabel.
As for the options you specified, I'd like to verify what the intended interaction is.
I suggest these (currently all failing) tests as a start:
```cpp
Style.BreakAfterAttributes = FormatStyle::ABS_Always;
verifyFormat("switch (n) {\n"
" break; case 0:\n"
" foo();\n"
" [[fallthrough]];\n"
" case 1:\n"
" bar();\n"
"}",
"switch (n) {\n"
" break; case 0:\n"
" foo();\n"
" [[fallthrough]]; case 1:\n"
" bar();\n"
"}",
Style);
Style.AllowShortCaseLabelsOnASingleLine = true;
Style.AlignConsecutiveShortCaseStatements.Enabled = true;
verifyFormat("switch (n) {\n"
" break; case 0: b = false;\n"
" break; default: b = true;\n"
"}",
Style);
Style.ColumnLimit = 54;
verifyFormat("switch (n) {\n"
" break; case some_namespace::\n"
" some_constant:\n"
" b = false;\n"
" break; default:"
" b = true;\n"
"}",
Style);
```
Is this acceptable as intended behavior?
https://github.com/llvm/llvm-project/pull/227668
More information about the cfe-commits
mailing list