Microsoft.CodeCoverage.Console.exe don't remove C++ compile time code

julian lalu 21 Reputation points
2022-11-18T09:46:30.333+00:00

Hello,
I generate C++ code coverage with Microsoft.CodeCoverage.Console.exe.

I have the following code :

template<typename type_t>  
[[nodiscard]]  
static constexpr type_t* allocate_array(const usize count) noexcept requires(is_not_same_v<type_t, void>) {  
    const usize allocation_size = count * sizeof(type_t);  
    if (std::is_constant_evaluated()) {  
        // Usage of std::allocator.allocate is allowed in constexpr dynamic allocation.   
        // The allocation should be freed with std::allocator<type_t>().deallocate in the same constexpr expression  
        return std::allocator<type_t>().allocate(count);  
    }  
    return reinterpret_cast<type_t*>(allocate(allocation_size));  
}  

The branch if(std::is_constant_evaluated()) should not be covered but it is.
Codecov show me that the branch is evaluated to false but never to true... and this is normal but it should not be in coverage data.

261881-image.png

llvm-cov gcov produce a far better coverage concerning constexpr evaluation.
261901-image.png

Is there a way to remove this from the coverage report? I instrument it statically (Dynamic produce the same result), here is the config file

<?xml version="1.0" encoding="utf-8"?>  
<Configuration>  
    <CodeCoverage>  
        <Functions>  
            <Exclude>  
                <Function>.*testing::.*</Function>  
            </Exclude>  
        </Functions>  
        <Sources>  
            <Exclude>  
                <Source>.*\\_deps\\.*</Source>  
            </Exclude>  
        </Sources>  
        <EnableStaticNativeInstrumentation>True</EnableStaticNativeInstrumentation>  
        <EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>  
        <EnableStaticNativeInstrumentationRestore>True</EnableStaticNativeInstrumentationRestore>  
    </CodeCoverage>  
</Configuration>  

Thank you for help!

Developer technologies Visual Studio Testing
Developer technologies C++
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.