Skip to content

Conversation

owenca
Copy link
Contributor

@owenca owenca commented May 8, 2025

Fix #61956

@llvmbot
Copy link
Member

llvmbot commented May 8, 2025

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Fix #61956


Full diff: https://github.com/llvm/llvm-project/pull/139034.diff

2 Files Affected:

  • (modified) clang/lib/Format/DefinitionBlockSeparator.cpp (+6)
  • (modified) clang/unittests/Format/DefinitionBlockSeparatorTest.cpp (+5)
diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 319236d3bd618..c4d609083977e 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -137,6 +137,12 @@ void DefinitionBlockSeparator::separateBlocks(
     const auto MayPrecedeDefinition = [&](const int Direction = -1) {
       assert(Direction >= -1);
       assert(Direction <= 1);
+
+      if (Style.isCSharp() &&
+          Lines[OpeningLineIndex]->First->is(TT_CSharpGenericTypeConstraint)) {
+        return true;
+      }
+
       const size_t OperateIndex = OpeningLineIndex + Direction;
       assert(OperateIndex < Lines.size());
       const auto &OperateLine = Lines[OperateIndex];
diff --git a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
index b26b9f4f4ff62..1f4245b703fb7 100644
--- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -574,6 +574,11 @@ TEST_F(DefinitionBlockSeparatorTest, CSharp) {
                "\r\n"
                "public class FoobarClass {\r\n"
                "  int foobar;\r\n"
+               "}\r\n"
+               "\r\n"
+               "public class LogFactory<TLogger>\r\n"
+               "    where TLogger : class, new() {\r\n"
+               "  int i;\r\n"
                "}",
                Style);
 }

@owenca owenca merged commit 4bcc083 into llvm:main May 9, 2025
7 of 10 checks passed
@owenca owenca deleted the 61956 branch May 9, 2025 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Places parameters of record class on new line
4 participants