From 9d726cc5fe0ed59ab98cc367a50956f802d3cca1 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sun, 1 Oct 2023 17:47:29 +0300 Subject: [PATCH] Switch to C++11 static_assert. --- CMakeLists.txt | 11 ++++++++++- include/boost/log/attributes/counter.hpp | 3 +-- include/boost/log/attributes/function.hpp | 3 +-- include/boost/log/attributes/mutable_constant.hpp | 3 +-- include/boost/log/detail/thread_specific.hpp | 3 +-- .../log/expressions/formatters/char_decorator.hpp | 3 +-- .../boost/log/expressions/formatters/named_scope.hpp | 9 ++++----- include/boost/log/sinks/async_frontend.hpp | 3 +-- include/boost/log/sinks/sync_frontend.hpp | 3 +-- include/boost/log/sinks/unlocked_frontend.hpp | 3 +-- include/boost/log/sources/severity_feature.hpp | 3 +-- .../utility/type_dispatch/static_type_dispatcher.hpp | 3 +-- .../log/utility/type_dispatch/type_dispatcher.hpp | 5 ++--- src/posix/ipc_reliable_message_queue.cpp | 1 - src/windows/ipc_reliable_message_queue.cpp | 1 - test/compile/current_function_support.cpp | 3 +-- 16 files changed, 27 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ce9546974..cdec5d7306 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2021-2022 Andrey Semashev +# Copyright 2021-2023 Andrey Semashev # # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt @@ -442,6 +442,10 @@ endif() set(boost_log_install_targets boost_log) add_library(Boost::log ALIAS boost_log) +target_compile_features(boost_log PUBLIC + cxx_static_assert +) + target_include_directories(boost_log PUBLIC include @@ -580,6 +584,11 @@ if (NOT BOOST_LOG_WITHOUT_SETTINGS_PARSERS) endif() list(APPEND boost_log_install_targets boost_log_setup) + target_compile_features(boost_log_setup PUBLIC + cxx_static_assert + cxx_uniform_initialization + ) + target_include_directories(boost_log_setup PUBLIC include diff --git a/include/boost/log/attributes/counter.hpp b/include/boost/log/attributes/counter.hpp index b7d9994027..fa3522a887 100644 --- a/include/boost/log/attributes/counter.hpp +++ b/include/boost/log/attributes/counter.hpp @@ -15,7 +15,6 @@ #ifndef BOOST_LOG_ATTRIBUTES_COUNTER_HPP_INCLUDED_ #define BOOST_LOG_ATTRIBUTES_COUNTER_HPP_INCLUDED_ -#include #include #include #include @@ -48,7 +47,7 @@ template< typename T > class counter : public attribute { - BOOST_STATIC_ASSERT_MSG(is_integral< T >::value, "Boost.Log: Only integral types are supported by the counter attribute"); + static_assert(is_integral< T >::value, "Boost.Log: Only integral types are supported by the counter attribute"); public: //! A counter value type diff --git a/include/boost/log/attributes/function.hpp b/include/boost/log/attributes/function.hpp index 488416c5df..409a604d68 100644 --- a/include/boost/log/attributes/function.hpp +++ b/include/boost/log/attributes/function.hpp @@ -15,7 +15,6 @@ #ifndef BOOST_LOG_ATTRIBUTES_FUNCTION_HPP_INCLUDED_ #define BOOST_LOG_ATTRIBUTES_FUNCTION_HPP_INCLUDED_ -#include #include #include #include @@ -49,7 +48,7 @@ template< typename R > class function : public attribute { - BOOST_STATIC_ASSERT_MSG(!is_void< R >::value, "Boost.Log: Function object return type must not be void"); + static_assert(!is_void< R >::value, "Boost.Log: Function object return type must not be void"); public: //! The attribute value type diff --git a/include/boost/log/attributes/mutable_constant.hpp b/include/boost/log/attributes/mutable_constant.hpp index 9357dafa02..ca659f56a2 100644 --- a/include/boost/log/attributes/mutable_constant.hpp +++ b/include/boost/log/attributes/mutable_constant.hpp @@ -15,7 +15,6 @@ #ifndef BOOST_LOG_ATTRIBUTES_MUTABLE_CONSTANT_HPP_INCLUDED_ #define BOOST_LOG_ATTRIBUTES_MUTABLE_CONSTANT_HPP_INCLUDED_ -#include #include #include #include @@ -99,7 +98,7 @@ class mutable_constant : typedef ScopedReadLockT scoped_read_lock; //! Exclusive lock type typedef ScopedWriteLockT scoped_write_lock; - BOOST_STATIC_ASSERT_MSG(!(is_void< mutex_type >::value || is_void< scoped_read_lock >::value || is_void< scoped_write_lock >::value), "Boost.Log: Mutex and both lock types either must not be void or must all be void"); + static_assert(!(is_void< mutex_type >::value || is_void< scoped_read_lock >::value || is_void< scoped_write_lock >::value), "Boost.Log: Mutex and both lock types either must not be void or must all be void"); //! Attribute value wrapper typedef attribute_value_impl< value_type > attr_value; diff --git a/include/boost/log/detail/thread_specific.hpp b/include/boost/log/detail/thread_specific.hpp index 7e38be5aab..badcbb9370 100644 --- a/include/boost/log/detail/thread_specific.hpp +++ b/include/boost/log/detail/thread_specific.hpp @@ -16,7 +16,6 @@ #ifndef BOOST_LOG_DETAIL_THREAD_SPECIFIC_HPP_INCLUDED_ #define BOOST_LOG_DETAIL_THREAD_SPECIFIC_HPP_INCLUDED_ -#include #include #include @@ -62,7 +61,7 @@ template< typename T > class thread_specific : public thread_specific_base { - BOOST_STATIC_ASSERT_MSG(sizeof(T) <= sizeof(void*) && is_pod< T >::value, "Boost.Log: Thread-specific values must be PODs and must not exceed the size of a pointer"); + static_assert(sizeof(T) <= sizeof(void*) && is_pod< T >::value, "Boost.Log: Thread-specific values must be PODs and must not exceed the size of a pointer"); //! Union to perform type casting union value_storage diff --git a/include/boost/log/expressions/formatters/char_decorator.hpp b/include/boost/log/expressions/formatters/char_decorator.hpp index 229e72ae89..7dca657fae 100644 --- a/include/boost/log/expressions/formatters/char_decorator.hpp +++ b/include/boost/log/expressions/formatters/char_decorator.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -561,7 +560,7 @@ class char_decorator_gen2 typedef typename boost::log::aux::deduce_char_type< typename range_value< FromRangeT >::type >::type from_char_type; typedef typename boost::log::aux::deduce_char_type< typename range_value< ToRangeT >::type >::type to_char_type; - BOOST_STATIC_ASSERT_MSG((is_same< from_char_type, to_char_type >::value), "Boost.Log: character decorator cannot be instantiated with different character types for source and replacement strings"); + static_assert(is_same< from_char_type, to_char_type >::value, "Boost.Log: character decorator cannot be instantiated with different character types for source and replacement strings"); public: char_decorator_gen2(FromRangeT const& from, ToRangeT const& to) : m_from(from), m_to(to) diff --git a/include/boost/log/expressions/formatters/named_scope.hpp b/include/boost/log/expressions/formatters/named_scope.hpp index ae140b1956..e4b754f568 100644 --- a/include/boost/log/expressions/formatters/named_scope.hpp +++ b/include/boost/log/expressions/formatters/named_scope.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -524,7 +523,7 @@ template< typename DescriptorT, template< typename > class ActorT, typename Char BOOST_FORCEINLINE format_named_scope_actor< fallback_to_none, CharT, ActorT > format_named_scope(attribute_keyword< DescriptorT, ActorT > const& keyword, const CharT* element_format) { - BOOST_STATIC_ASSERT_MSG((is_same< typename DescriptorT::value_type, attributes::named_scope::value_type >::value),\ + static_assert(is_same< typename DescriptorT::value_type, attributes::named_scope::value_type >::value, "Boost.Log: Named scope formatter only accepts attribute values of type attributes::named_scope::value_type."); typedef format_named_scope_actor< fallback_to_none, CharT, ActorT > actor_type; @@ -544,7 +543,7 @@ template< typename DescriptorT, template< typename > class ActorT, typename Char BOOST_FORCEINLINE format_named_scope_actor< fallback_to_none, CharT, ActorT > format_named_scope(attribute_keyword< DescriptorT, ActorT > const& keyword, std::basic_string< CharT > const& element_format) { - BOOST_STATIC_ASSERT_MSG((is_same< typename DescriptorT::value_type, attributes::named_scope::value_type >::value),\ + static_assert(is_same< typename DescriptorT::value_type, attributes::named_scope::value_type >::value, "Boost.Log: Named scope formatter only accepts attribute values of type attributes::named_scope::value_type."); typedef format_named_scope_actor< fallback_to_none, CharT, ActorT > actor_type; @@ -564,7 +563,7 @@ template< typename T, typename FallbackPolicyT, typename TagT, template< typenam BOOST_FORCEINLINE format_named_scope_actor< FallbackPolicyT, CharT, ActorT > format_named_scope(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& placeholder, const CharT* element_format) { - BOOST_STATIC_ASSERT_MSG((is_same< T, attributes::named_scope::value_type >::value),\ + static_assert(is_same< T, attributes::named_scope::value_type >::value, "Boost.Log: Named scope formatter only accepts attribute values of type attributes::named_scope::value_type."); typedef format_named_scope_actor< FallbackPolicyT, CharT, ActorT > actor_type; @@ -584,7 +583,7 @@ template< typename T, typename FallbackPolicyT, typename TagT, template< typenam BOOST_FORCEINLINE format_named_scope_actor< FallbackPolicyT, CharT, ActorT > format_named_scope(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& placeholder, std::basic_string< CharT > const& element_format) { - BOOST_STATIC_ASSERT_MSG((is_same< T, attributes::named_scope::value_type >::value),\ + static_assert(is_same< T, attributes::named_scope::value_type >::value, "Boost.Log: Named scope formatter only accepts attribute values of type attributes::named_scope::value_type."); typedef format_named_scope_actor< FallbackPolicyT, CharT, ActorT > actor_type; diff --git a/include/boost/log/sinks/async_frontend.hpp b/include/boost/log/sinks/async_frontend.hpp index 3d20718978..79fade5b68 100644 --- a/include/boost/log/sinks/async_frontend.hpp +++ b/include/boost/log/sinks/async_frontend.hpp @@ -26,7 +26,6 @@ #error Boost.Log: Asynchronous sink frontend is only supported in multithreaded environment #endif -#include #include #include #include @@ -221,7 +220,7 @@ class asynchronous_sink : //! Sink implementation type typedef SinkBackendT sink_backend_type; //! \cond - BOOST_STATIC_ASSERT_MSG((has_requirement< typename sink_backend_type::frontend_requirements, synchronized_feeding >::value), "Asynchronous sink frontend is incompatible with the specified backend: thread synchronization requirements are not met"); + static_assert(has_requirement< typename sink_backend_type::frontend_requirements, synchronized_feeding >::value, "Asynchronous sink frontend is incompatible with the specified backend: thread synchronization requirements are not met"); //! \endcond #ifndef BOOST_LOG_DOXYGEN_PASS diff --git a/include/boost/log/sinks/sync_frontend.hpp b/include/boost/log/sinks/sync_frontend.hpp index d92df8d971..738b688055 100644 --- a/include/boost/log/sinks/sync_frontend.hpp +++ b/include/boost/log/sinks/sync_frontend.hpp @@ -25,7 +25,6 @@ #error Boost.Log: Synchronous sink frontend is only supported in multithreaded environment #endif -#include #include #include #include @@ -82,7 +81,7 @@ class synchronous_sink : //! Sink implementation type typedef SinkBackendT sink_backend_type; //! \cond - BOOST_STATIC_ASSERT_MSG((has_requirement< typename sink_backend_type::frontend_requirements, synchronized_feeding >::value), "Synchronous sink frontend is incompatible with the specified backend: thread synchronization requirements are not met"); + static_assert(has_requirement< typename sink_backend_type::frontend_requirements, synchronized_feeding >::value, "Synchronous sink frontend is incompatible with the specified backend: thread synchronization requirements are not met"); //! \endcond #ifndef BOOST_LOG_DOXYGEN_PASS diff --git a/include/boost/log/sinks/unlocked_frontend.hpp b/include/boost/log/sinks/unlocked_frontend.hpp index 0b8c7570c6..472a9624bd 100644 --- a/include/boost/log/sinks/unlocked_frontend.hpp +++ b/include/boost/log/sinks/unlocked_frontend.hpp @@ -15,7 +15,6 @@ #ifndef BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_ #define BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_ -#include #include #include #include @@ -72,7 +71,7 @@ class unlocked_sink : //! Sink implementation type typedef SinkBackendT sink_backend_type; //! \cond - BOOST_STATIC_ASSERT_MSG((has_requirement< typename sink_backend_type::frontend_requirements, concurrent_feeding >::value), "Unlocked sink frontend is incompatible with the specified backend: thread synchronization requirements are not met"); + static_assert(has_requirement< typename sink_backend_type::frontend_requirements, concurrent_feeding >::value, "Unlocked sink frontend is incompatible with the specified backend: thread synchronization requirements are not met"); //! \endcond //! Type of pointer to the backend diff --git a/include/boost/log/sources/severity_feature.hpp b/include/boost/log/sources/severity_feature.hpp index 2fdd21235e..a7db0d92c9 100644 --- a/include/boost/log/sources/severity_feature.hpp +++ b/include/boost/log/sources/severity_feature.hpp @@ -16,7 +16,6 @@ #define BOOST_LOG_SOURCES_SEVERITY_FEATURE_HPP_INCLUDED_ #include -#include #include #include #include @@ -60,7 +59,7 @@ namespace aux { public: //! Stored level type typedef LevelT value_type; - BOOST_STATIC_ASSERT_MSG(sizeof(value_type) <= sizeof(uintmax_t), "Boost.Log: Unsupported severity level type, the severity level must fit into uintmax_t"); + static_assert(sizeof(value_type) <= sizeof(uintmax_t), "Boost.Log: Unsupported severity level type, the severity level must fit into uintmax_t"); protected: //! Factory implementation diff --git a/include/boost/log/utility/type_dispatch/static_type_dispatcher.hpp b/include/boost/log/utility/type_dispatch/static_type_dispatcher.hpp index dcf2cd033d..c78852024d 100644 --- a/include/boost/log/utility/type_dispatch/static_type_dispatcher.hpp +++ b/include/boost/log/utility/type_dispatch/static_type_dispatcher.hpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -82,7 +81,7 @@ struct dispatching_map_initializer p->first = typeindex::type_id< T >(); typedef void (*trampoline_t)(void*, T const&); - BOOST_STATIC_ASSERT_MSG(sizeof(trampoline_t) == sizeof(void*), "Boost.Log: Unsupported platform, the size of a function pointer differs from the size of a pointer"); + static_assert(sizeof(trampoline_t) == sizeof(void*), "Boost.Log: Unsupported platform, the size of a function pointer differs from the size of a pointer"); union { void* as_pvoid; diff --git a/include/boost/log/utility/type_dispatch/type_dispatcher.hpp b/include/boost/log/utility/type_dispatch/type_dispatcher.hpp index 148595fcf3..ca633aa16c 100644 --- a/include/boost/log/utility/type_dispatch/type_dispatcher.hpp +++ b/include/boost/log/utility/type_dispatch/type_dispatcher.hpp @@ -16,7 +16,6 @@ #define BOOST_LOG_TYPE_DISPATCHER_HPP_INCLUDED_ #include -#include #include #include #include @@ -59,7 +58,7 @@ class type_dispatcher m_pVisitor(visitor) { typedef void (*trampoline_t)(void*, ValueT const&); - BOOST_STATIC_ASSERT_MSG(sizeof(trampoline_t) == sizeof(void*), "Boost.Log: Unsupported platform, the size of a function pointer differs from the size of a pointer"); + static_assert(sizeof(trampoline_t) == sizeof(void*), "Boost.Log: Unsupported platform, the size of a function pointer differs from the size of a pointer"); union { void* as_pvoid; @@ -100,7 +99,7 @@ class type_dispatcher void operator() (T const& value) const { - BOOST_STATIC_ASSERT_MSG(sizeof(trampoline_t) == sizeof(void*), "Boost.Log: Unsupported platform, the size of a function pointer differs from the size of a pointer"); + static_assert(sizeof(trampoline_t) == sizeof(void*), "Boost.Log: Unsupported platform, the size of a function pointer differs from the size of a pointer"); union { void* as_pvoid; diff --git a/src/posix/ipc_reliable_message_queue.cpp b/src/posix/ipc_reliable_message_queue.cpp index 39333834b5..c3b1cb6582 100644 --- a/src/posix/ipc_reliable_message_queue.cpp +++ b/src/posix/ipc_reliable_message_queue.cpp @@ -35,7 +35,6 @@ #include #endif #include -#include #include #include #include diff --git a/src/windows/ipc_reliable_message_queue.cpp b/src/windows/ipc_reliable_message_queue.cpp index aa12a68cad..146ae34739 100644 --- a/src/windows/ipc_reliable_message_queue.cpp +++ b/src/windows/ipc_reliable_message_queue.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/test/compile/current_function_support.cpp b/test/compile/current_function_support.cpp index cdcd1051ad..3367d4b0d2 100644 --- a/test/compile/current_function_support.cpp +++ b/test/compile/current_function_support.cpp @@ -20,13 +20,12 @@ #define BOOST_TEST_MODULE current_function_support #include -#include #include template< typename T > void check(T& param) { - BOOST_STATIC_ASSERT(boost::is_array< T >::value); + static_assert(boost::is_array< T >::value, "T must be an array"); } int main(int, char*[])