]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/94749.cc
1 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
19 // { dg-options "-DSIMULATOR_TEST" { target simulator } }
20 // { dg-timeout-factor 2 { target ilp32 } }
23 // basic_istream::ignore(n, c) discards n+1 if next character is equal to c.
27 #include <testsuite_hooks.h>
34 std::basic_istringstream
<C
> s(" + -");
36 VERIFY( s
.gcount() == 1 );
37 VERIFY( s
.get() == '+' );
39 VERIFY( s
.gcount() == 3 );
40 VERIFY( s
.get() == '-' );
46 std::basic_istringstream
<C
> s(".+...-");
48 VERIFY( s
.gcount() == 1 );
49 VERIFY( s
.get() == '+' );
51 VERIFY( s
.gcount() == 3 );
52 VERIFY( s
.get() == '-' );
58 std::basic_istringstream
<C
, __gnu_cxx::char_traits
<C
> > s(" + -");
60 VERIFY( s
.gcount() == 1 );
61 VERIFY( s
.get() == '+' );
63 VERIFY( s
.gcount() == 3 );
64 VERIFY( s
.get() == '-' );
70 std::basic_istringstream
<C
, __gnu_cxx::char_traits
<C
> > s(".+...-");
72 VERIFY( s
.gcount() == 1 );
73 VERIFY( s
.get() == '+' );
75 VERIFY( s
.gcount() == 3 );
76 VERIFY( s
.get() == '-' );
79 // The original fix for PR libstdc++/94749 failed to discard the delimiter
80 // if it occurred after numeric_limits<streamsize>::max() had been seen.
81 // This streambuf will keep filling the get area with zero bytes until
82 // almost numeric_limits<streamsize>::max() characters have been read,
83 // and then return one more buffer that has "123" at its end.
85 struct buff
: std::basic_streambuf
<typename
T::char_type
, T
>
87 typedef typename
T::char_type char_type
;
88 typedef typename
T::int_type int_type
;
89 typedef std::streamsize streamsize
;
90 typedef std::numeric_limits
<streamsize
> limits
;
92 buff() : count(0), buf() { }
96 // Number of characters left until we overflow the counter
97 const streamsize headroom
= limits::max() - count
;
102 if (bufsz
< headroom
)
104 this->setg(buf
, buf
, buf
+ bufsz
);
109 // write "123" across the 2GB boundary
110 buf
[headroom
-1] = '1';
111 buf
[headroom
+0] = '2';
112 buf
[headroom
+1] = '3';
113 this->setg(buf
, buf
, buf
+ headroom
+ 2);
114 count
= limits::max();
122 static const streamsize bufsz
= 2048 << limits::digits10
;
123 char_type buf
[bufsz
+ 2];
129 // Not possible to overflow 64-bit streamsize in reasonable time.
130 if (std::numeric_limits
<std::streamsize
>::digits
> 32)
133 typedef std::char_traits
<C
> T
;
135 std::basic_istream
<C
, T
> in(new buff
<T
>);
137 in
.ignore(std::numeric_limits
<std::streamsize
>::max(), '1');
139 VERIFY(in
.gcount() == std::numeric_limits
<std::streamsize
>::max());
140 VERIFY(in
.get() == '2');
141 VERIFY(in
.get() == '3');
142 VERIFY(in
.get() == T::eof());
144 delete in
.rdbuf(new buff
<T
>);
146 in
.ignore(std::numeric_limits
<std::streamsize
>::max(), '2');
148 // The standard doesn't say what gcount() should return in this case:
149 VERIFY(in
.gcount() == std::numeric_limits
<std::streamsize
>::max());
150 VERIFY(in
.get() == '3');
151 VERIFY(in
.get() == T::eof());
153 delete in
.rdbuf(new buff
<T
>);
155 in
.ignore(std::numeric_limits
<std::streamsize
>::max(), '3');
157 // The standard doesn't say what gcount() should return in this case:
158 VERIFY(in
.gcount() == std::numeric_limits
<std::streamsize
>::max());
159 VERIFY(in
.get() == T::eof());
161 delete in
.rdbuf(new buff
<T
>);
163 in
.ignore(std::numeric_limits
<std::streamsize
>::max(), '4');
165 // The standard doesn't say what gcount() should return in this case:
166 VERIFY(in
.gcount() == std::numeric_limits
<std::streamsize
>::max());
167 VERIFY(in
.get() == T::eof());
175 if (std::numeric_limits
<std::streamsize
>::digits
> 32)
178 typedef __gnu_cxx::char_traits
<C
> T
;
180 std::basic_istream
<C
, T
> in(new buff
<T
>);
182 in
.ignore(std::numeric_limits
<std::streamsize
>::max(), '1');
184 VERIFY(in
.gcount() == std::numeric_limits
<std::streamsize
>::max());
185 VERIFY(in
.get() == '2');
186 VERIFY(in
.get() == '3');
187 VERIFY(in
.get() == T::eof());
189 delete in
.rdbuf(new buff
<T
>);
191 in
.ignore(std::numeric_limits
<std::streamsize
>::max(), '2');
193 // The standard doesn't say what gcount() should return in this case:
194 VERIFY(in
.gcount() == std::numeric_limits
<std::streamsize
>::max());
195 VERIFY(in
.get() == '3');
196 VERIFY(in
.get() == T::eof());
198 delete in
.rdbuf(new buff
<T
>);
200 in
.ignore(std::numeric_limits
<std::streamsize
>::max(), '3');
202 // The standard doesn't say what gcount() should return in this case:
203 VERIFY(in
.gcount() == std::numeric_limits
<std::streamsize
>::max());
204 VERIFY(in
.get() == T::eof());
206 delete in
.rdbuf(new buff
<T
>);
208 in
.ignore(std::numeric_limits
<std::streamsize
>::max(), '4');
210 // The standard doesn't say what gcount() should return in this case:
211 VERIFY(in
.gcount() == std::numeric_limits
<std::streamsize
>::max());
212 VERIFY(in
.get() == T::eof());
225 #ifndef SIMULATOR_TEST