The C and POSIX standards guarantee that errno
is never set to zero by any library function.
The C++ standard has less to say about when errno
is or isn't set, but libstdc++ follows the same rule and never sets
it to zero.
On the other hand, there are few guarantees about when the C++ library
sets errno on error, beyond what is specified for
functions that come from the C library.
For example, when std::stoi throws an exception of
type std::out_of_range, errno
may or may not have been set to ERANGE.
Parts of the C++ library may be implemented in terms of C library
functions, which may result in errno being set
with no explicit call to a C function. For example, on a target where
operator new uses malloc
a failed memory allocation with operator new might
set errno to ENOMEM.
Which C++ library functions can set errno in this way
is unspecified because it may vary between platforms and between releases.