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
130 lines
3.0 KiB
C++
130 lines
3.0 KiB
C++
// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-non-zero-enum-to-bool-conversion %t -- \
|
|
// RUN: -config="{CheckOptions: {bugprone-non-zero-enum-to-bool-conversion.EnumIgnoreList: '::without::issue::IgnoredEnum;IgnoredSecondEnum'}}"
|
|
|
|
namespace with::issue {
|
|
|
|
typedef enum EStatus {
|
|
SUCCESS = 1,
|
|
FAILURE = 2,
|
|
INVALID_PARAM = 3,
|
|
UNKNOWN = 4
|
|
} Status;
|
|
|
|
bool testEnumConversion(EStatus value) {
|
|
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
|
|
return value;
|
|
}
|
|
|
|
bool testTypedefConversion(Status value) {
|
|
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
|
|
return value;
|
|
}
|
|
|
|
bool testExplicitConversion(EStatus value) {
|
|
// CHECK-MESSAGES: :[[@LINE+1]]:28: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
|
|
return static_cast<bool>(value);
|
|
}
|
|
|
|
bool testInIfConversion(EStatus value) {
|
|
// CHECK-MESSAGES: :[[@LINE+1]]:7: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
|
|
if (value) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool testWithNegation(EStatus value) {
|
|
// CHECK-MESSAGES: :[[@LINE+1]]:14: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
|
|
return not value;
|
|
}
|
|
|
|
}
|
|
|
|
namespace without::issue {
|
|
|
|
enum StatusWithZero {
|
|
UNK = 0,
|
|
OK = 1,
|
|
NOT_OK = 2
|
|
};
|
|
|
|
bool testEnumConversion(StatusWithZero value) {
|
|
return value;
|
|
}
|
|
|
|
enum WithDefault {
|
|
Value0,
|
|
Value1
|
|
};
|
|
|
|
bool testEnumConversion(WithDefault value) {
|
|
return value;
|
|
}
|
|
|
|
enum WithNegative : int {
|
|
Nen2 = -2,
|
|
Nen1,
|
|
Nen0
|
|
};
|
|
|
|
bool testEnumConversion(WithNegative value) {
|
|
return value;
|
|
}
|
|
|
|
enum EStatus {
|
|
SUCCESS = 1,
|
|
FAILURE,
|
|
INVALID_PARAM,
|
|
UNKNOWN
|
|
};
|
|
|
|
bool explicitCompare(EStatus value) {
|
|
return value == SUCCESS;
|
|
}
|
|
|
|
bool explicitBitUsage1(EStatus value) {
|
|
return (value & SUCCESS);
|
|
}
|
|
|
|
bool explicitBitUsage2(EStatus value) {
|
|
return (value | SUCCESS);
|
|
}
|
|
|
|
bool testEnumeratorCompare() {
|
|
return SUCCESS;
|
|
}
|
|
|
|
enum IgnoredEnum {
|
|
IGNORED_VALUE_1 = 1,
|
|
IGNORED_VALUE_2
|
|
};
|
|
|
|
enum IgnoredSecondEnum {
|
|
IGNORED_SECOND_VALUE_1 = 1,
|
|
IGNORED_SECOND_VALUE_2
|
|
};
|
|
|
|
bool testIgnored(IgnoredEnum value) {
|
|
return value;
|
|
}
|
|
|
|
bool testIgnored(IgnoredSecondEnum value) {
|
|
return value;
|
|
}
|
|
|
|
enum CustomOperatorEnum {
|
|
E0 = 0x1,
|
|
E1 = 0x2,
|
|
E2 = 0x4
|
|
};
|
|
|
|
CustomOperatorEnum operator&(CustomOperatorEnum a, CustomOperatorEnum b) { return static_cast<CustomOperatorEnum>(a & b); }
|
|
|
|
void testCustomOperator(CustomOperatorEnum e) {
|
|
if (e & E1) {}
|
|
if ((e & E1)) {}
|
|
if (!(e & E1)) {}
|
|
}
|
|
|
|
}
|