Template instrumentation

Code Coverage for C++

Code Coverage performs the instrumentation of templates, functions, and methods of template classes, considering that all instances share their branches. The number of branches computed by the feature is independent of the number of instances for this template. All instances will cover the same once-defined branches in the template code.

Files containing template definitions implicitly included by the compiler (no specific compilation command is required for such source files) are also instrumented by the Code Coverage feature and present in the instrumented files where they are needed.

For some compilers, you must specifically take care of certain templates (for example, static or external linkage). You must verify if your Code Coverage Runtime installation contains a file named templates.txt and, if it does, read that file carefully.

  • To instrument an application based upon Rogue Wave libraries , you must use the -DRW_COMPILE_INSTANTIATE compilation flag that suppresses the implicit include mechanism in the header files. (Corresponding source files are so included by pre-processing.)

  • To instrument an application based upon ObjectSpace C++ Component Series , you must use the -DOS_NO_AUTO_INSTANTIATE compilation flag that suppresses the implicit include mechanism in the header files. (Corresponding source files are so included by pre-processing.)

  • Any method (even unused ones) of an instantiated template class is analyzed and instrumented by the Instrumentor. Some compilers do not try to analyze such unused methods. It is possible that some of these methods are not fully compliant with C++ standards. For example, a template class with a formal class template argument named T can contain a compare method that uses the == operator of the T class. If the C class used for T at instantiation time does not define an == operator, and if the compare method is never used, compilation succeeds but instrumentation fails. In such a situation, you can declare an == operator for the C class or use the -instantiationmode=used Instrumentor option.

Related Topics

Selecting coverage types | Code Coverage settings