S3630 is raised on C++17 project

@Abbas_Sabra
I found this quite interesting topic because in our project we currently have a similar issue with C++20 vs. C++17.
The SQ scan detects a code smell (cpp:S3630) which can be solved by a C++20 feature only (std::bit_cast instead of reinterpret_cast).
But our compiler only supports C++17 which is set in the CMake file as compiler parameter:

07:30:02.249 DEBUG: Probing compiler: [/opt/gcc-arm-none-eabi-10.3-2021.07/bin/arm-none-eabi-g++, -x, c++, --std, c++17, -mcpu=cortex-m4, -mfloat-abi=hard, -mfpu=fpv4-sp-d16, -mthumb, -v, -dM, -E, -]

We are using SonarQube LTS Version 8.9.7 (build 52159) which has bundled CFamily v6.20 which should detect the correct C++ standard if I understood the previous comments right?

07:29:55.148 DEBUG:   * C++ (Community) 2.0.7.3119 (cxx)
07:29:55.148 DEBUG:   * CFamily Code Quality and Security 6.20.3.42796 (cpp)

Thank you,
Hubert

Hello @hstreidl,

Welcome to the community!

I moved you to another thread because I don’t think the two issues are related.

We are using SonarQube LTS Version 8.9.7 (build 52159) which has bundled CFamily v6.20 which should detect the correct C++ standard if I understood the previous comments right?

True and we should detect C++17 and not raise the issue with the since-c++20 tag. You can filter by tag on SonarQube to see the list of rules per C++standard or on rules.sonarsource,com.

for example here are the since-c++20 rules: https://rules.sonarsource.com/cpp/tag/since-c++20

You will notice that S3630 is not one of them. S3630 is a cppcoreguidline rule that says ““reinterpret_cast” should not be used”. Independently of the standard.

Now the rule message is standard dependent. if you are using C++20 and the cast can be replaced by bit_cast the rule message will be: “Replace “reinterpret_cast” with a “std::bit_cast”.”
But if you are not using C++20 or the cast is not equivalent to bit_cast, the rule message will be:
“Replace “reinterpret_cast” with a safer cast.”.
If I’m not wrong, you are getting the second message which is expected.

Let me know if you have further questions,

1 Like

Hello @Abbas_Sabra ,
Thank you for the quick response!
I obviously misinterpreted the verbose code smell explanation which mentioned a C++20 feature which might solve the issue. In future I will keep a closer look at the tags and also at the quite helpful list of rules per C++ standard. So I’m still learning to get more familiar with SonarQube and therefore appreciate the great support.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.