On Tuesday, May 19, 2026, Jonathan Wakely wrote:

 
But I think we'd be better off with an attribute that tells the compiler exactly what we have in mind. And of course the attribute would ensure that the function is not emitted in the object file.

You get that with consteval.



Inside the body of a consteval function, if you make a call to a non-constexpr function, you get a compiler warning.

Also if you were to invoke 'optional::operator*' before invoking 'optional::has_value', you might get a warning (e.g. from cppcheck).

To cut down on warnings, and to ensure that the function actually never gets invoked -- not even in a consteval context at compile time -- it would be better to tell the compiler (and also tell cppcheck) that the function is [[unevaluated]]. And if someone tries to take its address or invoke it, I would like this to be an error rather than a warning.