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/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc | |
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/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc')
-rw-r--r-- | libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc | 139 |
1 files changed, 139 insertions, 0 deletions
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; +} |