The keyword constexpr enforced pretty tight restrictions on functions on its introduction into the C++11 standard. These restrictions were loosened with C++14 and C++20 (most noteworthy):
- C++14 allowed multiple
return
statements,static_assert
s etc. - C++20 allowed
try
andasm
C++23 further softens these restrictions. From what I can see in cppreference, constexpr
for functions seems to only have the following meaning left:
- it must not be a coroutine
- for constructor and destructor, the class must have no virtual base classes
- For constexpr function templates and constexpr member functions of class templates, at least one specialization must satisfy the abovementioned requirements.
C++23 even removed the restriction that a constexpr function must be "evaluatable" at compile time for any type in p2448r2. From my understanding this completely removed the idea of a constexpr
function to be evaluated at compile time.
Is that it? If so, how is a constexpr
function even useful anymore?