Skip to content

Commit 4bcc083

Browse files
authored
[clang-format] Handle C# where clause in SeparateDefinitionBlocks (#139034)
Fix #61956
1 parent 7c7ea1e commit 4bcc083

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

clang/lib/Format/DefinitionBlockSeparator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ void DefinitionBlockSeparator::separateBlocks(
137137
const auto MayPrecedeDefinition = [&](const int Direction = -1) {
138138
assert(Direction >= -1);
139139
assert(Direction <= 1);
140+
141+
if (Lines[OpeningLineIndex]->First->is(TT_CSharpGenericTypeConstraint))
142+
return true;
143+
140144
const size_t OperateIndex = OpeningLineIndex + Direction;
141145
assert(OperateIndex < Lines.size());
142146
const auto &OperateLine = Lines[OperateIndex];

clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ TEST_F(DefinitionBlockSeparatorTest, CSharp) {
574574
"\r\n"
575575
"public class FoobarClass {\r\n"
576576
" int foobar;\r\n"
577+
"}\r\n"
578+
"\r\n"
579+
"public class LogFactory<TLogger>\r\n"
580+
" where TLogger : class, new() {\r\n"
581+
" int i;\r\n"
577582
"}",
578583
Style);
579584
}

0 commit comments

Comments
 (0)