MISRA Discussion Forums

Full Version: Rule 6-3-1: Does it also apply to "case" blocks?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Consider this piece of code:

Code:
enum Foo
{
  a,
  b
};


void foo(Foo f)
{
  switch(f)
  {
    case a:
      std::cout << "a\n";
      break;
    case b:
      std::cout << "b\n";
      break;
  }

}

Is the above compliant with M6-3-1, or does one need to add braces also to the "case" blocks, e.g.:

Code:
case a:
{
  std::cout << "a\n";
  break;
}

Thanks!
No, braces are not required around the case clause, see switch syntax in 6-4-3