@@ -482,4 +482,88 @@ void test_compound_assignments() {
482482 l2 >>= 1 ; // COMPLIANT - compound assignment, rule does not apply
483483 l4 += l1; // COMPLIANT - compound assignment, rule does not apply
484484 l4 -= s32; // COMPLIANT - compound assignment, rule does not apply
485+ }
486+
487+ // Test constructor field initializers
488+ struct ConstructorTest {
489+ std::uint8_t m1;
490+ std::uint16_t m2;
491+ std::uint32_t m3;
492+ std::int8_t m4;
493+ std::int16_t m5;
494+ std::int32_t m6;
495+ float m7;
496+ double m8;
497+
498+ // Constructor with various member initializer scenarios
499+ ConstructorTest (std::uint8_t l1, std::uint16_t l2, std::int8_t l3)
500+ : m1(l1), // COMPLIANT - same type
501+ m2 (l2), // COMPLIANT - same type
502+ m3(l1), // COMPLIANT - widening of id-expression
503+ m4(l3), // COMPLIANT - same type
504+ m5(l3), // COMPLIANT - widening of id-expression
505+ m6(l3), // COMPLIANT - widening of id-expression
506+ m7(1 .0f ), // COMPLIANT - same type
507+ m8(1.0 ) { // COMPLIANT - same type
508+ }
509+
510+ // Constructor with non-compliant initializers
511+ ConstructorTest (std::uint32_t l1, std::int32_t l2, float l3)
512+ : m1(l1), // NON_COMPLIANT - narrowing
513+ m2(l1), // NON_COMPLIANT - narrowing
514+ m3(l1), // COMPLIANT - same type
515+ m4(l2), // NON_COMPLIANT - narrowing and different signedness
516+ m5(l2), // NON_COMPLIANT - narrowing and different signedness
517+ m6(l2), // COMPLIANT - same type
518+ m7(l3), // COMPLIANT - same type
519+ m8(l3) { // COMPLIANT - allowed to use float to initialize double
520+ }
521+
522+ // Constructor with constant initializers
523+ ConstructorTest ()
524+ : m1(100 ), // COMPLIANT - constant fits
525+ m2(65535 ), // COMPLIANT - constant fits
526+ m3(4294967295U ), // COMPLIANT - constant fits
527+ m4(127 ), // COMPLIANT - constant fits
528+ m5(32767 ), // COMPLIANT - constant fits
529+ m6(2147483647 ), // COMPLIANT - constant fits
530+ m7(3 .14f ), // COMPLIANT - same type constant
531+ m8(2.718 ) { // COMPLIANT - same type constant
532+ }
533+
534+ // Constructor with non-compliant constant initializers
535+ ConstructorTest (int )
536+ : m1(300 ), // NON_COMPLIANT - constant too large
537+ m2(70000 ), // NON_COMPLIANT - constant too large
538+ m3(0x1'0000'0000ULL ), // NON_COMPLIANT - constant too large
539+ m4(200 ), // NON_COMPLIANT - constant too large
540+ m5(40000 ), // NON_COMPLIANT - constant too large
541+ m6(0x1'0000'0000LL ), // NON_COMPLIANT - constant too large
542+ m7(1.0 ), // NON_COMPLIANT - different size
543+ m8(1 .0f ) { // NON_COMPLIANT - different size
544+ }
545+
546+ // Constructor with expression initializers
547+ ConstructorTest (std::uint8_t l1, std::uint8_t l2, std::int8_t l3)
548+ : m1(l1 + l2), // NON_COMPLIANT - expression result is int
549+ m2(l1 + l2), // NON_COMPLIANT - expression result is int
550+ m3(l1 + l2), // NON_COMPLIANT - expression result is int
551+ m4(l3), // COMPLIANT - widening of id-expression
552+ m5(l1), // NON_COMPLIANT - different signedness
553+ m6(l1), // NON_COMPLIANT - different signedness
554+ m7(l1), // NON_COMPLIANT - different type category
555+ m8(l1) { // NON_COMPLIANT - different type category
556+ }
557+ };
558+
559+ void test_constructor_field_initializers () {
560+ std::uint8_t l1 = 42 ;
561+ std::uint16_t l2 = 1000 ;
562+ std::int8_t l3 = 10 ;
563+
564+ ConstructorTest l4 (l1, l2, l3); // Test first constructor
565+ ConstructorTest l5 (u32 , s32, f); // Test second constructor
566+ ConstructorTest l6; // Test third constructor
567+ ConstructorTest l7 (0 ); // Test fourth constructor
568+ ConstructorTest l8 (l1, l1, l3); // Test fifth constructor
485569}
0 commit comments