From f1cdde273ab641d91eab9c4baf9ea218dac527c5 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Thu, 22 Jan 2009 14:47:50 +0000 Subject: [PATCH] System: move throws function to namespace boost to allow peaceful coexistence with throws object. [SVN r50727] --- include/boost/system/error_code.hpp | 30 ++++++++++++++++++++--------- src/error_code.cpp | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index 55c3b04..87f255d 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -384,18 +384,30 @@ namespace boost }; // predefined error_code object used as "throw on error" tag -# ifndef BOOST_SYSTEM_THROWS_FUNCTION +# ifndef BOOST_SYSTEM_NO_DEPRECATED BOOST_SYSTEM_DECL extern error_code throws; -# else - namespace detail { inline error_code * throws() { return 0; } } - // prevent misuse by poisoning the reference in a way that doesn't - // produce warnings or errors from popular compilers, and is also - // very efficient (as determined by inspectiing generated code) - - inline error_code & throws() - { return *detail::throws(); } # endif + // Moving from a "throws" object to a "throws" function without breaking + // existing code is a bit of a problem. The workaround is to place the + // "throws" function in namespace boost rather than namespace boost::system. + + } // namespace system + + namespace detail { inline system::error_code * throws() { return 0; } } + // Misuse of the error_code object is turned into a noisy failure by + // poisoning the reference. This particular implementation doesn't + // produce warnings or errors from popular compilers, is very efficient + // (as determined by inspecting generated code), and does not suffer + // from order of initialization problems. In practice, it also seems + // cause user function error handling implementation errors to be detected + // very early in the development cycle. + + inline system::error_code & throws() + { return *detail::throws(); } + + namespace system + { // non-member functions ------------------------------------------------// inline bool operator!=( const error_code & lhs, diff --git a/src/error_code.cpp b/src/error_code.cpp index fac174e..43119ae 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -411,7 +411,7 @@ namespace boost namespace system { -# ifndef BOOST_SYSTEM_THROWS_FUNCTION +# ifndef BOOST_SYSTEM_NO_DEPRECATED BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code; // note that it doesn't matter if this // isn't initialized before use since