diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp b/clang/lib/Format/DefinitionBlockSeparator.cpp --- a/clang/lib/Format/DefinitionBlockSeparator.cpp +++ b/clang/lib/Format/DefinitionBlockSeparator.cpp @@ -143,8 +143,10 @@ if (LikelyDefinition(OperateLine)) return false; - if (OperateLine->First->is(tok::comment)) + if (const auto *Tok = OperateLine->First; + Tok->is(tok::comment) && !isClangFormatOn(Tok->TokenText)) { return true; + } // A single line identifier that is not in the last line. if (OperateLine->First->is(tok::identifier) && diff --git a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp --- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp +++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp @@ -283,6 +283,15 @@ TEST_F(DefinitionBlockSeparatorTest, Always) { FormatStyle Style = getLLVMStyle(); Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always; + + verifyFormat("// clang-format off\n" + "template\n" + "concept C = not A>;\n" + "// clang-format on\n" + "\n" + "struct E {};", + Style); + std::string Prefix = "namespace {\n"; std::string Infix = "\n" "// Enum test1\n"