IT lexicon › Programming › consteval

consteval

Programming På svenska → Updated: 2026-07-29

The keyword for a function that must run at compile time. The missing half of constexpr, which only says it may.

The difference matters more than it sounds. A constexpr function that for some reason cannot be evaluated at compile time silently falls back to an ordinary runtime call, which may be exactly what you want — or an invisible performance surprise you discover only in a profile. With consteval the same situation becomes a compile error instead, so it is a guarantee you can build on. The most widespread use is validation: a format string can be checked against its arguments at compile time and rejected there if wrong, which is precisely the mechanism behind the checking in std::format. Other cases are tables that must not exist in the finished binary. C++23 relaxed the rules for calling such functions from constexpr code.

← Back to the lexicon