2
0
mirror of https://github.com/boostorg/log.git synced 2026-01-19 04:22:09 +00:00

Switch to C++11 static_assert.

This commit is contained in:
Andrey Semashev
2023-10-01 17:47:29 +03:00
parent 2352b7eacf
commit 9d726cc5fe
16 changed files with 27 additions and 33 deletions

View File

@@ -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

View File

@@ -15,7 +15,6 @@
#ifndef BOOST_LOG_ATTRIBUTES_COUNTER_HPP_INCLUDED_
#define BOOST_LOG_ATTRIBUTES_COUNTER_HPP_INCLUDED_
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/log/detail/config.hpp>
#include <boost/log/attributes/attribute.hpp>
@@ -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

View File

@@ -15,7 +15,6 @@
#ifndef BOOST_LOG_ATTRIBUTES_FUNCTION_HPP_INCLUDED_
#define BOOST_LOG_ATTRIBUTES_FUNCTION_HPP_INCLUDED_
#include <boost/static_assert.hpp>
#include <boost/utility/result_of.hpp>
#include <boost/type_traits/is_void.hpp>
#include <boost/type_traits/remove_cv.hpp>
@@ -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

View File

@@ -15,7 +15,6 @@
#ifndef BOOST_LOG_ATTRIBUTES_MUTABLE_CONSTANT_HPP_INCLUDED_
#define BOOST_LOG_ATTRIBUTES_MUTABLE_CONSTANT_HPP_INCLUDED_
#include <boost/static_assert.hpp>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <boost/move/core.hpp>
#include <boost/move/utility_core.hpp>
@@ -99,7 +98,7 @@ protected:
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;

View File

@@ -16,7 +16,6 @@
#ifndef BOOST_LOG_DETAIL_THREAD_SPECIFIC_HPP_INCLUDED_
#define BOOST_LOG_DETAIL_THREAD_SPECIFIC_HPP_INCLUDED_
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_pod.hpp>
#include <boost/log/detail/config.hpp>
@@ -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

View File

@@ -19,7 +19,6 @@
#include <string>
#include <iterator>
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
@@ -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)

View File

@@ -18,7 +18,6 @@
#include <string>
#include <iterator>
#include <utility>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/move/core.hpp>
#include <boost/move/utility_core.hpp>
@@ -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;

View File

@@ -26,7 +26,6 @@
#error Boost.Log: Asynchronous sink frontend is only supported in multithreaded environment
#endif
#include <boost/static_assert.hpp>
#include <boost/memory_order.hpp>
#include <boost/atomic/atomic.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
@@ -221,7 +220,7 @@ public:
//! 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

View File

@@ -25,7 +25,6 @@
#error Boost.Log: Synchronous sink frontend is only supported in multithreaded environment
#endif
#include <boost/static_assert.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/preprocessor/control/if.hpp>
@@ -82,7 +81,7 @@ public:
//! 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

View File

@@ -15,7 +15,6 @@
#ifndef BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
#define BOOST_LOG_SINKS_UNLOCKED_FRONTEND_HPP_INCLUDED_
#include <boost/static_assert.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/preprocessor/control/if.hpp>
@@ -72,7 +71,7 @@ public:
//! 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

View File

@@ -16,7 +16,6 @@
#define BOOST_LOG_SOURCES_SEVERITY_FEATURE_HPP_INCLUDED_
#include <boost/cstdint.hpp>
#include <boost/static_assert.hpp>
#include <boost/core/invoke_swap.hpp>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <boost/move/core.hpp>
@@ -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

View File

@@ -20,7 +20,6 @@
#include <iterator>
#include <algorithm>
#include <boost/array.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_index.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/size.hpp>
@@ -82,7 +81,7 @@ private:
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;

View File

@@ -16,7 +16,6 @@
#define BOOST_LOG_TYPE_DISPATCHER_HPP_INCLUDED_
#include <boost/type_index.hpp>
#include <boost/static_assert.hpp>
#include <boost/core/explicit_operator_bool.hpp>
#include <boost/log/detail/config.hpp>
#include <boost/log/detail/header.hpp>
@@ -59,7 +58,7 @@ public:
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 @@ public:
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;

View File

@@ -35,7 +35,6 @@
#include <time.h>
#endif
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/cstdint.hpp>
#include <boost/memory_order.hpp>
#include <boost/atomic/atomic.hpp>

View File

@@ -26,7 +26,6 @@
#include <algorithm>
#include <stdexcept>
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/cstdint.hpp>
#include <boost/memory_order.hpp>
#include <boost/atomic/ipc_atomic.hpp>

View File

@@ -20,13 +20,12 @@
#define BOOST_TEST_MODULE current_function_support
#include <boost/current_function.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_array.hpp>
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*[])