[[unevaluated]] auto Func(void)
{
if constexpr ( some_constant0 )
{
return SomeType{};
}
else
{
return SomeOtherType{ 0xFF };
}
}
The idea is that the compiler will forbid the use of Func outside of an unevaluated context.
One trick people are using is to put this in the body:
static_assert(1 == 2, "Func must only be used in an unevaluated context");
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.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals