From a41060227fe485f380423a9b31b4f2af03395ba2 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Sat, 18 Jan 2025 05:28:56 +0900 Subject: [PATCH] refactor: use BOOST_STATIC_ASSERT --- include/boost/python/args_fwd.hpp | 4 +++- include/boost/python/cast.hpp | 4 +++- include/boost/python/class.hpp | 6 ++++-- include/boost/python/def.hpp | 6 +++--- include/boost/python/detail/defaults_gen.hpp | 9 +++------ include/boost/python/init.hpp | 12 +++++------- include/boost/python/make_constructor.hpp | 5 ++--- include/boost/python/make_function.hpp | 5 ++--- include/boost/python/object/pickle_support.hpp | 6 +++--- 9 files changed, 28 insertions(+), 29 deletions(-) diff --git a/include/boost/python/args_fwd.hpp b/include/boost/python/args_fwd.hpp index 39239461b0..6394ef7a41 100644 --- a/include/boost/python/args_fwd.hpp +++ b/include/boost/python/args_fwd.hpp @@ -9,6 +9,7 @@ # include # include +# include # include # include @@ -39,10 +40,11 @@ namespace detail namespace error { + /// @deprecated template struct more_keywords_than_function_arguments { - typedef char too_many_keywords[keywords > function_args ? -1 : 1]; + BOOST_STATIC_ASSERT(keywords <= function_args); }; } } diff --git a/include/boost/python/cast.hpp b/include/boost/python/cast.hpp index c0dd229e84..6da72c36d9 100644 --- a/include/boost/python/cast.hpp +++ b/include/boost/python/cast.hpp @@ -12,6 +12,8 @@ # include # include +# include + namespace boost { namespace python { namespace detail @@ -69,7 +71,7 @@ namespace detail template inline void assert_castable(boost::type* = 0) { - typedef char must_be_a_complete_type[sizeof(T)] BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(sizeof(T)); } template diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 0f1c0fdc1a..db7792dea5 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -32,6 +32,8 @@ # include # include +# include + # include # include # include @@ -136,9 +138,9 @@ namespace detail // https://svn.boost.org/trac/boost/ticket/5803 //typedef typename assertion > >::failed test0; # if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - typedef typename assertion >::failed test1 BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(detail::is_polymorphic::value); # endif - typedef typename assertion >::failed test2 BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(detail::is_member_function_pointer::value); not_a_derived_class_member(Fn()); } }; diff --git a/include/boost/python/def.hpp b/include/boost/python/def.hpp index fe2c65f938..96e1f4b53e 100644 --- a/include/boost/python/def.hpp +++ b/include/boost/python/def.hpp @@ -15,6 +15,8 @@ # include # include +# include + namespace boost { namespace python { namespace detail @@ -35,9 +37,7 @@ namespace detail char const* name, F const& fn, Helper const& helper) { // Must not try to use default implementations except with method definitions. - typedef typename error::multiple_functions_passed_to_def< - Helper::has_default_implementation - >::type assertion BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(!Helper::has_default_implementation); detail::scope_setattr_doc( name, boost::python::make_function( diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index 88beeedb02..ae2f69c33b 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace boost { namespace python { @@ -211,18 +212,14 @@ namespace detail : ::boost::python::detail::overloads_common( \ doc, keywords.range()) \ { \ - typedef typename ::boost::python::detail:: \ - error::more_keywords_than_function_arguments< \ - N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \ + BOOST_STATIC_ASSERT(N <= n_args); \ } \ template \ fstubs_name(::boost::python::detail::keywords const& keywords, char const* doc = 0) \ : ::boost::python::detail::overloads_common( \ doc, keywords.range()) \ { \ - typedef typename ::boost::python::detail:: \ - error::more_keywords_than_function_arguments< \ - N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \ + BOOST_STATIC_ASSERT(N <= n_args); \ } # if defined(BOOST_NO_VOID_RETURNS) diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index 0ee763cc26..26febf48d5 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -65,10 +66,11 @@ namespace detail { namespace error { + /// @deprecated template struct more_keywords_than_init_arguments { - typedef char too_many_keywords[init_args - keywords >= 0 ? 1 : -1] BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(keywords <= init_args); }; } @@ -222,18 +224,14 @@ class init : public init_base > init(char const* doc_, detail::keywords const& kw) : base(doc_, kw.range()) { - typedef typename detail::error::more_keywords_than_init_arguments< - N, n_arguments::value + 1 - >::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(N <= n_arguments::value + 1); } template init(detail::keywords const& kw, char const* doc_ = 0) : base(doc_, kw.range()) { - typedef typename detail::error::more_keywords_than_init_arguments< - N, n_arguments::value + 1 - >::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(N <= n_arguments::value + 1); } template diff --git a/include/boost/python/make_constructor.hpp b/include/boost/python/make_constructor.hpp index 3769970cad..eaaf979c40 100644 --- a/include/boost/python/make_constructor.hpp +++ b/include/boost/python/make_constructor.hpp @@ -24,6 +24,7 @@ # include # include # include +# include namespace boost { namespace python { @@ -182,9 +183,7 @@ namespace detail { enum { arity = mpl::size::value - 1 }; - typedef typename detail::error::more_keywords_than_function_arguments< - NumKeywords::value, arity - >::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(NumKeywords::value <= arity); typedef typename outer_constructor_signature::type outer_signature; diff --git a/include/boost/python/make_function.hpp b/include/boost/python/make_function.hpp index 7dd7c316b3..a4742a53b5 100644 --- a/include/boost/python/make_function.hpp +++ b/include/boost/python/make_function.hpp @@ -15,6 +15,7 @@ # include # include +# include namespace boost { namespace python { @@ -53,9 +54,7 @@ namespace detail { enum { arity = mpl::size::value - 1 }; - typedef typename detail::error::more_keywords_than_function_arguments< - NumKeywords::value, arity - >::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(NumKeywords::value <= arity); return objects::function_object( detail::caller(f, p) diff --git a/include/boost/python/object/pickle_support.hpp b/include/boost/python/object/pickle_support.hpp index aa96d655ee..3b905c5745 100644 --- a/include/boost/python/object/pickle_support.hpp +++ b/include/boost/python/object/pickle_support.hpp @@ -7,6 +7,8 @@ # include +# include + namespace boost { namespace python { namespace api @@ -105,9 +107,7 @@ namespace detail { Class_&, ...) { - typedef typename - error_messages::missing_pickle_suite_function_or_incorrect_signature< - Class_>::error_type error_type BOOST_ATTRIBUTE_UNUSED; + BOOST_STATIC_ASSERT(false); } };