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
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>
13 #if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
15 BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
20 #include <system_error>
27 class my_category
: public boost::system::error_category
31 char const* name() const BOOST_NOEXCEPT
36 boost::system::error_condition
default_error_condition( int ev
) const BOOST_NOEXCEPT
42 return boost::system::error_condition( ENOENT
, boost::system::generic_category() );
46 return boost::system::error_condition( ev
, *this );
50 std::string
message( int ev
) const
56 return "No such entity";
60 return "Unknown error";
65 #if defined(BOOST_GCC) && BOOST_GCC < 70000
67 // g++ 6 and earlier do not allow specializations outside the namespace
74 template<> struct is_error_code_enum
<my_errc
>: std::true_type
{};
82 template<> struct is_error_code_enum
<my_errc
>: std::true_type
{};
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
{};
93 boost::system::error_code
make_error_code( my_errc e
)
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.
99 static /*BOOST_SYSTEM_CONSTEXPR*/ my_category cat
;
100 return boost::system::error_code( e
, cat
);
106 boost::system::error_code e1
= my_enoent
;
108 BOOST_TEST( e1
== my_enoent
);
109 BOOST_TEST_NOT( e1
!= my_enoent
);
111 BOOST_TEST( e1
== boost::system::errc::no_such_file_or_directory
);
112 BOOST_TEST( e1
== std::errc::no_such_file_or_directory
);
116 std::error_code e1
= my_enoent
;
118 BOOST_TEST( e1
== my_enoent
);
119 BOOST_TEST_NOT( e1
!= my_enoent
);
121 BOOST_TEST( e1
== std::errc::no_such_file_or_directory
);
124 return boost::report_errors();