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
121 lines
2.5 KiB
C++
121 lines
2.5 KiB
C++
// RUN: %check_clang_tidy %s bugprone-assignment-in-if-condition %t
|
|
|
|
void f(int arg) {
|
|
int f = 3;
|
|
if ((f = arg) || (f == (arg + 1)))
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
|
|
{
|
|
f = 5;
|
|
}
|
|
}
|
|
|
|
void f1(int arg) {
|
|
int f = 3;
|
|
if ((f == arg) || (f = (arg + 1)))
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
|
|
{
|
|
f = 5;
|
|
}
|
|
}
|
|
|
|
void f2(int arg) {
|
|
int f = 3;
|
|
if (f = arg)
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
|
|
{
|
|
f = 5;
|
|
}
|
|
}
|
|
|
|
volatile int v = 32;
|
|
|
|
void f3(int arg) {
|
|
int f = 3;
|
|
if ((f == arg) || ((arg + 6 < f) && (f = v)))
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
|
|
{
|
|
f = 5;
|
|
}
|
|
}
|
|
|
|
void f4(int arg) {
|
|
int f = 3;
|
|
if ((f == arg) || ((arg + 6 < f) && ((f = v) || (f < 8))))
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
|
|
{
|
|
f = 5;
|
|
} else if ((arg + 8 < f) && ((f = v) || (f < 8)))
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
|
|
{
|
|
f = 6;
|
|
}
|
|
}
|
|
|
|
class BrokenOperator {
|
|
public:
|
|
int d = 0;
|
|
int operator=(const int &val) {
|
|
d = val + 1;
|
|
return d;
|
|
}
|
|
};
|
|
|
|
void f5(int arg) {
|
|
BrokenOperator bo;
|
|
int f = 3;
|
|
bo = f;
|
|
if (bo.d == 3) {
|
|
f = 6;
|
|
}
|
|
if (bo = 3)
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
|
|
{
|
|
f = 7;
|
|
}
|
|
if ((arg == 3) || (bo = 6))
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
|
|
{
|
|
f = 8;
|
|
}
|
|
v = f;
|
|
}
|
|
|
|
// Tests that shouldn't trigger warnings.
|
|
void awesome_f2(int arg) {
|
|
int f = 3;
|
|
if ((f == arg) || (f == (arg + 1))) {
|
|
f = 5;
|
|
}
|
|
}
|
|
|
|
void awesome_f3(int arg) {
|
|
int f = 3;
|
|
if (f == arg) {
|
|
f = 5;
|
|
}
|
|
}
|
|
|
|
void awesome_f4(int arg) {
|
|
int f = 3;
|
|
if ((f == arg) || ((arg + 6 < f) && ((f == v) || (f < 8)))) {
|
|
f = 5;
|
|
}
|
|
}
|
|
|
|
template <typename Func> bool exec(Func F) { return F(); }
|
|
|
|
void lambda_if() {
|
|
int X;
|
|
if ([&X] {
|
|
X = 5;
|
|
return true;
|
|
}()) {
|
|
}
|
|
|
|
if (exec([&] {
|
|
X = 5;
|
|
return true;
|
|
})) {
|
|
}
|
|
}
|