]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/12.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_arithmetic / char / 12.cc
CommitLineData
8de6a6df
KG
1// 1999-04-12 bkoz
2
748086b7 3// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
6725add5 4// Free Software Foundation, Inc.
8de6a6df
KG
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
748086b7 9// Free Software Foundation; either version 3, or (at your option)
8de6a6df
KG
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
748086b7
JJ
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
8de6a6df
KG
20
21// 27.6.1.2.2 arithmetic extractors
22
23// XXX This test fails on sparc-solaris2 because of a bug in libc
24// XXX sscanf for very long input. See:
25// XXX http://gcc.gnu.org/ml/gcc/2002-12/msg01422.html
a5ea7a0b 26// { dg-do run { xfail { { sparc*-*-solaris2* } || lax_strtofp } } }
8de6a6df 27
8de6a6df 28#include <istream>
8de6a6df 29#include <sstream>
6725add5 30#include <limits>
8de6a6df
KG
31#include <testsuite_hooks.h>
32
8de6a6df
KG
33// libstdc++/3720
34// excess input should not cause a core dump
35template<typename T>
36bool test12_aux(bool integer_type)
37{
11f10e6b 38 bool test __attribute__((unused)) = true;
8de6a6df
KG
39
40 int digits_overflow;
41 if (integer_type)
42 // This many digits will overflow integer types in base 10.
43 digits_overflow = std::numeric_limits<T>::digits10 + 2;
44 else
45 // This might do it, unsure.
46 digits_overflow = std::numeric_limits<T>::max_exponent10 + 1;
47
48 std::string st;
49 std::string part = "1234567890123456789012345678901234567890";
11f10e6b 50 for (std::size_t i = 0; i < digits_overflow / part.size() + 1; ++i)
8de6a6df
KG
51 st += part;
52 std::stringbuf sb(st);
53 std::istream is(&sb);
54 T t;
55 is >> t;
56 VERIFY(is.fail());
57 return test;
58}
59
60bool test12()
61{
11f10e6b 62 bool test __attribute__((unused)) = true;
8de6a6df
KG
63 VERIFY(test12_aux<short>(true));
64 VERIFY(test12_aux<int>(true));
65 VERIFY(test12_aux<long>(true));
66 VERIFY(test12_aux<float>(false));
67 VERIFY(test12_aux<double>(false));
68 VERIFY(test12_aux<long double>(false));
69 return test;
70}
71
72int main()
73{
74 test12();
75 return 0;
76}