blob: 0c2e8f0860cef7ccb6b96a066853e1412392fb4c [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000010// <ios>
11
12// template <class charT, class traits> class basic_ios
13
14// void clear(iostate state = goodbit);
15
16#include <ios>
17#include <streambuf>
18#include <cassert>
19
20struct testbuf : public std::streambuf {};
21
22int main()
23{
24 {
25 std::ios ios(0);
26 ios.clear();
27 assert(ios.rdstate() == std::ios::badbit);
28 try
29 {
30 ios.exceptions(std::ios::badbit);
31 }
32 catch (...)
33 {
34 }
35 try
36 {
37 ios.clear();
38 assert(false);
39 }
40 catch (std::ios::failure&)
41 {
42 assert(ios.rdstate() == std::ios::badbit);
43 }
44 try
45 {
46 ios.clear(std::ios::eofbit);
47 assert(false);
48 }
49 catch (std::ios::failure&)
50 {
51 assert(ios.rdstate() == (std::ios::eofbit | std::ios::badbit));
52 }
53 }
54 {
55 testbuf sb;
56 std::ios ios(&sb);
57 ios.clear();
58 assert(ios.rdstate() == std::ios::goodbit);
59 ios.exceptions(std::ios::badbit);
60 ios.clear();
61 assert(ios.rdstate() == std::ios::goodbit);
62 ios.clear(std::ios::eofbit);
63 assert(ios.rdstate() == std::ios::eofbit);
64 }
65}