This is the mail archive of the
mailing list for the libstdc++ project.
Re: [patch] Leave errno unchanged by successful std::stoi etc
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 29 Sep 2015 18:15:20 +0200
- Subject: Re: [patch] Leave errno unchanged by successful std::stoi etc
- Authentication-results: sourceware.org; auth=none
- References: <20150929151541 dot GZ12094 at redhat dot com> <20150929152515 dot GJ1847 at tucnak dot redhat dot com> <20150929161020 dot GA12094 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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.
"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.