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 // XFAIL: libcpp-no-exceptions 11 // <ios> 12 13 // template <class charT, class traits> class basic_ios 14 15 // void setstate(iostate state); 16 17 #include <ios> 18 #include <streambuf> 19 #include <cassert> 20 21 struct testbuf : public std::streambuf {}; 22 23 int main() 24 { 25 { 26 std::ios ios(0); 27 ios.setstate(std::ios::goodbit); 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.setstate(std::ios::goodbit); 39 assert(false); 40 } 41 catch (std::ios::failure&) 42 { 43 assert(ios.rdstate() == std::ios::badbit); 44 } 45 try 46 { 47 ios.setstate(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.setstate(std::ios::goodbit); 59 assert(ios.rdstate() == std::ios::goodbit); 60 ios.setstate(std::ios::eofbit); 61 assert(ios.rdstate() == std::ios::eofbit); 62 ios.setstate(std::ios::failbit); 63 assert(ios.rdstate() == (std::ios::eofbit | std::ios::failbit)); 64 } 65 } 66