diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-06-16 09:58:54 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-06-16 09:58:54 +0000 |
commit | e05970393689191ca39888f8ad278e12382a82c6 (patch) | |
tree | 8685abf3ce961673fcc9761e7fded8aeef7e1b6a /libstdc++-v3 | |
parent | b645712a05586b981eb549069541cd9a641a137e (diff) | |
download | gcc-e05970393689191ca39888f8ad278e12382a82c6.tar.gz |
2008-06-16 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/basic_string.h (stod, stof, stoi, stol, stold, stoll,
stoul, stoull, to_string, to_wstring): Declare in C++0x mode.
* src/string_conversions.cc: Add.
* src/Makefile.am: Update.
* config/abi/pre/gnu.ver: Adjust exports.
* src/Makefile.in: Regenerate.
* testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc:
New.
* testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc:
Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/char/
to_string.cc: Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
stod.cc: New.
* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
stof.cc: Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
stoi.cc: Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
stol.cc: Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
stold.cc: Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
stoll.cc: Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
stoul.cc: Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
stoull.cc: Likewise.
* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/
to_wstring.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@136841 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
24 files changed, 2927 insertions, 8 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9380784bdf2..1b135fe6043 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,48 @@ +2008-06-16 Paolo Carlini <paolo.carlini@oracle.com> + + * include/bits/basic_string.h (stod, stof, stoi, stol, stold, stoll, + stoul, stoull, to_string, to_wstring): Declare in C++0x mode. + * src/string_conversions.cc: Add. + * src/Makefile.am: Update. + * config/abi/pre/gnu.ver: Adjust exports. + * src/Makefile.in: Regenerate. + * testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc: + New. + * testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc: + Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc: + Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc: + Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc: + Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc: + Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc: + Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc: + Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/char/ + to_string.cc: Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ + stod.cc: New. + * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ + stof.cc: Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ + stoi.cc: Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ + stol.cc: Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ + stold.cc: Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ + stoll.cc: Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ + stoul.cc: Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ + stoull.cc: Likewise. + * testsuite/21_strings/basic_string/numeric_conversions/wchar_t/ + to_wstring.cc: Likewise. + 2008-06-15 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> * include/Makefile.am: Remove trailing white space, fix typo. diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 547624c893f..9bec6f56cb3 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -122,7 +122,8 @@ GLIBCXX_3.4 { # std::string std::strstream*; std::strstreambuf*; - std::t[a-q]*; +# std::t[a-q]*; + std::t[a-n]*; std::tr1::h[^a]*; std::t[s-z]*; std::[A-Zu-z]*; @@ -895,6 +896,11 @@ GLIBCXX_3.4.11 { # char16_t and char32_t _ZNSt14numeric_limitsIu8char*; + # string conversions + _ZSt?sto*; + _ZSt9to_string*; + _ZSt10to_wstring*; + } GLIBCXX_3.4.10; # Symbols in the support library (libsupc++) have their own tag. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index d78e512ee34..99ef4bb7b40 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -2473,6 +2473,42 @@ _GLIBCXX_BEGIN_NAMESPACE(std) wchar_t __delim); #endif + +#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99)) + + // 21.4 Numeric Conversions [string.conversions]. + int stoi(const string&, size_t* = 0, int = 10); + long stol(const string&, size_t* = 0, int = 10); + unsigned long stoul(const string&, size_t* = 0, int = 10); + long long stoll(const string&, size_t* = 0, int = 10); + unsigned long long stoull(const string&, size_t* = 0, int = 10); + + float stof(const string&, size_t* = 0); + double stod(const string&, size_t* = 0); + long double stold(const string&, size_t* = 0); + + string to_string(long long); + string to_string(unsigned long long); + string to_string(long double); + +#ifdef _GLIBCXX_USE_WCHAR_T + int stoi(const wstring&, size_t* = 0, int = 10); + long stol(const wstring&, size_t* = 0, int = 10); + unsigned long stoul(const wstring&, size_t* = 0, int = 10); + long long stoll(const wstring&, size_t* = 0, int = 10); + unsigned long long stoull(const wstring&, size_t* = 0, int = 10); + + float stof(const wstring&, size_t* = 0); + double stod(const wstring&, size_t* = 0); + long double stold(const wstring&, size_t* = 0); + + wstring to_wstring(long long); + wstring to_wstring(unsigned long long); + wstring to_wstring(long double); +#endif + +#endif + _GLIBCXX_END_NAMESPACE #endif /* _BASIC_STRING_H */ diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am index f5d99c63525..fa1e7c8d427 100644 --- a/libstdc++-v3/src/Makefile.am +++ b/libstdc++-v3/src/Makefile.am @@ -182,6 +182,7 @@ sources = \ streambuf-inst.cc \ streambuf.cc \ string-inst.cc \ + string_conversions.cc \ valarray-inst.cc \ wlocale-inst.cc \ wstring-inst.cc \ @@ -278,6 +279,11 @@ atomic.lo: atomic.cc atomic.o: atomic.cc $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< +string_conversions.lo: string_conversions.cc + $(LTCXXCOMPILE) -x c++ -std=gnu++0x -c $< +string_conversions.o: string_conversions.cc + $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< + if GLIBCXX_LDBL_COMPAT # Use special rules for compatibility-ldbl.cc compilation, as we need to # pass -mlong-double-64. diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in index 508a399e7e8..7cf3f90414e 100644 --- a/libstdc++-v3/src/Makefile.in +++ b/libstdc++-v3/src/Makefile.in @@ -83,11 +83,12 @@ am__libstdc___la_SOURCES_DIST = atomic.cc bitmap_allocator.cc \ allocator-inst.cc concept-inst.cc fstream-inst.cc ext-inst.cc \ ios-inst.cc iostream-inst.cc istream-inst.cc istream.cc \ locale-inst.cc misc-inst.cc ostream-inst.cc sstream-inst.cc \ - streambuf-inst.cc streambuf.cc string-inst.cc valarray-inst.cc \ - wlocale-inst.cc wstring-inst.cc mutex.cc condition_variable.cc \ - atomicity.cc codecvt_members.cc collate_members.cc \ - ctype_members.cc messages_members.cc monetary_members.cc \ - numeric_members.cc time_members.cc basic_file.cc c++locale.cc \ + streambuf-inst.cc streambuf.cc string-inst.cc \ + string_conversions.cc valarray-inst.cc wlocale-inst.cc \ + wstring-inst.cc mutex.cc condition_variable.cc atomicity.cc \ + codecvt_members.cc collate_members.cc ctype_members.cc \ + messages_members.cc monetary_members.cc numeric_members.cc \ + time_members.cc basic_file.cc c++locale.cc \ compatibility-ldbl.cc parallel_list.cc parallel_settings.cc am__objects_1 = atomicity.lo codecvt_members.lo collate_members.lo \ ctype_members.lo messages_members.lo monetary_members.lo \ @@ -108,8 +109,8 @@ am__objects_5 = atomic.lo bitmap_allocator.lo pool_allocator.lo \ fstream-inst.lo ext-inst.lo ios-inst.lo iostream-inst.lo \ istream-inst.lo istream.lo locale-inst.lo misc-inst.lo \ ostream-inst.lo sstream-inst.lo streambuf-inst.lo streambuf.lo \ - string-inst.lo valarray-inst.lo wlocale-inst.lo \ - wstring-inst.lo mutex.lo condition_variable.lo \ + string-inst.lo string_conversions.lo valarray-inst.lo \ + wlocale-inst.lo wstring-inst.lo mutex.lo condition_variable.lo \ $(am__objects_1) $(am__objects_4) am_libstdc___la_OBJECTS = $(am__objects_5) libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS) @@ -418,6 +419,7 @@ sources = \ streambuf-inst.cc \ streambuf.cc \ string-inst.cc \ + string_conversions.cc \ valarray-inst.cc \ wlocale-inst.cc \ wstring-inst.cc \ @@ -872,6 +874,11 @@ atomic.lo: atomic.cc atomic.o: atomic.cc $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< +string_conversions.lo: string_conversions.cc + $(LTCXXCOMPILE) -x c++ -std=gnu++0x -c $< +string_conversions.o: string_conversions.cc + $(CXXCOMPILE) -x c++ -std=gnu++0x -c $< + # Use special rules for compatibility-ldbl.cc compilation, as we need to # pass -mlong-double-64. @GLIBCXX_LDBL_COMPAT_TRUE@compatibility-ldbl.lo: compatibility-ldbl.cc diff --git a/libstdc++-v3/src/string_conversions.cc b/libstdc++-v3/src/string_conversions.cc new file mode 100644 index 00000000000..627ddfad413 --- /dev/null +++ b/libstdc++-v3/src/string_conversions.cc @@ -0,0 +1,195 @@ +// String Conversions -*- C++ -*- + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include <string> +#include <limits> +#include <cerrno> +#include <cstdlib> + +#ifdef _GLIBCXX_USE_C99 + +_GLIBCXX_BEGIN_NAMESPACE(std) + + // Helper for all the sto* functions. + template<typename _TRet, typename _Ret = _TRet, typename _CharT, + typename... _Base> + inline _Ret + __stoa(_TRet (*__convf) (const _CharT*, _CharT**, _Base...), + const char* __name, const basic_string<_CharT>& __str, + size_t* __idx, _Base... __base) + { + _Ret __ret; + + _CharT* __endptr; + errno = 0; + const _TRet __tmp = __convf(__str.c_str(), &__endptr, __base...); + + if (__endptr == __str.c_str()) + __throw_invalid_argument(__name); + else if (errno == ERANGE + || (__are_same<_Ret, int>::__value + && (__tmp < numeric_limits<_Ret>::min() + || __tmp > numeric_limits<_Ret>::max()))) + __throw_out_of_range(__name); + else + __ret = __tmp; + + if (__idx) + *__idx = __endptr - __str.c_str(); + + return __ret; + } + + + int + stoi(const string& __str, size_t* __idx, int __base) + { return std::__stoa<long, int>(&std::strtol, "stoi", __str, + __idx, __base); } + + long + stol(const string& __str, size_t* __idx, int __base) + { return std::__stoa(&std::strtol, "stol", __str, __idx, __base); } + + unsigned long + stoul(const string& __str, size_t* __idx, int __base) + { return std::__stoa(&std::strtoul, "stoul", __str, __idx, __base); } + + long long + stoll(const string& __str, size_t* __idx, int __base) + { return std::__stoa(&std::strtoll, "stoll", __str, __idx, __base); } + + unsigned long long + stoull(const string& __str, size_t* __idx, int __base) + { return std::__stoa(&std::strtoull, "stoull", __str, __idx, __base); } + + // NB: strtof vs strtod. + float + stof(const string& __str, size_t* __idx) + { return std::__stoa(&std::strtof, "stof", __str, __idx); } + + double + stod(const string& __str, size_t* __idx) + { return std::__stoa(&std::strtod, "stod", __str, __idx); } + + long double + stold(const string& __str, size_t* __idx) + { return std::__stoa(&std::strtold, "stold", __str, __idx); } + + string + to_string(long long __val) + { + // XXX Eventually the result will be constructed in place in + // the C++0x string, likely with the help of internal hooks. + const int __n = 4 * sizeof(long long); + char* __s = static_cast<char*>(__builtin_alloca(__n)); + return string(__s, __s + std::snprintf(__s, __n, "%lld", __val)); + } + + string + to_string(unsigned long long __val) + { + const int __n = 4 * sizeof(unsigned long long); + char* __s = static_cast<char*>(__builtin_alloca(__n)); + return string(__s, __s + std::snprintf(__s, __n, "%llu", __val)); + } + + string + to_string(long double __val) + { + const int __n = numeric_limits<long double>::max_exponent10 + 20; + char* __s = static_cast<char*>(__builtin_alloca(__n)); + return string(__s, __s + std::snprintf(__s, __n, "%Lf", __val)); + } + +#ifdef _GLIBCXX_USE_WCHAR_T + int + stoi(const wstring& __str, size_t* __idx, int __base) + { return std::__stoa<long, int>(&std::wcstol, "stoi", __str, + __idx, __base); } + + long + stol(const wstring& __str, size_t* __idx, int __base) + { return std::__stoa(&std::wcstol, "stol", __str, __idx, __base); } + + unsigned long + stoul(const wstring& __str, size_t* __idx, int __base) + { return std::__stoa(&std::wcstoul, "stoul", __str, __idx, __base); } + + long long + stoll(const wstring& __str, size_t* __idx, int __base) + { return std::__stoa(&std::wcstoll, "stoll", __str, __idx, __base); } + + unsigned long long + stoull(const wstring& __str, size_t* __idx, int __base) + { return std::__stoa(&std::wcstoull, "stoull", __str, __idx, __base); } + + // NB: wcstof vs wcstod. + float + stof(const wstring& __str, size_t* __idx) + { return std::__stoa(&std::wcstof, "stof", __str, __idx); } + + double + stod(const wstring& __str, size_t* __idx) + { return std::__stoa(&std::wcstod, "stod", __str, __idx); } + + long double + stold(const wstring& __str, size_t* __idx) + { return std::__stoa(&std::wcstold, "stold", __str, __idx); } + + wstring + to_wstring(long long __val) + { + const int __n = 4 * sizeof(long long); + wchar_t* __s = static_cast<wchar_t*>(__builtin_alloca(sizeof(wchar_t) + * __n)); + return wstring(__s, __s + std::swprintf(__s, __n, L"%lld", __val)); + } + + wstring + to_wstring(unsigned long long __val) + { + const int __n = 4 * sizeof(unsigned long long); + wchar_t* __s = static_cast<wchar_t*>(__builtin_alloca(sizeof(wchar_t) + * __n)); + return wstring(__s, __s + std::swprintf(__s, __n, L"%llu", __val)); + } + + wstring + to_wstring(long double __val) + { + const int __n = numeric_limits<long double>::max_exponent10 + 20; + wchar_t* __s = static_cast<wchar_t*>(__builtin_alloca(sizeof(wchar_t) + * __n)); + return wstring(__s, __s + std::swprintf(__s, __n, L"%Lf", __val)); + } +#endif + +_GLIBCXX_END_NAMESPACE + +#endif diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc new file mode 100644 index 00000000000..f26a865684d --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc @@ -0,0 +1,139 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + string one; + stod(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + string one("a"); + stod(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + double d1 = 0.0; + size_t idx1 = 0; + try + { + string one("2.0a"); + d1 = stod(one, &idx1); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( d1 == 2.0 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + string one("1e"); + one.append(2 * numeric_limits<double>::max_exponent10, '9'); + d1 = stod(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( d1 == 2.0 ); + + try + { + long double ld0 = numeric_limits<double>::max() / 100.0; + string one(to_string(ld0)); + stod(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + + if (sizeof(double) < sizeof(long double)) + { + test = false; + d1 = -1.0; + try + { + long double ld1 = numeric_limits<double>::max(); + ld1 *= 100.0; + string one(to_string(ld1)); + d1 = stod(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( d1 == -1.0 ); + } + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc new file mode 100644 index 00000000000..515769e18f7 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc @@ -0,0 +1,139 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + string one; + stof(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + string one("a"); + stof(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + float f1 = 0.0f; + size_t idx1 = 0; + try + { + string one("2.0a"); + f1 = stof(one, &idx1); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( f1 == 2.0f ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + string one("1e"); + one.append(2 * numeric_limits<float>::max_exponent10, '9'); + f1 = stof(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( f1 == 2.0f ); + + try + { + long double ld0 = numeric_limits<float>::max() / 100.0; + string one(to_string(ld0)); + stof(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + + if (sizeof(float) < sizeof(long double)) + { + test = false; + f1 = -1.0f; + try + { + long double ld1 = numeric_limits<float>::max(); + ld1 *= 100.0; + string one(to_string(ld1)); + f1 = stof(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( f1 == -1.0f ); + } + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc new file mode 100644 index 00000000000..6f1efd0f4b9 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc @@ -0,0 +1,205 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + string one; + stoi(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + string one("a"); + stoi(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + int i1 = 0; + try + { + string one("a"); + i1 = stoi(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == 10 ); + + size_t idx1 = 0; + try + { + string one("78"); + i1 = stoi(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + string one("10112"); + i1 = stoi(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + string one("0XE"); + i1 = stoi(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + string one(1000, '9'); + i1 = stoi(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( i1 == 14 ); + + try + { + i1 = numeric_limits<int>::max(); + string one(to_string((long long)i1)); + i1 = stoi(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == numeric_limits<int>::max() ); + + try + { + i1 = numeric_limits<int>::min(); + string one(to_string((long long)i1)); + i1 = stoi(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == numeric_limits<int>::min() ); + + test = false; + i1 = 1; + try + { + long long ll0 = numeric_limits<int>::max(); + ++ll0; + string one(to_string(ll0)); + i1 = stoi(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( i1 == 1 ); + + test = false; + try + { + long long ll1 = numeric_limits<int>::min(); + --ll1; + string one(to_string(ll1)); + i1 = stoi(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( i1 == 1 ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc new file mode 100644 index 00000000000..683063fadf0 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc @@ -0,0 +1,168 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + string one; + stol(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + string one("a"); + stol(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + long l1 = 0; + try + { + string one("a"); + l1 = stol(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == 10 ); + + size_t idx1 = 0; + try + { + string one("78"); + l1 = stol(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + string one("10112"); + l1 = stol(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + string one("0XE"); + l1 = stol(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + string one(1000, '9'); + l1 = stol(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( l1 == 14 ); + + try + { + l1 = numeric_limits<long>::max(); + string one(to_string((long long)l1)); + l1 = stol(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == numeric_limits<long>::max() ); + + try + { + l1 = numeric_limits<long>::min(); + string one(to_string((long long)l1)); + l1 = stol(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == numeric_limits<long>::min() ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc new file mode 100644 index 00000000000..3a5d73a954b --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc @@ -0,0 +1,117 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + string one; + stold(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + string one("a"); + stold(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + long double ld1 = 0.0L; + size_t idx1 = 0; + try + { + string one("2.0a"); + ld1 = stold(one, &idx1); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ld1 == 2.0L ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + string one("1e"); + one.append(2 * numeric_limits<long double>::max_exponent10, '9'); + ld1 = stold(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( ld1 == 2.0L ); + + try + { + long double ld0 = numeric_limits<long double>::max() / 100.0L; + string one(to_string(ld0)); + stold(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc new file mode 100644 index 00000000000..6d922156281 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc @@ -0,0 +1,168 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + string one; + stoll(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + string one("a"); + stoll(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + long long ll1 = 0; + try + { + string one("a"); + ll1 = stoll(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == 10 ); + + size_t idx1 = 0; + try + { + string one("78"); + ll1 = stoll(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + string one("10112"); + ll1 = stoll(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + string one("0XE"); + ll1 = stoll(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + string one(1000, '9'); + ll1 = stoll(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( ll1 == 14 ); + + try + { + ll1 = numeric_limits<long long>::max(); + string one(to_string(ll1)); + ll1 = stoll(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == numeric_limits<long long>::max() ); + + try + { + ll1 = numeric_limits<long long>::min(); + string one(to_string(ll1)); + ll1 = stoll(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == numeric_limits<long long>::min() ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc new file mode 100644 index 00000000000..c2d6cead337 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc @@ -0,0 +1,155 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + string one; + stoul(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + string one("a"); + stoul(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + unsigned long ul1 = 0; + try + { + string one("a"); + ul1 = stoul(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == 10 ); + + size_t idx1 = 0; + try + { + string one("78"); + ul1 = stoul(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + string one("10112"); + ul1 = stoul(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + string one("0XE"); + ul1 = stoul(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + string one(1000, '9'); + ul1 = stoul(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( ul1 == 14 ); + + try + { + ul1 = numeric_limits<unsigned long>::max(); + string one(to_string((unsigned long long)ul1)); + ul1 = stoul(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == numeric_limits<unsigned long>::max() ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc new file mode 100644 index 00000000000..30c94ff8255 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc @@ -0,0 +1,155 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + string one; + stoull(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + string one("a"); + stoull(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + unsigned long long ull1 = 0; + try + { + string one("a"); + ull1 = stoull(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == 10 ); + + size_t idx1 = 0; + try + { + string one("78"); + ull1 = stoull(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + string one("10112"); + ull1 = stoull(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + string one("0XE"); + ull1 = stoull(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + string one(1000, '9'); + ull1 = stoull(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( ull1 == 14 ); + + try + { + ull1 = numeric_limits<unsigned long long>::max(); + string one(to_string(ull1)); + ull1 = stoull(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == numeric_limits<unsigned long long>::max() ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/to_string.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/to_string.cc new file mode 100644 index 00000000000..7a7d0657340 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/to_string.cc @@ -0,0 +1,66 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = true; + using namespace std; + + long long ll1 = -2; + string one(to_string(ll1)); + VERIFY( one == "-2" ); + + long long ll2 = 10; + string two(to_string(ll2)); + VERIFY( two == "10" ); + + unsigned long long ull1 = 2; + string three(to_string(ull1)); + VERIFY( three == "2" ); + + unsigned long long ull2 = 3000; + string four(to_string(ull2)); + VERIFY( four == "3000" ); + + long double ld1 = 2.0L; + string five(to_string(ld1)); + VERIFY( five == "2.000000" ); + + long double ld2 = -4.0L; + string six(to_string(ld2)); + VERIFY( six == "-4.000000" ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stod.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stod.cc new file mode 100644 index 00000000000..c1ebbb228d9 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stod.cc @@ -0,0 +1,139 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + wstring one; + stod(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + wstring one(L"a"); + stod(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + double d1 = 0.0; + size_t idx1 = 0; + try + { + wstring one(L"2.0a"); + d1 = stod(one, &idx1); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( d1 == 2.0 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + wstring one(L"1e"); + one.append(2 * numeric_limits<double>::max_exponent10, L'9'); + d1 = stod(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( d1 == 2.0 ); + + try + { + long double ld0 = numeric_limits<double>::max() / 100.0; + wstring one(to_wstring(ld0)); + stod(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + + if (sizeof(double) < sizeof(long double)) + { + test = false; + d1 = -1.0; + try + { + long double ld1 = numeric_limits<double>::max(); + ld1 *= 100.0; + wstring one(to_wstring(ld1)); + d1 = stod(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( d1 == -1.0 ); + } + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc new file mode 100644 index 00000000000..6f443c8bf97 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc @@ -0,0 +1,139 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + wstring one; + stof(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + wstring one(L"a"); + stof(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + float f1 = 0.0f; + size_t idx1 = 0; + try + { + wstring one(L"2.0a"); + f1 = stof(one, &idx1); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( f1 == 2.0f ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + wstring one(L"1e"); + one.append(2 * numeric_limits<float>::max_exponent10, L'9'); + f1 = stof(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( f1 == 2.0f ); + + try + { + long double ld0 = numeric_limits<float>::max() / 100.0; + wstring one(to_wstring(ld0)); + stof(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + + if (sizeof(float) < sizeof(long double)) + { + test = false; + f1 = -1.0f; + try + { + long double ld1 = numeric_limits<float>::max(); + ld1 *= 100.0; + wstring one(to_wstring(ld1)); + f1 = stof(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( f1 == -1.0f ); + } + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoi.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoi.cc new file mode 100644 index 00000000000..d8c637dfdf3 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoi.cc @@ -0,0 +1,205 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + wstring one; + stoi(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + wstring one(L"a"); + stoi(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + int i1 = 0; + try + { + wstring one(L"a"); + i1 = stoi(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == 10 ); + + size_t idx1 = 0; + try + { + wstring one(L"78"); + i1 = stoi(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + wstring one(L"10112"); + i1 = stoi(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + wstring one(L"0XE"); + i1 = stoi(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + wstring one(1000, L'9'); + i1 = stoi(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( i1 == 14 ); + + try + { + i1 = numeric_limits<int>::max(); + wstring one(to_wstring((long long)i1)); + i1 = stoi(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == numeric_limits<int>::max() ); + + try + { + i1 = numeric_limits<int>::min(); + wstring one(to_wstring((long long)i1)); + i1 = stoi(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == numeric_limits<int>::min() ); + + test = false; + i1 = 1; + try + { + long long ll0 = numeric_limits<int>::max(); + ++ll0; + wstring one(to_wstring(ll0)); + i1 = stoi(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( i1 == 1 ); + + test = false; + try + { + long long ll1 = numeric_limits<int>::min(); + --ll1; + wstring one(to_wstring(ll1)); + i1 = stoi(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( i1 == 1 ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stol.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stol.cc new file mode 100644 index 00000000000..1ae6a37de72 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stol.cc @@ -0,0 +1,168 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + wstring one; + stol(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + wstring one(L"a"); + stol(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + long l1 = 0; + try + { + wstring one(L"a"); + l1 = stol(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == 10 ); + + size_t idx1 = 0; + try + { + wstring one(L"78"); + l1 = stol(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + wstring one(L"10112"); + l1 = stol(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + wstring one(L"0XE"); + l1 = stol(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + wstring one(1000, L'9'); + l1 = stol(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( l1 == 14 ); + + try + { + l1 = numeric_limits<long>::max(); + wstring one(to_wstring((long long)l1)); + l1 = stol(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == numeric_limits<long>::max() ); + + try + { + l1 = numeric_limits<long>::min(); + wstring one(to_wstring((long long)l1)); + l1 = stol(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == numeric_limits<long>::min() ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stold.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stold.cc new file mode 100644 index 00000000000..7183a46fbf8 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stold.cc @@ -0,0 +1,117 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + wstring one; + stold(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + wstring one(L"a"); + stold(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + long double ld1 = 0.0L; + size_t idx1 = 0; + try + { + wstring one(L"2.0a"); + ld1 = stold(one, &idx1); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ld1 == 2.0L ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + wstring one(L"1e"); + one.append(2 * numeric_limits<long double>::max_exponent10, L'9'); + ld1 = stold(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( ld1 == 2.0L ); + + try + { + long double ld0 = numeric_limits<long double>::max() / 100.0L; + wstring one(to_wstring(ld0)); + stold(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoll.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoll.cc new file mode 100644 index 00000000000..9ebaff26989 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoll.cc @@ -0,0 +1,168 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + wstring one; + stoll(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + wstring one(L"a"); + stoll(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + long long ll1 = 0; + try + { + wstring one(L"a"); + ll1 = stoll(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == 10 ); + + size_t idx1 = 0; + try + { + wstring one(L"78"); + ll1 = stoll(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + wstring one(L"10112"); + ll1 = stoll(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + wstring one(L"0XE"); + ll1 = stoll(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + wstring one(1000, L'9'); + ll1 = stoll(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( ll1 == 14 ); + + try + { + ll1 = numeric_limits<long long>::max(); + wstring one(to_wstring(ll1)); + ll1 = stoll(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == numeric_limits<long long>::max() ); + + try + { + ll1 = numeric_limits<long long>::min(); + wstring one(to_wstring(ll1)); + ll1 = stoll(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == numeric_limits<long long>::min() ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoul.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoul.cc new file mode 100644 index 00000000000..3fd45097c20 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoul.cc @@ -0,0 +1,155 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + wstring one; + stoul(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + wstring one(L"a"); + stoul(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + unsigned long ul1 = 0; + try + { + wstring one(L"a"); + ul1 = stoul(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == 10 ); + + size_t idx1 = 0; + try + { + wstring one(L"78"); + ul1 = stoul(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + wstring one(L"10112"); + ul1 = stoul(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + wstring one(L"0XE"); + ul1 = stoul(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + wstring one(1000, L'9'); + ul1 = stoul(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( ul1 == 14 ); + + try + { + ul1 = numeric_limits<unsigned long>::max(); + wstring one(to_wstring((unsigned long long)ul1)); + ul1 = stoul(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == numeric_limits<unsigned long>::max() ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoull.cc new file mode 100644 index 00000000000..7605dc07e81 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoull.cc @@ -0,0 +1,155 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <limits> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = false; + using namespace std; + + try + { + wstring one; + stoull(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + test = false; + try + { + wstring one(L"a"); + stoull(one); + } + catch(std::invalid_argument) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + + unsigned long long ull1 = 0; + try + { + wstring one(L"a"); + ull1 = stoull(one, 0, 16); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == 10 ); + + size_t idx1 = 0; + try + { + wstring one(L"78"); + ull1 = stoull(one, &idx1, 8); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == 7 ); + VERIFY( idx1 = 1 ); + + try + { + wstring one(L"10112"); + ull1 = stoull(one, &idx1, 2); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == 11 ); + VERIFY( idx1 == 4 ); + + try + { + wstring one(L"0XE"); + ull1 = stoull(one, &idx1, 0); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == 14 ); + VERIFY( idx1 == 3 ); + + test = false; + try + { + wstring one(1000, L'9'); + ull1 = stoull(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( ull1 == 14 ); + + try + { + ull1 = numeric_limits<unsigned long long>::max(); + wstring one(to_wstring(ull1)); + ull1 = stoull(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == numeric_limits<unsigned long long>::max() ); + +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/to_wstring.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/to_wstring.cc new file mode 100644 index 00000000000..f8b640948db --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/to_wstring.cc @@ -0,0 +1,66 @@ +// { dg-options "-std=gnu++0x" } +// 2008-06-15 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2008 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 21.4 Numeric Conversions [string.conversions] + +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ +#ifdef _GLIBCXX_USE_C99 + + bool test __attribute__((unused)) = true; + using namespace std; + + long long ll1 = -2; + wstring one(to_wstring(ll1)); + VERIFY( one == L"-2" ); + + long long ll2 = 10; + wstring two(to_wstring(ll2)); + VERIFY( two == L"10" ); + + unsigned long long ull1 = 2; + wstring three(to_wstring(ull1)); + VERIFY( three == L"2" ); + + unsigned long long ull2 = 3000; + wstring four(to_wstring(ull2)); + VERIFY( four == L"3000" ); + + long double ld1 = 2.0L; + wstring five(to_wstring(ld1)); + VERIFY( five == L"2.000000" ); + + long double ld2 = -4.0L; + wstring six(to_wstring(ld2)); + VERIFY( six == L"-4.000000" ); + +#endif +} + +int main() +{ + test01(); + return 0; +} |