27-10-2023, 03:41 PM
It’s not the intention of this rule to force constexpr to be added to all functions who’s return value can be evaluated at compile time.
The example const std::int32_t threeSquare = Pow1(3); should be shown as compliant, because Pow1 has to be evaluated at run-time as its not constexpr.
However, const std::int32_t fourSquare = Pow2(4); would be non-compliant, as Pow2 is declared constexpr, and Pow2(4) can be evaluated at compile-time, so foursquare can be declared constexpr.
The example const std::int32_t threeSquare = Pow1(3); should be shown as compliant, because Pow1 has to be evaluated at run-time as its not constexpr.
However, const std::int32_t fourSquare = Pow2(4); would be non-compliant, as Pow2 is declared constexpr, and Pow2(4) can be evaluated at compile-time, so foursquare can be declared constexpr.
Posted by and on behalf of
the MISRA C++ Working Group
the MISRA C++ Working Group