I want to make compilation unsuccessful for calling any function, but not for others. The function call that I want to crash is those that do not handle return values ββwhen the value is of a particular type. In the example below, not processing a function that returns Error is a compilation error, but not processing a function that returns anything else should work just fine.
Note: our runtime (built-in) does not allow us to use the following constructs: RTTI, exceptions.
This code is only needed by the compiler with Clang, I would prefer not to comment on every function.
We prefer a solution that is not executed at compile time rather than at run time.
enum class Error { INVAL, NOERR, }; // do something that can fail. Error DoThing(); // may return different return codes, we never care (we can't change prototype) int DoIgnoredThing(); int main() { DoThing(); // compilation failure here, unused "Error" result DoIgnoredThing(); // compilation succeeds, OK to ignore unused "int" result return 0; }
source share