BullseyeCoverage Up Contents Search

Expression Not Constant Error

Symptoms

An error such as shown below occurs.

Microsoft C++
error C2131: expression did not evaluate to a constant
note: failure was caused by non-constant arguments or reference to a non-constant symbol
note: see usage of 'cov_v_…'
GNU C++
error: '…' called in a constant expression
error: the value of 'cov_v_…' is not usable in a constant expression
Clang
error: … is not an integral constant expression
note: read of non-constexpr variable 'cov_v_…' is not allowed in a constant expression

Cause

A lambda expression is invoked in a context where a constant expression is required, but the lambda expression is defined without constexpr or consteval. When neither of these keywords are used, BullseyeCoverage instruments the lambda expression.

Resolution

Use one of the alternatives below.

Updated: 3 Mar 2025