On Tue, Sep 29, 2015 at 05:10:20PM +0100, Jonathan Wakely wrote: > >That looks wrong to me, you only restore errno if you don't throw :(. > >If you throw, then errno might remain 0, which is IMHO undesirable. > > My thinking was that a failed conversion that throws an exception > should be allowed to modify errno, and that the second case sets it to > ERANGE sometimes anyway.
Well, you can modify errno, you just shouldn't change it from non-zero to zero as far as the user is concerned. http://pubs.opengroup.org/onlinepubs/009695399/functions/errno.html "No function in this volume of IEEE Std 1003.1-2001 shall set errno to 0." Of course, this part of STL is not POSIX, still, as you said, it would be nice to guarantee the same. > > But I suppose it would be better to consistently set it to non-zero > when an exception is thrown, or consistently restore the original > value in all cases. > > >So, I'd say you want to restore it earlier, right after __convf, and > >immediately before that copy the current errno to some other temporary > >for the use in the condition? Or restore errno = __saved_errno; > >in all the 3 spots instead of just one. > > Or in a destructor so it happens however we exit the function, like > this ... Works for me. Jakub