diff --git a/doc/reference.html b/doc/reference.html index 05c2102..24efd4e 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -38,6 +38,7 @@ Introduction
+ C++11
Macros
Deprecated names
Breaking changes
@@ -70,11 +71,15 @@

Introduction

-

This reference documentation describes components that  -programs may use to report error conditions originating from the operating +

This reference documentation describes components that programs may use to report error conditions originating from the operating system or other low-level application program interfaces.

Boost.System library components never change the value of errno.

+

C++11

+

The library is documented to use several C++11 features, including +noexcept and explicit conversion operators. The actual implementation +uses C++11 features only when they are available, and otherwise falls back on +C++03 features.

Macros

Users may defined the following macros if desired. Sensible defaults are provided, so users may ignore these macros if they prefer.

@@ -178,6 +183,9 @@ fixed by globally adding () to these names to turn them into function calls.

namespace system { class error_category; + const error_category & system_category() noexcept; + const error_category & generic_category() noexcept; + class error_code; class error_condition; @@ -281,21 +289,21 @@ fixed by globally adding () to these names to turn them into function calls.

// non-member functions - bool operator==( const error_code & lhs, const error_code & rhs ); - bool operator==( const error_code & code, const error_condition & condition ); - bool operator==( const error_condition & condition, const error_code & code ); - bool operator==( const error_condition & lhs, const error_condition & rhs ); + bool operator==( const error_code & lhs, const error_code & rhs ) noexcept; + bool operator==( const error_code & code, const error_condition & condition ) noexcept; + bool operator==( const error_condition & condition, const error_code & code ) noexcept; + bool operator==( const error_condition & lhs, const error_condition & rhs ) noexcept; - bool operator!=( const error_code & lhs, const error_code & rhs ); - bool operator!=( const error_code & code, const error_condition & condition ); - bool operator!=( const error_condition & condition, const error_code & code ); - bool operator!=( const error_condition & lhs, const error_condition & rhs ); + bool operator!=( const error_code & lhs, const error_code & rhs ) noexcept; + bool operator!=( const error_code & code, const error_condition & condition ) noexcept; + bool operator!=( const error_condition & condition, const error_code & code ) noexcept; + bool operator!=( const error_condition & lhs, const error_condition & rhs ) noexcept; - bool operator<( const error_code & lhs, const error_code & rhs ); - bool operator<( const error_condition & lhs, const error_condition & rhs ); + bool operator<( const error_code & lhs, const error_code & rhs ) noexcept; + bool operator<( const error_condition & lhs, const error_condition & rhs ) noexcept; - error_code make_error_code( errc::errc_t e ); - error_condition make_error_condition( errc::errc_t e ); + error_code make_error_code( errc::errc_t e ) noexcept; + error_condition make_error_condition( errc::errc_t e ) noexcept; template <class charT, class traits> std::basic_ostream<charT,traits>& @@ -312,6 +320,17 @@ is_error_condition_enum templates to indicate that a type is eligible for class error_code and error_condition automatic conversions respectively.

+
const error_category & system_category();
+
+

Returns: A reference to a error_category object + identifying errors originating from the operating system.

+
+
const error_category & generic_category();
+
+

Returns: A reference to a error_category object + identifying portable error conditions.

+
+

Class error_category

The class error_category defines the base class for types used to identify the source and encoding of a particular category of error code.

@@ -336,37 +355,33 @@ types should create a single object of each such type. public: virtual ~error_category(); - virtual const char * name() const = 0; + virtual const char * name() const noexcept = 0; virtual string message( int ev ) const = 0; - virtual error_condition default_error_condition( int ev ) const; - virtual bool equivalent( int code, const error_condition & condition ) const; - virtual bool equivalent( const error_code & code, int condition ) const; + virtual error_condition default_error_condition( int ev ) const noexcept; + virtual bool equivalent( int code, const error_condition & condition ) + const noexcept; + virtual bool equivalent( const error_code & code, int condition ) const noexcept; - bool operator==( const error_category & rhs ) const; - bool operator!=( const error_category & rhs ) const; - bool operator< ( const error_category & rhs ) const; + bool operator==( const error_category & rhs ) const noexcept; + bool operator!=( const error_category & rhs ) const noexcept; + bool operator< ( const error_category & rhs ) const noexcept; }; - - const error_category & system_category(); - const error_category & generic_category(); } }

Class error_category virtual members

Classes derived from error_category shall behave as specified in this subclause.

-
virtual const char * name() const=0;
+
virtual const char * name() const noexcept =0;

Returns: a string naming the error category.

-

Throws: Nothing.

-
virtual string message( int ev ) const=0;
+
virtual string message( int ev ) const noexcept =0;

Returns: A string that describes the error denoted by ev.

-

Throws: Nothing.

-

virtual error_condition default_error_condition( int ev ) const;

+
virtual error_condition default_error_condition( int ev ) const noexcept;

Returns:  error_condition( ev, *this ).

@@ -375,52 +390,33 @@ this subclause.

and return it as an error_condition for that category. --end note]

-

Throws: Nothing.

-
-

virtual bool equivalent( int code, const error_condition & -condition ) -const;

+ +
virtual bool equivalent( int code, const error_condition & condition ) const noexcept;

Returns: default_error_condition( code ) == condition.

-

Throws: Nothing.

-
-

virtual bool equivalent( const error_code & code, int condition ) const;

+ +
virtual bool equivalent( const error_code & code, int condition ) const noexcept;

Returns: *this == code.category() && code.value() == condition.

-

Throws: Nothing.

-
+

Class error_category non-virtual members

-

bool operator==( const error_category & rhs ) const;

+
bool operator==( const error_category & rhs ) const noexcept;

Returns: this == &rhs.

-

bool operator!=( const error_category & rhs ) const;

+
bool operator!=( const error_category & rhs ) const noexcept;

Returns: this != &rhs.

-
bool operator<( const error_category & rhs ) const;
+
bool operator<( const error_category & rhs ) const noexcept;
-

Returns: std::less<const error_category*>()( this, &rhs ).

+

Returns: std::less<const error_category*>()( this, &rhs  + noexcept).

[Note: std::less provides a total ordering for pointers. --end note]

-

Throws: Nothing.

-
-

Class error_category -non-member functions

-
const error_category & system_category();
-
-

Returns: A reference to a error_category object - identifying errors originating from the operating system.

-

Throws: Nothing.

-
-
const error_category & generic_category();
-
-

Returns: A reference to a error_category object - identifying portable error conditions.

-

Throws: Nothing.

Class error_code

@@ -440,21 +436,21 @@ error_code synopsis public: // constructors: - error_code(); - error_code( val, const error_category & cat ); + error_code() noexcept; + error_code( val, const error_category & cat ) noexcept; template <class ErrorCodeEnum> - error_code( ErrorCodeEnum e ); + error_code( ErrorCodeEnum e ) noexcept; // modifiers: - void assign( int val, const error_category & cat ); + void assign( int val, const error_category & cat ) noexcept; template<typename ErrorCodeEnum> - error_code & operator=( ErrorCodeEnum val );; - void clear(); + error_code & operator=( ErrorCodeEnum val ) noexcept; + void clear() noexcept; // observers: - int value() const; - cont error_category & category() const; - error_condition default_error_condition() const; + int value() const noexcept; + cont error_category & category() const noexcept; + error_condition default_error_condition() const noexcept; string message() const; operator unspecified-bool-type() const; @@ -467,71 +463,63 @@ error_code synopsis

Class error_code constructors

-
error_code();
+
error_code() noexcept;

Effects: Constructs an object of type error_code.

Postconditions: val_ == 0 && cat_ == &system_category().

-

Throws: Nothing.

-
error_code( int val, const error_category & cat );
+
error_code( int val, const error_category & cat ) noexcept;

Effects: Constructs an object of type error_code.

Postconditions: val_ == val && cat_ == &cat.

-

Throws: Nothing.

template <class ErrorCodeEnum>
-  error_code( ErrorCodeEnum val );
+ error_code( ErrorCodeEnum val ) noexcept;

Effects: Constructs an object of type error_code.

Postconditions: *this == make_error_code( val ).

-

Throws: Nothing.

Remarks: This constructor shall not participate in overload resolution unless is_error_code_enum<ErrorCodeEnum>::value is true.

Class error_code modifiers

-
void assign( int val, const error_category & cat );
+
void assign( int val, const error_category & cat ) noexcept;

Postconditions: val_ == val && cat_ == &cat.

-

Throws: Nothing.

template<typename ErrorCodeEnum>
-  error_code & operator=( ErrorCodeEnum val );
+ error_code & operator=( ErrorCodeEnum val ) noexcept;

Postconditions: *this == make_error_code( val ).

-

Throws: Nothing.

Remarks: This operator shall not participate in overload resolution unless is_error_code_enum<ErrorCodeEnum>::value is true.

-

void clear();

+
void clear() noexcept;

postcondition: value() == 0 && category() == system_category()

Class error_code observers

-

int value() const;

+
int value() const noexcept;

Returns: val_.

-

Throws: Nothing.

-
-

const error_category & category() const;

+ +
const error_category & category() const noexcept;

Returns: *cat_.

-

Throws: Nothing.

-
-
error_condition default_error_condition() const;
+ +
error_condition default_error_condition() const noexcept;

Returns:  category().default_error_condition( value()).

-

Throws: Nothing.

-

string message() const;

+
string message() const;

Returns:  category().message( value()).

Throws: Nothing.

-

operator unspecified-bool-type() const;

+
operator unspecified-bool-type() const;

Returns: if value() != 0, returns a value that will evaluate true in a boolean context; otherwise, returns a value that will @@ -560,22 +548,22 @@ implementation specific. --end note ]

public: // constructors: - error_condition(); - error_condition( int val, const error_category & cat ); + error_condition() noexcept; + error_condition( int val, const error_category & cat ) noexcept; template <class ErrorConditionEnum> - error_condition( errorConditionEnum val ); + error_condition( errorConditionEnum val ) noexcept; // modifiers: - void assign( int val, const error_category & cat ); + void assign( int val, const error_category & cat ) noexcept; template<typename ErrorConditionEnum> - error_condition & operator=( ErrorConditionEnum val ); - void clear(); + error_condition & operator=( ErrorConditionEnum val ) noexcept; + void clear() noexcept; // observers: - int value() const; - const error_category & category() const; + int value() const noexcept; + const error_category & category() const noexcept; string message() const; - operator unspecified-bool-type () const; + operator unspecified-bool-type () const noexcept; private: int val_; // exposition only @@ -586,65 +574,57 @@ implementation specific. --end note ]

Class error_condition constructors

-
error_condition(); 
+
error_condition() noexcept; 

Effects: Constructs an object of type error_condition.

Postconditions: val_ == 0 and cat_ == &generic_category().

-

Throws: Nothing.

-
error_condition( int val, const error_category & cat );
+
error_condition( int val, const error_category & cat ) noexcept;

Effects: Constructs an object of type error_condition.

Postconditions: val_ == val and cat_ == &cat.

-

Throws: Nothing.

template <class ErrorConditionEnum>
-  error_condition( ErrorConditionEnum e );
+ error_condition( ErrorConditionEnum e ) noexcept;

Effects: Constructs an object of type error_condition.

Postconditions: *this == make_error_condition(e).

-

Throws: Nothing.

Remarks: This constructor shall not participate in overload resolution unless is_error_condition_enum<ErrorConditionEnum>::value is true.

Class error_condition modifiers

-
void assign( int val, const error_category & cat ); 
+
void assign( int val, const error_category & cat ) noexcept; 

Postconditions: val_ == val and cat_ == &cat.

-

Throws: Nothing.

template<typename ErrorConditionEnum>
-  error_condition & operator=( ErrorConditionEnum e );
+ error_condition & operator=( ErrorConditionEnum e ) noexcept;

Postconditions: *this == make_error_condition( e ).

Returns: *this.

-

Throws: Nothing.

Remarks: This operator shall not participate in overload resolution unless is_error_condition_enum<ErrorConditionEnum>::value is true.

-

void clear();

+
void clear() noexcept;
-

postcondition: value() == 0 && category() == generic_category()

+

Postcondition: value() == 0 && category() == generic_category()

Class error_condition observers

-
int value() const;
+
int value() const noexcept;

Returns: val_.

-

Throws: Nothing

-
const error_category & category() const;
+
const error_category & category() const noexcept;

Returns: *cat_.

-

Throws: Nothing.

string message() const;

Returns: category().message( value() ).

-

Throws: Nothing.

operator unspecified-bool-type () const;
@@ -690,58 +670,50 @@ semantics:

Non-member functions

-
bool operator==( const error_code & lhs, const error_code & rhs );
+
bool operator==( const error_code & lhs, const error_code & rhs ) noexcept;

Returns: lhs.category() == rhs.category() && lhs.value() == rhs.value().

-

Throws: Nothing.

-
bool operator==( const error_code & code, const error_condition & condition );
-bool operator==( const error_condition & condition, const error_code & code );
+
bool operator==( const error_code & code, const error_condition & condition ) noexcept;
+bool operator==( const error_condition & condition, const error_code & code ) noexcept;

Returns: code.category().equivalent( code.value(), condition )
|| condition.category().equivalent( code, condition.value() )
.

-

Throws: Nothing.

-
bool operator==( const error_condition & lhs, const error_condition & rhs );
+
bool operator==( const error_condition & lhs, const error_condition & rhs ) noexcept;

Returns: lhs.category() == rhs.category() && lhs.value() == rhs.value().

-

Throws: Nothing.

-
bool operator!=( const error_code & lhs, const error_code & rhs );
+
bool operator!=( const error_code & lhs, const error_code & rhs ) noexcept;

Returns: !(lhs == rhs ).

-

Throws: Nothing.

-
bool operator!=( const error_code & code, const error_condition & condition );
-bool operator!=( const error_condition & condition, const error_code & code );
+
bool operator!=( const error_code & code, const error_condition & condition ) noexcept;
+bool operator!=( const error_condition & condition, const error_code & code ) noexcept;

Returns: !( code ==  condition ).

-

Throws: Nothing.

-
bool operator!=( const error_condition & lhs, const error_condition & rhs );
+
bool operator!=( const error_condition & lhs, const error_condition & rhs ) noexcept;

Returns: !(lhs == rhs ).

-

Throws: Nothing.

-
bool operator<( const error_code & lhs, const error_code & rhs );
+
bool operator<( const error_code & lhs, const error_code & rhs ) noexcept;

Returns: lhs.category() < rhs.category()
  || (lhs.category() == rhs.category() && lhs.value() < rhs.value())
.

-

Throws: Nothing.

-
bool operator<( const error_condition & lhs, const error_condition & rhs );
+
bool operator<( const error_condition & lhs, const error_condition & rhs ) noexcept;

Returns: lhs.category() < rhs.category()
  || (lhs.category() == rhs.category() && lhs.value() < rhs.value())
.

-

Throws: Nothing.

-
error_code make_error_code( errc::errc_t e );
+
error_code make_error_code( errc::errc_t e ) noexcept;

Returns: error_code( e, generic_category()).

-
error_condition make_error_condition( errc::errc_t e );
+
error_condition make_error_condition( errc::errc_t e ) noexcept;

Returns: error_condition( static_cast<int>( e ), generic_category()).

@@ -840,10 +812,10 @@ application program interfaces.


Revised -June 29, 2010 +February 27, 2013

-

© Copyright Beman Dawes, 2006, 2007, 2008

+

© Copyright Beman Dawes, 2006, 2007, 2008, 2013

Distributed under the Boost Software License, Version 1.0. See www.boost.org/LICENSE_1_0.txt

diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index b22775f..3e7689c 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -23,7 +23,7 @@ #include // TODO: undef these macros if not already defined -#include +#include #if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API) # error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined @@ -31,6 +31,10 @@ #include // must be the last #include +#ifndef BOOST_SYSTEM_NOEXCEPT +#define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT +#endif + namespace boost { namespace system @@ -184,17 +188,17 @@ namespace boost public: 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 error_condition default_error_condition( int ev ) const; - virtual bool equivalent( int code, - const error_condition & condition ) const; - virtual bool equivalent( const error_code & code, - int condition ) const; + inline virtual error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT; + inline virtual bool equivalent( int code, + const error_condition & condition ) const BOOST_SYSTEM_NOEXCEPT; + inline virtual bool equivalent( const error_code & code, + int condition ) const BOOST_SYSTEM_NOEXCEPT; - bool operator==(const error_category & rhs) const { return this == &rhs; } - bool operator!=(const error_category & rhs) const { return this != &rhs; } - bool operator<( const error_category & rhs ) const + 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()( this, &rhs ); } @@ -202,9 +206,13 @@ namespace boost // predefined error categories -----------------------------------------// - BOOST_SYSTEM_DECL const error_category & system_category(); - BOOST_SYSTEM_DECL const error_category & generic_category(); - +# 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 --------------------------------------------------// # ifndef BOOST_SYSTEM_NO_DEPRECATED @@ -225,52 +233,52 @@ namespace boost public: // constructors: - error_condition() : m_val(0), m_cat(&generic_category()) {} - error_condition( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} + error_condition() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&generic_category()) {} + error_condition( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT : m_val(val), m_cat(&cat) {} template error_condition(ErrorConditionEnum e, - typename boost::enable_if >::type* = 0) + typename boost::enable_if >::type* = 0) BOOST_SYSTEM_NOEXCEPT { *this = make_error_condition(e); } // modifiers: - void assign( int val, const error_category & cat ) - { + void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT + { m_val = val; m_cat = &cat; } - + template typename boost::enable_if, error_condition>::type & - operator=( ErrorConditionEnum val ) - { + operator=( ErrorConditionEnum val ) BOOST_SYSTEM_NOEXCEPT + { *this = make_error_condition(val); return *this; } - void clear() + void clear() BOOST_SYSTEM_NOEXCEPT { m_val = 0; m_cat = &generic_category(); } // observers: - int value() const { return m_val; } - const error_category & category() const { return *m_cat; } + int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; } + const error_category & category() const BOOST_SYSTEM_NOEXCEPT { return *m_cat; } std::string message() const { return m_cat->message(value()); } typedef void (*unspecified_bool_type)(); 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; } - bool operator!() const // true if no error + bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error { return m_val == 0; } @@ -279,13 +287,13 @@ namespace boost // the more symmetrical non-member syntax allows enum // conversions work for both rhs and 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; - } + } 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 // conversions work for both rhs and lhs. { @@ -312,59 +320,59 @@ namespace boost public: // constructors: - error_code() : m_val(0), m_cat(&system_category()) {} - error_code( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} + error_code() BOOST_SYSTEM_NOEXCEPT : m_val(0), m_cat(&system_category()) {} + error_code( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT : m_val(val), m_cat(&cat) {} template error_code(ErrorCodeEnum e, - typename boost::enable_if >::type* = 0) + typename boost::enable_if >::type* = 0) BOOST_SYSTEM_NOEXCEPT { *this = make_error_code(e); } // modifiers: - void assign( int val, const error_category & cat ) - { + void assign( int val, const error_category & cat ) BOOST_SYSTEM_NOEXCEPT + { m_val = val; m_cat = &cat; } - + template typename boost::enable_if, error_code>::type & - operator=( ErrorCodeEnum val ) - { + operator=( ErrorCodeEnum val ) BOOST_SYSTEM_NOEXCEPT + { *this = make_error_code(val); return *this; } - void clear() + void clear() BOOST_SYSTEM_NOEXCEPT { m_val = 0; m_cat = &system_category(); } // observers: - int value() const { return m_val; } - const error_category & category() const { return *m_cat; } - error_condition default_error_condition() const { return m_cat->default_error_condition(value()); } + int value() const BOOST_SYSTEM_NOEXCEPT { return m_val; } + 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()); } typedef void (*unspecified_bool_type)(); 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; } - bool operator!() const // true if no error + bool operator!() const BOOST_SYSTEM_NOEXCEPT // true if no error { return m_val == 0; } // relationals: 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 // conversions work for both rhs and lhs. { @@ -372,15 +380,15 @@ namespace boost } 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 // conversions work for both rhs and lhs. { return lhs.m_cat < rhs.m_cat || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val); } - - private: + + private: int m_val; const error_category * m_cat; @@ -414,43 +422,43 @@ namespace boost // non-member functions ------------------------------------------------// inline bool operator!=( const error_code & lhs, - const error_code & rhs ) + const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT { return !(lhs == rhs); } inline bool operator!=( const error_condition & lhs, - const error_condition & rhs ) + const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT { return !(lhs == rhs); } 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 ) || condition.category().equivalent( code, condition.value() ); } - + inline bool operator!=( const error_code & lhs, - const error_condition & rhs ) + const error_condition & rhs ) BOOST_SYSTEM_NOEXCEPT { return !(lhs == rhs); } - + 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() ) || code.category().equivalent( code.value(), condition ); } - + inline bool operator!=( const error_condition & lhs, - const error_code & rhs ) + const error_code & rhs ) BOOST_SYSTEM_NOEXCEPT { return !(lhs == rhs); } - + // TODO: both of these may move elsewhere, but the LWG hasn't spoken yet. template @@ -472,29 +480,29 @@ namespace boost namespace errc { // explicit conversion: - inline error_code make_error_code( errc_t e ) + inline error_code make_error_code( errc_t e ) BOOST_SYSTEM_NOEXCEPT { return error_code( e, generic_category() ); } // implicit conversion: - inline error_condition make_error_condition( errc_t e ) + inline error_condition make_error_condition( errc_t e ) BOOST_SYSTEM_NOEXCEPT { return error_condition( e, generic_category() ); } } // 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 ); } - inline bool error_category::equivalent( int code, - const error_condition & condition ) const + bool error_category::equivalent( int code, + const error_condition & condition ) const BOOST_SYSTEM_NOEXCEPT { return default_error_condition( code ) == condition; } - inline bool error_category::equivalent( const error_code & code, - int condition ) const + bool error_category::equivalent( const error_code & code, + int condition ) const BOOST_SYSTEM_NOEXCEPT { return *this == code.category() && code.value() == condition; } diff --git a/include/boost/system/system_error.hpp b/include/boost/system/system_error.hpp index 065d365..b306aae 100644 --- a/include/boost/system/system_error.hpp +++ b/include/boost/system/system_error.hpp @@ -21,7 +21,7 @@ namespace boost 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 - // 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: system_error( error_code ec ) @@ -61,13 +61,17 @@ namespace boost { if ( m_what.empty() ) { +#ifndef BOOST_NO_EXCEPTIONS try +#endif { m_what = this->std::runtime_error::what(); if ( !m_what.empty() ) m_what += ": "; m_what += m_error_code.message(); } +#ifndef BOOST_NO_EXCEPTIONS catch (...) { return std::runtime_error::what(); } +#endif } return m_what.c_str(); } diff --git a/src/error_code.cpp b/src/error_code.cpp index 6772d15..cb1cb80 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -22,9 +22,6 @@ #include #include -using namespace boost::system; -using namespace boost::system::errc; - #include // for strerror/strerror_r # if defined( BOOST_WINDOWS_API ) @@ -36,19 +33,21 @@ using namespace boost::system::errc; # endif //----------------------------------------------------------------------------// +namespace boost +{ + namespace system + { namespace { -#if defined(__PGI) - using boost::system::errc::invalid_argument; -#endif + // standard error categories ---------------------------------------------// class generic_error_category : public error_category { public: generic_error_category(){} - const char * name() const; + const char * name() const BOOST_SYSTEM_NOEXCEPT; std::string message( int ev ) const; }; @@ -56,20 +55,25 @@ namespace { public: system_error_category(){} - const char * name() const; + const char * name() const BOOST_SYSTEM_NOEXCEPT; 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 ---------------------------------// - const char * generic_error_category::name() const + const char * generic_error_category::name() const BOOST_SYSTEM_NOEXCEPT { return "generic"; } 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" ); // strerror_r is preferred because it is always thread safe, // however, we fallback to strerror in certain cases because: @@ -133,7 +137,9 @@ namespace } } std::string msg; +# ifndef BOOST_NO_EXCEPTIONS try +# endif { msg = ( ( result == invalid_argument ) ? "Unknown error" : bp ); } @@ -154,13 +160,18 @@ namespace } // system_error_category implementation --------------------------------// - const char * system_error_category::name() const + const char * system_error_category::name() const BOOST_SYSTEM_NOEXCEPT { 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 ) { case 0: return make_error_condition( success ); @@ -401,10 +412,6 @@ namespace } // unnamed namespace -namespace boost -{ - namespace system - { # ifndef BOOST_SYSTEM_NO_DEPRECATED BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code; @@ -414,13 +421,13 @@ namespace boost // address for comparison purposes # 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; 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; return generic_category_const; diff --git a/test/error_code_user_test.cpp b/test/error_code_user_test.cpp index 4f4eb30..a006a8d 100644 --- a/test/error_code_user_test.cpp +++ b/test/error_code_user_test.cpp @@ -75,7 +75,7 @@ namespace boost namespace lib3 { // 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(); enum error @@ -112,12 +112,12 @@ namespace boost public: lib3_error_category_imp() : boost::system::error_category() { } - const char * name() const + const char * name() const BOOST_SYSTEM_NOEXCEPT { 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 ? 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; return l3ecat; @@ -156,7 +156,7 @@ namespace boost namespace lib4 { // 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(); extern const boost::system::error_code boo_boo; @@ -174,12 +174,12 @@ namespace lib4 public: lib4_error_category_imp() : boost::system::error_category() { } - const char * name() const + const char * name() const BOOST_SYSTEM_NOEXCEPT { 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() ? 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; return l4ecat;