Code Coverage on MSVC

Answered

I have to use MSVC, but I love CLion too much, so I managed to get it working to the compiler. Sadly, it seems that code coverage does not work with MSVC, and on the coverage tutorial MSVC isn't specified, just GCC/G++ and Clang. If anyone could tell me a way to test coverage using the specified toolchan, thank you in advance.

1
4 comments

Hello!

Only gcc and clang support code coverage out of the box, therefore we support these compilers. In case of MSVC there is a possibility to support using code coverage with clang-cl. Feel free to comment or upvote https://youtrack.jetbrains.com/issue/CPP-19937. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.

1

I'm having the same scenario, I need to use MSVC, but would like to setup code coverage. I see the linked CPP-19937 issue is closed as fixed. But, it's not clear to me how you setup CLion with code coverage for MSVC toolchain. Any instructions anywhere?

0

Thomas Thomassen, when you call Run with Coverage, but no coverage files (.gcov or .profraw) are found, CLion should suggest adding the coverage flags. See https://www.jetbrains.com/help/clion/code-coverage-clion.html#run-coverage.

Please note that for Clang-cl, code coverage is available only for the x86 architecture. Make sure to select it in the Architecture field of your Visual Studio toolchain.

0

Oh, only x86? Not x64? That's unfortunate, that's also one of my requirements. A very unexpected limitation these days. Wouldn't expect x86 to be that relevant for desktop environment any more.

I wonder, is it possible to supply code coverage via a plugin? Wondering if a plugin could drive OpenCppCoverage would work? (Been using a Visual Studio plugin for that on VS). MSVC and x64 is an absolute requirement for many (most?) of my projects on Windows. I really like CLion, but lack of code coverage and profiling for Windows under MSVC are key blockers that holds me back from fully migrating.

On some projects I might be able to switch to Clang, but MSVC has better C++ support for C++20/23 which makes also that a challenge.

1

Please sign in to leave a comment.