Skip to content

Commit

Permalink
Switch to C++11 static_assert.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastique committed Oct 1, 2023
1 parent 2352b7e commit 9d726cc
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 33 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/boost/log/attributes/counter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/boost/log/attributes/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/boost/log/attributes/mutable_constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions include/boost/log/detail/thread_specific.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/boost/log/expressions/formatters/char_decorator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions include/boost/log/expressions/formatters/named_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions include/boost/log/sinks/async_frontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/boost/log/sinks/sync_frontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/boost/log/sinks/unlocked_frontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/boost/log/sources/severity_feature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions include/boost/log/utility/type_dispatch/type_dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/posix/ipc_reliable_message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion src/windows/ipc_reliable_message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 1 addition & 2 deletions test/compile/current_function_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*[])
Expand Down

0 comments on commit 9d726cc

Please sign in to comment.