|
|
|
|
|
by jcelerier
1121 days ago
|
|
> constexpr isn't a guarantee of it being evaluated at compile time constexpr is a guarantee that you can use the thing in a constexpr context, and this is where the "evaluated at compile-time" guarantee can come from: template<typename T>
auto func() {
// here some compilers can still choose to evaluate x at run-time - and very likely all of them if no optimizations are enabled
constexpr int x = f();
// but here it becomes mandatory for this use of x to be evaluated at compile-time, since the number is literally going to be part of the compiled binary as part of the function name mangling
return std::integral_constant<int, x>{};
}
|
|
Except of course the subset of parameters for which it is constexpr callable can't be checked at function definition time (if it exists at all), only at function invocation time.
Which makes the constexpr annotation useless and it is in only because the authors couldn't otherwise get the paper through some committee objections.