I have tried to analyze my project, which I have switched to C++20 modules recently. As my used tools are supporting C++20 modules since some months (cmake 3.28, GCC 14), I did the switch and the C++20 modules are working fine.
However, Sonar Scanner seems not yet to work with C++20 modules. I have used the latest available Scanner 5.0.1.3006, which is from 2023-08-04. The message I get is:
ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
* you are using the latest version of the build-wrapper and the CFamily analyzer
* you are correctly invoking the scanner with correct configuration
* your compiler is supported
* you are wrapping your build correctly
* you are wrapping a full/clean build
* you are providing the path to the correct build-wrapper output directory
* you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
The problem seems to be that the .cppm files are not recognized:
but 0 C/C++/Objective-C files were analyzed
Is there an update available, when C++20 modules support can be expected?
Indeed, we currently do not support modules and do not have yet an estimated timeline for doing so.
However, it is on our radar, and we have recently started examining the C++ ecosystem to see how modules are implemented by tooling and used by developers. If your project is open source, it would be helpful if you could share it so we can better understand the use cases.
Of course this is early work in progress and I don’t guarantee anything, but it
compiles
has test cases
a Github action runner with Sonar Cloud setup
and a very small example app (besides the test cases).
You can also install it under /usr/local, it will populate the folders
src/c++-modules/guardfw/ (for the .cppm files) and
lib64/cmake/guardfw/ (for cmake files).
You will also need:
cmake 3.28
gcc-14
Ninja
The library itself is a generic and highly configurable wrapper for Posix library functions. Instead of returning error codes, it throws exceptions (and exceptions can’t be ignored, but this behaviour can be changed for each wrapped call). But for you the most interesting thing is, that it heavily uses C++20 modules.
To your sonar-scanner configuration (via command line or sonar-project.properties)
If everything works as intended, you will see some new entries on the logs such as
INFO: 52 compilation units were scanned for C++ modules
INFO: C++ module dependency scanning cache: 0/52 hits
INFO: 21 BMIs were built for C++ modules
...
INFO: C and C++ analysis quality score: 100/100