MISRA Discussion Forums
Rule 6-3-1: Does it also apply to "case" blocks? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.6 Statements (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=135)
+---- Thread: Rule 6-3-1: Does it also apply to "case" blocks? (/showthread.php?tid=1656)



Rule 6-3-1: Does it also apply to "case" blocks? - cgpzs - 24-08-2023

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!


RE: Rule 6-3-1: Does it also apply to "case" blocks? - misra cpp - 06-11-2023

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