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 // class ios_base::failure 13 14 // explicit failure(const string& msg, const error_code& ec = io_errc::stream); 15 16 #include <ios> 17 #include <string> 18 #include <cassert> 19 20 int main() 21 { 22 // LWG2462 std::ios_base::failure is overspecified 23 static_assert((std::is_base_of<std::system_error, std::ios_base::failure>::value), ""); 24 25 { 26 std::string what_arg("io test message"); 27 std::ios_base::failure se(what_arg, make_error_code(std::errc::is_a_directory)); 28 assert(se.code() == std::make_error_code(std::errc::is_a_directory)); 29 std::string what_message(se.what()); 30 assert(what_message.find(what_arg) != std::string::npos); 31 assert(what_message.find("Is a directory") != std::string::npos); 32 } 33 { 34 std::string what_arg("io test message"); 35 std::ios_base::failure se(what_arg); 36 assert(se.code() == std::make_error_code(std::io_errc::stream)); 37 std::string what_message(se.what()); 38 assert(what_message.find(what_arg) != std::string::npos); 39 assert(what_message.find(std::iostream_category().message(static_cast<int> 40 (std::io_errc::stream))) != std::string::npos); 41 } 42 } 43