| 1 |
// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-non-zero-enum-to-bool-conversion %t |
| 2 |
|
| 3 |
namespace with::issue { |
| 4 |
|
| 5 |
enum class EStatusC : char { |
| 6 |
SUCCESS = 1, |
| 7 |
FAILURE = 2, |
| 8 |
INVALID_PARAM = 3, |
| 9 |
UNKNOWN = 4 |
| 10 |
}; |
| 11 |
|
| 12 |
bool testEnumConversion(EStatusC value) { |
| 13 |
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusC' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion] |
| 14 |
return static_cast<bool>(value); |
| 15 |
} |
| 16 |
|
| 17 |
enum class EStatusS : short { |
| 18 |
SUCCESS = 1, |
| 19 |
FAILURE = 2, |
| 20 |
INVALID_PARAM = 3, |
| 21 |
UNKNOWN = 4 |
| 22 |
}; |
| 23 |
|
| 24 |
bool testEnumConversion(EStatusS value) { |
| 25 |
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusS' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion] |
| 26 |
return static_cast<bool>(value); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
enum class EStatusI : int { |
| 31 |
SUCCESS = 1, |
| 32 |
FAILURE = 2, |
| 33 |
INVALID_PARAM = 3, |
| 34 |
UNKNOWN = 4 |
| 35 |
}; |
| 36 |
|
| 37 |
bool testEnumConversion(EStatusI value) { |
| 38 |
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusI' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion] |
| 39 |
return static_cast<bool>(value); |
| 40 |
} |
| 41 |
|
| 42 |
enum class EStatus { |
| 43 |
SUCCESS = 1, |
| 44 |
FAILURE = 2, |
| 45 |
INVALID_PARAM = 3, |
| 46 |
UNKNOWN = 4 |
| 47 |
}; |
| 48 |
|
| 49 |
bool testEnumConversion(EStatus value) { |
| 50 |
// 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] |
| 51 |
return static_cast<bool>(value); |
| 52 |
} |
| 53 |
|
| 54 |
namespace enum_int { |
| 55 |
|
| 56 |
enum EResult : int { |
| 57 |
OK = 1, |
| 58 |
NOT_OK |
| 59 |
}; |
| 60 |
|
| 61 |
bool testEnumConversion(const EResult& value) { |
| 62 |
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EResult' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion] |
| 63 |
return value; |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
namespace enum_short { |
| 69 |
|
| 70 |
enum EResult : short { |
| 71 |
OK = 1, |
| 72 |
NOT_OK |
| 73 |
}; |
| 74 |
|
| 75 |
bool testEnumConversion(const EResult& value) { |
| 76 |
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EResult' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion] |
| 77 |
return value; |
| 78 |
} |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
namespace enum_char { |
| 83 |
|
| 84 |
enum EResult : char { |
| 85 |
OK = 1, |
| 86 |
NOT_OK |
| 87 |
}; |
| 88 |
|
| 89 |
bool testEnumConversion(const EResult& value) { |
| 90 |
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EResult' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion] |
| 91 |
return value; |
| 92 |
} |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
namespace enum_default { |
| 97 |
|
| 98 |
enum EResult { |
| 99 |
OK = 1, |
| 100 |
NOT_OK |
| 101 |
}; |
| 102 |
|
| 103 |
bool testEnumConversion(const EResult& value) { |
| 104 |
// CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EResult' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion] |
| 105 |
return value; |
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
} |