blob: c4aad797801da78a34a4a085442eb457a14bd04b [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
Asiri Rathnayakecc2e93c2015-11-10 11:41:22 +000010// XFAIL: libcpp-no-exceptions
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000011// <ios>
12
13// template <class charT, class traits> class basic_ios
14
15// void clear(iostate state = goodbit);
16
17#include <ios>
18#include <streambuf>
19#include <cassert>
20
21struct testbuf : public std::streambuf {};
22
23int main()
24{
25 {
26 std::ios ios(0);
27 ios.clear();
28 assert(ios.rdstate() == std::ios::badbit);
29 try
30 {
31 ios.exceptions(std::ios::badbit);
32 }
33 catch (...)
34 {
35 }
36 try
37 {
38 ios.clear();
39 assert(false);
40 }
41 catch (std::ios::failure&)
42 {
43 assert(ios.rdstate() == std::ios::badbit);
44 }
45 try
46 {
47 ios.clear(std::ios::eofbit);
48 assert(false);
49 }
50 catch (std::ios::failure&)
51 {
52 assert(ios.rdstate() == (std::ios::eofbit | std::ios::badbit));
53 }
54 }
55 {
56 testbuf sb;
57 std::ios ios(&sb);
58 ios.clear();
59 assert(ios.rdstate() == std::ios::goodbit);
60 ios.exceptions(std::ios::badbit);
61 ios.clear();
62 assert(ios.rdstate() == std::ios::goodbit);
63 ios.clear(std::ios::eofbit);
64 assert(ios.rdstate() == std::ios::eofbit);
65 }
66}