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
91 lines
2.3 KiB
C++
91 lines
2.3 KiB
C++
// RUN: %clang_cc1 -fsyntax-only -Wself-assign -verify %s
|
|
|
|
void f() {
|
|
int a = 42, b = 42;
|
|
a = a; // expected-warning{{explicitly assigning}}
|
|
b = b; // expected-warning{{explicitly assigning}}
|
|
a = b;
|
|
b = a = b;
|
|
a = a = a; // expected-warning{{explicitly assigning}}
|
|
a = b = b = a;
|
|
|
|
a *= a;
|
|
a /= a;
|
|
a %= a;
|
|
a += a;
|
|
a -= a;
|
|
a <<= a;
|
|
a >>= a;
|
|
a &= a; // expected-warning {{explicitly assigning}}
|
|
a |= a; // expected-warning {{explicitly assigning}}
|
|
a ^= a;
|
|
}
|
|
|
|
// Dummy type.
|
|
struct S {};
|
|
|
|
void false_positives() {
|
|
#define OP =
|
|
#define LHS a
|
|
#define RHS a
|
|
int a = 42;
|
|
// These shouldn't warn due to the use of the preprocessor.
|
|
a OP a;
|
|
LHS = a;
|
|
a = RHS;
|
|
LHS OP RHS;
|
|
#undef OP
|
|
#undef LHS
|
|
#undef RHS
|
|
|
|
// A way to silence the warning.
|
|
a = (int &)a;
|
|
|
|
// Volatile stores aren't side-effect free.
|
|
volatile int vol_a;
|
|
vol_a = vol_a;
|
|
volatile int &vol_a_ref = vol_a;
|
|
vol_a_ref = vol_a_ref;
|
|
}
|
|
|
|
// Do not diagnose self-assignment in an unevaluated context
|
|
void false_positives_unevaluated_ctx(int a) noexcept(noexcept(a = a)) // expected-warning {{expression with side effects has no effect in an unevaluated context}}
|
|
{
|
|
decltype(a = a) b = a; // expected-warning {{expression with side effects has no effect in an unevaluated context}}
|
|
static_assert(noexcept(a = a), ""); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
|
|
static_assert(sizeof(a = a), ""); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
|
|
}
|
|
|
|
template <typename T>
|
|
void g() {
|
|
T a;
|
|
a = a; // expected-warning{{explicitly assigning}}
|
|
}
|
|
void instantiate() {
|
|
g<int>();
|
|
g<S>();
|
|
}
|
|
|
|
struct Foo {
|
|
int A;
|
|
|
|
Foo(int A) : A(A) {}
|
|
|
|
void setA(int A) {
|
|
A = A; // expected-warning{{explicitly assigning value of variable of type 'int' to itself; did you mean to assign to member 'A'?}}
|
|
}
|
|
|
|
void setThroughLambda() {
|
|
[](int A) {
|
|
// To fix here we would need to insert an explicit capture 'this'
|
|
A = A; // expected-warning{{explicitly assigning}}
|
|
}(5);
|
|
|
|
[this](int A) {
|
|
this->A = 0;
|
|
// This fix would be possible by just adding this-> as above, but currently unsupported.
|
|
A = A; // expected-warning{{explicitly assigning}}
|
|
}(5);
|
|
}
|
|
};
|