From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- .../numeric_conversions/char/dr1261.cc | 64 +++++++ .../basic_string/numeric_conversions/char/stod.cc | 137 ++++++++++++++ .../basic_string/numeric_conversions/char/stof.cc | 137 ++++++++++++++ .../basic_string/numeric_conversions/char/stoi.cc | 202 +++++++++++++++++++++ .../basic_string/numeric_conversions/char/stol.cc | 165 +++++++++++++++++ .../basic_string/numeric_conversions/char/stold.cc | 114 ++++++++++++ .../basic_string/numeric_conversions/char/stoll.cc | 165 +++++++++++++++++ .../basic_string/numeric_conversions/char/stoul.cc | 152 ++++++++++++++++ .../numeric_conversions/char/stoull.cc | 152 ++++++++++++++++ .../numeric_conversions/char/to_string.cc | 63 +++++++ 10 files changed, 1351 insertions(+) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/to_string.cc (limited to 'libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char') diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc new file mode 100644 index 000000000..2030b7f63 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/dr1261.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2009-11-11 Paolo Carlini + +// Copyright (C) 2009 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 +// . + +#include +#include + +// DR 1261. Insufficient overloads for to_string / to_wstring +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + const string one(to_string(-2)); + VERIFY( one == "-2" ); + + const string two(to_string(10u)); + VERIFY( two == "10" ); + + const string three(to_string(2l)); + VERIFY( three == "2" ); + + const string four(to_string(3000ul)); + VERIFY( four == "3000" ); + + const string five(to_string(7ll)); + VERIFY( five == "7" ); + + const string six(to_string(400ull)); + VERIFY( six == "400" ); + + const string seven(to_string(-1.0F)); + VERIFY( seven == "-1.000000" ); + + const string eight(to_string(2.0)); + VERIFY( eight == "2.000000" ); + + const string nine(to_string(-4.0L)); + VERIFY( nine == "-4.000000" ); +} + +int main() +{ + test01(); + return 0; +} 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 000000000..e4608d106 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc @@ -0,0 +1,137 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2008-06-15 Paolo Carlini + +// Copyright (C) 2008, 2009 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 +// . + +// 21.4 Numeric Conversions [string.conversions] + +#include +#include +#include +#include + +void +test01() +{ + 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::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::max() / 100.0; + string one(to_string(ld0)); + stod(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + + if ((numeric_limits::max() / 10000.0L) + > numeric_limits::max()) + { + test = false; + d1 = -1.0; + try + { + long double ld1 = numeric_limits::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 ); + } +} + +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 000000000..6f14bd3ad --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc @@ -0,0 +1,137 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2008-06-15 Paolo Carlini + +// Copyright (C) 2008, 2009 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 +// . + +// 21.4 Numeric Conversions [string.conversions] + +#include +#include +#include +#include + +void +test01() +{ + 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::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::max() / 100.0; + string one(to_string(ld0)); + stof(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + + if ((numeric_limits::max() / 10000.0L) + > numeric_limits::max()) + { + test = false; + f1 = -1.0f; + try + { + long double ld1 = numeric_limits::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 ); + } +} + +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 000000000..7bcd123cb --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc @@ -0,0 +1,202 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2008-06-15 Paolo Carlini + +// Copyright (C) 2008, 2009 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 +// . + +// 21.4 Numeric Conversions [string.conversions] + +#include +#include +#include +#include + +void +test01() +{ + 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::max(); + string one(to_string((long long)i1)); + i1 = stoi(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == numeric_limits::max() ); + + try + { + i1 = numeric_limits::min(); + string one(to_string((long long)i1)); + i1 = stoi(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( i1 == numeric_limits::min() ); + + test = false; + i1 = 1; + try + { + long long ll0 = numeric_limits::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::min(); + --ll1; + string one(to_string(ll1)); + i1 = stoi(one); + } + catch(std::out_of_range) + { + test = true; + } + catch(...) + { + } + VERIFY( test ); + VERIFY( i1 == 1 ); +} + +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 000000000..7b61db6fb --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc @@ -0,0 +1,165 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2008-06-15 Paolo Carlini + +// Copyright (C) 2008, 2009 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 +// . + +// 21.4 Numeric Conversions [string.conversions] + +#include +#include +#include +#include + +void +test01() +{ + 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::max(); + string one(to_string((long long)l1)); + l1 = stol(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == numeric_limits::max() ); + + try + { + l1 = numeric_limits::min(); + string one(to_string((long long)l1)); + l1 = stol(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( l1 == numeric_limits::min() ); +} + +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 000000000..c8123bcd2 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc @@ -0,0 +1,114 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2008-06-15 Paolo Carlini + +// Copyright (C) 2008, 2009 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 +// . + +// 21.4 Numeric Conversions [string.conversions] + +#include +#include +#include +#include + +void +test01() +{ + 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::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::max() / 100.0L; + string one(to_string(ld0)); + stold(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); +} + +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 000000000..161c94a09 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc @@ -0,0 +1,165 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2008-06-15 Paolo Carlini + +// Copyright (C) 2008, 2009 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 +// . + +// 21.4 Numeric Conversions [string.conversions] + +#include +#include +#include +#include + +void +test01() +{ + 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::max(); + string one(to_string(ll1)); + ll1 = stoll(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == numeric_limits::max() ); + + try + { + ll1 = numeric_limits::min(); + string one(to_string(ll1)); + ll1 = stoll(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ll1 == numeric_limits::min() ); +} + +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 000000000..b6f42f15b --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc @@ -0,0 +1,152 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2008-06-15 Paolo Carlini + +// Copyright (C) 2008, 2009 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 +// . + +// 21.4 Numeric Conversions [string.conversions] + +#include +#include +#include +#include + +void +test01() +{ + 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::max(); + string one(to_string((unsigned long long)ul1)); + ul1 = stoul(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ul1 == numeric_limits::max() ); +} + +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 000000000..15e3e85e5 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc @@ -0,0 +1,152 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2008-06-15 Paolo Carlini + +// Copyright (C) 2008, 2009 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 +// . + +// 21.4 Numeric Conversions [string.conversions] + +#include +#include +#include +#include + +void +test01() +{ + 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::max(); + string one(to_string(ull1)); + ull1 = stoull(one); + } + catch(...) + { + test = false; + } + VERIFY( test ); + VERIFY( ull1 == numeric_limits::max() ); +} + +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 000000000..ede975271 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/numeric_conversions/char/to_string.cc @@ -0,0 +1,63 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-string-conversions "" } + +// 2008-06-15 Paolo Carlini + +// Copyright (C) 2008, 2009 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 +// . + +// 21.4 Numeric Conversions [string.conversions] + +#include +#include + +void +test01() +{ + 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" ); +} + +int main() +{ + test01(); + return 0; +} -- cgit v1.2.3