Hi SQ community!
I have a question regarding code coverage analysis.
In our project, we use gcov for analyzing coverage for our C++ code and publish it to a SQ server to render results. It works pretty well so far but we are facing problems with header-only code, templates in particular. It is always shown as 0% covered although unit tests are executed that call the functions. Invoking a template function that is just declared inside the header but defined and used inside a cpp file only works fine.
Does anybody have an idea how to fix this?
I’ve spend several hours now to try out different things, e.g., playing around with compiler options, but none of them worked.
Sample .hpp file:
#include <iostream>
static auto i = 0;
inline void inlineFunction() {
std::cout << "inlineFunction(); i = " << i++ << std::endl;
}
void regularFunction();
template< typename T >
void templateFunctionInHeader( T&& arg ) {
std::cout << "templateFunctionInHeader(" << std::forward< T >( arg ) << "); i = " << i++ << std::endl;
}
void regularFunctionCallingTemplateFunctionInSource();
The corresponding .cpp file:
#include "SQTest.hpp"
void regularFunction() {
std::cout << "regularFunction(); i = " << i++ << std::endl;
}
template< typename T >
void templateFunctionInSource( T&& arg ) {
std::cout << "templateFunctionInSource(" << std::forward< T >( arg ) << "); i = " << i++ << std::endl;
}
void regularFunctionCallingTemplateFunctionInSource() {
templateFunctionInSource( 42 );
templateFunctionInSource( std::string{"X"} );
}
Coverage reports for the header:
Coverage report for the source:

