This change correctly implements https://wg21.link/P2539/ for both C streams and C++ iostreams. Fixes #3688.