]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/2.cc
[committed][RISC-V][PR target/114139] Verify we have a CONST_INT before extracting...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_streambuf / overflow / char / 2.cc
CommitLineData
23cac885 1// 1999-10-11 bkoz
b2dad0e3 2
a945c346 3// Copyright (C) 1999-2024 Free Software Foundation, Inc.
b2dad0e3
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
b2dad0e3
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
b2dad0e3 19
b2dad0e3 20
23cac885 21// 27.5.2 template class basic_streambuf
b2dad0e3 22
23cac885 23#include <streambuf>
b2dad0e3 24#include <ostream>
6f422965 25#include <string>
f13a69ec 26#include <testsuite_hooks.h>
b2dad0e3 27
23cac885
BK
28// test03
29// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html
30template<typename charT, typename traits = std::char_traits<charT> >
31 class basic_nullbuf : public std::basic_streambuf<charT, traits>
32 {
33 protected:
34 typedef typename
35 std::basic_streambuf<charT, traits>::int_type int_type;
36 virtual int_type
37 overflow(int_type c)
38 { return traits::not_eof(c); }
39 };
e6705174 40
23cac885
BK
41typedef basic_nullbuf<char> nullbuf;
42
43template<typename T>
44 char
45 print(const T& x)
46 {
47 nullbuf ob;
48 std::ostream out(&ob);
49 out << x << std::endl;
50 return (!out ? '0' : '1');
51 }
bcc6a03a 52
23cac885 53void test03()
e6705174 54{
23cac885
BK
55 const std::string control01("11111");
56 std::string test01;
57
58 test01 += print(true);
59 test01 += print(3.14159);
60 test01 += print(10);
61 test01 += print('x');
62 test01 += print("pipo");
63
64 VERIFY( test01 == control01 );
65}
b2dad0e3 66
e6705174
BK
67int main()
68{
23cac885 69 test03();
b2dad0e3
BK
70 return 0;
71}