kentsommer created this revision. kentsommer added a project: clang-format. kentsommer requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
- Fixes a bug that caused `// clang-format off` in a includes section to disabled include sorting even after a `// clang-format on` was found. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D94287 Files: clang/lib/Format/Format.cpp clang/test/Format/line-disable-include-sorting.cpp Index: clang/test/Format/line-disable-include-sorting.cpp =================================================================== --- /dev/null +++ clang/test/Format/line-disable-include-sorting.cpp @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s \ +// RUN: | clang-format -style="{BasedOnStyle: LLVM, SortIncludes: true}" \ +// RUN: | FileCheck -strict-whitespace %s +// CHECK: {{^//\ clang-format\ off$}} +// CHECK-NEXT: {{^#include\ <c>$}} +// CHECK-NEXT: {{^//\ clang-format\ on$}} +// CHECK-NEXT: {{^#include\ <a>$}} +// CHECK-NEXT: {{^#include\ <b>$}} +// clang-format off +#include <c> +// clang-format on +#include <b> +#include <a> Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -2307,8 +2307,8 @@ IncludesInBlock.clear(); FirstIncludeBlock = false; } - Prev = Pos + 1; } + Prev = Pos + 1; if (Pos == StringRef::npos || Pos + 1 == Code.size()) break; SearchFrom = Pos + 1;
Index: clang/test/Format/line-disable-include-sorting.cpp =================================================================== --- /dev/null +++ clang/test/Format/line-disable-include-sorting.cpp @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s \ +// RUN: | clang-format -style="{BasedOnStyle: LLVM, SortIncludes: true}" \ +// RUN: | FileCheck -strict-whitespace %s +// CHECK: {{^//\ clang-format\ off$}} +// CHECK-NEXT: {{^#include\ <c>$}} +// CHECK-NEXT: {{^//\ clang-format\ on$}} +// CHECK-NEXT: {{^#include\ <a>$}} +// CHECK-NEXT: {{^#include\ <b>$}} +// clang-format off +#include <c> +// clang-format on +#include <b> +#include <a> Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -2307,8 +2307,8 @@ IncludesInBlock.clear(); FirstIncludeBlock = false; } - Prev = Pos + 1; } + Prev = Pos + 1; if (Pos == StringRef::npos || Pos + 1 == Code.size()) break; SearchFrom = Pos + 1;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits