mirror of
https://github.com/boostorg/system.git
synced 2025-07-29 20:17:13 +02:00
Merge pull request #23 from boostorg/feature/constexpr
Make error_code and error_condition constexpr, as proposed in https://cplusplus.github.io/LWG/issue2992
This commit is contained in:
@ -202,6 +202,7 @@ matrix:
|
||||
apt:
|
||||
packages:
|
||||
- clang-4.0
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-4.0
|
||||
@ -213,6 +214,7 @@ matrix:
|
||||
apt:
|
||||
packages:
|
||||
- clang-5.0
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-5.0
|
||||
@ -224,6 +226,7 @@ matrix:
|
||||
apt:
|
||||
packages:
|
||||
- clang-5.0
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-5.0
|
||||
|
@ -35,45 +35,22 @@
|
||||
//--------------------------------------------------------------------------------------//
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace system
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// standard error categories -------------------------------------------------------//
|
||||
|
||||
class generic_error_category : public error_category
|
||||
{
|
||||
public:
|
||||
generic_error_category(){}
|
||||
const char * name() const BOOST_SYSTEM_NOEXCEPT;
|
||||
std::string message( int ev ) const;
|
||||
};
|
||||
|
||||
class system_error_category : public error_category
|
||||
{
|
||||
public:
|
||||
system_error_category(){}
|
||||
const char * name() const BOOST_SYSTEM_NOEXCEPT;
|
||||
std::string message( int ev ) const;
|
||||
error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT;
|
||||
};
|
||||
|
||||
#ifdef BOOST_ERROR_CODE_HEADER_ONLY
|
||||
# define BOOST_SYSTEM_INLINE inline
|
||||
# define BOOST_SYSTEM_DECL_ inline
|
||||
#else
|
||||
# define BOOST_SYSTEM_INLINE
|
||||
# define BOOST_SYSTEM_DECL_ BOOST_SYSTEM_DECL
|
||||
#endif
|
||||
|
||||
// generic_error_category implementation ---------------------------------//
|
||||
|
||||
BOOST_SYSTEM_INLINE const char * generic_error_category::name() const BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return "generic";
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_INLINE std::string generic_error_category::message( int ev ) const
|
||||
BOOST_SYSTEM_DECL_ std::string generic_error_category::message( int ev ) const
|
||||
{
|
||||
using namespace boost::system::errc;
|
||||
#if defined(__PGI)
|
||||
@ -166,12 +143,7 @@ namespace detail
|
||||
}
|
||||
// system_error_category implementation --------------------------------------------//
|
||||
|
||||
BOOST_SYSTEM_INLINE const char * system_error_category::name() const BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return "system";
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_INLINE error_condition system_error_category::default_error_condition( int ev ) const
|
||||
BOOST_SYSTEM_DECL_ error_condition system_error_category::default_error_condition( int ev ) const
|
||||
BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
using namespace boost::system::errc;
|
||||
@ -376,13 +348,13 @@ namespace detail
|
||||
|
||||
# if !defined( BOOST_WINDOWS_API )
|
||||
|
||||
BOOST_SYSTEM_INLINE std::string system_error_category::message( int ev ) const
|
||||
BOOST_SYSTEM_DECL_ std::string system_error_category::message( int ev ) const
|
||||
{
|
||||
return generic_category().message( ev );
|
||||
}
|
||||
# else
|
||||
|
||||
BOOST_SYSTEM_INLINE std::string system_error_category::message( int ev ) const
|
||||
BOOST_SYSTEM_DECL_ std::string system_error_category::message( int ev ) const
|
||||
{
|
||||
#if defined(UNDER_CE) || BOOST_PLAT_WINDOWS_RUNTIME || defined(BOOST_NO_ANSI_APIS)
|
||||
std::wstring buf(128, wchar_t());
|
||||
@ -461,7 +433,7 @@ namespace detail
|
||||
}
|
||||
# endif
|
||||
|
||||
#undef BOOST_SYSTEM_INLINE
|
||||
#undef BOOST_SYSTEM_DECL_
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@ -474,23 +446,51 @@ namespace detail
|
||||
// address for comparison purposes
|
||||
# endif
|
||||
|
||||
# ifdef BOOST_ERROR_CODE_HEADER_ONLY
|
||||
# define BOOST_SYSTEM_LINKAGE inline
|
||||
# else
|
||||
# define BOOST_SYSTEM_LINKAGE BOOST_SYSTEM_DECL
|
||||
# endif
|
||||
#if defined(BOOST_ERROR_CODE_HEADER_ONLY)
|
||||
|
||||
BOOST_SYSTEM_LINKAGE const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
static const detail::system_error_category system_category_const;
|
||||
return system_category_const;
|
||||
}
|
||||
// defined in error_code.hpp
|
||||
|
||||
BOOST_SYSTEM_LINKAGE const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
static const detail::generic_error_category generic_category_const;
|
||||
return generic_category_const;
|
||||
}
|
||||
#elif defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
BOOST_SYSTEM_REQUIRE_CONST_INIT BOOST_SYSTEM_DECL system_error_category system_category_instance;
|
||||
BOOST_SYSTEM_REQUIRE_CONST_INIT BOOST_SYSTEM_DECL generic_error_category generic_category_instance;
|
||||
|
||||
BOOST_SYSTEM_DECL const error_category & system_category_ncx() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return system_category_instance;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_DECL const error_category & generic_category_ncx() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return generic_category_instance;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#else
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
BOOST_SYSTEM_DECL const error_category & system_category_ncx() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
static const detail::system_error_category system_category_instance;
|
||||
return system_category_instance;
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_DECL const error_category & generic_category_ncx() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
static const detail::generic_error_category generic_category_instance;
|
||||
return generic_category_instance;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace system
|
||||
|
||||
} // namespace system
|
||||
} // namespace boost
|
||||
|
@ -39,6 +39,21 @@
|
||||
#define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX14_CONSTEXPR)
|
||||
# define BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 7 || __GNUC__ == 8) && __cplusplus >= 201700L
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83835
|
||||
# undef BOOST_SYSTEM_HAS_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
# define BOOST_SYSTEM_CONSTEXPR constexpr
|
||||
#else
|
||||
# define BOOST_SYSTEM_CONSTEXPR
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace system
|
||||
@ -186,31 +201,6 @@ namespace boost
|
||||
|
||||
// --------------------------------------------------------------------------------//
|
||||
|
||||
class error_category;
|
||||
|
||||
// predefined error categories ---------------------------------------------------//
|
||||
|
||||
#ifdef BOOST_ERROR_CODE_HEADER_ONLY
|
||||
inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT;
|
||||
inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT;
|
||||
#else
|
||||
BOOST_SYSTEM_DECL const error_category & system_category() BOOST_SYSTEM_NOEXCEPT;
|
||||
BOOST_SYSTEM_DECL const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT;
|
||||
#endif
|
||||
// deprecated synonyms ------------------------------------------------------------//
|
||||
|
||||
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
|
||||
inline const error_category & get_system_category() { return system_category(); }
|
||||
inline const error_category & get_generic_category() { return generic_category(); }
|
||||
inline const error_category & get_posix_category() { return generic_category(); }
|
||||
static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED
|
||||
= generic_category();
|
||||
static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED
|
||||
= generic_category();
|
||||
static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED
|
||||
= system_category();
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
// 'this' : used in base member initializer list
|
||||
@ -233,7 +223,7 @@ namespace boost
|
||||
|
||||
public:
|
||||
|
||||
explicit std_category( boost::system::error_category const * pc ): pc_( pc )
|
||||
BOOST_SYSTEM_CONSTEXPR explicit std_category( boost::system::error_category const * pc ): pc_( pc )
|
||||
{
|
||||
}
|
||||
|
||||
@ -259,7 +249,7 @@ namespace boost
|
||||
|
||||
public:
|
||||
|
||||
error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {}
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {}
|
||||
|
||||
operator std::error_category const & () const BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
@ -284,7 +274,7 @@ namespace boost
|
||||
|
||||
public:
|
||||
|
||||
explicit std_category( boost::system::error_category const * pc ): pc_( pc )
|
||||
BOOST_SYSTEM_CONSTEXPR explicit std_category( boost::system::error_category const * pc ): pc_( pc )
|
||||
{
|
||||
}
|
||||
|
||||
@ -310,7 +300,7 @@ namespace boost
|
||||
|
||||
public:
|
||||
|
||||
error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {}
|
||||
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_SYSTEM_NOEXCEPT: std_cat_( this ) {}
|
||||
|
||||
#endif
|
||||
|
||||
@ -326,19 +316,183 @@ namespace boost
|
||||
BOOST_SYSTEM_NOEXCEPT;
|
||||
inline virtual bool equivalent( const error_code & code,
|
||||
int condition ) const BOOST_SYSTEM_NOEXCEPT;
|
||||
|
||||
bool operator==(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT
|
||||
{ return this == &rhs; }
|
||||
bool operator!=(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT
|
||||
{ return this != &rhs; }
|
||||
bool operator<( const error_category & rhs ) const BOOST_SYSTEM_NOEXCEPT
|
||||
{ return std::less<const error_category*>()( this, &rhs ); }
|
||||
};
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator==( const error_category & lhs,
|
||||
const error_category & rhs ) BOOST_SYSTEM_NOEXCEPT
|
||||
{ return &lhs == &rhs; }
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_category & lhs,
|
||||
const error_category & rhs ) BOOST_SYSTEM_NOEXCEPT
|
||||
{ return &lhs != &rhs; }
|
||||
|
||||
inline bool operator<( const error_category & lhs,
|
||||
const error_category & rhs ) BOOST_SYSTEM_NOEXCEPT
|
||||
{ return std::less<const error_category*>()( &lhs, &rhs ); }
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
// predefined error categories ---------------------------------------------------//
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#ifdef BOOST_ERROR_CODE_HEADER_ONLY
|
||||
# define BOOST_SYSTEM_DECL_
|
||||
#else
|
||||
# define BOOST_SYSTEM_DECL_ BOOST_SYSTEM_DECL
|
||||
#endif
|
||||
|
||||
class generic_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
// clang++ 3.8 and below: initialization of const object
|
||||
// requires a user-provided default constructor
|
||||
BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
const char * name() const BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return "generic";
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_DECL_ std::string message( int ev ) const;
|
||||
};
|
||||
|
||||
class system_error_category: public error_category
|
||||
{
|
||||
public:
|
||||
|
||||
BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
const char * name() const BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return "system";
|
||||
}
|
||||
|
||||
BOOST_SYSTEM_DECL_ std::string message( int ev ) const;
|
||||
BOOST_SYSTEM_DECL_ error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT;
|
||||
};
|
||||
|
||||
#undef BOOST_SYSTEM_DECL_
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#define BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
|
||||
#if defined(__has_cpp_attribute)
|
||||
#if __has_cpp_attribute(clang::require_constant_initialization)
|
||||
# undef BOOST_SYSTEM_REQUIRE_CONST_INIT
|
||||
# define BOOST_SYSTEM_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_ERROR_CODE_HEADER_ONLY)
|
||||
|
||||
# if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T> struct cat_holder
|
||||
{
|
||||
static system_error_category system_category_instance;
|
||||
static generic_error_category generic_category_instance;
|
||||
};
|
||||
|
||||
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT system_error_category cat_holder<T>::system_category_instance;
|
||||
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT generic_error_category cat_holder<T>::generic_category_instance;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
constexpr const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return detail::cat_holder<void>::system_category_instance;
|
||||
}
|
||||
|
||||
constexpr const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return detail::cat_holder<void>::generic_category_instance;
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
static const detail::system_error_category system_category_instance;
|
||||
return system_category_instance;
|
||||
}
|
||||
|
||||
inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
static const detail::generic_error_category generic_category_instance;
|
||||
return generic_category_instance;
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
#elif defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
extern system_error_category system_category_instance;
|
||||
extern generic_error_category generic_category_instance;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
constexpr const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return detail::system_category_instance;
|
||||
}
|
||||
|
||||
constexpr const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return detail::generic_category_instance;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
BOOST_SYSTEM_DECL const error_category & system_category_ncx() BOOST_SYSTEM_NOEXCEPT;
|
||||
BOOST_SYSTEM_DECL const error_category & generic_category_ncx() BOOST_SYSTEM_NOEXCEPT;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return detail::system_category_ncx();
|
||||
}
|
||||
|
||||
inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return detail::generic_category_ncx();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// deprecated synonyms ------------------------------------------------------------//
|
||||
|
||||
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
|
||||
inline const error_category & get_system_category() { return system_category(); }
|
||||
inline const error_category & get_generic_category() { return generic_category(); }
|
||||
inline const error_category & get_posix_category() { return generic_category(); }
|
||||
static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED
|
||||
= generic_category();
|
||||
static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED
|
||||
= generic_category();
|
||||
static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED
|
||||
= system_category();
|
||||
#endif
|
||||
|
||||
// class error_condition ---------------------------------------------------------//
|
||||
|
||||
// error_conditions are portable, error_codes are system or library specific
|
||||
@ -348,8 +502,8 @@ namespace boost
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
error_condition() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&generic_category()) {}
|
||||
error_condition( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&generic_category()) {}
|
||||
BOOST_SYSTEM_CONSTEXPR error_condition( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
|
||||
: m_val(val), m_cat(&cat) {}
|
||||
|
||||
template <class ErrorConditionEnum>
|
||||
@ -362,7 +516,7 @@ namespace boost
|
||||
|
||||
// modifiers:
|
||||
|
||||
void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
m_val = val;
|
||||
m_cat = &cat;
|
||||
@ -377,20 +531,20 @@ namespace boost
|
||||
return *this;
|
||||
}
|
||||
|
||||
void clear() BOOST_SYSTEM_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
m_val = 0;
|
||||
m_cat = &generic_category();
|
||||
}
|
||||
|
||||
// observers:
|
||||
int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; }
|
||||
const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; }
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
|
||||
std::string message() const { return m_cat->message(value()); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
|
||||
explicit operator bool() const BOOST_SYSTEM_NOEXCEPT // true if error
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_SYSTEM_NOEXCEPT // true if error
|
||||
{
|
||||
return m_val != 0;
|
||||
}
|
||||
@ -400,12 +554,12 @@ namespace boost
|
||||
typedef void (*unspecified_bool_type)();
|
||||
static void unspecified_bool_true() {}
|
||||
|
||||
operator unspecified_bool_type() const BOOST_SYSTEM_NOEXCEPT // true if error
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_SYSTEM_NOEXCEPT // true if error
|
||||
{
|
||||
return m_val == 0 ? 0 : unspecified_bool_true;
|
||||
}
|
||||
|
||||
bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error
|
||||
{
|
||||
return m_val == 0;
|
||||
}
|
||||
@ -415,7 +569,7 @@ namespace boost
|
||||
// relationals:
|
||||
// the more symmetrical non-member syntax allows enum
|
||||
// conversions work for both rhs and lhs.
|
||||
inline friend bool operator==( const error_condition & lhs,
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs,
|
||||
const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
|
||||
@ -458,8 +612,8 @@ namespace boost
|
||||
public:
|
||||
|
||||
// constructors:
|
||||
error_code() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&system_category()) {}
|
||||
error_code( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR error_code() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&system_category()) {}
|
||||
BOOST_SYSTEM_CONSTEXPR error_code( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
|
||||
: m_val(val), m_cat(&cat) {}
|
||||
|
||||
template <class ErrorCodeEnum>
|
||||
@ -471,7 +625,7 @@ namespace boost
|
||||
}
|
||||
|
||||
// modifiers:
|
||||
void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
m_val = val;
|
||||
m_cat = &cat;
|
||||
@ -485,22 +639,22 @@ namespace boost
|
||||
return *this;
|
||||
}
|
||||
|
||||
void clear() BOOST_SYSTEM_NOEXCEPT
|
||||
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
m_val = 0;
|
||||
m_cat = &system_category();
|
||||
}
|
||||
|
||||
// observers:
|
||||
int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; }
|
||||
const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
|
||||
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; }
|
||||
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
|
||||
error_condition default_error_condition() const BOOST_SYSTEM_NOEXCEPT
|
||||
{ return m_cat->default_error_condition(value()); }
|
||||
std::string message() const { return m_cat->message(value()); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
|
||||
explicit operator bool() const BOOST_SYSTEM_NOEXCEPT // true if error
|
||||
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_SYSTEM_NOEXCEPT // true if error
|
||||
{
|
||||
return m_val != 0;
|
||||
}
|
||||
@ -510,12 +664,12 @@ namespace boost
|
||||
typedef void (*unspecified_bool_type)();
|
||||
static void unspecified_bool_true() {}
|
||||
|
||||
operator unspecified_bool_type() const BOOST_SYSTEM_NOEXCEPT // true if error
|
||||
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_SYSTEM_NOEXCEPT // true if error
|
||||
{
|
||||
return m_val == 0 ? 0 : unspecified_bool_true;
|
||||
}
|
||||
|
||||
bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error
|
||||
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error
|
||||
{
|
||||
return m_val == 0;
|
||||
}
|
||||
@ -523,7 +677,7 @@ namespace boost
|
||||
#endif
|
||||
|
||||
// relationals:
|
||||
inline friend bool operator==( const error_code & lhs,
|
||||
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs,
|
||||
const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT
|
||||
// the more symmetrical non-member syntax allows enum
|
||||
// conversions work for both rhs and lhs.
|
||||
@ -596,13 +750,13 @@ namespace boost
|
||||
{
|
||||
// non-member functions ------------------------------------------------//
|
||||
|
||||
inline bool operator!=( const error_code & lhs,
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_code & lhs,
|
||||
const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=( const error_condition & lhs,
|
||||
BOOST_SYSTEM_CONSTEXPR inline bool operator!=( const error_condition & lhs,
|
||||
const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
|
@ -126,6 +126,7 @@ else
|
||||
[ run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <link>shared : single_instance_lib_shared ]
|
||||
[ system-run before_main_test.cpp ]
|
||||
[ run-fail throws_assign_fail.cpp ]
|
||||
[ system-run- constexpr_test.cpp ]
|
||||
;
|
||||
|
||||
# Quick (CI) test
|
||||
|
68
test/constexpr_test.cpp
Normal file
68
test/constexpr_test.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
|
||||
// Copyright 2018 Peter Dimov.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
#if !defined(BOOST_SYSTEM_HAS_CONSTEXPR)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping constexpr test, BOOST_SYSTEM_HAS_CONSTEXPR isn't defined")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
using namespace boost::system;
|
||||
|
||||
constexpr error_code e1( 1, system_category() );
|
||||
|
||||
BOOST_STATIC_ASSERT( e1.value() == 1 );
|
||||
BOOST_STATIC_ASSERT( e1.category() == system_category() );
|
||||
BOOST_STATIC_ASSERT( e1 );
|
||||
BOOST_STATIC_ASSERT( e1 == e1 );
|
||||
|
||||
constexpr error_code e2( 2, generic_category() );
|
||||
|
||||
BOOST_STATIC_ASSERT( e2.value() == 2 );
|
||||
BOOST_STATIC_ASSERT( e2.category() == generic_category() );
|
||||
BOOST_STATIC_ASSERT( e2 );
|
||||
BOOST_STATIC_ASSERT( e2 == e2 );
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 80000)
|
||||
|
||||
BOOST_STATIC_ASSERT( e1 != e2 );
|
||||
|
||||
#endif
|
||||
|
||||
constexpr error_code e3;
|
||||
|
||||
BOOST_STATIC_ASSERT( e3.value() == 0 );
|
||||
BOOST_STATIC_ASSERT( e3.category() == system_category() );
|
||||
BOOST_STATIC_ASSERT( !e3 );
|
||||
BOOST_STATIC_ASSERT( e3 == e3 );
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 80000)
|
||||
|
||||
BOOST_STATIC_ASSERT( e1 != e3 );
|
||||
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
error_code e1_( 1, system_category() );
|
||||
BOOST_TEST_EQ( e1, e1_ );
|
||||
|
||||
error_code e2_( 2, generic_category() );
|
||||
BOOST_TEST_EQ( e2, e2_ );
|
||||
|
||||
error_code e3_;
|
||||
BOOST_TEST_EQ( e3, e3_ );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
@ -38,7 +38,6 @@ static void test_generic_category()
|
||||
std::error_category const & st = bt;
|
||||
|
||||
BOOST_TEST_CSTR_EQ( bt.name(), st.name() );
|
||||
BOOST_TEST_EQ( bt.name(), st.name() );
|
||||
}
|
||||
|
||||
static void test_system_category()
|
||||
@ -47,7 +46,6 @@ static void test_system_category()
|
||||
std::error_category const & st = bt;
|
||||
|
||||
BOOST_TEST_CSTR_EQ( bt.name(), st.name() );
|
||||
BOOST_TEST_EQ( bt.name(), st.name() );
|
||||
}
|
||||
|
||||
int main()
|
||||
|
Reference in New Issue
Block a user