Mark public API with "C" linkage as "noexcept"
I suggest to mark exported functions with C linkage as noexcept for better c++ support. Most of them wrapped in miopen::try_ internally, so it is possible to add noexcept to them.
@averinevg Can you please explain here why this is needed (or provide a link if explanation exists somewhere)?
Please set appropriate category labels (bug, enhancement, quality...), urgency label and set milestone, if it is applicable (let's discuss if something is unclear). Thanks!
Consider, for example, miopenCreate() function, which is declared as:
extern "C" miopenStatus_t miopenCreate(miopenHandle_t* handle);
The only information we have about this function is that it has a C linkage and some return value indicating the execution status. Functions with C linkage called from C++ are not implicitly noexcept, so the compiler will have to treat them as if they may throw. However we don't have any information about exceptions in the description provided in the header. I's very uncomfortable to get some unknown exception.
On the other side, library can be linked with C code. What will be if given function throws exception?
To avoid unpleasant consequences, I suggest marking exported functions as noexcept.
@pfultz2 Can you please share your opinion on this?
To avoid unpleasant consequences, I suggest marking exported functions as noexcept.
noexcept wont prevent us from throwing an exception. The application will just abort instead. Using noexcept is just useful to callers to detect if the function they are calling will throw an exceptions(ie noexcept(miopenCreate(&handle)) will return true instead of false).
We may want to have some kind of custom linting to make sure we are always catching the exceptions in our api calls.
Most of our API are always catch exceptions, they are wrapped in miopen::try_. We can add noexcept to them at first stage. And then prepare remaining functions for proper exception handling.
We may want to have some kind of custom linting to make sure we are always catching the exceptions in our api calls.
Maybe something like this:
extern "C" miopenStatus_t miopenSomeFunction() noexcept
{
static_assert(noexcept(miopenSomeFunctionInternal()));
return miopenSomeFunctionInternal();
}
@averinevg This looks good to me, please go ahead with PR ;)
@averinevg Has this been resolved? If so, please close ticket. Thanks!
@ppanchad-amd Not yet