CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
161 lines
5.9 KiB
C++
161 lines
5.9 KiB
C++
// RUN: %check_clang_tidy %s llvm-use-ranges %t
|
|
#include <vector>
|
|
|
|
// Test that the header is included
|
|
// CHECK-FIXES: #include "llvm/ADT/STLExtras.h"
|
|
|
|
namespace std {
|
|
|
|
template <typename T> T* begin(T (&arr)[5]);
|
|
template <typename T> T* end(T (&arr)[5]);
|
|
|
|
template <class InputIt, class T>
|
|
T accumulate(InputIt first, InputIt last, T init);
|
|
|
|
template <class InputIt, class T, class BinaryOp>
|
|
T accumulate(InputIt first, InputIt last, T init, BinaryOp op);
|
|
|
|
template <class InputIt, class T>
|
|
InputIt find(InputIt first, InputIt last, const T &value);
|
|
|
|
template <class RandomIt>
|
|
void sort(RandomIt first, RandomIt last);
|
|
|
|
template <class RandomIt>
|
|
void stable_sort(RandomIt first, RandomIt last);
|
|
|
|
template <class InputIt, class UnaryPredicate>
|
|
bool all_of(InputIt first, InputIt last, UnaryPredicate p);
|
|
|
|
template <class InputIt, class UnaryFunction>
|
|
UnaryFunction for_each(InputIt first, InputIt last, UnaryFunction f);
|
|
|
|
template <class ForwardIt, class T>
|
|
ForwardIt remove(ForwardIt first, ForwardIt last, const T& value);
|
|
|
|
template <class ForwardIt>
|
|
ForwardIt min_element(ForwardIt first, ForwardIt last);
|
|
|
|
template <class InputIt1, class InputIt2>
|
|
bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2);
|
|
|
|
template <class InputIt1, class InputIt2>
|
|
bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2);
|
|
|
|
template <class InputIt, class OutputIt>
|
|
OutputIt copy(InputIt first, InputIt last, OutputIt d_first);
|
|
|
|
template <class ForwardIt, class T>
|
|
void fill(ForwardIt first, ForwardIt last, const T& value);
|
|
|
|
template <class BidirIt>
|
|
void reverse(BidirIt first, BidirIt last);
|
|
|
|
template <class ForwardIt>
|
|
ForwardIt unique(ForwardIt first, ForwardIt last);
|
|
|
|
template <class ForwardIt>
|
|
bool is_sorted(ForwardIt first, ForwardIt last);
|
|
|
|
template <class InputIt1, class InputIt2>
|
|
bool includes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2);
|
|
|
|
template <class InputIt, class OutputIt, class T>
|
|
OutputIt replace_copy(InputIt first, InputIt last, OutputIt d_first,
|
|
const T& old_value, const T& new_value);
|
|
|
|
template <class InputIt, class OutputIt, class UnaryPredicate, class T>
|
|
OutputIt replace_copy_if(InputIt first, InputIt last, OutputIt d_first,
|
|
UnaryPredicate p, const T& new_value);
|
|
|
|
} // namespace std
|
|
|
|
bool is_even(int x);
|
|
void double_ref(int& x);
|
|
int multiply(int a, int b);
|
|
|
|
void test_positive() {
|
|
std::vector<int> vec;
|
|
int arr[5] = {1, 2, 3, 4, 5};
|
|
|
|
int sum = std::accumulate(vec.begin(), vec.end(), 0);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: int sum = llvm::accumulate(vec, 0);
|
|
|
|
int product = std::accumulate(vec.begin(), vec.end(), 1, multiply);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: int product = llvm::accumulate(vec, 1, multiply);
|
|
|
|
auto it1 = std::find(vec.begin(), vec.end(), 3);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: auto it1 = llvm::find(vec, 3);
|
|
|
|
auto it2 = std::find(std::begin(arr), std::end(arr), 3);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: auto it2 = llvm::find(arr, 3);
|
|
|
|
std::stable_sort(vec.begin(), vec.end());
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: llvm::stable_sort(vec);
|
|
|
|
bool all = std::all_of(vec.begin(), vec.end(), is_even);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: bool all = llvm::all_of(vec, is_even);
|
|
|
|
std::for_each(vec.begin(), vec.end(), double_ref);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: llvm::for_each(vec, double_ref);
|
|
|
|
auto min_it = std::min_element(vec.begin(), vec.end());
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: auto min_it = llvm::min_element(vec);
|
|
|
|
std::vector<int> vec2;
|
|
bool eq = std::equal(vec.begin(), vec.end(), vec2.begin(), vec2.end());
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: bool eq = llvm::equal(vec, vec2);
|
|
|
|
std::copy(vec.begin(), vec.end(), vec2.begin());
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: llvm::copy(vec, vec2.begin());
|
|
|
|
std::fill(vec.begin(), vec.end(), 0);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: llvm::fill(vec, 0);
|
|
|
|
auto last = std::unique(vec.begin(), vec.end());
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: auto last = llvm::unique(vec);
|
|
|
|
bool sorted = std::is_sorted(vec.begin(), vec.end());
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: bool sorted = llvm::is_sorted(vec);
|
|
|
|
std::includes(vec.begin(), vec.end(), std::begin(arr), std::end(arr));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: llvm::includes(vec, arr);
|
|
|
|
std::replace_copy(vec.begin(), vec.end(), vec2.begin(), 1, 2);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: llvm::replace_copy(vec, vec2.begin(), 1, 2);
|
|
|
|
std::replace_copy_if(vec.begin(), vec.end(), vec2.begin(), is_even, 0);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use an LLVM range-based algorithm
|
|
// CHECK-FIXES: llvm::replace_copy_if(vec, vec2.begin(), is_even, 0);
|
|
}
|
|
|
|
void test_negative() {
|
|
std::vector<int> v;
|
|
|
|
// can not use `llvm::sort` because of potential different ordering from `std::sort`.
|
|
std::sort(v.begin(), v.end());
|
|
|
|
//non-begin/end iterators
|
|
auto it1 = std::find(v.begin() + 1, v.end(), 2);
|
|
auto it2 = std::find(v.begin(), v.end() - 1, 2);
|
|
|
|
// Using different containers (3-arg equal)
|
|
std::vector<int> v2;
|
|
bool eq = std::equal(v.begin(), v.end(), v2.begin());
|
|
}
|