Rule c:S128 allows _intentional_ fallthrough, but our compiler does not like the marker. waht do?

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension)
  • sq server 2025.1
  • how is SonarQube deployed:
  • zip
  • what are you trying to achieve
  • i want to allow an intentional fallthrough in a switch()
  • what have you tried so far to achieve this
    i wrote the switch the following way:
switch (myVariable) {
  case 1:
    foo();
    break;
  case 2:  // Both 'doSomething()' and 'doSomethingElse()' will be executed. Is it on purpose ?
    doSomething();
  default:
    doSomethingElse();
    break;
}

which, obviously, fails rule c:S128. This falthrough is intentional though, and i would like to allow it. The sonarqube help recommends to add “[[fallthrough]];” to the case, to mark the intention. our compiler does not like this line. is there a way to change the format for marking the intentional fallthrough? for example, can we make “//fallthrough” the code for allowing a fallthrough?

Hi,

I think your best bet here is just to mark this issue a false positive.

 
HTH,
Ann