Need float exclusion for rule cpp:S813

In our project we would like

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    • SonarQube 9.7.1-enterprise
  • what are you trying to achieve
    • Have a sensible ruleset for us based on MISRA rules.
  • what have you tried so far to achieve this
    • Parametrize and select appropriate rules.

The rule cpp:S813: “typedefs that indicate size and signedness should be used in place of the basic types”, currently applies to integer and floating point types. We would like to activate it only for integer types, because it doesn’t make much sense in our view to apply this to floating point types, since a) their bit-width is not usually the issue, and b) the layout and operations are much more important to ascertain in this case, so this creates a false sense of security.

For this reason we would like to have a parameter to disable this rule for float and double and only enable it for integer types.

Hi @Carl,

Since this rule follows MISRA guidelines, we try to stick to them as much as possible, and in this case, it means reporting on float.

But you’ll be happy to know that the upcoming version of MISRA agrees with you on this point, and should no longer mention floating point types in this rule. So stay tuned!

1 Like

Hi @JolyLoic ,

that’s good news, although I think it wouldn’t hurt to allow parametrization in the meantime. The parameter could still be default true for reporting on float, conforming to MISRA, but would allow projects that want to deviate here to do so systematically without disabling this otherwise very useful rule.

Hi @Carl,

We don’t add parameters to rules unless the rule makes no sense without them because it makes the product significantly more complex to use.

Hopefully, the release date of a version with the improved rule should not be too different from what the release date of a version with a parameter would have been.

HI @JolyLoic ,

I’m sad to hear that, if you ask me it adds no more complexity for the user if the defaults lead to the same behavior as before.

I also hope the release is soon of the new ruleset.

Well, the rule has still not been updated to exclude floats ! :slight_smile:

@Oodini,

I hope you’ll be glad to learn that the improved rule was released at the end of 2023. It is not an update of the existing rule (S813) because we did not want to break the existing behavior for users relying on MISRA C++2008 but a brand new rule, named M23_058.

I apologize for not mentioning it on this thread when it was added to the product, it would have been helpful.

1 Like

Thanks for your prompt reply.
Did Sonar implemented all the rules of Misra C++:2023 ?
Can I get rid of Misra C++:2008 ?

Not yet. You can see the rules that are currently implemented.

2 Likes