dimanche 6 janvier 2019

C++ Compiler Optimization - Why is constexpr Needed?

I am wondering why are the benefits of constexpr not optimized away by the compiler?

The compiler should be able to deduce that a value is known at compile time much better than a human (for example if all inputs to a function call are known), and then it should be able to mark that value as known for subsequent analysis until it becomes ambiguous. So why is it that we have to manually tell the compiler when that is the case (instead of just using the const keyword and leaving it to the compiler to evaluate the value at compile time).

Is this because the compiler technology is not yet capable of doing this or is there some sort of inherent limitation that prevents the compiler to do so?

Aucun commentaire:

Enregistrer un commentaire