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. --- .../basic_istream/extractors_arithmetic/char/01.cc | 123 +++++++++++++++++ .../basic_istream/extractors_arithmetic/char/02.cc | 47 +++++++ .../basic_istream/extractors_arithmetic/char/03.cc | 46 +++++++ .../basic_istream/extractors_arithmetic/char/06.cc | 60 +++++++++ .../basic_istream/extractors_arithmetic/char/07.cc | 148 +++++++++++++++++++++ .../basic_istream/extractors_arithmetic/char/08.cc | 67 ++++++++++ .../basic_istream/extractors_arithmetic/char/09.cc | 51 +++++++ .../basic_istream/extractors_arithmetic/char/10.cc | 134 +++++++++++++++++++ .../basic_istream/extractors_arithmetic/char/11.cc | 56 ++++++++ .../basic_istream/extractors_arithmetic/char/12.cc | 77 +++++++++++ .../basic_istream/extractors_arithmetic/char/13.cc | 70 ++++++++++ .../extractors_arithmetic/char/9555-ia.cc | 77 +++++++++++ .../extractors_arithmetic/char/dr696.cc | 101 ++++++++++++++ .../char/exceptions_badbit_throw.cc | 75 +++++++++++ .../char/exceptions_failbit.cc | 66 +++++++++ .../char/exceptions_failbit_throw.cc | 68 ++++++++++ .../extractors_arithmetic/pod/3983-1.cc | 68 ++++++++++ .../extractors_arithmetic/wchar_t/01.cc | 120 +++++++++++++++++ .../extractors_arithmetic/wchar_t/02.cc | 45 +++++++ .../extractors_arithmetic/wchar_t/03.cc | 44 ++++++ .../extractors_arithmetic/wchar_t/06.cc | 58 ++++++++ .../extractors_arithmetic/wchar_t/07.cc | 145 ++++++++++++++++++++ .../extractors_arithmetic/wchar_t/08.cc | 65 +++++++++ .../extractors_arithmetic/wchar_t/09.cc | 49 +++++++ .../extractors_arithmetic/wchar_t/10.cc | 132 ++++++++++++++++++ .../extractors_arithmetic/wchar_t/11.cc | 53 ++++++++ .../extractors_arithmetic/wchar_t/12.cc | 74 +++++++++++ .../extractors_arithmetic/wchar_t/13.cc | 67 ++++++++++ .../extractors_arithmetic/wchar_t/9555-ia.cc | 77 +++++++++++ .../extractors_arithmetic/wchar_t/dr696.cc | 101 ++++++++++++++ .../wchar_t/exceptions_badbit_throw.cc | 73 ++++++++++ .../wchar_t/exceptions_failbit.cc | 65 +++++++++ .../wchar_t/exceptions_failbit_throw.cc | 68 ++++++++++ 33 files changed, 2570 insertions(+) create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/02.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/03.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/06.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/08.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/11.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/12.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/9555-ia.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/pod/3983-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/02.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/03.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/06.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/07.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/08.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/11.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/12.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/9555-ia.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_badbit_throw.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit_throw.cc (limited to 'libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic') diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc new file mode 100644 index 000000000..a8d91695b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc @@ -0,0 +1,123 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009, 2010 +// 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include // for printf +#include +#include +#include +#include + +std::string str_01; +std::string str_02("true false 0 1 110001"); +std::string str_03("-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5"); +std::string str_04("0123"); + +std::stringbuf isbuf_01(std::ios_base::in); +std::stringbuf isbuf_02(str_02, std::ios_base::in); +std::stringbuf isbuf_03(str_03, std::ios_base::in); +std::stringbuf isbuf_04(str_04, std::ios_base::in); + +std::istream is_01(0); +std::istream is_02(&isbuf_02); +std::istream is_03(&isbuf_03); +std::istream is_04(&isbuf_04); +std::stringstream ss_01(str_01); + +// minimal sanity check +bool test01() { + + bool test __attribute__((unused)) = true; + + // Integral Types: + bool b1 = false; + short s1 = 0; + int i1 = 0; + long l1 = 0; + unsigned short us1 = 0; + unsigned int ui1 = 0; + unsigned long ul1 = 0; + + // Floating-point Types: + float f1 = 0; + double d1 = 0; + long double ld1 = 0; + + // process alphanumeric versions of bool values + is_02.setf(std::ios_base::boolalpha); + is_02.flags(); + is_02 >> b1; + VERIFY( b1 == 1 ); + is_02 >> b1; + VERIFY( b1 == 0 ); + + // process numeric versions of of bool values + is_02.unsetf(std::ios_base::boolalpha); + is_02.flags(); + is_02 >> b1; + VERIFY( b1 == 0 ); + is_02 >> b1; + VERIFY( b1 == 1 ); + + // is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5" + is_03 >> l1; + VERIFY( l1 == -19999999 ); + is_03 >> ul1; + VERIFY( ul1 == 777777 ); + is_03 >> i1; + VERIFY( i1 == -234234 ); + is_03 >> ui1; + VERIFY( ui1 == 233 ); + is_03 >> s1; + VERIFY( s1 == -234 ); + is_03 >> us1; + VERIFY( us1 == 33 ); + is_03 >> b1; + VERIFY( b1 == 1 ); + is_03 >> ld1; + VERIFY( ld1 == 66300.25 ); + is_03 >> d1; + VERIFY( d1 == .315 ); + is_03 >> f1; + VERIFY( f1 == 1.5 ); + + is_04 >> std::hex >> i1; + std::printf ("%d %d %d\n", i1, i1 == 0x123, test); + VERIFY( i1 == 0x123 ); + std::printf ("%d %d %d\n", i1, i1 == 0x123, test); + + // test void pointers + int i = 55; + void* po = &i; + void* pi; + + ss_01 << po; + ss_01 >> pi; + std::printf ("%p %p\n", pi, po); + VERIFY( po == pi ); + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/02.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/02.cc new file mode 100644 index 000000000..3c82f3b91 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/02.cc @@ -0,0 +1,47 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +// elaborated test for ints +bool test02() +{ + bool test __attribute__((unused)) = true; + const std::string str_01("20000AB"); + std::stringbuf strb_01(str_01, std::ios_base::in); + std::istream is(&strb_01); + + int n = 15; + is >> n; + VERIFY( n == 20000 ); + char c = is.peek(); + VERIFY( c == 65 ); + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/03.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/03.cc new file mode 100644 index 000000000..a2d983573 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/03.cc @@ -0,0 +1,46 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +bool test03() +{ + std::stringbuf sbuf; + std::istream istr(&sbuf); + std::ostream ostr(&sbuf); + + bool test __attribute__((unused)) = true; + long l01; + ostr << "12220101"; + istr >> l01; // _M_in_end set completely incorrectly here. + VERIFY( l01 == 12220101 ); + VERIFY( istr.rdstate() == std::ios_base::eofbit ); + return test; +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/06.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/06.cc new file mode 100644 index 000000000..bfe7042f3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/06.cc @@ -0,0 +1,60 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00081.html +// Jim Parsons +void test06() +{ + // default locale, grouping is turned off + bool test __attribute__((unused)) = true; + unsigned int h4; + char c; + std::string s("205,199,144"); + std::istringstream is(s); + + is >> h4; // 205 + VERIFY( h4 == 205 ); + is >> c; // ',' + VERIFY( c == ',' ); + + is >> h4; // 199 + VERIFY( h4 == 199 ); + is >> c; // ',' + VERIFY( c == ',' ); + + is >> h4; // 144 + VERIFY( is.rdstate() == std::ios_base::eofbit ); + VERIFY( h4 == 144 ); + is >> c; // EOF + VERIFY( c == ',' ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc new file mode 100644 index 000000000..45975870c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc @@ -0,0 +1,148 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +namespace std { + class test_numpunct1 : public numpunct + { + protected: + string + do_grouping() const + { return string(1, '\003'); } + }; +} // namespace std + +void test07() +{ + // manufactured locale, grouping is turned on + bool test __attribute__((unused)) = true; + unsigned int h4 = 0, h3 = 0, h2 = 0; + float f1 = 0.0; + const std::string s1("205,199 23,445.25 1,024,365 123,22,24"); + std::istringstream is(s1); + is.imbue(std::locale(std::locale(), new std::test_numpunct1)); + + // Basic operation. + is >> h4; + VERIFY( h4 == 205199 ); + VERIFY( is.good() ); + + is.clear(); + is >> f1; + VERIFY( f1 == 23445.25 ); + VERIFY( is.good() ); + + is.clear(); + is >> h3; + VERIFY( h3 == 1024365 ); + VERIFY( is.good() ); + + is.clear(); + is >> h2; + VERIFY( h2 == 1232224 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + VERIFY( static_cast(is.rdstate() & std::ios_base::eofbit) ); + + // Stress tests for explicit errors in grouping corner cases. The + // validity of these tests and results have been hammered out in + // private email between bkoz and ncm between Jan 25 and Jan 27, 2000. + // Thanks nate -- benjamin + const std::string s2(",111 4,,4 0.25,345 5..25 156,, 1,000000 1000000 1234,567"); + h3 = h4 = h2 = 0; + f1 = 0.0; + const char c_control = '?'; + char c = c_control; + is.clear(); + is.str(s2); + + is >> h4; + VERIFY( h4 == 0 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == ',' ); + VERIFY( is.good() ); + + is.ignore(3); + is >> f1; + VERIFY( f1 == 0.0 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == ',' ); + is >> c; + VERIFY( c == '4' ); + VERIFY( is.good() ); + + is >> f1; + VERIFY( f1 == 0.25 ); + VERIFY( is.good() ); + is >> c; + VERIFY( c == ',' ); + is >> h2; + VERIFY( h2 == 345 ); + VERIFY( is.good() ); + f1 = 0.0; + h2 = 0; + + is >> f1; + VERIFY( f1 == 5.0 ); + VERIFY( is.good() ); + is >> f1; + VERIFY( f1 == .25 ); + VERIFY( is.good() ); + + is >> h3; + VERIFY( h3 == 0 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == ',' ); // second one + VERIFY( is.good() ); + + is >> h2; + VERIFY( h2 == 1000000 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + h2 = 0; + is.clear(); + + is >> h2; + VERIFY( h2 == 1000000 ); + VERIFY( is.good() ); + h2 = 0; + + is >> h2; + VERIFY( h2 == 1234567 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + VERIFY( static_cast(is.rdstate() & std::ios_base::eofbit) ); + is.clear(); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/08.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/08.cc new file mode 100644 index 000000000..99c017aa5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/08.cc @@ -0,0 +1,67 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +namespace std { + class test_numpunct2 : public numpunct + { + protected: + string + do_grouping() const + { return string("\002\003"); } + }; +} // namespace std + +void test08() +{ + // manufactured locale, grouping is turned on + bool test __attribute__((unused)) = true; + unsigned int h4 = 0, h3 = 0, h2 = 0; + const std::string s1("1,22 205,19 22,123,22"); + + std::istringstream is(s1); + is.imbue(std::locale(std::locale(), new std::test_numpunct2)); + + // Basic operation. + is >> h4; + VERIFY( h4 == 122 ); + VERIFY( is.good() ); + + is.clear(); + is >> h3; + VERIFY( h3 == 20519 ); + VERIFY( is.good() ); + + is.clear(); + is >> h2; + VERIFY( h2 == 2212322 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::eofbit) ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc new file mode 100644 index 000000000..bf64448bf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc @@ -0,0 +1,51 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +// { dg-do run { xfail lax_strtofp } } + +#include +#include +#include +#include + +bool test09() +{ + bool test __attribute__((unused)) = true; + + std::string st("2.456e3-+0.567e-2"); + std::stringbuf sb(st); + std::istream is(&sb); + double f1 = 0, f2 = 0; + char c; + (is>>std::ws) >> f1; + (is>>std::ws) >> c; + (is>>std::ws) >> f2; + test = f1 == 2456; + VERIFY( f2 == 0.00567 ); + VERIFY( c == '-' ); + return test; +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc new file mode 100644 index 000000000..bd7241b38 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc @@ -0,0 +1,134 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +bool test10() +{ + std::string str_01("0 00 000 +0 +0 -0"); + std::stringbuf isbuf_01(str_01); + std::istream is_01(&isbuf_01); + + bool test __attribute__((unused)) = true; + + int n = 365; + is_01 >> n; + VERIFY( n == 0 ); + n = 364; + is_01 >> n; + VERIFY( n == 0 ); + n = 363; + is_01 >> n; + VERIFY( n == 0 ); + n = 362; + is_01 >> n; + VERIFY( n == 0 ); + n = 361; + is_01 >> n; + VERIFY( n == 0 ); + n = 360; + is_01 >> n; + VERIFY( n == 0 ); + VERIFY( is_01.rdstate() == std::ios_base::eofbit ); + + std::string str_02("0x32 0X33 033 33"); + std::stringbuf isbuf_02(str_02); + std::istream is_02(&isbuf_02); + is_02.unsetf(std::ios_base::basefield); + is_02 >> n; + VERIFY( n == 50 ); + is_02 >> n; + VERIFY( n == 51 ); + is_02 >> n; + VERIFY( n == 27 ); + is_02 >> n; + VERIFY( n == 33 ); + VERIFY( is_02.rdstate() == std::ios_base::eofbit ); + + std::stringbuf isbuf_03(str_02); + std::istream is_03(&isbuf_03); + char c; + int m; + + is_03 >> std::dec >> n >> c >> m; + VERIFY( n == 0 ); + VERIFY( c == 'x' ); + VERIFY( m == 32 ); + + is_03 >> std::oct >> m >> c >> n; + VERIFY( m == 0 ); + VERIFY( c == 'X' ); + VERIFY( n == 27 ); + + is_03 >> std::dec >> m >> n; + VERIFY( m == 33 ); + VERIFY( n == 33 ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + std::string str_04("3. 4.5E+2a5E-3 .6E1"); + std::stringbuf isbuf_04(str_04); + std::istream is_04(&isbuf_04); + + double f; + is_04 >> f; + VERIFY( f == 3.0 ); + is_04 >> f; + VERIFY( f == 450.0 ); + is_04.ignore(); + is_04 >> f; + VERIFY( f == 0.005 ); + is_04 >> f; + VERIFY( f == 6 ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + std::string str_05("0E20 5Ea E16"); + std::stringbuf isbuf_05(str_05); + std::istream is_05(&isbuf_05); + + is_05 >> f; + VERIFY( f == 0 ); + f = 1; + is_05 >> f; + VERIFY( f == 0 ); + VERIFY( is_05.rdstate() == std::ios_base::failbit ); + is_05.clear(); + is_05 >> c; + VERIFY( c == 'a' ); + f = 1; + is_05 >> f; + VERIFY( f == 0 ); + VERIFY( is_05.rdstate() == std::ios_base::failbit ); + is_05.clear(); + is_05.ignore(); + is_05 >> n; + VERIFY( n == 16 ); + return test; +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/11.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/11.cc new file mode 100644 index 000000000..cffb39a76 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/11.cc @@ -0,0 +1,56 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include +#include + +// In the presence of no fmtflags, the input operator should behave +// like strtol(x, y, 0) +// libstdc++/90 +bool test11() +{ + bool test __attribute__((unused)) = true; + const char* cstrlit = "0x2a"; + + // sanity check via 'C' library call + char* err; + long l = std::strtol(cstrlit, &err, 0); + + std::istringstream iss(cstrlit); + iss.setf(std::ios::fmtflags(0), std::ios::basefield); + int i; + iss >> i; + + VERIFY (!iss.fail()); + VERIFY (l == i); + + return test; +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/12.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/12.cc new file mode 100644 index 000000000..70f74fd7a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/12.cc @@ -0,0 +1,77 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, +// 2010 +// 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +// XXX This test fails on Solaris 8 and 9 because of a bug in libc +// XXX sscanf for very long input. See: +// XXX http://gcc.gnu.org/ml/gcc/2002-12/msg01422.html +// { dg-do run { xfail { { *-*-solaris2.[89] } || lax_strtofp } } } + +#include +#include +#include +#include + +// libstdc++/3720 +// excess input should not cause a core dump +template +bool test12_aux(bool integer_type) +{ + bool test __attribute__((unused)) = true; + + int digits_overflow; + if (integer_type) + // This many digits will overflow integer types in base 10. + digits_overflow = std::numeric_limits::digits10 + 2; + else + // This might do it, unsure. + digits_overflow = std::numeric_limits::max_exponent10 + 1; + + std::string st; + std::string part = "1234567890123456789012345678901234567890"; + for (std::size_t i = 0; i < digits_overflow / part.size() + 1; ++i) + st += part; + std::stringbuf sb(st); + std::istream is(&sb); + T t; + is >> t; + VERIFY(is.fail()); + return test; +} + +bool test12() +{ + bool test __attribute__((unused)) = true; + VERIFY(test12_aux(true)); + VERIFY(test12_aux(true)); + VERIFY(test12_aux(true)); + VERIFY(test12_aux(false)); + VERIFY(test12_aux(false)); + VERIFY(test12_aux(false)); + return test; +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc new file mode 100644 index 000000000..ac5533a49 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc @@ -0,0 +1,70 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include +#include + +// libstdc++/3720 part two +void test13() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* l2 = "1.2345678901234567890123456789012345678901234567890123456" + " " + "1246.9"; + + // 1 + // used to core. + double d; + istringstream iss1(l2); + iss1 >> d; + iss1 >> d; + VERIFY (d > 1246 && d < 1247); + + // 2 + // quick test for failbit on maximum length extraction. + int i; + int max_digits = numeric_limits::digits10 + 1; + string digits; + for (int j = 0; j < max_digits; ++j) + digits += '1'; + istringstream iss2(digits); + iss2 >> i; + VERIFY( !iss2.fail() ); + + digits += '1'; + i = 0; + iss2.str(digits); + iss2.clear(); + iss2 >> i; + VERIFY( i == numeric_limits::max() ); + VERIFY( iss2.fail() ); +} + +int main() +{ + test13(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/9555-ia.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/9555-ia.cc new file mode 100644 index 000000000..44a695def --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/9555-ia.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2003, 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 +#include + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::istream is(&b); + is.exceptions(std::ios::badbit); + + try + { + is >> arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( is.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + bool b = true; + short s = -4; + unsigned short us = 4; + int i = -45; + unsigned int ui = 45; + long l = -456; + unsigned long ul = 456; + float f = 3.4; + double d = 3.45; + long double ld = 3.456; + + testthrow(b); + testthrow(s); + testthrow(us); + testthrow(i); + testthrow(ui); + testthrow(l); + testthrow(ul); + testthrow(f); + testthrow(d); + testthrow(ld); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc new file mode 100644 index 000000000..a1a71cc57 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc @@ -0,0 +1,101 @@ +// 2009-07-15 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include + +// DR 696. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + short s1 = 0; + ostringstream oss1; + oss1 << numeric_limits::max(); + istringstream iss1(oss1.str()); + iss1 >> s1; + VERIFY( s1 == numeric_limits::max() ); + VERIFY( !iss1.fail() && iss1.eof() ); + + short s2 = 0; + ostringstream oss2; + oss2 << static_cast(numeric_limits::max()) + 1; + istringstream iss2(oss2.str()); + iss2 >> s2; + VERIFY( s2 == numeric_limits::max() ); + VERIFY( iss2.fail() && iss2.eof() ); + + short s3 = 0; + ostringstream oss3; + oss3 << numeric_limits::min(); + istringstream iss3(oss3.str()); + iss3 >> s3; + VERIFY( s3 == numeric_limits::min() ); + VERIFY( !iss3.fail() && iss3.eof() ); + + short s4 = 0; + ostringstream oss4; + oss4 << static_cast(numeric_limits::min()) - 1; + istringstream iss4(oss4.str()); + iss4 >> s4; + VERIFY( s4 == numeric_limits::min() ); + VERIFY( iss4.fail() && iss4.eof() ); + + int i1 = 0; + ostringstream oss5; + oss5 << numeric_limits::max(); + istringstream iss5(oss5.str()); + iss5 >> i1; + VERIFY( i1 == numeric_limits::max() ); + VERIFY( !iss5.fail() && iss5.eof() ); + + int i2 = 0; + ostringstream oss6; + oss6 << static_cast(numeric_limits::max()) + 1; + istringstream iss6(oss6.str()); + iss6 >> i2; + VERIFY( i1 == numeric_limits::max() ); + VERIFY( iss6.fail() && iss6.eof() ); + + int i3 = 0; + ostringstream oss7; + oss7 << numeric_limits::min(); + istringstream iss7(oss7.str()); + iss7 >> i3; + VERIFY( i3 == numeric_limits::min() ); + VERIFY( !iss7.fail() && iss7.eof() ); + + int i4 = 0; + ostringstream oss8; + oss8 << static_cast(numeric_limits::min()) - 1; + istringstream iss8(oss8.str()); + iss8 >> i4; + VERIFY( i4 == numeric_limits::min() ); + VERIFY( iss8.fail() && iss8.eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..30bfa334a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc @@ -0,0 +1,75 @@ +// 2003-03-08 Jerry Quinn + +// Copyright (C) 2003, 2004, 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 +#include +#include + +// libstdc++/9561 +template +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get_char); + istringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + + +int main() +{ + test_badbit(); + test_badbit(); + test_badbit(); + test_badbit(); + test_badbit(); + test_badbit(); + test_badbit(); + + test_badbit(); + test_badbit(); + + test_badbit(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc new file mode 100644 index 000000000..b14647126 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2003, 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 + +// libstdc++/10093 +template +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + istringstream stream("jaylib - champion sound"); + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const ios_base::failure&) + { + // stream should set failbit and throw ios_base::failure. + VERIFY( stream.fail() ); + VERIFY( !stream.bad() ); + VERIFY( !stream.eof() ); + } + catch(...) + { VERIFY( false ); } +} + +int main() +{ + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + + test_failbit(); + test_failbit(); + + test_failbit(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc new file mode 100644 index 000000000..23237ccf1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc @@ -0,0 +1,68 @@ +// Copyright (C) 2003, 2004, 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 +#include + +// libstdc++/10093 +template +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get_char); + istringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + + test_failbit(); + test_failbit(); + + test_failbit(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/pod/3983-1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/pod/3983-1.cc new file mode 100644 index 000000000..311b4d410 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/pod/3983-1.cc @@ -0,0 +1,68 @@ +// 2001-06-05 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2005, 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 +// . + + +// 27.4.2.1.6 class ios_base::init + +#include +#include +#include +#include + +// libstdc++/3983 +// Sentry uses locale info, so have to try one formatted input/output. +void test03() +{ + using namespace std; + using __gnu_test::pod_ushort; + typedef basic_stringbuf stringbuf_type; + typedef basic_istream istream_type; + + stringbuf_type strbuf01; + istream_type iss(&strbuf01); + + bool test __attribute__((unused)) = true; + + try + { + int i; + iss >> i; + } + catch (std::bad_cast& obj) + { } + catch (std::exception& obj) + { VERIFY( false ); } +} + +#if !__GXX_WEAK__ +// Explicitly instantiate for systems with no COMDAT or weak support. +template + const std::basic_string<__gnu_test::pod_ushort>::size_type + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size; + +template + const __gnu_test::pod_ushort + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal; +#endif + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc new file mode 100644 index 000000000..5d7ec97a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc @@ -0,0 +1,120 @@ +// Copyright (C) 2004, 2009, 2010 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include // for printf +#include +#include +#include +#include + +std::wstring str_01; +std::wstring str_02(L"true false 0 1 110001"); +std::wstring str_03(L"-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5"); +std::wstring str_04(L"0123"); + +std::wstringbuf isbuf_01(std::ios_base::in); +std::wstringbuf isbuf_02(str_02, std::ios_base::in); +std::wstringbuf isbuf_03(str_03, std::ios_base::in); +std::wstringbuf isbuf_04(str_04, std::ios_base::in); + +std::wistream is_01(0); +std::wistream is_02(&isbuf_02); +std::wistream is_03(&isbuf_03); +std::wistream is_04(&isbuf_04); +std::wstringstream ss_01(str_01); + +// minimal sanity check +bool test01() { + + bool test __attribute__((unused)) = true; + + // Integral Types: + bool b1 = false; + short s1 = 0; + int i1 = 0; + long l1 = 0; + unsigned short us1 = 0; + unsigned int ui1 = 0; + unsigned long ul1 = 0; + + // Floating-point Types: + float f1 = 0; + double d1 = 0; + long double ld1 = 0; + + // process alphanumeric versions of bool values + is_02.setf(std::ios_base::boolalpha); + is_02.flags(); + is_02 >> b1; + VERIFY( b1 == 1 ); + is_02 >> b1; + VERIFY( b1 == 0 ); + + // process numeric versions of of bool values + is_02.unsetf(std::ios_base::boolalpha); + is_02.flags(); + is_02 >> b1; + VERIFY( b1 == 0 ); + is_02 >> b1; + VERIFY( b1 == 1 ); + + // is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5" + is_03 >> l1; + VERIFY( l1 == -19999999 ); + is_03 >> ul1; + VERIFY( ul1 == 777777 ); + is_03 >> i1; + VERIFY( i1 == -234234 ); + is_03 >> ui1; + VERIFY( ui1 == 233 ); + is_03 >> s1; + VERIFY( s1 == -234 ); + is_03 >> us1; + VERIFY( us1 == 33 ); + is_03 >> b1; + VERIFY( b1 == 1 ); + is_03 >> ld1; + VERIFY( ld1 == 66300.25 ); + is_03 >> d1; + VERIFY( d1 == .315 ); + is_03 >> f1; + VERIFY( f1 == 1.5 ); + + is_04 >> std::hex >> i1; + std::printf ("%d %d %d\n", i1, i1 == 0x123, test); + VERIFY( i1 == 0x123 ); + std::printf ("%d %d %d\n", i1, i1 == 0x123, test); + + // test void pointers + int i = 55; + void* po = &i; + void* pi; + + ss_01 << po; + ss_01 >> pi; + std::printf ("%p %p\n", pi, po); + VERIFY( po == pi ); + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/02.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/02.cc new file mode 100644 index 000000000..86c43afcd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/02.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2004, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +// elaborated test for ints +bool test02() +{ + bool test __attribute__((unused)) = true; + const std::wstring str_01(L"20000AB"); + std::wstringbuf strb_01(str_01, std::ios_base::in); + std::wistream is(&strb_01); + + int n = 15; + is >> n; + VERIFY( n == 20000 ); + wchar_t c = is.peek(); + VERIFY( c == L'A' ); + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/03.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/03.cc new file mode 100644 index 000000000..a357814c2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/03.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2004, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +bool test03() +{ + std::wstringbuf sbuf; + std::wistream istr(&sbuf); + std::wostream ostr(&sbuf); + + bool test __attribute__((unused)) = true; + long l01; + ostr << L"12220101"; + istr >> l01; // _M_in_end set completely incorrectly here. + VERIFY( l01 == 12220101 ); + VERIFY( istr.rdstate() == std::ios_base::eofbit ); + return test; +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/06.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/06.cc new file mode 100644 index 000000000..52c25a5bd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/06.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2004, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00081.html +// Jim Parsons +void test06() +{ + // default locale, grouping is turned off + bool test __attribute__((unused)) = true; + unsigned int h4; + wchar_t c; + std::wstring s(L"205,199,144"); + std::wistringstream is(s); + + is >> h4; // 205 + VERIFY( h4 == 205 ); + is >> c; // L',' + VERIFY( c == L',' ); + + is >> h4; // 199 + VERIFY( h4 == 199 ); + is >> c; // L',' + VERIFY( c == L',' ); + + is >> h4; // 144 + VERIFY( is.rdstate() == std::ios_base::eofbit ); + VERIFY( h4 == 144 ); + is >> c; // EOF + VERIFY( c == L',' ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/07.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/07.cc new file mode 100644 index 000000000..8e56816cf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/07.cc @@ -0,0 +1,145 @@ +// Copyright (C) 2004, 2005, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +namespace std { + class test_numpunct1 : public numpunct + { + protected: + string + do_grouping() const + { return string(1, '\003'); } + }; +} // namespace std + +void test07() +{ + // manufactured locale, grouping is turned on + bool test __attribute__((unused)) = true; + unsigned int h4 = 0, h3 = 0, h2 = 0; + float f1 = 0.0; + const std::wstring s1(L"205,199 23,445.25 1,024,365 123,22,24"); + std::wistringstream is(s1); + is.imbue(std::locale(std::locale(), new std::test_numpunct1)); + + // Basic operation. + is >> h4; + VERIFY( h4 == 205199 ); + VERIFY( is.good() ); + + is.clear(); + is >> f1; + VERIFY( f1 == 23445.25 ); + VERIFY( is.good() ); + + is.clear(); + is >> h3; + VERIFY( h3 == 1024365 ); + VERIFY( is.good() ); + + is.clear(); + is >> h2; + VERIFY( h2 == 1232224 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + VERIFY( static_cast(is.rdstate() & std::ios_base::eofbit) ); + + // Stress tests for explicit errors in grouping corner cases. The + // validity of these tests and results have been hammered out in + // private email between bkoz and ncm between Jan 25 and Jan 27, 2000. + // Thanks nate -- benjamin + const std::wstring s2(L",111 4,,4 0.25,345 5..25 156,, 1,000000 1000000 1234,567"); + h3 = h4 = h2 = 0; + f1 = 0.0; + const wchar_t c_control = L'?'; + wchar_t c = c_control; + is.clear(); + is.str(s2); + + is >> h4; + VERIFY( h4 == 0 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == L',' ); + VERIFY( is.good() ); + + is.ignore(3); + is >> f1; + VERIFY( f1 == 0.0 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == L',' ); + is >> c; + VERIFY( c == L'4' ); + VERIFY( is.good() ); + + is >> f1; + VERIFY( f1 == 0.25 ); + VERIFY( is.good() ); + is >> c; + VERIFY( c == L',' ); + is >> h2; + VERIFY( h2 == 345 ); + VERIFY( is.good() ); + f1 = 0.0; + h2 = 0; + + is >> f1; + VERIFY( f1 == 5.0 ); + VERIFY( is.good() ); + is >> f1; + VERIFY( f1 == .25 ); + VERIFY( is.good() ); + + is >> h3; + VERIFY( h3 == 0 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == L',' ); // second one + VERIFY( is.good() ); + + is >> h2; + VERIFY( h2 == 1000000 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + h2 = 0; + is.clear(); + + is >> h2; + VERIFY( h2 == 1000000 ); + VERIFY( is.good() ); + h2 = 0; + + is >> h2; + VERIFY( h2 == 1234567 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::failbit) ); + VERIFY( static_cast(is.rdstate() & std::ios_base::eofbit) ); + is.clear(); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/08.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/08.cc new file mode 100644 index 000000000..c5d78cfb2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/08.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +namespace std { + class test_numpunct2 : public numpunct + { + protected: + string + do_grouping() const + { return string("\002\003"); } + }; +} // namespace std + +void test08() +{ + // manufactured locale, grouping is turned on + bool test __attribute__((unused)) = true; + unsigned int h4 = 0, h3 = 0, h2 = 0; + const std::wstring s1(L"1,22 205,19 22,123,22"); + + std::wistringstream is(s1); + is.imbue(std::locale(std::locale(), new std::test_numpunct2)); + + // Basic operation. + is >> h4; + VERIFY( h4 == 122 ); + VERIFY( is.good() ); + + is.clear(); + is >> h3; + VERIFY( h3 == 20519 ); + VERIFY( is.good() ); + + is.clear(); + is >> h2; + VERIFY( h2 == 2212322 ); + VERIFY( static_cast(is.rdstate() & std::ios_base::eofbit) ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc new file mode 100644 index 000000000..fbf6e5db5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2004, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +// { dg-do run { xfail lax_strtofp } } + +#include +#include +#include +#include + +bool test09() +{ + bool test __attribute__((unused)) = true; + + std::wstring st(L"2.456e3-+0.567e-2"); + std::wstringbuf sb(st); + std::wistream is(&sb); + double f1 = 0, f2 = 0; + wchar_t c; + (is >> std::ws) >> f1; + (is >> std::ws) >> c; + (is >> std::ws) >> f2; + test = f1 == 2456; + VERIFY( f2 == 0.00567 ); + VERIFY( c == L'-' ); + return test; +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc new file mode 100644 index 000000000..f960f0cfb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc @@ -0,0 +1,132 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include + +bool test10() +{ + std::wstring str_01(L"0 00 000 +0 +0 -0"); + std::wstringbuf isbuf_01(str_01); + std::wistream is_01(&isbuf_01); + + bool test __attribute__((unused)) = true; + + int n = 365; + is_01 >> n; + VERIFY( n == 0 ); + n = 364; + is_01 >> n; + VERIFY( n == 0 ); + n = 363; + is_01 >> n; + VERIFY( n == 0 ); + n = 362; + is_01 >> n; + VERIFY( n == 0 ); + n = 361; + is_01 >> n; + VERIFY( n == 0 ); + n = 360; + is_01 >> n; + VERIFY( n == 0 ); + VERIFY( is_01.rdstate() == std::ios_base::eofbit ); + + std::wstring str_02(L"0x32 0X33 033 33"); + std::wstringbuf isbuf_02(str_02); + std::wistream is_02(&isbuf_02); + is_02.unsetf(std::ios_base::basefield); + is_02 >> n; + VERIFY( n == 50 ); + is_02 >> n; + VERIFY( n == 51 ); + is_02 >> n; + VERIFY( n == 27 ); + is_02 >> n; + VERIFY( n == 33 ); + VERIFY( is_02.rdstate() == std::ios_base::eofbit ); + + std::wstringbuf isbuf_03(str_02); + std::wistream is_03(&isbuf_03); + wchar_t c; + int m; + + is_03 >> std::dec >> n >> c >> m; + VERIFY( n == 0 ); + VERIFY( c == L'x' ); + VERIFY( m == 32 ); + + is_03 >> std::oct >> m >> c >> n; + VERIFY( m == 0 ); + VERIFY( c == L'X' ); + VERIFY( n == 27 ); + + is_03 >> std::dec >> m >> n; + VERIFY( m == 33 ); + VERIFY( n == 33 ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + std::wstring str_04(L"3. 4.5E+2a5E-3 .6E1"); + std::wstringbuf isbuf_04(str_04); + std::wistream is_04(&isbuf_04); + + double f; + is_04 >> f; + VERIFY( f == 3.0 ); + is_04 >> f; + VERIFY( f == 450.0 ); + is_04.ignore(); + is_04 >> f; + VERIFY( f == 0.005 ); + is_04 >> f; + VERIFY( f == 6 ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + std::wstring str_05(L"0E20 5Ea E16"); + std::wstringbuf isbuf_05(str_05); + std::wistream is_05(&isbuf_05); + + is_05 >> f; + VERIFY( f == 0 ); + f = 1; + is_05 >> f; + VERIFY( f == 0 ); + VERIFY( is_05.rdstate() == std::ios_base::failbit ); + is_05.clear(); + is_05 >> c; + VERIFY( c == L'a' ); + f = 1; + is_05 >> f; + VERIFY( f == 0 ); + VERIFY( is_05.rdstate() == std::ios_base::failbit ); + is_05.clear(); + is_05.ignore(); + is_05 >> n; + VERIFY( n == 16 ); + return test; +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/11.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/11.cc new file mode 100644 index 000000000..5eb256ef9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/11.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2004, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include +#include + +// In the presence of no fmtflags, the input operator should behave +// like strtol(x, y, 0) +// libstdc++/90 +bool test11() +{ + bool test __attribute__((unused)) = true; + const wchar_t* cstrlit = L"0x2a"; + + // sanity check via 'C' library call + wchar_t* err; + long l = std::wcstol(cstrlit, &err, 0); + + std::wistringstream iss(cstrlit); + iss.setf(std::wios::fmtflags(0), std::ios::basefield); + int i; + iss >> i; + + VERIFY( !iss.fail() ); + VERIFY( l == i ); + + return test; +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/12.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/12.cc new file mode 100644 index 000000000..dcadf8669 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/12.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 +// 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +// XXX This test fails on Solaris 8 and 9 because of a bug in libc +// XXX sscanf for very long input. See: +// XXX http://gcc.gnu.org/ml/gcc/2002-12/msg01422.html +// { dg-do run { xfail { { *-*-solaris2.[89] } || lax_strtofp } } } + +#include +#include +#include +#include + +// libstdc++/3720 +// excess input should not cause a core dump +template +bool test12_aux(bool integer_type) +{ + bool test __attribute__((unused)) = true; + + int digits_overflow; + if (integer_type) + // This many digits will overflow integer types in base 10. + digits_overflow = std::numeric_limits::digits10 + 2; + else + // This might do it, unsure. + digits_overflow = std::numeric_limits::max_exponent10 + 1; + + std::wstring st; + std::wstring part = L"1234567890123456789012345678901234567890"; + for (std::size_t i = 0; i < digits_overflow / part.size() + 1; ++i) + st += part; + std::wstringbuf sb(st); + std::wistream is(&sb); + T t; + is >> t; + VERIFY( is.fail() ); + return test; +} + +bool test12() +{ + bool test __attribute__((unused)) = true; + VERIFY( test12_aux(true) ); + VERIFY( test12_aux(true) ); + VERIFY( test12_aux(true) ); + VERIFY( test12_aux(false) ); + VERIFY( test12_aux(false) ); + VERIFY( test12_aux(false) ); + return test; +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc new file mode 100644 index 000000000..0a44b1ffb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include +#include +#include + +// libstdc++/3720 part two +void test13() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const wchar_t* l2 = L"1.2345678901234567890123456789012345678901234567890123456" + L" " + L"1246.9"; + + // 1 + // used to core. + double d; + wistringstream iss1(l2); + iss1 >> d; + iss1 >> d; + VERIFY ( d > 1246 && d < 1247 ); + + // 2 + // quick test for failbit on maximum length extraction. + int i; + int max_digits = numeric_limits::digits10 + 1; + wstring digits; + for (int j = 0; j < max_digits; ++j) + digits += L'1'; + wistringstream iss2(digits); + iss2 >> i; + VERIFY( !iss2.fail() ); + + digits += L'1'; + i = 0; + iss2.str(digits); + iss2.clear(); + iss2 >> i; + VERIFY( i == numeric_limits::max() ); + VERIFY( iss2.fail() ); +} + +int main() +{ + test13(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/9555-ia.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/9555-ia.cc new file mode 100644 index 000000000..8ae2f09ed --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/9555-ia.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2004, 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 +#include + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wistream is(&b); + is.exceptions(std::ios::badbit); + + try + { + is >> arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( is.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + bool b = true; + short s = -4; + unsigned short us = 4; + int i = -45; + unsigned int ui = 45; + long l = -456; + unsigned long ul = 456; + float f = 3.4; + double d = 3.45; + long double ld = 3.456; + + testthrow(b); + testthrow(s); + testthrow(us); + testthrow(i); + testthrow(ui); + testthrow(l); + testthrow(ul); + testthrow(f); + testthrow(d); + testthrow(ld); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc new file mode 100644 index 000000000..2ed5b309b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc @@ -0,0 +1,101 @@ +// 2009-07-15 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 +// . + +// 27.6.1.2.2 arithmetic extractors + +#include +#include +#include + +// DR 696. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + short s1 = 0; + wostringstream oss1; + oss1 << numeric_limits::max(); + wistringstream iss1(oss1.str()); + iss1 >> s1; + VERIFY( s1 == numeric_limits::max() ); + VERIFY( !iss1.fail() && iss1.eof() ); + + short s2 = 0; + wostringstream oss2; + oss2 << static_cast(numeric_limits::max()) + 1; + wistringstream iss2(oss2.str()); + iss2 >> s2; + VERIFY( s2 == numeric_limits::max() ); + VERIFY( iss2.fail() && iss2.eof() ); + + short s3 = 0; + wostringstream oss3; + oss3 << numeric_limits::min(); + wistringstream iss3(oss3.str()); + iss3 >> s3; + VERIFY( s3 == numeric_limits::min() ); + VERIFY( !iss3.fail() && iss3.eof() ); + + short s4 = 0; + wostringstream oss4; + oss4 << static_cast(numeric_limits::min()) - 1; + wistringstream iss4(oss4.str()); + iss4 >> s4; + VERIFY( s4 == numeric_limits::min() ); + VERIFY( iss4.fail() && iss4.eof() ); + + int i1 = 0; + wostringstream oss5; + oss5 << numeric_limits::max(); + wistringstream iss5(oss5.str()); + iss5 >> i1; + VERIFY( i1 == numeric_limits::max() ); + VERIFY( !iss5.fail() && iss5.eof() ); + + int i2 = 0; + wostringstream oss6; + oss6 << static_cast(numeric_limits::max()) + 1; + wistringstream iss6(oss6.str()); + iss6 >> i2; + VERIFY( i1 == numeric_limits::max() ); + VERIFY( iss6.fail() && iss6.eof() ); + + int i3 = 0; + wostringstream oss7; + oss7 << numeric_limits::min(); + wistringstream iss7(oss7.str()); + iss7 >> i3; + VERIFY( i3 == numeric_limits::min() ); + VERIFY( !iss7.fail() && iss7.eof() ); + + int i4 = 0; + wostringstream oss8; + oss8 << static_cast(numeric_limits::min()) - 1; + wistringstream iss8(oss8.str()); + iss8 >> i4; + VERIFY( i4 == numeric_limits::min() ); + VERIFY( iss8.fail() && iss8.eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..983aac745 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2004, 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 +#include +#include + +// libstdc++/9561 +template +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get_wchar_t); + wistringstream stream(L"jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + + +int main() +{ + test_badbit(); + test_badbit(); + test_badbit(); + test_badbit(); + test_badbit(); + test_badbit(); + test_badbit(); + + test_badbit(); + test_badbit(); + + test_badbit(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc new file mode 100644 index 000000000..0a31e91dc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 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 + +// libstdc++/10093 +template +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wistringstream stream(L"jaylib - champion sound"); + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const ios_base::failure&) + { + // stream should set failbit and throw ios_base::failure. + VERIFY( stream.fail() ); + VERIFY( !stream.bad() ); + VERIFY( !stream.eof() ); + } + catch(...) + { VERIFY( false ); } +} + +int main() +{ + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + + test_failbit(); + test_failbit(); + + test_failbit(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit_throw.cc new file mode 100644 index 000000000..b3a1b7614 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit_throw.cc @@ -0,0 +1,68 @@ +// Copyright (C) 2004, 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 +#include + +// libstdc++/10093 +template +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get_wchar_t); + wistringstream stream(L"jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + test_failbit(); + + test_failbit(); + test_failbit(); + + test_failbit(); + + return 0; +} -- cgit v1.2.3