Why are constexpr functions possibly ill-formed, NDR (10.1.5)?

Viewed 56

Paragraph 10.1.5 says that a program is ill-formed, no diagnostic required, if a function is declared constexpr but no set of arguments exist that make it evaluable at compile-time.

What's the rationale behind this?

Since it's not feasible for the compiler to check that precondition, how can it benefit from this rule? However, the only alternative I would see is to declare such programs well-formed (and so barely enforcing constexpr at all, making it rather a kind of hint to the compiler and reader). But wouldn't this still be preferable to having more UB in C++, with all its undesirable consequences? Maybe constexpr is indeed going in the wrong direction...

0 Answers
Related