[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 5 00:49:22 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff f1903431558b93f0fc48f195282f61194cb024fe 9f9895da9657543724ccce2b8bbabbfa8df4ea1d -- clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp clang-tools-extra/clang-tidy/boost/UseRangesCheck.h clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp clang-tools-extra/clang-tidy/modernize/UseRangesCheck.h clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp clang-tools-extra/clang-tidy/utils/UseRangesCheck.h clang-tools-extra/test/clang-tidy/checkers/boost/use-ranges.cpp clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp clang-tools-extra/clang-tidy/boost/BoostTidyModule.cpp clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
index ae6c88c89d..b6cbba97f4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
@@ -23,7 +23,8 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::GetReplacerMap() const {
std::string getReplaceName(const NamedDecl &OriginalName) const override {
return ("std::ranges::" + OriginalName.getName()).str();
}
- ArrayRef<UseRangesCheck::Signature> getReplacementSignatures() const override {
+ ArrayRef<UseRangesCheck::Signature>
+ getReplacementSignatures() const override {
return Indexes;
}
std::optional<std::string>
@@ -36,7 +37,7 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::GetReplacerMap() const {
};
utils::UseRangesCheck::ReplacerMap Result;
-
+
// template<typename Iter> Func(Iter first, Iter last,...).
static const Signature SingleRangeArgs = {{0}};
// template<typename Policy, typename Iter>
@@ -52,85 +53,83 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::GetReplacerMap() const {
static const Signature SingleRangeFunc[] = {SingleRangeArgs};
- static const Signature SingleRangeExecFunc[] = {
- SingleRangeArgs, SingleRangeExecPolicy};
+ static const Signature SingleRangeExecFunc[] = {SingleRangeArgs,
+ SingleRangeExecPolicy};
static const Signature TwoRangeExecFunc[] = {TwoRangeArgs,
- TwoRangeExecPolicy};
- static const Signature OneOrTwoFunc[] = {SingleRangeArgs,
- TwoRangeArgs};
+ TwoRangeExecPolicy};
+ static const Signature OneOrTwoFunc[] = {SingleRangeArgs, TwoRangeArgs};
static const Signature OneOrTwoExecFunc[] = {
SingleRangeArgs, SingleRangeExecPolicy, TwoRangeArgs, TwoRangeExecPolicy};
- static const std::pair<ArrayRef<Signature>, ArrayRef<StringRef>>
- Names[] = {
- {SingleRangeFunc,
- {"all_of",
- "any_of",
- "none_of",
- "for_each",
- "find",
- "find_if",
- "find_if_not",
- "adjacent_find",
- "copy",
- "copy_if",
- "copy_backward",
- "move",
- "move_backward",
- "fill",
- "transform",
- "replace",
- "replace_if",
- "generate",
- "remove",
- "remove_if",
- "remove_copy",
- "remove_copy_if",
- "unique",
- "unique_copy",
- "sample",
- "partition_point",
- "lower_bound",
- "upper_bound",
- "equal_range",
- "binary_search",
- "push_heap",
- "pop_heap",
- "make_heap",
- "sort_heap",
- "next_permutation",
- "prev_permutation",
- "iota"}},
- {SingleRangeExecFunc,
- {"reverse",
- "reverse_copy",
- "shift_left",
- "shift_right",
- "is_partitioned",
- "partition",
- "partition_copy",
- "stable_partition",
- "sort",
- "stable_sort",
- "is_sorted",
- "is_sorted_until",
- "is_heap",
- "is_heap_until",
- "max_element",
- "min_element",
- "minmax_element",
- "uninitialized_copy",
- "uninitialized_fill",
- "uninitialized_move",
- "uninitialized_default_construct",
- "uninitialized_value_construct",
- "destroy"}},
- {TwoRangeExecFunc,
- {"partial_sort_copy", "includes", "set_union", "set_intersection",
- "set_difference", "set_symmetric_difference", "merge",
- "lexicographical_compare", "find_end", "search"}},
- {OneOrTwoFunc, {"is_permutation"}},
- {OneOrTwoExecFunc, {"equal", "mismatch"}}};
+ static const std::pair<ArrayRef<Signature>, ArrayRef<StringRef>> Names[] = {
+ {SingleRangeFunc,
+ {"all_of",
+ "any_of",
+ "none_of",
+ "for_each",
+ "find",
+ "find_if",
+ "find_if_not",
+ "adjacent_find",
+ "copy",
+ "copy_if",
+ "copy_backward",
+ "move",
+ "move_backward",
+ "fill",
+ "transform",
+ "replace",
+ "replace_if",
+ "generate",
+ "remove",
+ "remove_if",
+ "remove_copy",
+ "remove_copy_if",
+ "unique",
+ "unique_copy",
+ "sample",
+ "partition_point",
+ "lower_bound",
+ "upper_bound",
+ "equal_range",
+ "binary_search",
+ "push_heap",
+ "pop_heap",
+ "make_heap",
+ "sort_heap",
+ "next_permutation",
+ "prev_permutation",
+ "iota"}},
+ {SingleRangeExecFunc,
+ {"reverse",
+ "reverse_copy",
+ "shift_left",
+ "shift_right",
+ "is_partitioned",
+ "partition",
+ "partition_copy",
+ "stable_partition",
+ "sort",
+ "stable_sort",
+ "is_sorted",
+ "is_sorted_until",
+ "is_heap",
+ "is_heap_until",
+ "max_element",
+ "min_element",
+ "minmax_element",
+ "uninitialized_copy",
+ "uninitialized_fill",
+ "uninitialized_move",
+ "uninitialized_default_construct",
+ "uninitialized_value_construct",
+ "destroy"}},
+ {TwoRangeExecFunc,
+ {"partial_sort_copy", "includes", "set_union", "set_intersection",
+ "set_difference", "set_symmetric_difference", "merge",
+ "lexicographical_compare", "find_end", "search"}},
+ {OneOrTwoFunc, {"is_permutation"}},
+ {OneOrTwoExecFunc, {"equal", "mismatch"}}};
SmallString<64> Buff;
for (const auto &[Signature, Values] : Names) {
auto Replacer = llvm::makeIntrusiveRefCnt<StdReplacer>(
diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index e0fd407539..43d4f9e820 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -54,7 +54,8 @@ std::string getFullPrefix(ArrayRef<UseRangesCheck::Indexes> Signature) {
}
static llvm::hash_code hash_value(const UseRangesCheck::Indexes &Indexes) {
- return llvm::hash_combine(Indexes.BeginArg, Indexes.EndArg, Indexes.ReplaceArg);
+ return llvm::hash_combine(Indexes.BeginArg, Indexes.EndArg,
+ Indexes.ReplaceArg);
}
static llvm::hash_code hash_value(const UseRangesCheck::Signature &Sig) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/97764
More information about the cfe-commits
mailing list