c++constexprlanguage-designc++23constexpr-function

Given C++23 relaxations on constexpr, can't constexpr be the default?


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++23 further softens these restrictions. From what I can see in cppreference, constexpr for functions seems to only have the following meaning left:

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?


Solution

  • What you actually seem to ask is: why not make anything constexpr by default?

    Because you might want others to not use a function at compile-time, to give you a possibility to switch to a non-constexpr implementation later.

    Imagine this: