MISRA Discussion Forums
MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.16 Switch statements (https://forum.misra.org.uk/forumdisplay.php?fid=171)
+---- Thread: MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed (/showthread.php?tid=1534)



MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed - jsleeman - 26-03-2020

Hello everyone,

I have 2 functions below, the top one, I get a MISRAC2012-Rule-16.1 warning, the second one I do not get the warning, the only difference between them is where 'i' is declared.
Is the warning I am seeing correct? If it is why is it not allowed?
I have looked through the 16.x rules and I could not see anything that suggested I could it was banned.
I am using IAR C-STAT to do the analysis.

Code:
/***************
* I get the following warning on this switch statement: MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed.
***************/
uint32_t func(uint32_t num)
{
   uint32_t result;

   switch(num)
   {
      case 0:
      {
         result = 123U;
         break;
      }
      case 1:
      {
         result = 567U;

         for (uint32_t i = 0U; i < 10U; i++)
         {
            result = i + result;
         }
         break;
      }
      default:
      {
         result = 0;
         break;
      }
   }

   return result;
}

uint32_t func_b(uint32_t num)
{
   uint32_t result;

   switch(num)
   {
      case 0:
      {
         result = 123U;
         break;
      }
      case 1:
      {
         uint32_t i;
         result = 567U;
         /***************
          * If I declare 'i' outside of the loop this warning goes away: MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed.
          ***************/
         for (i = 0U; i < 10U; i++)
         {
            result = i + result;
         }
         break;
      }
      default:
      {
         result = 0;
         break;
      }
   }

   return result;
}

Thanks,
James


Re: MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed - misra-c - 17-04-2020

There are no violations of rule 16.1 in your example.