A similar question has been asked here but the context is slightly different. The way noexcept
is generally specified by the standard library is to do so only when it would be potentially beneficial. Keep in mind that a function lacking noexpect
specification may still be called from within a noexcept
function (unlike the analogous situation for const
), so omitting noexcept
is not restrictive in any way. Merely, noexcept
indicates to the compiler that no exception handling is necessary/possible which can convey dramatic performance benefits, especially in situations where the compiler can only reason on the function based on its signature. However std::complex::(real|imag)
are both likely to be inlined anyway and the exception handling can be elided in that case anyway.
That being said, I can also not see anything wrong with declaring noexcept
in this case. Generally, one should be cautious not to declare any library API noexcept
as this potentially restricts implementators. In the case of std::complex
, however, the wiggle room for implementations is so narrow that it is fair to stipulate that no exceptions could be thrown. My guess is that, std::complex
predating noexcept
, there was never enough of a reason to add noexcept
specifiers retroactively.