Date: Wed, 20 May 2026 10:13:56 +0200
Why not use an empty function body?
Then you don't get compile errors or warnings?
Or you want a warning?
Then why isn't static code analysis enough?
-----Ursprüngliche Nachricht-----
Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Mi 20.05.2026 08:15
Betreff:Re: [std-proposals] [[unevaluated]]
An:std-proposals <std-proposals_at_[hidden]>;
CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>;
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.
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2026-05-20 08:16:36
