Given two programs where the only difference in the source code is the presence or absence of one constexpr
, is it possible that the meaning of the program changes?
In other words, if there was a compiler option to ask the compiler to try really hard to infer constexpr
where possible, would it break existing standard code and/or change its meaning in bad ways?
Imagine dealing with a codebase where the original developer forgot to include constexpr
in places where it was possible, perhaps code written before C++11. It would be great if the compiler would infer constexpr
to help you get on with your work. Of course, perhaps it should also warn about each time it does this inference, encouraging you to explicitly add the constexpr
later. But it would still be useful. My worry is that it might break things?
So far, the only thing I can think of is that constexpr
functions are implicitly inline
and there can be situations where adding inline
can change things in bad ways; for example if you break the one-definition-rule.