C++ analysis engine covers more rules from MISRA C++ 2008 standard

Hello C++ developers,

We’ve further stepped up our game in supporting MISRA C++ 2008! As promised in our blog post earlier this year, we’ve been working hard to better support the MISRA C++ 2008 standard. We’ve just released a new version of our C++ analysis engine and it includes 9 new rules supporting MISRA C++ 2008 bringing the total to 43 rules compliant with this standard.

Bug Detection:

  • S1042: Handlers of a function-try-block implementation of a class constructor or destructor shall not reference non-static members from this class or its bases. (Bug)
  • S1002: Multiple declarations for an identifier in the same namespace shall not straddle a using-declaration for that identifier. (Bug)
  • S5359: Each operand of the ! operator, the logical && or the logical || operators shall have type bool. (Bug)

Code Smell Detection:

  • S994: A variable which is not modified shall be const qualified. (Code Smell)
  • S963: In the definition of a function-like macro, each instance of a parameter shall be enclosed in parentheses, unless it is used as the operand of # or ##. (Code Smell)
  • S5356: An object with pointer type shall not be converted to an unrelated pointer type, either directly or indirectly. (Code Smell)
  • S5357: An object with integral type or pointer to void type shall not be converted to an object with pointer type. (Code Smell)
  • S5358: A cast should not convert a pointer type to an integral type. (Code Smell)
  • S5350: Pointer and reference local variables should be “const” if the corresponding object is not modified. (Code Smell)

In parallel to this effort related to MISRA C++ 2008, we started to look at the C++ Core Guidelines. From this study, we extracted 3 rule ideas that are implemented in this release.

  • S5421: Non-const global variables should not be used. (Code Smell)
  • S5416: “using” should be preferred to “typedef” for type aliasing. (Code Smell)
  • S5408: A “constexpr” function should not be declared “inline”. (Code Smell)

For more information you can read the changelog.

You can already enjoy these new features on SonarCloud. As for SonarQube, this will be built-in the next version (8.0), and meanwhile you can get it by installing v6.4 of the C/C++/Objective-C analysis engine.

All feedback is welcome.

Cheers,
Alex

1 Like

Hi,
This is very good!
This post was written in 2019 and its now 2023, What is the coverage of MISRA C++ 2008 rules in Sonar today? Did you get them all in? Or only the most important ones? Is there any MISRA version that is fully covered by Sonar rules?

Thanks and regards,
Dennis

Hi @Dennis1

You will find the information you need in that post.
No MISRA rule was added in the meantime and we do not plan to add more at the moment.

Note that we are going to work on the upcoming MISRA 202x which can be used with modern C++.

I hope it helps.