]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/system/test/std_interop_test12.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / system / test / std_interop_test12.cpp
1 // Copyright 2021, 2022 Peter Dimov.
2 // Distributed under the Boost Software License, Version 1.0.
3 // http://www.boost.org/LICENSE_1_0.txt
4
5 #include <boost/system/error_code.hpp>
6 #include <boost/system/error_category.hpp>
7 #include <boost/system/errc.hpp>
8 #include <boost/core/lightweight_test.hpp>
9 #include <boost/config/pragma_message.hpp>
10 #include <boost/config.hpp>
11 #include <cerrno>
12
13 #if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
14
15 BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
16 int main() {}
17
18 #else
19
20 #include <system_error>
21
22 enum my_errc
23 {
24 my_enoent = ENOENT
25 };
26
27 class my_category: public boost::system::error_category
28 {
29 public:
30
31 char const* name() const BOOST_NOEXCEPT
32 {
33 return "mycat";
34 }
35
36 boost::system::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT
37 {
38 switch( ev )
39 {
40 case my_enoent:
41
42 return boost::system::error_condition( ENOENT, boost::system::generic_category() );
43
44 default:
45
46 return boost::system::error_condition( ev, *this );
47 }
48 }
49
50 std::string message( int ev ) const
51 {
52 switch( ev )
53 {
54 case my_enoent:
55
56 return "No such entity";
57
58 default:
59
60 return "Unknown error";
61 }
62 }
63 };
64
65 #if defined(BOOST_GCC) && BOOST_GCC < 70000
66
67 // g++ 6 and earlier do not allow specializations outside the namespace
68
69 namespace boost
70 {
71 namespace system
72 {
73
74 template<> struct is_error_code_enum<my_errc>: std::true_type {};
75
76 } // namespace system
77 } // namespace boost
78
79 namespace std
80 {
81
82 template<> struct is_error_code_enum<my_errc>: std::true_type {};
83
84 } // namespace std
85
86 #else
87
88 template<> struct boost::system::is_error_code_enum<my_errc>: std::true_type {};
89 template<> struct std::is_error_code_enum<my_errc>: std::true_type {};
90
91 #endif
92
93 boost::system::error_code make_error_code( my_errc e )
94 {
95 // If `cat` is declared constexpr or const, msvc-14.1 and
96 // msvc-14.2 before 19.29 put it in read-only memory,
97 // despite the `ps_` member being mutable. So it crashes.
98
99 static /*BOOST_SYSTEM_CONSTEXPR*/ my_category cat;
100 return boost::system::error_code( e, cat );
101 }
102
103 int main()
104 {
105 {
106 boost::system::error_code e1 = my_enoent;
107
108 BOOST_TEST( e1 == my_enoent );
109 BOOST_TEST_NOT( e1 != my_enoent );
110
111 BOOST_TEST( e1 == boost::system::errc::no_such_file_or_directory );
112 BOOST_TEST( e1 == std::errc::no_such_file_or_directory );
113 }
114
115 {
116 std::error_code e1 = my_enoent;
117
118 BOOST_TEST( e1 == my_enoent );
119 BOOST_TEST_NOT( e1 != my_enoent );
120
121 BOOST_TEST( e1 == std::errc::no_such_file_or_directory );
122 }
123
124 return boost::report_errors();
125 }
126
127 #endif