]>
Commit | Line | Data |
---|---|---|
a5544970 | 1 | // Copyright (C) 2000-2019 Free Software Foundation, Inc. |
d422980b BK |
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 | |
748086b7 | 6 | // Free Software Foundation; either version 3, or (at your option) |
d422980b BK |
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 | |
748086b7 JJ |
15 | // with this library; see the file COPYING3. If not see |
16 | // <http://www.gnu.org/licenses/>. | |
d422980b | 17 | |
23cac885 BK |
18 | // 27.8.1.10 ofstream member functions |
19 | // @require@ %-*.tst | |
20 | // @diff@ %-*.tst %-*.txt | |
d422980b | 21 | |
23cac885 | 22 | #include <ostream> |
d422980b | 23 | #include <fstream> |
fe413112 | 24 | #include <testsuite_hooks.h> |
d422980b | 25 | |
23cac885 BK |
26 | const char name_01[] = "ofstream_members-1.tst"; |
27 | ||
d422980b BK |
28 | void |
29 | redirect_buffer(std::ios& stream, std::streambuf* new_buf) | |
30 | { stream.rdbuf(new_buf); } | |
31 | ||
32 | std::streambuf* | |
33 | active_buffer(std::ios& stream) | |
34 | { return stream.rdbuf(); } | |
35 | ||
36 | // libstdc++/2832 | |
23cac885 | 37 | void test03() |
d422980b | 38 | { |
d422980b | 39 | const char* strlit01 = "fuck war"; |
d422980b BK |
40 | const std::string str00; |
41 | const std::string str01(strlit01); | |
42 | std::string str02; | |
43 | std::filebuf fbuf; | |
44 | std::streambuf* pbasebuf0 = &fbuf; | |
45 | ||
23cac885 | 46 | std::ofstream sstrm1; |
d422980b BK |
47 | // derived rdbuf() always returns original streambuf, even though |
48 | // it's no longer associated with the stream. | |
49 | std::filebuf* const buf1 = sstrm1.rdbuf(); | |
50 | // base rdbuf() returns the currently associated streambuf | |
51 | std::streambuf* pbasebuf1 = active_buffer(sstrm1); | |
52 | redirect_buffer(sstrm1, &fbuf); | |
53 | std::filebuf* const buf2 = sstrm1.rdbuf(); | |
54 | std::streambuf* pbasebuf2 = active_buffer(sstrm1); | |
55 | VERIFY( buf1 == buf2 ); | |
56 | VERIFY( pbasebuf1 != pbasebuf2 ); | |
57 | VERIFY( pbasebuf2 == pbasebuf0 ); | |
58 | ||
59 | // How confusing and non-intuitive is this? | |
60 | // These semantics are a joke, a serious defect, and incredibly lame. | |
61 | } | |
62 | ||
63 | int main() | |
64 | { | |
23cac885 | 65 | test03(); |
d422980b BK |
66 | return 0; |
67 | } | |
68 | ||
69 | ||
70 |