[clang] 58a71c6 - [clang-format] Handle "// clang-format on" for SeparateDefinitionBlocks
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 5 12:31:36 PDT 2023
Author: Owen Pan
Date: 2023-08-05T12:31:27-07:00
New Revision: 58a71c66db85f65bb6cdefe314f62318b95e9fc4
URL: https://github.com/llvm/llvm-project/commit/58a71c66db85f65bb6cdefe314f62318b95e9fc4
DIFF: https://github.com/llvm/llvm-project/commit/58a71c66db85f65bb6cdefe314f62318b95e9fc4.diff
LOG: [clang-format] Handle "// clang-format on" for SeparateDefinitionBlocks
Fixes 63393.
Differential Revision: https://reviews.llvm.org/D156971
Added:
Modified:
clang/lib/Format/DefinitionBlockSeparator.cpp
clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 576c6597b27afe..8fb6f55f629edd 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -143,8 +143,10 @@ void DefinitionBlockSeparator::separateBlocks(
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
index 45dd2fdc46b68f..5cf4edcbdf2e5a 100644
--- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -283,6 +283,15 @@ TEST_F(DefinitionBlockSeparatorTest, UntouchBlockStartStyle) {
TEST_F(DefinitionBlockSeparatorTest, Always) {
FormatStyle Style = getLLVMStyle();
Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always;
+
+ verifyFormat("// clang-format off\n"
+ "template<class T>\n"
+ "concept C = not A<S<T>>;\n"
+ "// clang-format on\n"
+ "\n"
+ "struct E {};",
+ Style);
+
std::string Prefix = "namespace {\n";
std::string Infix = "\n"
"// Enum test1\n"
More information about the cfe-commits
mailing list