@@ -63,17 +63,20 @@ auto stlab_enable_arithmetic_enum(mixed_enum) -> std::true_type;
63
63
TEST_CASE (" Bitmask: bitwise OR operator" ) {
64
64
// Test enum class with unsigned underlying type
65
65
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 });
67
68
CHECK ((result & bitmask_flags::flag_a) == bitmask_flags::flag_a);
68
69
CHECK ((result & bitmask_flags::flag_b) == bitmask_flags::flag_b);
69
70
70
71
// Test enum class with signed underlying type
71
72
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 });
73
75
74
76
// Test unscoped enum
75
77
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 });
77
80
78
81
// Verify result type is same as operands
79
82
static_assert (
@@ -96,7 +99,8 @@ TEST_CASE("Bitmask: bitwise AND operator") {
96
99
97
100
TEST_CASE (" Bitmask: bitwise XOR operator" ) {
98
101
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 });
100
104
101
105
// XOR with self should give zero
102
106
CHECK ((bitmask_flags::flag_a ^ bitmask_flags::flag_a) == bitmask_flags::none);
@@ -176,10 +180,12 @@ TEST_CASE("Bitmask: assignment operators") {
176
180
177
181
TEST_CASE (" Bitmask: subtraction with underlying type" ) {
178
182
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 });
180
185
181
186
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 });
183
189
184
190
// Test with signed enum
185
191
auto perm_result = permissions::execute - 2 ;
@@ -216,18 +222,22 @@ TEST_CASE("Arithmetic: binary operators") {
216
222
217
223
// Multiplication (enum * scalar)
218
224
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 });
220
227
221
228
// Multiplication (scalar * enum)
222
229
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 });
224
232
225
233
// 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 ;
227
236
CHECK (div_result == arithmetic_int::three);
228
237
229
238
// 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 ;
231
241
CHECK (mod_result == arithmetic_int::one);
232
242
233
243
static_assert (
@@ -250,15 +260,18 @@ TEST_CASE("Arithmetic: assignment operators") {
250
260
// Multiplication assignment
251
261
value = arithmetic_int::two;
252
262
value *= 3 ;
253
- CHECK (value == static_cast <arithmetic_int>(6 ));
263
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
264
+ CHECK (value == arithmetic_int{6 });
254
265
255
266
// Division assignment
256
- value = static_cast <arithmetic_int>(6 );
267
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
268
+ value = arithmetic_int{6 };
257
269
value /= 2 ;
258
270
CHECK (value == arithmetic_int::three);
259
271
260
272
// Modulo assignment
261
- value = static_cast <arithmetic_int>(7 );
273
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
274
+ value = arithmetic_int{7 };
262
275
value %= 3 ;
263
276
CHECK (value == arithmetic_int::one);
264
277
@@ -356,14 +369,16 @@ TEST_CASE("Logical: NOT operator") {
356
369
TEST_CASE (" Mixed enum: both bitmask and arithmetic operations" ) {
357
370
// Bitmask operations
358
371
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 });
360
374
361
375
auto and_result = mixed_four & mixed_one;
362
376
CHECK (and_result == mixed_none);
363
377
364
378
// Arithmetic operations
365
379
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 });
367
382
368
383
auto mult_result = mixed_two * 2 ;
369
384
CHECK (mult_result == mixed_four);
@@ -375,7 +390,8 @@ TEST_CASE("Mixed enum: both bitmask and arithmetic operations") {
375
390
376
391
mixed_enum value = mixed_two;
377
392
value += mixed_one;
378
- CHECK (value == static_cast <mixed_enum>(3 ));
393
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
394
+ CHECK (value == mixed_enum{3 });
379
395
}
380
396
381
397
/* *************************************************************************************************/
@@ -390,9 +406,11 @@ TEST_CASE("Constexpr: compile-time evaluation") {
390
406
constexpr auto shift_left_result = bitmask_flags::flag_a << 1 ;
391
407
constexpr auto shift_right_result = bitmask_flags::flag_b >> 1 ;
392
408
393
- CHECK (or_result == static_cast <bitmask_flags>(3u ));
409
+ // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
410
+ CHECK (or_result == bitmask_flags{3u });
394
411
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 });
396
414
CHECK (not_result != bitmask_flags::none);
397
415
CHECK (shift_left_result == bitmask_flags::flag_b);
398
416
CHECK (shift_right_result == bitmask_flags::flag_a);
@@ -401,14 +419,17 @@ TEST_CASE("Constexpr: compile-time evaluation") {
401
419
constexpr auto add_result = arithmetic_int::one + arithmetic_int::two;
402
420
constexpr auto sub_result = arithmetic_int::three - arithmetic_int::one;
403
421
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 ;
406
426
constexpr auto unary_minus_result = -arithmetic_int::one;
407
427
constexpr auto unary_plus_result = +arithmetic_int::two;
408
428
409
429
CHECK (add_result == arithmetic_int::three);
410
430
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 });
412
433
CHECK (div_result == arithmetic_int::three);
413
434
CHECK (mod_result == arithmetic_int::one);
414
435
CHECK (unary_minus_result == arithmetic_int::neg_one);
0 commit comments