From 77817d88476f72f5a9857e50e817c04c8bba82db Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 22 Jan 2018 02:20:01 +0200 Subject: [PATCH] Fix MinGW link errors by properly exporting symbols --- include/boost/system/detail/error_code.ipp | 40 ++++++--------- include/boost/system/error_code.hpp | 60 ++++++++++++++-------- test/std_mismatch_test.cpp | 2 - 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/include/boost/system/detail/error_code.ipp b/include/boost/system/detail/error_code.ipp index 6ed777c..d93fb1f 100644 --- a/include/boost/system/detail/error_code.ipp +++ b/include/boost/system/detail/error_code.ipp @@ -43,19 +43,14 @@ namespace detail { #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) @@ -148,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; @@ -358,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()); @@ -443,7 +433,7 @@ namespace detail } # endif -#undef BOOST_SYSTEM_INLINE +#undef BOOST_SYSTEM_DECL_ } // namespace detail @@ -474,17 +464,17 @@ namespace detail namespace detail { -BOOST_SYSTEM_CONST_INIT const system_error_category system_category_const; -BOOST_SYSTEM_CONST_INIT const generic_error_category generic_category_const; +BOOST_SYSTEM_CONST_INIT BOOST_SYSTEM_DECL system_error_category system_category_instance; +BOOST_SYSTEM_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_const; + return system_category_instance; } BOOST_SYSTEM_DECL const error_category & generic_category_ncx() BOOST_SYSTEM_NOEXCEPT { - return generic_category_const; + return generic_category_instance; } } // namespace detail @@ -498,14 +488,14 @@ namespace detail BOOST_SYSTEM_DECL const error_category & system_category_ncx() BOOST_SYSTEM_NOEXCEPT { - static const detail::system_error_category system_category_const; - return system_category_const; + 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_const; - return generic_category_const; + static const detail::generic_error_category generic_category_instance; + return generic_category_instance; } } // namespace detail diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index bb557f3..367d485 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -338,22 +338,38 @@ namespace boost namespace detail { - class generic_error_category : public error_category - { - public: - BOOST_SYSTEM_CONSTEXPR generic_error_category(){} - const char * name() const BOOST_SYSTEM_NOEXCEPT; - std::string message( int ev ) const; - }; +#ifdef BOOST_ERROR_CODE_HEADER_ONLY +# define BOOST_SYSTEM_DECL_ +#else +# define BOOST_SYSTEM_DECL_ BOOST_SYSTEM_DECL +#endif - class system_error_category : public error_category +class generic_error_category: public error_category +{ +public: + + const char * name() const BOOST_SYSTEM_NOEXCEPT { - public: - BOOST_SYSTEM_CONSTEXPR 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; - }; + return "generic"; + } + + BOOST_SYSTEM_DECL_ std::string message( int ev ) const; +}; + +class system_error_category: public error_category +{ +public: + + 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 @@ -361,14 +377,14 @@ namespace detail BOOST_SYSTEM_CONSTEXPR inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT { - static const detail::system_error_category system_category_const; - return system_category_const; + static const detail::system_error_category system_category_instance; + return system_category_instance; } BOOST_SYSTEM_CONSTEXPR inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT { - static const detail::generic_error_category generic_category_const; - return generic_category_const; + static const detail::generic_error_category generic_category_instance; + return generic_category_instance; } #elif defined(BOOST_SYSTEM_HAS_CONSTEXPR) @@ -376,19 +392,19 @@ BOOST_SYSTEM_CONSTEXPR inline const error_category & generic_category() BOOST_SY namespace detail { -extern const system_error_category system_category_const; -extern const generic_error_category generic_category_const; +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_const; + return detail::system_category_instance; } constexpr const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT { - return detail::generic_category_const; + return detail::generic_category_instance; } #else diff --git a/test/std_mismatch_test.cpp b/test/std_mismatch_test.cpp index 37a606b..9c97cdd 100644 --- a/test/std_mismatch_test.cpp +++ b/test/std_mismatch_test.cpp @@ -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()