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 char* 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 **)22 int main(int, char**)
23 {
24     {
25         std::string what_arg("io test message");
26         std::ios_base::failure se(what_arg.c_str(), make_error_code(std::errc::is_a_directory));
27         assert(se.code() == std::make_error_code(std::errc::is_a_directory));
28         std::string what_message(se.what());
29         assert(what_message.find(what_arg) != std::string::npos);
30         assert(what_message.find(std::generic_category().message(static_cast<int>
31             (std::errc::is_a_directory))) != std::string::npos);
32     }
33     {
34         std::string what_arg("io test message");
35         std::ios_base::failure se(what_arg.c_str());
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   return 0;
44 }
45