Functions with Specifier constexpr
C++ functions with the specifier constexpr
are not instrumented by
Testwell CTC++. In general, this is not possible as the
instrumentation would destroy key properties of these functions and their return
values.
constexpr
and the restrictions for functions to qualify
for this specifier evolve with C++ standards. On a general level,
constexpr
indicates that the compiler may execute some of the
function calls during compilation. From ctc's point of
view, the following properties contradict an instrumentation: - The result of calls during compilation can be used as compile-time constant, for example to size an array.
- The function must have at least one execution path that can be evaluated at compile time, i.e., without side effects.
When instrumenting code, ctc adds counters and increments them during execution. This would violate property 2, leading to a compilation error. Even more fundamental, no compile-time evaluation would be possible with the instrumented version of the function.
Workaround
It is sometimes possible to (unit) test these functions with coverage measurement in an
isolated setup. Crucial for the "isolation" property is: The specifier
constexpr
must be omitted, for example by setting an empty
#define
for this keyword. Hence the associated tests must not
rely on any output being calculated at compile-time.
For larger parts of the code, it is typically not possible to omit
constexpr
by macro definition.