| 1 |
// Copyright (C) 2005-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 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) |
| 7 |
// any later version. |
| 8 |
|
| 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. |
| 13 |
|
| 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/>. |
| 17 |
|
| 18 |
// 27.6.2.5.3 basic_ostream manipulator inserters |
| 19 |
// |
| 20 |
// _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 21 |
// DR 60. What is a formatted input function? |
| 22 |
// Inserters for manipulators do not behave as formatted output functions. |
| 23 |
|
| 24 |
#include <ostream> |
| 25 |
#include <stdexcept> |
| 26 |
#include <testsuite_hooks.h> |
| 27 |
#include <testsuite_io.h> |
| 28 |
|
| 29 |
std::wostream& func1(std::wostream&) |
| 30 |
{ throw std::runtime_error(""); } |
| 31 |
|
| 32 |
std::wios& func2(std::wios&) |
| 33 |
{ throw std::runtime_error(""); } |
| 34 |
|
| 35 |
std::ios_base& func3(std::ios_base&) |
| 36 |
{ throw std::runtime_error(""); } |
| 37 |
|
| 38 |
template<typename T> |
| 39 |
void test(T& (*f)(T&)) |
| 40 |
{ |
| 41 |
__gnu_test::sync_wstreambuf buf; |
| 42 |
std::wostream os(&buf); |
| 43 |
|
| 44 |
__gnu_test::sync_wstreambuf buf_tie; |
| 45 |
std::wostream os_tie(&buf_tie); |
| 46 |
|
| 47 |
// No sentry should be constructed so os.tie()->flush() should not be |
| 48 |
// called. |
| 49 |
os.tie(&os_tie); |
| 50 |
|
| 51 |
try |
| 52 |
{ |
| 53 |
os << f; |
| 54 |
// Exceptions thrown by f should not be caught |
| 55 |
VERIFY( false ); |
| 56 |
} |
| 57 |
catch (std::runtime_error&) |
| 58 |
{ |
| 59 |
} |
| 60 |
|
| 61 |
// Exceptions thrown by f should not cause badbit to be set |
| 62 |
VERIFY( os.good() ); |
| 63 |
VERIFY( !buf_tie.sync_called() ); |
| 64 |
|
| 65 |
// The manipulator should be called even if !os.good(). |
| 66 |
os.setstate(std::ios_base::eofbit); |
| 67 |
|
| 68 |
try |
| 69 |
{ |
| 70 |
os << f; |
| 71 |
// Exceptions thrown by f should not be caught |
| 72 |
VERIFY( false ); |
| 73 |
} |
| 74 |
catch (std::runtime_error&) |
| 75 |
{ |
| 76 |
} |
| 77 |
|
| 78 |
// Exceptions thrown by f should not cause badbit to be set |
| 79 |
VERIFY( os.rdstate() == std::ios_base::eofbit ); |
| 80 |
VERIFY( !buf_tie.sync_called() ); |
| 81 |
} |
| 82 |
|
| 83 |
void test05() |
| 84 |
{ |
| 85 |
test(&func1); |
| 86 |
test(&func2); |
| 87 |
test(&func3); |
| 88 |
} |
| 89 |
|
| 90 |
int main() |
| 91 |
{ |
| 92 |
test05(); |
| 93 |
return 0; |
| 94 |
} |