diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2015-09-29 16:15:39 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2015-09-29 16:15:39 +0100 |
commit | 6d601106549923b90769b0bbf6bad9052a9667ac (patch) | |
tree | 74c85314b244738eea02747fe675e1b840e41f3d | |
parent | 44799f87c36be1a05c9b314e00a767c43b3c3190 (diff) | |
download | gcc-6d601106549923b90769b0bbf6bad9052a9667ac.zip gcc-6d601106549923b90769b0bbf6bad9052a9667ac.tar.gz gcc-6d601106549923b90769b0bbf6bad9052a9667ac.tar.bz2 |
Leave errno unchanged by successful std::stoi etc
* include/ext/string_conversions.h (__stoa): Save and restore errno.
* testsuite/21_strings/basic_string/numeric_conversions/char/errno.cc:
New.
From-SVN: r228249
-rw-r--r-- | libstdc++-v3/ChangeLog | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/string_conversions.h | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/errno.cc | 36 |
3 files changed, 42 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4408e46..a53e3ae 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,9 @@ 2015-09-29 Jonathan Wakely <jwakely@redhat.com> + * include/ext/string_conversions.h (__stoa): Save and restore errno. + * testsuite/21_strings/basic_string/numeric_conversions/char/errno.cc: + New. + PR libstdc++/67583 * testsuite/27_io/basic_stringbuf/seekoff/char/1.cc: Fix sputn call with mismatched arguments. diff --git a/libstdc++-v3/include/ext/string_conversions.h b/libstdc++-v3/include/ext/string_conversions.h index f4648a8..58387a2 100644 --- a/libstdc++-v3/include/ext/string_conversions.h +++ b/libstdc++-v3/include/ext/string_conversions.h @@ -58,6 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Ret __ret; _CharT* __endptr; + const int __saved_errno = errno; errno = 0; const _TRet __tmp = __convf(__str, &__endptr, __base...); @@ -70,6 +71,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::__throw_out_of_range(__name); else __ret = __tmp; + errno = __saved_errno; if (__idx) *__idx = __endptr - __str; diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/errno.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/errno.cc new file mode 100644 index 0000000..4079744 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/errno.cc @@ -0,0 +1,36 @@ +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++11" } +// { dg-require-string-conversions "" } + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + errno = ERANGE; + std::stoi("42"); + VERIFY( errno == ERANGE ); // errno should not be altered by successful call +} + +int +main() +{ + test01(); +} |