Skip to content

Commit 11a3f6f

Browse files
committed
[clang-format] Handle C# where clause in SeparateDefinitionBlocks
Fix llvm#61956
1 parent 5df01ab commit 11a3f6f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/Format/DefinitionBlockSeparator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ void DefinitionBlockSeparator::separateBlocks(
137137
const auto MayPrecedeDefinition = [&](const int Direction = -1) {
138138
assert(Direction >= -1);
139139
assert(Direction <= 1);
140+
141+
if (Style.isCSharp() &&
142+
Lines[OpeningLineIndex]->First->is(TT_CSharpGenericTypeConstraint)) {
143+
return true;
144+
}
145+
140146
const size_t OperateIndex = OpeningLineIndex + Direction;
141147
assert(OperateIndex < Lines.size());
142148
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)