• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <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 
20 #include "test_macros.h"
21 
22 struct testbuf : public std::streambuf {};
23 
main()24 int main()
25 {
26     {
27         std::ios ios(0);
28         ios.clear();
29         assert(ios.rdstate() == std::ios::badbit);
30 #ifndef TEST_HAS_NO_EXCEPTIONS
31         try
32         {
33             ios.exceptions(std::ios::badbit);
34             assert(false);
35         }
36         catch (...)
37         {
38         }
39         try
40         {
41             ios.clear();
42             assert(false);
43         }
44         catch (std::ios::failure&)
45         {
46             assert(ios.rdstate() == std::ios::badbit);
47         }
48         try
49         {
50             ios.clear(std::ios::eofbit);
51             assert(false);
52         }
53         catch (std::ios::failure&)
54         {
55             assert(ios.rdstate() == (std::ios::eofbit | std::ios::badbit));
56         }
57 #endif
58     }
59     {
60         testbuf sb;
61         std::ios ios(&sb);
62         ios.clear();
63         assert(ios.rdstate() == std::ios::goodbit);
64         ios.exceptions(std::ios::badbit);
65         ios.clear();
66         assert(ios.rdstate() == std::ios::goodbit);
67         ios.clear(std::ios::eofbit);
68         assert(ios.rdstate() == std::ios::eofbit);
69     }
70 }
71