[PATCH] D156971: [clang-format] Handle "// clang-format on" for SeparateDefinitionBlocks

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 5 12:31:48 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG58a71c66db85: [clang-format] Handle "// clang-format on" for SeparateDefinitionBlocks (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156971/new/

https://reviews.llvm.org/D156971

Files:
  clang/lib/Format/DefinitionBlockSeparator.cpp
  clang/unittests/Format/DefinitionBlockSeparatorTest.cpp


Index: clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
===================================================================
--- clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ 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<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"
Index: clang/lib/Format/DefinitionBlockSeparator.cpp
===================================================================
--- clang/lib/Format/DefinitionBlockSeparator.cpp
+++ 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) &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156971.547506.patch
Type: text/x-patch
Size: 1404 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230805/8e6bdb21/attachment.bin>


More information about the cfe-commits mailing list