C26498 USE_CONSTEXPR_FOR_FUNCTIONCALL

This rule helps to enforce Con.5 from the C++ Core Guidelines: use constexpr for values that can be computed at compile time.

Remarks

The warning is triggered by assigning the result of a constexpr function to any non-constexpr variable whose value doesn't change after the initial assignment.

Example

This sample code shows where C26498 may appear, and how to avoid it:

constexpr int getMyValue()
{
    return 1;
}

void foo()
{
    constexpr int val0 = getMyValue(); // no C26498
    const int val1 = getMyValue();     // C26498, C26814
    int val2 = getMyValue();           // C26498, value is never modified
    int val3 = getMyValue();           // no C26498, val3 is assigned to below.
    val3 = val3 * val2;
}