MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed

Moderators: misra-c, david ward

Post Reply
jsleeman
Posts: 1
Joined: Fri Apr 03, 2015 3:42 pm
Company: Renishaw

MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed

Post by jsleeman » Thu Mar 26, 2020 10:53 am

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: Select all

/***************
 * 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

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: MISRAC2012-Rule-16.1 : The body of this switch statement is not well-formed

Post by misra-c » Fri Apr 17, 2020 1:27 pm

There are no violations of rule 16.1 in your example.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.16 Switch statements”