/* >>>------------------------------------------------------------ * * File: rule_10.1.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 10.1 (Required): * The value of an expression of integer type shall not be * implicitly converted to a different underlying type if: * a) it is not a conversion to a wider integer type of the same * signedness, or * b) the expression is complex, or * c) the expression is not constant and is a function argument, * or * d) the expression is not constant and is a return expression * * Implemented by messages: * 570 This switch case label of 'essential type' '%1s', is not * consistent with a controlling expression of essential * type '%2s'. * * 572 This switch case label of 'essential type' '%1s' is not * consistent with a controlling expression which has an * essential type of lower rank (%2s). * * 1256 An integer constant suffixed with L is being converted * to type signed or unsigned long long on assignment. * * 1257 An integer constant suffixed with L or LL is being * converted to a type of lower rank on assignment. * * 1290 An integer constant of 'essentially signed' type is * being converted to unsigned type on assignment. * * 1291 An integer constant of 'essentially unsigned' type is * being converted to signed type on assignment. * * 1292 An integer constant of 'essentially signed' type is * being converted to type char on assignment. * * 1293 An integer constant of 'essentially unsigned' type is * being converted to type char on assignment. * * 1294 An integer constant of 'essentially signed' type is * being converted to type _Bool on assignment. * * 1295 An integer constant of 'essentially unsigned' type is * being converted to type _Bool on assignment. * * 1296 An integer constant of 'essentially signed' type is * being converted to enum type on assignment. * * 1297 An integer constant of 'essentially unsigned' type is * being converted to enum type on assignment. * * 1298 An integer constant of 'essentially signed' type is * being converted to floating type on assignment. * * 1299 An integer constant of 'essentially unsigned' type is * being converted to floating type on assignment. * * 1317 Value of constant expression is not in the enum type to * which it is being converted. * * 1461 Value of constant expression is not in the enum type to * which it is being converted, but is bitwise OR of * constants in the enum type. * * 1800 The %1s operand (essential type: '%2s') will be * implicitly converted to a floating type, '%3s', in this * arithmetic operation. * * 1802 The %1s operand (essential type: '%2s') will be * implicitly converted to a floating type, '%3s', in this * relational operation. * * 1803 The %1s operand (essential type: '%2s') will be * implicitly converted to a floating type, '%3s', in this * equality operation. * * 1804 The %1s operand (essential type: '%2s') will be * implicitly converted to a floating type, '%3s', in this * conditional operation. * * 1810 An operand of 'essentially character' type is being * added to another operand of 'essentially character' * type. * * 1811 An operand of 'essentially character' type is being * subtracted from an operand of 'essentially signed' type. * * 1812 An operand of 'essentially character' type is being * subtracted from an operand of 'essentially unsigned' * type. * * 1813 An operand of 'essentially character' type is being * balanced with an operand of 'essentially floating' type * in this arithmetic operation. * * 1820 The %1s operand is non-constant and 'essentially signed' * (%2s) but will be implicitly converted to an unsigned * type (%3s) in this arithmetic operation. * * 1821 The %1s operand is non-constant and 'essentially signed' * (%2s) but will be implicitly converted to an unsigned * type (%3s) in this bitwise operation. * * 1822 The %1s operand is non-constant and 'essentially signed' * (%2s) but will be implicitly converted to an unsigned * type (%3s) in this relational operation. * * 1823 The %1s operand is non-constant and 'essentially signed' * (%2s) but will be implicitly converted to an unsigned * type (%3s) in this equality operation. * * 1824 The %1s operand is non-constant and 'essentially signed' * (%2s) but will be implicitly converted to an unsigned * type (%3s) in this conditional operation. * * 1830 The %1s operand is constant, 'essentially signed' (%2s) * and negative but will be implicitly converted to an * unsigned type (%3s) in this arithmetic operation. * * 1831 The %1s operand is constant, 'essentially signed' (%2s) * and negative but will be implicitly converted to an * unsigned type (%3s) in this bitwise operation. * * 1832 The %1s operand is constant, 'essentially signed' (%2s) * and negative but will be implicitly converted to an * unsigned type (%3s) in this relational operation. * * 1833 The %1s operand is constant, 'essentially signed' (%2s) * and negative but will be implicitly converted to an * unsigned type (%3s) in this equality operation. * * 1834 The %1s operand is constant, 'essentially signed' (%2s) * and negative but will be implicitly converted to an * unsigned type (%3s) in this conditional operation. * * 1840 The %1s operand is constant, 'essentially signed' (%2s) * and non-negative but will be implicitly converted to an * unsigned type (%3s) in this arithmetic operation. * * 1841 The %1s operand is constant, 'essentially signed' (%2s) * and non-negative but will be implicitly converted to an * unsigned type (%3s) in this bitwise operation. * * 1842 The %1s operand is constant, 'essentially signed' (%2s) * and non-negative but will be implicitly converted to an * unsigned type (%3s) in this relational operation. * * 1843 The %1s operand is constant, 'essentially signed' (%2s) * and non-negative but will be implicitly converted to an * unsigned type (%3s) in this equality operation. * * 1844 The %1s operand is constant, 'essentially signed' (%2s) * and non-negative but will be implicitly converted to an * unsigned type (%3s) in this conditional operation. * * 1850 The %1s operand is 'essentially unsigned' (%2s) but will * be implicitly converted to a signed type (%3s) in this * arithmetic operation. * * 1851 The %1s operand is 'essentially unsigned' (%2s) but will * be implicitly converted to a signed type (%3s) in this * bitwise operation. * * 1852 The %1s operand is 'essentially unsigned' (%2s) but will * be implicitly converted to a signed type (%3s) in this * relational operation. * * 1853 The %1s operand is 'essentially unsigned' (%2s) but will * be implicitly converted to a signed type (%3s) in this * equality operation. * * 1854 The %1s operand is 'essentially unsigned' (%2s) but will * be implicitly converted to a signed type (%3s) in this * conditional operation. * * 1860 The operands of this arithmetic operator are of * different 'essential signedness' but will generate a * result of type 'signed int'. * * 1861 The operands of this bitwise operator are of different * 'essential signedness' but will generate a result of * type 'signed int'. * * 1862 The operands of this relational operator are of * different 'essential signedness' but will both be * promoted to 'signed int' for comparison. * * 1863 The operands of this equality operator are of different * 'essential signedness' but will both be promoted to * 'signed int' for comparison. * * 1864 The 2nd and 3rd operands of this conditional operator * are of different 'essential signedness'. The result will * be in the promoted type 'signed int'. * * 1880 The operands of this relational operator are expressions * of different 'essential type' categories (%1s and %2s). * * 1881 The operands of this equality operator are expressions * of different 'essential type' categories (%1s and %2s). * * 1882 The 2nd and 3rd operands of this conditional operator * are expressions of different 'essential type' categories * (%1s and %2s). * * 1890 A composite expression of 'essentially signed' type * (%1s) is being implicitly converted to a wider signed * type, '%2s'. * * 1891 A composite expression of 'essentially unsigned' type * (%1s) is being implicitly converted to a wider unsigned * type, '%2s'. * * 2900 Constant: Positive integer value truncated by implicit * conversion to a smaller unsigned type. * * 4117 Result of integer division operation implicitly * converted to a floating type. * * 4401 An expression of 'essentially Boolean' type (%1s) is * being converted to character type, '%2s' on assignment. * * 4402 An expression of 'essentially Boolean' type (%1s) is * being converted to enum type, '%2s' on assignment. * * 4403 An expression of 'essentially Boolean' type (%1s) is * being converted to signed type, '%2s' on assignment. * * 4404 An expression of 'essentially Boolean' type (%1s) is * being converted to unsigned type, '%2s' on assignment. * * 4405 An expression of 'essentially Boolean' type (%1s) is * being converted to floating type, '%2s' on assignment. * * 4410 An expression of 'essentially character' type (%1s) is * being converted to Boolean type, '%2s' on assignment. * * 4412 An expression of 'essentially character' type (%1s) is * being converted to enum type, '%2s' on assignment. * * 4413 An expression of 'essentially character' type (%1s) is * being converted to signed type, '%2s' on assignment. * * 4414 An expression of 'essentially character' type (%1s) is * being converted to unsigned type, '%2s' on assignment. * * 4415 An expression of 'essentially character' type (%1s) is * being converted to floating type, '%2s' on assignment. * * 4420 An expression of 'essentially enum' type (%1s) is being * converted to Boolean type, '%2s' on assignment. * * 4421 An expression of 'essentially enum' type (%1s) is being * converted to character type, '%2s' on assignment. * * 4422 An expression of 'essentially enum' type (%1s) is being * converted to a different enum type, '%2s' on assignment. * * 4423 An expression of 'essentially enum' type (%1s) is being * converted to signed type, '%2s' on assignment. * * 4424 An expression of 'essentially enum' type (%1s) is being * converted to unsigned type, '%2s' on assignment. * * 4425 An expression of 'essentially enum' type (%1s) is being * converted to floating type, '%2s' on assignment. * * 4430 An expression of 'essentially signed' type (%1s) is * being converted to Boolean type, '%2s' on assignment. * * 4431 An expression of 'essentially signed' type (%1s) is * being converted to character type, '%2s' on assignment. * * 4432 An expression of 'essentially signed' type (%1s) is * being converted to enum type, '%2s' on assignment. * * 4434 A non-constant expression of 'essentially signed' type * (%1s) is being converted to unsigned type, '%2s' on * assignment. * * 4435 A non-constant expression of 'essentially signed' type * (%1s) is being converted to floating type, '%2s' on * assignment. * * 4436 A constant expression of 'essentially signed' type (%1s) * is being converted to unsigned type, '%2s' on * assignment. * * 4437 A constant expression of 'essentially signed' type (%1s) * is being converted to floating type, '%2s' on * assignment. * * 4440 An expression of 'essentially unsigned' type (%1s) is * being converted to Boolean type, '%2s' on assignment. * * 4441 An expression of 'essentially unsigned' type (%1s) is * being converted to character type, '%2s' on assignment. * * 4442 An expression of 'essentially unsigned' type (%1s) is * being converted to enum type, '%2s' on assignment. * * 4443 A non-constant expression of 'essentially unsigned' type * (%1s) is being converted to a wider signed type, '%2s' * on assignment. * * 4445 An expression of 'essentially unsigned' type (%1s) is * being converted to floating type, '%2s' on assignment. * * 4446 A non-constant expression of 'essentially unsigned' type * (%1s) is being converted to signed type, '%2s' on * assignment. * * 4447 A constant expression of 'essentially unsigned' type * (%1s) is being converted to signed type, '%2s' on * assignment. * * 4451 An expression of 'essentially floating' type (%1s) is * being converted to character type, '%2s' on assignment. * * 4460 A non-constant expression of 'essentially signed' type * (%1s) is being converted to narrower signed type, '%2s' * on assignment. * * 4461 A non-constant expression of 'essentially unsigned' type * (%1s) is being converted to narrower unsigned type, * '%2s' on assignment. * * 4463 A constant expression of 'essentially signed' type (%1s) * is being converted to narrower signed type, '%2s' on * assignment. * * 4464 A constant expression of 'essentially unsigned' type * (%1s) is being converted to narrower unsigned type, * '%2s' on assignment. * * 4470 A non-constant expression of 'essentially signed' type * (%1s) is being passed to a function parameter of wider * signed type, '%2s'. * * 4471 A non-constant expression of 'essentially unsigned' type * (%1s) is being passed to a function parameter of wider * unsigned type, '%2s'. * * 4480 A non-constant expression of 'essentially signed' type * (%1s) is being returned from a function defined with a * wider signed return type, '%2s'. * * 4481 A non-constant expression of 'essentially unsigned' type * (%1s) is being returned from a function defined with a * wider unsigned return type, '%2s'. * * 4490 A composite expression of 'essentially signed' type * (%1s) is being converted to wider signed type, '%2s' on * assignment. * * 4491 A composite expression of 'essentially unsigned' type * (%1s) is being converted to wider unsigned type, '%2s' * on assignment. * * 4500 An expression of 'essentially Boolean' type (%1s) is * being used as an array subscript. * * 4501 An expression of 'essentially Boolean' type (%1s) is * being used as the %2s operand of this arithmetic * operator (%3s). * * 4502 An expression of 'essentially Boolean' type (%1s) is * being used as the %2s operand of this bitwise operator * (%3s). * * 4503 An expression of 'essentially Boolean' type (%1s) is * being used as the left-hand operand of this shift * operator (%2s). * * 4504 An expression of 'essentially Boolean' type (%1s) is * being used as the right-hand operand of this shift * operator (%2s). * * 4505 An expression of 'essentially Boolean' type (%1s) is * being used as the %2s operand of this relational * operator (%3s). * * 4507 An expression of 'essentially Boolean' type (%1s) is * being used as the operand of this increment/decrement * operator (%2s). * * <<<------------------------------------------------------------ */ /* PRQA S 2889,2982,3112,3203,3205 ++ */ #include "misra.h" #include "m2cmex.h" enum Colors { Red , Blue, Green, Purple, Yellow }; enum Fruit { Lemon = -1, Orange = 1, Apple = 3 }; static U32 test_1001a ( void ); static S8 test_1001b ( S16 mode ); static U8 test_1001c ( S16 mode ); static enum Colors color; extern S16 test_1001( void ) { static enum Fruit fruit; /*************** Assignments ****************/ u16a = u8a; u16a = 21U + 32U; f64a = 12.3F * 23.4F; s16a = s32a; /* MISRA Violation */ s16a = 4L; /* MISRA Violation */ u16a = s8a; /* MISRA Violation */ u16a = 4; /* MISRA Violation */ s32a = u16a; /* MISRA Violation */ s32a = 4U; /* MISRA Violation */ u16a = u8a + u8b; /* MISRA Violation */ f32a = s16a; /* MISRA Violation */ f32a = 45; /* MISRA Violation */ color = Apple; /* MISRA Violation */ color = 1; /* MISRA Violation */ /*************** Balancing ****************/ u16a * u8a; f64a + f32a; fruit * 5; s16a * u8a; /* MISRA Violation */ u16a * s8a; /* MISRA Violation */ f64a * s16a; /* MISRA Violation */ f32a + 42; /* MISRA Violation */ u32a + (u8a * u8b); /* MISRA Violation */ /********************************************* Switch case labels **********************************************/ switch ( u8a + u8b ) { case 3: /* MISRA Violation */ { use_u32 ( u32a ); break; } case 5u: { use_u32 ( u32a + u32b ); break; } default: /* empty default comment */ { break; } } /********************************************* Conversion of function arguments **********************************************/ use_s16 ( s32a ); /* MISRA Violation */ use_u16 ( u32a ); /* MISRA Violation */ use_u16 ( s16a ); /* MISRA Violation */ use_s16 ( u16a ); /* MISRA Violation */ use_f32 ( 1 ); /* MISRA Violation */ use_s16 ( 5u ); /* MISRA Violation */ use_u32 ( 5 ); /* MISRA Violation */ u8a = test_1001b ( 1 ); s8a = test_1001c ( 2 ); return 1; } static S8 test_1001b ( S16 mode ) { if (mode == 0) { return 4U; /* MISRA Violation */ } else if (mode == 1) { return s16a; /* MISRA Violation */ } else { return color; /* MISRA Violation */ } } static U8 test_1001c ( S16 mode ) { if (mode == 0) { return 4; /* MISRA Violation */ } else if (mode == 1) { return u16a; /* MISRA Violation */ } else { return color; /* MISRA Violation */ } }