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!

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,632 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
337 questions
{count} votes