the IAR compiler added support for some c++20 symbols in libc++ (We upgraded from 9.50.1 to 9.70.2), but they aren’t recognized by SonarQube yet. A specific example is the use of std::bit_cast:
no member named ‘bit_cast’ in namespace ‘std’
We have included libcpp in our project using std::bit_cast and IAR is able to compile without any error.
Is it possible to configure SonarScanner to enable support for these new symbols? Or do you potentially have a clue how else this problem could be fixed?
would you be able to share the analysis log and the build-wrapper-output/compile_commands files? I am sending you a private message where you can share.
I have shared some log files in the DM channel as you mentioned. The log output of sonar-scanner revealed a general issue with analysis of the libc++ dependency since we updated from EWARM 9.50.1 to 9.70.2. Are you planning to continue looking into this issue?
before continuing this thread I’ll place your response from the DM here for context:
The issue comes from the fact that the compiler claims to be on C++17, see #define __cplusplus 201703L in the probe in the scanner log, and at the same time the libcpp that is embedded is using c++20 features and that is the reason why you are seeing the parsing errors.
From the official documentation:
Note that __cplusplus is still defined to 201703L (but individual feature testing macros are updated
according to their respective supported level. For example, __cpp_constexpr is defined to 202002L).
This is not a standard practice, they should bump __cplusplus to c++20 version.
Also, I don’t see an option to force the c++ standard. You may want to open a ticket to IAR.
I have raised the issue at IAR support, where they claim conformity to C++ with their approach:
The C++ standard defines __cplusplus as a conformance indicator, not a feature-by-feature capability flag. Its value simply shows the highest C++ standard revision the compiler claims to fully support. It is common for compilers to report different values for __cplusplus and for feature-specific macros. This is why preprocessor macros tied to specific C++ language and library features are used.
The supported c++20 features are configured in arm/inc/libcpp/version. E.g. bit_cast is configured in this section with the __cpp_lib_bit_cast macro:
but with no improvement. Also when using Compile-Commands, Sonar-Scanner doesn’t allow adding custom PreProcessor Defines: java.lang.IllegalArgumentException: The property sonar.cfamily.customPreprocessor (...) is not supported in Compile-Commands mode. Another test I did was to define the symbols in IAR’s Preprocessor settings, which added the feature test macros to compile_commands.json, but still with no improvement.
My question now is, can we inform Sonar-Scanner in some other way on what additional feature test macros are enabled in order to have c++20 features correctly analyzed in libcpp?