Item 14 of "Effective Modern C++" recommends declaring functions noexcept
whenever they don't emit exceptions. I have a class with a number of small member functions that cannot throw for very trivial reasons e.g. they only perform simple mathematical operations on PODs. Should I declare such functions noexcept
? It seems like overkill to me when even the compiler can surely detect that there is no possibility of throwing.
EDIT: To clarify my question somewhat, the advice given in this question is to "use it when it's obvious that the function will never throw." But if it's obvious (even to the compiler) that the function will never throw, why use noexcept
at all? Note that I would have to mark the overwhelming majority of the functions my program as noexcept
, which I will only do if given a compelling reason.