1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <ios> 10 11 // class ios_base::failure 12 13 // explicit failure(const string& msg, const error_code& ec = io_errc::stream); 14 15 #include <ios> 16 #include <string> 17 #include <system_error> 18 #include <cassert> 19 20 #include "test_macros.h" 21 main(int,char **)22int main(int, char**) 23 { 24 // LWG2462 std::ios_base::failure is overspecified 25 static_assert((std::is_base_of<std::system_error, std::ios_base::failure>::value), ""); 26 27 { 28 std::string what_arg("io test message"); 29 std::ios_base::failure se(what_arg, make_error_code(std::errc::is_a_directory)); 30 assert(se.code() == std::make_error_code(std::errc::is_a_directory)); 31 std::string what_message(se.what()); 32 assert(what_message.find(what_arg) != std::string::npos); 33 assert(what_message.find(std::generic_category().message(static_cast<int> 34 (std::errc::is_a_directory))) != std::string::npos); 35 } 36 { 37 std::string what_arg("io test message"); 38 std::ios_base::failure se(what_arg); 39 assert(se.code() == std::make_error_code(std::io_errc::stream)); 40 std::string what_message(se.what()); 41 assert(what_message.find(what_arg) != std::string::npos); 42 assert(what_message.find(std::iostream_category().message(static_cast<int> 43 (std::io_errc::stream))) != std::string::npos); 44 } 45 46 return 0; 47 } 48