We have a class which implements IUnknown (or any interface which we don't own). We started marking most/all of our methods with noexcept for any potential optimization since we don't throw any exceptions anyway; although some of the libraries we depend on may. The question was raised whether or not QueryInterface/AddRef/Release should be marked noexcept since the interface isn't.
Are there any side effects or gotchas when only some of the derived classes are marked noexcept?
noexcept
isn't free. It's not a great idea to throw it on all the functions. The cost is that you can't really remove it once you've put it on. Othernoexcept
code might rely on your function'snoexcept
so for backwards compatibility you are stuck with. That means you can't ever change the implementation to something that might throw. Addingnoexcept
is a one way street, safe to add (if it's correct) but unsafe to remove. You have to be sure that the function, intrinsically, could never throw. - François Andrieux