System/FileSystem/Asio/Thread: ref #7278 Added noexcept to Boost.System to conform with C++11

[SVN r81808]
This commit is contained in:
Vicente J. Botet Escriba
2012-12-09 14:47:39 +00:00
parent 8fbde538f3
commit 65e14ff167
4 changed files with 108 additions and 89 deletions

View File

@ -23,7 +23,7 @@
#include <functional> #include <functional>
// TODO: undef these macros if not already defined // TODO: undef these macros if not already defined
#include <boost/cerrno.hpp> #include <boost/cerrno.hpp>
#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API) #if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined # error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
@ -31,6 +31,10 @@
#include <boost/config/abi_prefix.hpp> // must be the last #include #include <boost/config/abi_prefix.hpp> // must be the last #include
#ifndef BOOST_SYSTEM_NOEXCEPT
#define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT
#endif
namespace boost namespace boost
{ {
namespace system namespace system
@ -184,17 +188,17 @@ namespace boost
public: public:
virtual ~error_category(){} virtual ~error_category(){}
virtual const char * name() const = 0; virtual const char * name() const BOOST_SYSTEM_NOEXCEPT = 0;
virtual std::string message( int ev ) const = 0; virtual std::string message( int ev ) const = 0;
virtual error_condition default_error_condition( int ev ) const; inline virtual error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT;
virtual bool equivalent( int code, inline virtual bool equivalent( int code,
const error_condition & condition ) const; const error_condition & condition ) const BOOST_SYSTEM_NOEXCEPT;
virtual bool equivalent( const error_code & code, inline virtual bool equivalent( const error_code & code,
int condition ) const; int condition ) const BOOST_SYSTEM_NOEXCEPT;
bool operator==(const error_category & rhs) const { return this == &rhs; } bool operator==(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT { return this == &rhs; }
bool operator!=(const error_category & rhs) const { return this != &rhs; } bool operator!=(const error_category & rhs) const BOOST_SYSTEM_NOEXCEPT { return this != &rhs; }
bool operator<( const error_category & rhs ) const bool operator<( const error_category & rhs ) const BOOST_SYSTEM_NOEXCEPT
{ {
return std::less<const error_category*>()( this, &rhs ); return std::less<const error_category*>()( this, &rhs );
} }
@ -202,9 +206,13 @@ namespace boost
// predefined error categories -----------------------------------------// // predefined error categories -----------------------------------------//
BOOST_SYSTEM_DECL const error_category & system_category(); # ifdef BOOST_ERROR_CODE_HEADER_ONLY
BOOST_SYSTEM_DECL const error_category & generic_category(); 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 --------------------------------------------------// // deprecated synonyms --------------------------------------------------//
# ifndef BOOST_SYSTEM_NO_DEPRECATED # ifndef BOOST_SYSTEM_NO_DEPRECATED
@ -225,52 +233,52 @@ namespace boost
public: public:
// constructors: // constructors:
error_condition() : m_val(0), m_cat(&generic_category()) {} error_condition() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&generic_category()) {}
error_condition( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} error_condition( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT : m_val(val), m_cat(&cat) {}
template <class ErrorConditionEnum> template <class ErrorConditionEnum>
error_condition(ErrorConditionEnum e, error_condition(ErrorConditionEnum e,
typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum> >::type* = 0) typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum> >::type* = 0) BOOST_SYSTEM_NOEXCEPT
{ {
*this = make_error_condition(e); *this = make_error_condition(e);
} }
// modifiers: // modifiers:
void assign( int val, const error_category & cat ) void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
{ {
m_val = val; m_val = val;
m_cat = &cat; m_cat = &cat;
} }
template<typename ErrorConditionEnum> template<typename ErrorConditionEnum>
typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum>, error_condition>::type & typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum>, error_condition>::type &
operator=( ErrorConditionEnum val ) operator=( ErrorConditionEnum val ) BOOST_SYSTEM_NOEXCEPT
{ {
*this = make_error_condition(val); *this = make_error_condition(val);
return *this; return *this;
} }
void clear() void clear() BOOST_SYSTEM_NOEXCEPT
{ {
m_val = 0; m_val = 0;
m_cat = &generic_category(); m_cat = &generic_category();
} }
// observers: // observers:
int value() const { return m_val; } int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; }
const error_category & category() const { return *m_cat; } const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
std::string message() const { return m_cat->message(value()); } std::string message() const { return m_cat->message(value()); }
typedef void (*unspecified_bool_type)(); typedef void (*unspecified_bool_type)();
static void unspecified_bool_true() {} static void unspecified_bool_true() {}
operator unspecified_bool_type() const // true if error operator unspecified_bool_type() const BOOST_SYSTEM_NOEXCEPT // true if error
{ {
return m_val == 0 ? 0 : unspecified_bool_true; return m_val == 0 ? 0 : unspecified_bool_true;
} }
bool operator!() const // true if no error bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error
{ {
return m_val == 0; return m_val == 0;
} }
@ -279,13 +287,13 @@ namespace boost
// the more symmetrical non-member syntax allows enum // the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs. // conversions work for both rhs and lhs.
inline friend bool operator==( const error_condition & lhs, inline friend bool operator==( const error_condition & lhs,
const error_condition & rhs ) const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT
{ {
return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val; return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
} }
inline friend bool operator<( const error_condition & lhs, inline friend bool operator<( const error_condition & lhs,
const error_condition & rhs ) const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT
// the more symmetrical non-member syntax allows enum // the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs. // conversions work for both rhs and lhs.
{ {
@ -312,59 +320,59 @@ namespace boost
public: public:
// constructors: // constructors:
error_code() : m_val(0), m_cat(&system_category()) {} error_code() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&system_category()) {}
error_code( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} error_code( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT : m_val(val), m_cat(&cat) {}
template <class ErrorCodeEnum> template <class ErrorCodeEnum>
error_code(ErrorCodeEnum e, error_code(ErrorCodeEnum e,
typename boost::enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0) typename boost::enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0) BOOST_SYSTEM_NOEXCEPT
{ {
*this = make_error_code(e); *this = make_error_code(e);
} }
// modifiers: // modifiers:
void assign( int val, const error_category & cat ) void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT
{ {
m_val = val; m_val = val;
m_cat = &cat; m_cat = &cat;
} }
template<typename ErrorCodeEnum> template<typename ErrorCodeEnum>
typename boost::enable_if<is_error_code_enum<ErrorCodeEnum>, error_code>::type & typename boost::enable_if<is_error_code_enum<ErrorCodeEnum>, error_code>::type &
operator=( ErrorCodeEnum val ) operator=( ErrorCodeEnum val ) BOOST_SYSTEM_NOEXCEPT
{ {
*this = make_error_code(val); *this = make_error_code(val);
return *this; return *this;
} }
void clear() void clear() BOOST_SYSTEM_NOEXCEPT
{ {
m_val = 0; m_val = 0;
m_cat = &system_category(); m_cat = &system_category();
} }
// observers: // observers:
int value() const { return m_val; } int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; }
const error_category & category() const { return *m_cat; } const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; }
error_condition default_error_condition() const { return m_cat->default_error_condition(value()); } 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()); } std::string message() const { return m_cat->message(value()); }
typedef void (*unspecified_bool_type)(); typedef void (*unspecified_bool_type)();
static void unspecified_bool_true() {} static void unspecified_bool_true() {}
operator unspecified_bool_type() const // true if error operator unspecified_bool_type() const BOOST_SYSTEM_NOEXCEPT // true if error
{ {
return m_val == 0 ? 0 : unspecified_bool_true; return m_val == 0 ? 0 : unspecified_bool_true;
} }
bool operator!() const // true if no error bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error
{ {
return m_val == 0; return m_val == 0;
} }
// relationals: // relationals:
inline friend bool operator==( const error_code & lhs, inline friend bool operator==( const error_code & lhs,
const error_code & rhs ) const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT
// the more symmetrical non-member syntax allows enum // the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs. // conversions work for both rhs and lhs.
{ {
@ -372,14 +380,14 @@ namespace boost
} }
inline friend bool operator<( const error_code & lhs, inline friend bool operator<( const error_code & lhs,
const error_code & rhs ) const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT
// the more symmetrical non-member syntax allows enum // the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs. // conversions work for both rhs and lhs.
{ {
return lhs.m_cat < rhs.m_cat return lhs.m_cat < rhs.m_cat
|| (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val); || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val);
} }
private: private:
int m_val; int m_val;
const error_category * m_cat; const error_category * m_cat;
@ -426,31 +434,31 @@ namespace boost
} }
inline bool operator==( const error_code & code, inline bool operator==( const error_code & code,
const error_condition & condition ) const error_condition & condition ) BOOST_SYSTEM_NOEXCEPT
{ {
return code.category().equivalent( code.value(), condition ) return code.category().equivalent( code.value(), condition )
|| condition.category().equivalent( code, condition.value() ); || condition.category().equivalent( code, condition.value() );
} }
inline bool operator!=( const error_code & lhs, inline bool operator!=( const error_code & lhs,
const error_condition & rhs ) const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
inline bool operator==( const error_condition & condition, inline bool operator==( const error_condition & condition,
const error_code & code ) const error_code & code ) BOOST_SYSTEM_NOEXCEPT
{ {
return condition.category().equivalent( code, condition.value() ) return condition.category().equivalent( code, condition.value() )
|| code.category().equivalent( code.value(), condition ); || code.category().equivalent( code.value(), condition );
} }
inline bool operator!=( const error_condition & lhs, inline bool operator!=( const error_condition & lhs,
const error_code & rhs ) const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
// TODO: both of these may move elsewhere, but the LWG hasn't spoken yet. // TODO: both of these may move elsewhere, but the LWG hasn't spoken yet.
template <class charT, class traits> template <class charT, class traits>
@ -482,19 +490,19 @@ namespace boost
// error_category default implementation -------------------------------// // error_category default implementation -------------------------------//
inline error_condition error_category::default_error_condition( int ev ) const error_condition error_category::default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT
{ {
return error_condition( ev, *this ); return error_condition( ev, *this );
} }
inline bool error_category::equivalent( int code, bool error_category::equivalent( int code,
const error_condition & condition ) const const error_condition & condition ) const BOOST_SYSTEM_NOEXCEPT
{ {
return default_error_condition( code ) == condition; return default_error_condition( code ) == condition;
} }
inline bool error_category::equivalent( const error_code & code, bool error_category::equivalent( const error_code & code,
int condition ) const int condition ) const BOOST_SYSTEM_NOEXCEPT
{ {
return *this == code.category() && code.value() == condition; return *this == code.category() && code.value() == condition;
} }

View File

@ -21,7 +21,7 @@ namespace boost
class BOOST_SYMBOL_VISIBLE system_error : public std::runtime_error class BOOST_SYMBOL_VISIBLE system_error : public std::runtime_error
// BOOST_SYMBOL_VISIBLE is needed by GCC to ensure system_error thrown from a shared // BOOST_SYMBOL_VISIBLE is needed by GCC to ensure system_error thrown from a shared
// library can be caught. See svn.boost.org/trac/boost/ticket/3697 // library can be caught. See svn.boost.org/trac/boost/ticket/3697
{ {
public: public:
system_error( error_code ec ) system_error( error_code ec )
@ -61,13 +61,17 @@ namespace boost
{ {
if ( m_what.empty() ) if ( m_what.empty() )
{ {
#ifndef BOOST_NO_EXCEPTIONS
try try
#endif
{ {
m_what = this->std::runtime_error::what(); m_what = this->std::runtime_error::what();
if ( !m_what.empty() ) m_what += ": "; if ( !m_what.empty() ) m_what += ": ";
m_what += m_error_code.message(); m_what += m_error_code.message();
} }
#ifndef BOOST_NO_EXCEPTIONS
catch (...) { return std::runtime_error::what(); } catch (...) { return std::runtime_error::what(); }
#endif
} }
return m_what.c_str(); return m_what.c_str();
} }

View File

@ -22,9 +22,6 @@
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
using namespace boost::system;
using namespace boost::system::errc;
#include <cstring> // for strerror/strerror_r #include <cstring> // for strerror/strerror_r
# if defined( BOOST_WINDOWS_API ) # if defined( BOOST_WINDOWS_API )
@ -36,19 +33,21 @@ using namespace boost::system::errc;
# endif # endif
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
namespace boost
{
namespace system
{
namespace namespace
{ {
#if defined(__PGI)
using boost::system::errc::invalid_argument;
#endif
// standard error categories ---------------------------------------------// // standard error categories ---------------------------------------------//
class generic_error_category : public error_category class generic_error_category : public error_category
{ {
public: public:
generic_error_category(){} generic_error_category(){}
const char * name() const; const char * name() const BOOST_SYSTEM_NOEXCEPT;
std::string message( int ev ) const; std::string message( int ev ) const;
}; };
@ -56,20 +55,25 @@ namespace
{ {
public: public:
system_error_category(){} system_error_category(){}
const char * name() const; const char * name() const BOOST_SYSTEM_NOEXCEPT;
std::string message( int ev ) const; std::string message( int ev ) const;
error_condition default_error_condition( int ev ) const; error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT;
}; };
// generic_error_category implementation ---------------------------------// // generic_error_category implementation ---------------------------------//
const char * generic_error_category::name() const const char * generic_error_category::name() const BOOST_SYSTEM_NOEXCEPT
{ {
return "generic"; return "generic";
} }
std::string generic_error_category::message( int ev ) const std::string generic_error_category::message( int ev ) const
{ {
using namespace boost::system::errc;
#if defined(__PGI)
using boost::system::errc::invalid_argument;
#endif
static std::string unknown_err( "Unknown error" ); static std::string unknown_err( "Unknown error" );
// strerror_r is preferred because it is always thread safe, // strerror_r is preferred because it is always thread safe,
// however, we fallback to strerror in certain cases because: // however, we fallback to strerror in certain cases because:
@ -133,7 +137,9 @@ namespace
} }
} }
std::string msg; std::string msg;
# ifndef BOOST_NO_EXCEPTIONS
try try
# endif
{ {
msg = ( ( result == invalid_argument ) ? "Unknown error" : bp ); msg = ( ( result == invalid_argument ) ? "Unknown error" : bp );
} }
@ -154,13 +160,18 @@ namespace
} }
// system_error_category implementation --------------------------------// // system_error_category implementation --------------------------------//
const char * system_error_category::name() const const char * system_error_category::name() const BOOST_SYSTEM_NOEXCEPT
{ {
return "system"; return "system";
} }
error_condition system_error_category::default_error_condition( int ev ) const error_condition system_error_category::default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT
{ {
using namespace boost::system::errc;
#if defined(__PGI)
using boost::system::errc::invalid_argument;
#endif
switch ( ev ) switch ( ev )
{ {
case 0: return make_error_condition( success ); case 0: return make_error_condition( success );
@ -401,10 +412,6 @@ namespace
} // unnamed namespace } // unnamed namespace
namespace boost
{
namespace system
{
# ifndef BOOST_SYSTEM_NO_DEPRECATED # ifndef BOOST_SYSTEM_NO_DEPRECATED
BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code; BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code;
@ -414,13 +421,13 @@ namespace boost
// address for comparison purposes // address for comparison purposes
# endif # endif
BOOST_SYSTEM_DECL const error_category & system_category() BOOST_SYSTEM_DECL const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
{ {
static const system_error_category system_category_const; static const system_error_category system_category_const;
return system_category_const; return system_category_const;
} }
BOOST_SYSTEM_DECL const error_category & generic_category() BOOST_SYSTEM_DECL const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
{ {
static const generic_error_category generic_category_const; static const generic_error_category generic_category_const;
return generic_category_const; return generic_category_const;

View File

@ -75,7 +75,7 @@ namespace boost
namespace lib3 namespace lib3
{ {
// lib3 has its own error_category: // lib3 has its own error_category:
const boost::system::error_category & get_lib3_error_category(); const boost::system::error_category & get_lib3_error_category() BOOST_SYSTEM_NOEXCEPT;
const boost::system::error_category & lib3_error_category = get_lib3_error_category(); const boost::system::error_category & lib3_error_category = get_lib3_error_category();
enum error enum error
@ -112,12 +112,12 @@ namespace boost
public: public:
lib3_error_category_imp() : boost::system::error_category() { } lib3_error_category_imp() : boost::system::error_category() { }
const char * name() const const char * name() const BOOST_SYSTEM_NOEXCEPT
{ {
return "lib3"; return "lib3";
} }
boost::system::error_condition default_error_condition( int ev ) const boost::system::error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT
{ {
return ev == boo_boo return ev == boo_boo
? boost::system::error_condition( boost::system::errc::io_error, ? boost::system::error_condition( boost::system::errc::io_error,
@ -135,7 +135,7 @@ namespace boost
}; };
const boost::system::error_category & get_lib3_error_category() const boost::system::error_category & get_lib3_error_category() BOOST_SYSTEM_NOEXCEPT
{ {
static const lib3_error_category_imp l3ecat; static const lib3_error_category_imp l3ecat;
return l3ecat; return l3ecat;
@ -156,7 +156,7 @@ namespace boost
namespace lib4 namespace lib4
{ {
// lib4 has its own error_category: // lib4 has its own error_category:
const boost::system::error_category & get_lib4_error_category(); const boost::system::error_category & get_lib4_error_category() BOOST_SYSTEM_NOEXCEPT;
const boost::system::error_category & lib4_error_category = get_lib4_error_category(); const boost::system::error_category & lib4_error_category = get_lib4_error_category();
extern const boost::system::error_code boo_boo; extern const boost::system::error_code boo_boo;
@ -174,12 +174,12 @@ namespace lib4
public: public:
lib4_error_category_imp() : boost::system::error_category() { } lib4_error_category_imp() : boost::system::error_category() { }
const char * name() const const char * name() const BOOST_SYSTEM_NOEXCEPT
{ {
return "lib4"; return "lib4";
} }
boost::system::error_condition default_error_condition( int ev ) const boost::system::error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT
{ {
return ev == boo_boo.value() return ev == boo_boo.value()
? boost::system::error_condition( boost::system::errc::io_error, ? boost::system::error_condition( boost::system::errc::io_error,
@ -195,7 +195,7 @@ namespace lib4
} }
}; };
const boost::system::error_category & get_lib4_error_category() const boost::system::error_category & get_lib4_error_category() BOOST_SYSTEM_NOEXCEPT
{ {
static const lib4_error_category_imp l4ecat; static const lib4_error_category_imp l4ecat;
return l4ecat; return l4ecat;