OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_istream/] [extractors_arithmetic/] [char/] [12.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 1999-04-12 bkoz
2
 
3
// Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 2, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// You should have received a copy of the GNU General Public License along
17
// with this library; see the file COPYING.  If not, write to the Free
18
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
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
26
// { dg-do run { xfail sparc*-*-solaris2* } }
27
 
28
#include <istream>
29
#include <sstream>
30
#include <testsuite_hooks.h>
31
 
32
// libstdc++/3720
33
// excess input should not cause a core dump
34
template<typename T>
35
bool test12_aux(bool integer_type)
36
{
37
  bool test __attribute__((unused)) = true;
38
 
39
  int digits_overflow;
40
  if (integer_type)
41
    // This many digits will overflow integer types in base 10.
42
    digits_overflow = std::numeric_limits<T>::digits10 + 2;
43
  else
44
    // This might do it, unsure.
45
    digits_overflow = std::numeric_limits<T>::max_exponent10 + 1;
46
 
47
  std::string st;
48
  std::string part = "1234567890123456789012345678901234567890";
49
  for (std::size_t i = 0; i < digits_overflow / part.size() + 1; ++i)
50
    st += part;
51
  std::stringbuf sb(st);
52
  std::istream is(&sb);
53
  T t;
54
  is >> t;
55
  VERIFY(is.fail());
56
  return test;
57
}
58
 
59
bool test12()
60
{
61
  bool test __attribute__((unused)) = true;
62
  VERIFY(test12_aux<short>(true));
63
  VERIFY(test12_aux<int>(true));
64
  VERIFY(test12_aux<long>(true));
65
  VERIFY(test12_aux<float>(false));
66
  VERIFY(test12_aux<double>(false));
67
  VERIFY(test12_aux<long double>(false));
68
  return test;
69
}
70
 
71
int main()
72
{
73
  test12();
74
  return 0;
75
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.