By default, C/C++test will not apply code instrumentation to 'constexpr' functions. As a result, the following limitations will be imposed:
- By default, code coverage analysis will not be performed for 'constexpr' functions. See Collecting Code Coverage for C++ 'constexpr' Functions for information how to enable collecting coverage for 'constexpr' functions for selected compilers.
- Stubs will not be available for 'constexpr' functions or functions called from 'constexpr'.
- Reported stack traces may be incomplete if a 'constexpr' function is on an execution path.
- Reported Runtime Error Detection violations may be inaccurate if a 'constexpr' function is on an execution path.
The limitations apply also to the following cases:
- 'constexpr' functions which are used in a 'non-constexpr' context
- functions which are implicitly treated as 'constexpr', for example, lambda expressions in C++17
- functions declared with C++20 'consteval' specifier
Collecting Code Coverage for C++ 'constexpr' Functions
C/C++test can collect code coverage for 'constexpr' functions executed during run-time. No coverage will be reported for a 'constexpr' function used only at compilation time.
Note: A 'constexpr' function called from a unit test case will be executed during run-time, so code coverage will be collected for it.
Enabling Code Coverage for 'constexpr' Functions
Follow these steps to enable collecting coverage for 'constexpr' functions:
- Open the test configuration and go to the Execution> General tab.
- In Execution details, click Edit in the Instrumentation mode section.
- Go to the Test Configuration's Execution tab Instrumentation features panel, and enable the Enable coverage for constexpr function option in the Advanced options section.
Supported Compilers
Collecting code coverage for C++ 'constexpr' functions is supported for the following compilers:
- GCC 9.x or newer in C++14 (or higher) mode
- Clang 9.0.x or newer
- Visual C++ 2019 or newer
The following known limitations apply to compiler usage:
- For GCC up to version 11.x, the coverage for the subtree of 'constexpr' functions called from 'operator alignas()' is not available.
- The size of 'constexpr' functions will increase when the coverage feature is enabled, which may lead to reaching the internal compiler size limits (for 'constexpr' functions). Typically, these limits can be adjusted via compiler options:
- GCC: -fconstexpr-depth, -fconstexpr-ops-limit, -fconstexpr-loop-limit
- Clang: -fconstexpr-depth, -fconstexpr-steps
- Visual C++: /constexpr:depth, /constexpr:steps