I’m trying to integrate sonarcloud into a C++23 application.
I’m facing an issue on sonar-scanner run.
#0 35.63 14:35:12.609 ERROR: Error during SonarScanner execution
#0 35.63 java.lang.UnsupportedOperationException: Unsupported value of __cplusplus macro: 202100L
#0 35.63 at com.sonar.cpp.analyzer.StdFlags.fromCppMacrosWithoutConditionalFeatures(StdFlags.java:56)
Do you have any solution to avoid this issue ?
Note: We don’t have any issue on MSVC but our target is gcc-12.
We must run sonnar-scanner with c++23 on linux. If not, we will have to drop sonar cloud unfortunately.
We wish that sonar support c++23 feature but for today, it’s not a must. We only wish that sonar-scaner does not fail. In other words, it will work for us if sonar ignores C++23 features but does not block at runtime.
I should have clarified that by experimental, we mean that user support is limited, and the property may be modified or removed. We can not guarantee the results: the compiler support for C++23 is limited, and our rules have not yet been adjusted.
You are still welcome to use it, but please, keep this in mind
Just for the probe, would it be possible to let the scanner do the probe with a dummy “compiler” (i.e.: a script that just outputs a “compatible” __cplusplus version) instead?
I would advise against that workaround. If you are using C++23 features, but trick the C++ analyzer into thinking you are using, say, C++20, the analysis results will be unreliable at best.
C++23 language constructs (i.e. if consteval), will become parsing errors in C++20. C++23 standard libraries features will go missing (since they are usually enabled conditionally based on the value of __cplusplus). In summary, the code will “look” broken from the analyzer’s perspective.
If your code can be compiled with C++20, it would be better to do just so and analyze that version.
I hope this helps clarify why it is important for the analyzer to be aware of how the code is compiled.
In the meantime I saw that some of my readings/assumptions were “not quite accurate”:
as it seems from newer posts, c++23 may already be "experimental"ly supported in the meantime.
on reading the first post again, he doesn’t explicitly say that he isn’t using c++23 features.
(only: “it will work for us if sonar ignores C++23 features but does not block at runtime.”)