False Negative cpp:S811 cpp:S867

  • Language: C++
  • Rules: cpp:S811 cpp:S867 (equivalent MISRA and non-MISRA rules)
  • False negative because the condition has type int32_t and according to the rule it should have type bool
  • I am using SonarQube Cloud, and the VSCode edition in connected mode

Minimal reproduction code:

int32_t foo() { return 0; }

void bar() {
  if (const int32_t fooRet = foo()) {
    LOGGER << "foo-ailed\n";
  } else {
    // call baz
  }
}

Hello @pauljnixon, welcome to community!

  • Regarding rule cpp:S811, note that it is a strict implementation of the MISRA C++:2008 rule 5-0-13. And this has an explicit exception for conditions of the form type-specifier-seq declarator because in this case the developer intent is clear.

  • Instead, it does appear to be a false negative for the case of rule cpp:S867. This rule is inspired by MISRA C++:2008 rule 5-3-1 but has been specified by us, including many additions. It is in the plan to eventually update or even revamp this rule, but with no known timeline. I have created a ticket for this: Jira.

Thank you for sharing your feedback!