Author: Björn Schäpers Date: 2026-08-23T19:14:26Z New Revision: 66a285ca58cb19c1cc20baa18ad6ab061e07a123
URL: https://github.com/llvm/llvm-project/commit/66a285ca58cb19c1cc20baa18ad6ab061e07a123 DIFF: https://github.com/llvm/llvm-project/commit/66a285ca58cb19c1cc20baa18ad6ab061e07a123.diff LOG: [clang-format] Honor new lines before // clang-format on (#218022) Fixes #217872. (cherry picked from commit 6978738e1efe0c33a9540b70697ce0c83852d9c7) Added: Modified: clang/lib/Format/UnwrappedLineFormatter.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 7afc7a46dd1c0..b783876b6da8f 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1637,6 +1637,8 @@ static auto computeNewlines(const AnnotatedLine &Line, const SmallVectorImpl<AnnotatedLine *> &Lines, const FormatStyle &Style) { const auto &RootToken = *Line.First; + if (isClangFormatOn(RootToken.TokenText)) + return RootToken.NewlinesBefore; auto Newlines = std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1); // Remove empty lines before "}" where applicable. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 72e0182181763..92bc4c918fb21 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -22420,6 +22420,14 @@ TEST_F(FormatTest, DisableRegions) { " #endif\n" "#endif\n" "// clang-format on"); + + verifyNoChange("// clang-format off\n" + "\n" + "\n" + " int i ;\n" + "\n" + "\n" + "// clang-format on"); } TEST_F(FormatTest, OneLineFormatOffRegex) { _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
