| 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 | // <system_error> |
| 10 | |
| 11 | // class system_error |
| 12 | |
| 13 | // system_error(error_code ec, const string& what_arg); |
| 14 | |
| 15 | // Test is slightly non-portable |
| 16 | |
| 17 | #include <system_error> |
| 18 | #include <string> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | int main(int, char**) { |
| 24 | { |
| 25 | std::string what_arg("test message"); |
| 26 | std::system_error se(make_error_code(e: std::errc::not_a_directory), what_arg); |
| 27 | assert(se.code() == std::make_error_code(std::errc::not_a_directory)); |
| 28 | std::string what_message(se.what()); |
| 29 | assert(what_message.find(what_arg) != std::string::npos); |
| 30 | assert(what_message.find(what_arg.c_str()) != std::string::npos); |
| 31 | assert(what_message.find("Not a directory") != std::string::npos); |
| 32 | } |
| 33 | |
| 34 | { |
| 35 | std::string what_arg("test LWG3112 with and With embedded \0 character"); |
| 36 | std::system_error se(make_error_code(e: std::errc::not_a_directory), what_arg); |
| 37 | assert(se.code() == std::make_error_code(std::errc::not_a_directory)); |
| 38 | std::string what_message(se.what()); |
| 39 | assert(what_message.find(what_arg) != std::string::npos); |
| 40 | assert(what_message.find(what_arg.c_str()) != std::string::npos); |
| 41 | assert(what_message.find("Not a directory") != std::string::npos); |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 |
