/* >>>------------------------------------------------------------ * * File: rule_5.3.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 5.3 (Required): * A typedef name shall be a unique identifier. * * Implemented by messages: * 1506 The identifier '%1s' is declared as a typedef and is * used elsewhere for a different kind of declaration. * * 1507 '%1s' is used as a typedef for different types. * * 1508 The typedef '%1s' is declared in more than one location. * * 3448 Declaration of typedef '%s' is not in a header file * although it is used in a definition or declaration with * external linkage. * * <<<------------------------------------------------------------ */ /* PRQA S 2983,2984,3205 ++ */ #include "misra.h" #include "m2cmex.h" static S16 test_0503a( S16 n ); static S16 test_0503b( void ); static S16 test_0503c( S16 n ); static S16 test_0503d( void ); static S16 test_0503e( S16 n ); static S16 test_0503f( void ); static S16 test_0503g( void ); typedef S16 T1; T1 obj_0503 = 1; /************************************************************ Hiding of a typedef identifier - Rule 5.2 ************************************************************/ extern S16 test_0503( void ) { typedef S32 T1; /* MISRA Violation - Rule 5.2 */ S16 r = 0; r = r + test_0503a( 1 ); r = r + test_0503b( ); r = r + test_0503c( 1 ); r = r + test_0503d( ); r = r + test_0503e( 1 ); r = r + test_0503f( ); r = r + test_0503g( ); return 0; } /***************************************************************** Identical redefinition of a typedef in a different scope *****************************************************************/ static S16 test_0503a( S16 n ) { typedef S8 T2; if ( n == 2 ) { typedef S16 T3; } else { typedef S16 T3; /* MISRA Violation */ } return 0; } static S16 test_0503b( void ) { typedef S8 T2; /* MISRA Violation */ return 0; } /***************************************************************** Non-identical redefinition of a typedef in a different scope *****************************************************************/ static S16 test_0503c( S16 n ) { typedef S8 T4; if ( n == 2 ) { typedef S16 T5; } else { typedef S32 T5; /* MISRA Violation */ } return 0; } static S16 test_0503d( void ) { typedef S16 T4; /* MISRA Violation */ return 0; } /***************************************************************** Re-use of a typedef identifier in a different scope as a non-typedef identifier *****************************************************************/ static S16 test_0503e( S16 n ) { typedef S8 T6; typedef S16 T8; typedef S32 T9; if ( n == 2 ) { typedef S16 T7; } else { S32 T7; /* MISRA Violation */ } return 0; } static S16 test_0503f( void ) { S16 T6; /* MISRA Violation */ enum etag { T8, Y }; /* MISRA Violation */ struct stag { S16 T9; S16 x; }; return 0; } /***************************************************************** Re-use of a typedef identifier at the same scope in a different namespace *****************************************************************/ static S16 test_0503g( void ) { typedef S16 T10; struct T10 {S16 a; S16 b;}; return 0; }