C++20 commands in libc++ from IAR Build not recognized

Hello everyone,

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?

Thanks in advance!

Version Information:

  • SonarQube server 2025.4.3.113915
  • SonarScanner 5.0.1.3006
  • IAR EWARM 9.70.2
2 Likes

Hi @maufri ,

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.

Hi @mpaladin

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?

Thank you and kind regards.

Hi @maufri ,

sorry about the delay, I am going to have a look at it in the next days. Thank you for your patience.

1 Like

Hi @mpaladin

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:

// IAR
#if __cpp_concepts >= 202002L
# define __cpp_lib_concepts                             202002L
#endif
#if __cpp_constexpr_dynamic_alloc >= 201907L
# define __cpp_lib_constexpr_dynamic_alloc              201907L
#endif

#if defined(__IAR_SYSTEMS_ICC__)
# define __cpp_lib_type_identity                        201806L
# define __cpp_lib_bit_cast                             201806L
# define __cpp_lib_is_constant_evaluated                201811L
# define __cpp_lib_remove_cvref                         201711L
#endif

I already experimented with different configurations in sonar-project.properties by either setting

sonar.cfamily.customPreprocessor=#define __cpp_lib_type_identity 201806L\n#define __cpp_lib_bit_cast 201806L\n#define __cpp_lib_is_constant_evaluated 201811L\n#define __cpp_lib_remove_cvref 201711L

and

sonar.cfamily.reportingCppStandardOverride=c++20

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?