Skip to content

Commit c84fb81

Browse files
committed
removing static_cast from tests.
1 parent 984da28 commit c84fb81

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

tests/enum_ops_tests.cpp

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,20 @@ auto stlab_enable_arithmetic_enum(mixed_enum) -> std::true_type;
6363
TEST_CASE("Bitmask: bitwise OR operator") {
6464
// Test enum class with unsigned underlying type
6565
auto result = bitmask_flags::flag_a | bitmask_flags::flag_b;
66-
CHECK(result == static_cast<bitmask_flags>(3u));
66+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
67+
CHECK(result == bitmask_flags{3u});
6768
CHECK((result & bitmask_flags::flag_a) == bitmask_flags::flag_a);
6869
CHECK((result & bitmask_flags::flag_b) == bitmask_flags::flag_b);
6970

7071
// Test enum class with signed underlying type
7172
auto perms = permissions::read | permissions::write;
72-
CHECK(perms == static_cast<permissions>(3));
73+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
74+
CHECK(perms == permissions{3});
7375

7476
// Test unscoped enum
7577
auto mixed = mixed_one | mixed_two;
76-
CHECK(mixed == static_cast<mixed_enum>(3));
78+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
79+
CHECK(mixed == mixed_enum{3});
7780

7881
// Verify result type is same as operands
7982
static_assert(
@@ -96,7 +99,8 @@ TEST_CASE("Bitmask: bitwise AND operator") {
9699

97100
TEST_CASE("Bitmask: bitwise XOR operator") {
98101
auto result = bitmask_flags::flag_a ^ bitmask_flags::flag_b;
99-
CHECK(result == static_cast<bitmask_flags>(3u));
102+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
103+
CHECK(result == bitmask_flags{3u});
100104

101105
// XOR with self should give zero
102106
CHECK((bitmask_flags::flag_a ^ bitmask_flags::flag_a) == bitmask_flags::none);
@@ -176,10 +180,12 @@ TEST_CASE("Bitmask: assignment operators") {
176180

177181
TEST_CASE("Bitmask: subtraction with underlying type") {
178182
auto result = bitmask_flags::flag_c - 1u;
179-
CHECK(result == static_cast<bitmask_flags>(3u));
183+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
184+
CHECK(result == bitmask_flags{3u});
180185

181186
result = bitmask_flags::all - 1u;
182-
CHECK(result == static_cast<bitmask_flags>(6u));
187+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
188+
CHECK(result == bitmask_flags{6u});
183189

184190
// Test with signed enum
185191
auto perm_result = permissions::execute - 2;
@@ -216,18 +222,22 @@ TEST_CASE("Arithmetic: binary operators") {
216222

217223
// Multiplication (enum * scalar)
218224
auto mult_result = arithmetic_int::two * 3;
219-
CHECK(mult_result == static_cast<arithmetic_int>(6));
225+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
226+
CHECK(mult_result == arithmetic_int{6});
220227

221228
// Multiplication (scalar * enum)
222229
auto mult_result2 = 3 * arithmetic_int::two;
223-
CHECK(mult_result2 == static_cast<arithmetic_int>(6));
230+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
231+
CHECK(mult_result2 == arithmetic_int{6});
224232

225233
// Division
226-
auto div_result = static_cast<arithmetic_int>(6) / 2;
234+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
235+
auto div_result = arithmetic_int{6} / 2;
227236
CHECK(div_result == arithmetic_int::three);
228237

229238
// Modulo
230-
auto mod_result = static_cast<arithmetic_int>(5) % 2;
239+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
240+
auto mod_result = arithmetic_int{5} % 2;
231241
CHECK(mod_result == arithmetic_int::one);
232242

233243
static_assert(
@@ -250,15 +260,18 @@ TEST_CASE("Arithmetic: assignment operators") {
250260
// Multiplication assignment
251261
value = arithmetic_int::two;
252262
value *= 3;
253-
CHECK(value == static_cast<arithmetic_int>(6));
263+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
264+
CHECK(value == arithmetic_int{6});
254265

255266
// Division assignment
256-
value = static_cast<arithmetic_int>(6);
267+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
268+
value = arithmetic_int{6};
257269
value /= 2;
258270
CHECK(value == arithmetic_int::three);
259271

260272
// Modulo assignment
261-
value = static_cast<arithmetic_int>(7);
273+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
274+
value = arithmetic_int{7};
262275
value %= 3;
263276
CHECK(value == arithmetic_int::one);
264277

@@ -356,14 +369,16 @@ TEST_CASE("Logical: NOT operator") {
356369
TEST_CASE("Mixed enum: both bitmask and arithmetic operations") {
357370
// Bitmask operations
358371
auto bitmask_result = mixed_one | mixed_two;
359-
CHECK(bitmask_result == static_cast<mixed_enum>(3));
372+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
373+
CHECK(bitmask_result == mixed_enum{3});
360374

361375
auto and_result = mixed_four & mixed_one;
362376
CHECK(and_result == mixed_none);
363377

364378
// Arithmetic operations
365379
auto arith_result = mixed_one + mixed_two;
366-
CHECK(arith_result == static_cast<mixed_enum>(3));
380+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
381+
CHECK(arith_result == mixed_enum{3});
367382

368383
auto mult_result = mixed_two * 2;
369384
CHECK(mult_result == mixed_four);
@@ -375,7 +390,8 @@ TEST_CASE("Mixed enum: both bitmask and arithmetic operations") {
375390

376391
mixed_enum value = mixed_two;
377392
value += mixed_one;
378-
CHECK(value == static_cast<mixed_enum>(3));
393+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
394+
CHECK(value == mixed_enum{3});
379395
}
380396

381397
/**************************************************************************************************/
@@ -390,9 +406,11 @@ TEST_CASE("Constexpr: compile-time evaluation") {
390406
constexpr auto shift_left_result = bitmask_flags::flag_a << 1;
391407
constexpr auto shift_right_result = bitmask_flags::flag_b >> 1;
392408

393-
CHECK(or_result == static_cast<bitmask_flags>(3u));
409+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
410+
CHECK(or_result == bitmask_flags{3u});
394411
CHECK(and_result == bitmask_flags::flag_a);
395-
CHECK(xor_result == static_cast<bitmask_flags>(3u));
412+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
413+
CHECK(xor_result == bitmask_flags{3u});
396414
CHECK(not_result != bitmask_flags::none);
397415
CHECK(shift_left_result == bitmask_flags::flag_b);
398416
CHECK(shift_right_result == bitmask_flags::flag_a);
@@ -401,14 +419,17 @@ TEST_CASE("Constexpr: compile-time evaluation") {
401419
constexpr auto add_result = arithmetic_int::one + arithmetic_int::two;
402420
constexpr auto sub_result = arithmetic_int::three - arithmetic_int::one;
403421
constexpr auto mult_result = arithmetic_int::two * 3;
404-
constexpr auto div_result = static_cast<arithmetic_int>(6) / 2;
405-
constexpr auto mod_result = static_cast<arithmetic_int>(5) % 2;
422+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
423+
constexpr auto div_result = arithmetic_int{6} / 2;
424+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
425+
constexpr auto mod_result = arithmetic_int{5} % 2;
406426
constexpr auto unary_minus_result = -arithmetic_int::one;
407427
constexpr auto unary_plus_result = +arithmetic_int::two;
408428

409429
CHECK(add_result == arithmetic_int::three);
410430
CHECK(sub_result == arithmetic_int::two);
411-
CHECK(mult_result == static_cast<arithmetic_int>(6));
431+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
432+
CHECK(mult_result == arithmetic_int{6});
412433
CHECK(div_result == arithmetic_int::three);
413434
CHECK(mod_result == arithmetic_int::one);
414435
CHECK(unary_minus_result == arithmetic_int::neg_one);

0 commit comments

Comments
 (0)