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
101 lines
2.9 KiB
C++
101 lines
2.9 KiB
C++
// RUN: %check_clang_tidy %s bugprone-inaccurate-erase %t
|
|
|
|
namespace std {
|
|
template <typename T> struct vec_iterator {
|
|
T ptr;
|
|
vec_iterator operator++(int);
|
|
|
|
template <typename X>
|
|
vec_iterator(const vec_iterator<X> &); // Omit enable_if<...>.
|
|
};
|
|
|
|
template <typename T> struct vector {
|
|
typedef vec_iterator<T*> iterator;
|
|
|
|
iterator begin();
|
|
iterator end();
|
|
|
|
void erase(iterator);
|
|
void erase(iterator, iterator);
|
|
};
|
|
|
|
template <typename T> struct vector_with_const_iterator {
|
|
typedef vec_iterator<T*> iterator;
|
|
typedef vec_iterator<const T*> const_iterator;
|
|
|
|
iterator begin();
|
|
iterator end();
|
|
|
|
void erase(const_iterator);
|
|
void erase(const_iterator, const_iterator);
|
|
};
|
|
|
|
template <typename FwIt, typename T>
|
|
FwIt remove(FwIt begin, FwIt end, const T &val);
|
|
|
|
template <typename FwIt, typename Func>
|
|
FwIt remove_if(FwIt begin, FwIt end, Func f);
|
|
|
|
template <typename FwIt> FwIt unique(FwIt begin, FwIt end);
|
|
|
|
template <typename T> struct unique_ptr {};
|
|
} // namespace std
|
|
|
|
struct custom_iter {};
|
|
struct custom_container {
|
|
void erase(...);
|
|
custom_iter begin();
|
|
custom_iter end();
|
|
};
|
|
|
|
template <typename T> void g() {
|
|
T t;
|
|
t.erase(std::remove(t.begin(), t.end(), 10));
|
|
// CHECK-FIXES: t.erase(std::remove(t.begin(), t.end(), 10));
|
|
|
|
std::vector<int> v;
|
|
v.erase(remove(v.begin(), v.end(), 10));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one
|
|
// CHECK-FIXES: v.erase(remove(v.begin(), v.end(), 10), v.end());
|
|
}
|
|
|
|
#define ERASE(x, y) x.erase(remove(x.begin(), x.end(), y))
|
|
// CHECK-FIXES: #define ERASE(x, y) x.erase(remove(x.begin(), x.end(), y))
|
|
|
|
int main() {
|
|
std::vector<int> v;
|
|
|
|
v.erase(remove(v.begin(), v.end(), 10));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one item even when multiple items should be removed [bugprone-inaccurate-erase]
|
|
// CHECK-FIXES: v.erase(remove(v.begin(), v.end(), 10), v.end());
|
|
v.erase(remove(v.begin(), v.end(), 20), v.end());
|
|
|
|
auto *p = &v;
|
|
p->erase(remove(p->begin(), p->end(), 11));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one
|
|
// CHECK-FIXES: p->erase(remove(p->begin(), p->end(), 11), p->end());
|
|
|
|
std::vector_with_const_iterator<int> v2;
|
|
v2.erase(remove(v2.begin(), v2.end(), 12));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one
|
|
// CHECK-FIXES: v2.erase(remove(v2.begin(), v2.end(), 12), v2.end());
|
|
|
|
// Fix is not trivial.
|
|
auto it = v.end();
|
|
v.erase(remove(v.begin(), it, 10));
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one
|
|
// CHECK-FIXES: v.erase(remove(v.begin(), it, 10));
|
|
|
|
g<std::vector<int>>();
|
|
g<custom_container>();
|
|
|
|
ERASE(v, 15);
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: this call will remove at most one
|
|
// CHECK-FIXES: ERASE(v, 15);
|
|
|
|
std::vector<std::unique_ptr<int>> vupi;
|
|
auto iter = vupi.begin();
|
|
vupi.erase(iter++);
|
|
// CHECK-FIXES: vupi.erase(iter++);
|
|
}
|