Enable constexpr in header-only mode as well

This commit is contained in:
Peter Dimov
2018-01-22 04:56:40 +02:00
parent 8416ba067f
commit 587ceaf739
2 changed files with 44 additions and 16 deletions

View File

@ -452,20 +452,11 @@ namespace detail
#elif defined(BOOST_SYSTEM_HAS_CONSTEXPR)
#define BOOST_SYSTEM_CONST_INIT
#if defined(__has_cpp_attribute)
#if __has_cpp_attribute(clang::require_constant_initialization)
# undef BOOST_SYSTEM_CONST_INIT
# define BOOST_SYSTEM_CONST_INIT [[clang::require_constant_initialization]]
#endif
#endif
namespace detail
{
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_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
{
@ -479,8 +470,6 @@ BOOST_SYSTEM_DECL const error_category & generic_category_ncx() BOOST_SYSTEM_NOE
} // namespace detail
#undef BOOST_SYSTEM_CONST_INIT
#else
namespace detail

View File

@ -38,7 +38,7 @@
#define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT
#endif
#if !defined(BOOST_NO_CXX14_CONSTEXPR) && !defined(BOOST_ERROR_CODE_HEADER_ONLY)
#if !defined(BOOST_NO_CXX14_CONSTEXPR)
# define BOOST_SYSTEM_HAS_CONSTEXPR
#endif
@ -373,20 +373,59 @@ public:
} // 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)
BOOST_SYSTEM_CONSTEXPR inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
# 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;
}
BOOST_SYSTEM_CONSTEXPR inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
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