From 353849e9ad88c0bfa92b4caaadf09ff83652c5ec Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Thu, 9 Jul 2020 19:39:48 +0200 Subject: [PATCH] Use default/delete for ctor/dtor --- ...limitations_template_base_class_method.cpp | 3 +- doc/example/limitations_throw_specifier.cpp | 3 +- doc/example/reference.cpp | 15 +++----- include/turtle/constraint.hpp | 3 +- include/turtle/detail/action.hpp | 12 +++--- include/turtle/detail/context.hpp | 10 +++-- include/turtle/detail/function.hpp | 1 - include/turtle/detail/invocation.hpp | 10 +++-- .../turtle/detail/matcher_base_template.hpp | 6 ++- include/turtle/detail/mutex.hpp | 22 ++++++----- include/turtle/detail/parent.hpp | 3 +- include/turtle/detail/sequence_impl.hpp | 3 +- include/turtle/detail/singleton.hpp | 2 +- include/turtle/detail/verifiable.hpp | 9 +++-- include/turtle/object.hpp | 3 +- include/turtle/stream.hpp | 14 ++++--- ...classes_30_methods_30_args_30_max_args.cpp | 2 +- test/bench_30_classes_30_methods_9_args.cpp | 2 +- ..._classes_30_methods_9_args_10_max_args.cpp | 2 +- ..._classes_30_methods_9_args_20_max_args.cpp | 2 +- ..._classes_30_methods_9_args_30_max_args.cpp | 2 +- test/detail/test_function.cpp | 11 ++++-- test/fail_ambiguous_mock_method.cpp | 2 +- ...sting_base_class_method_in_mock_method.cpp | 2 +- ...of_arguments_greater_than_max_constant.cpp | 2 +- ...fail_too_many_arguments_in_mock_method.cpp | 2 +- test/test_integration.cpp | 38 +++++++++++-------- test/test_mock.cpp | 6 +-- 28 files changed, 100 insertions(+), 92 deletions(-) diff --git a/doc/example/limitations_template_base_class_method.cpp b/doc/example/limitations_template_base_class_method.cpp index 5b5461b..b847f68 100644 --- a/doc/example/limitations_template_base_class_method.cpp +++ b/doc/example/limitations_template_base_class_method.cpp @@ -17,8 +17,7 @@ namespace class base { public: - virtual ~base() - {} + virtual ~base() = default; virtual void method() = 0; }; diff --git a/doc/example/limitations_throw_specifier.cpp b/doc/example/limitations_throw_specifier.cpp index 01e70fe..77b44c8 100644 --- a/doc/example/limitations_throw_specifier.cpp +++ b/doc/example/limitations_throw_specifier.cpp @@ -15,8 +15,7 @@ namespace //[ limitations_throw_specifier_problem struct base_class { - virtual ~base_class() - {} + virtual ~base_class() = default; virtual void method() throw (); }; diff --git a/doc/example/reference.cpp b/doc/example/reference.cpp index e2e3574..d599a59 100644 --- a/doc/example/reference.cpp +++ b/doc/example/reference.cpp @@ -121,8 +121,7 @@ namespace member_function_example_1 //[ member_function_example_1 struct base_class { - virtual ~base_class() - {} + virtual ~base_class() = default; virtual void method( int ) = 0; }; @@ -138,8 +137,7 @@ namespace member_function_example_2 //[ member_function_example_2 struct base_class { - virtual ~base_class() - {} + virtual ~base_class() = default; virtual void method( int, const std::string& ) = 0; virtual void method( float ) = 0; }; @@ -157,8 +155,7 @@ namespace member_function_example_3 //[ member_function_example_3 struct base_class { - virtual ~base_class() - {} + virtual ~base_class() = default; virtual void method( float ) = 0; virtual void method( float ) const = 0; }; @@ -175,8 +172,7 @@ namespace member_function_example_4 //[ member_function_example_4 struct base_class { - virtual ~base_class() - {} + virtual ~base_class() = default; virtual void method( float ) = 0; virtual void method( float ) const = 0; }; @@ -194,8 +190,7 @@ namespace member_function_example_5 //[ member_function_example_5 struct base_class { - virtual ~base_class() - {} + virtual ~base_class() = default; virtual void method( float ) = 0; }; diff --git a/include/turtle/constraint.hpp b/include/turtle/constraint.hpp index ff744dc..dd30eab 100644 --- a/include/turtle/constraint.hpp +++ b/include/turtle/constraint.hpp @@ -26,8 +26,7 @@ namespace mock template< typename Constraint > struct constraint { - constraint() - {} + constraint() {} constraint( const Constraint& c ) : c_( c ) {} diff --git a/include/turtle/detail/action.hpp b/include/turtle/detail/action.hpp index 1984dac..a959c31 100644 --- a/include/turtle/detail/action.hpp +++ b/include/turtle/detail/action.hpp @@ -10,7 +10,6 @@ #define MOCK_ACTION_HPP_INCLUDED #include "../config.hpp" -#include #include #include #include @@ -112,10 +111,12 @@ namespace detail { return std::move( t ); } - struct value : boost::noncopyable + struct value { - virtual ~value() - {} + value() = default; + value(const value&) = delete; + value& operator=(const value&) = delete; + virtual ~value() = default; }; template< typename T > struct value_imp : value @@ -177,8 +178,7 @@ namespace detail : public action_base< std::auto_ptr< Result >, Signature > { public: - action() - {} + action() = default; action( const action& rhs ) : v_( rhs.v_.release() ) { diff --git a/include/turtle/detail/context.hpp b/include/turtle/detail/context.hpp index 9b275a3..3e46813 100644 --- a/include/turtle/detail/context.hpp +++ b/include/turtle/detail/context.hpp @@ -11,7 +11,6 @@ #include "../config.hpp" #include "type_name.hpp" -#include #include #include #include @@ -22,11 +21,14 @@ namespace detail { class verifiable; - class context : boost::noncopyable + class context { public: - context() {} - virtual ~context() {} + context() = default; + context(const context&) = delete; + context& operator=(const context&) = delete; + + virtual ~context() = default; virtual void add( const void* p, verifiable& v, boost::unit_test::const_string instance, diff --git a/include/turtle/detail/function.hpp b/include/turtle/detail/function.hpp index 6443d16..e723a42 100644 --- a/include/turtle/detail/function.hpp +++ b/include/turtle/detail/function.hpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/include/turtle/detail/invocation.hpp b/include/turtle/detail/invocation.hpp index fd1c0f6..cf37dff 100644 --- a/include/turtle/detail/invocation.hpp +++ b/include/turtle/detail/invocation.hpp @@ -10,7 +10,6 @@ #define MOCK_INVOCATION_HPP_INCLUDED #include "../config.hpp" -#include #include #include #include @@ -19,11 +18,14 @@ namespace mock { namespace detail { - class invocation : private boost::noncopyable + class invocation { public: - invocation() {} - virtual ~invocation() {} + invocation() = default; + invocation(const invocation&) = delete; + invocation& operator=(const invocation&) = delete; + + virtual ~invocation() = default; virtual bool invoke() = 0; virtual bool verify() const = 0; diff --git a/include/turtle/detail/matcher_base_template.hpp b/include/turtle/detail/matcher_base_template.hpp index 07fa326..2de909e 100644 --- a/include/turtle/detail/matcher_base_template.hpp +++ b/include/turtle/detail/matcher_base_template.hpp @@ -18,10 +18,12 @@ namespace detail template< BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, typename T) > class matcher_base< void( BOOST_PP_ENUM_PARAMS(MOCK_NUM_ARGS, T) ) > - : boost::noncopyable { public: - virtual ~matcher_base() {} + matcher_base() = default; + matcher_base(const matcher_base&) = delete; + matcher_base& operator=(const matcher_base&) = delete; + virtual ~matcher_base() = default; virtual bool operator()( BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_REF_ARG, _) ) = 0; diff --git a/include/turtle/detail/mutex.hpp b/include/turtle/detail/mutex.hpp index d9f0563..5cc193b 100644 --- a/include/turtle/detail/mutex.hpp +++ b/include/turtle/detail/mutex.hpp @@ -11,7 +11,6 @@ #include "../config.hpp" #include "singleton.hpp" -#include #include #ifdef MOCK_THREAD_SAFE @@ -75,8 +74,12 @@ namespace mock { namespace detail { - struct mutex : boost::noncopyable + struct mutex { + mutex() = default; + mutex(const mutex&) = delete; + mutex& operator=(const mutex&) = delete; + void lock() {} void unlock() @@ -86,18 +89,17 @@ namespace detail // Constructor + Destructor make it RAII classes for compilers and avoid unused variable warnings struct scoped_lock { - scoped_lock( mutex& ) - {} - ~scoped_lock() - {} + scoped_lock(const scoped_lock&) = delete; + scoped_lock& operator=(const scoped_lock&) = delete; + + scoped_lock( mutex& ) {} + ~scoped_lock() {} }; class lock { public: - lock( const std::shared_ptr< mutex >& ) - {} - ~lock() - {} + lock( const std::shared_ptr< mutex >& ) {} + ~lock() {} lock(const lock&) = delete; lock( lock&& ) = default; lock& operator=( const lock& ) = delete; diff --git a/include/turtle/detail/parent.hpp b/include/turtle/detail/parent.hpp index 0d14e77..aedb373 100644 --- a/include/turtle/detail/parent.hpp +++ b/include/turtle/detail/parent.hpp @@ -22,8 +22,7 @@ namespace detail class parent { public: - parent() - {} + parent() = default; parent( boost::unit_test::const_string instance, boost::optional< type_name > type ) : instance_( instance ) diff --git a/include/turtle/detail/sequence_impl.hpp b/include/turtle/detail/sequence_impl.hpp index 37db2b6..84087c4 100644 --- a/include/turtle/detail/sequence_impl.hpp +++ b/include/turtle/detail/sequence_impl.hpp @@ -11,7 +11,6 @@ #include "../config.hpp" #include "mutex.hpp" -#include #include #include #include @@ -20,7 +19,7 @@ namespace mock { namespace detail { - class sequence_impl : private boost::noncopyable + class sequence_impl { public: sequence_impl() diff --git a/include/turtle/detail/singleton.hpp b/include/turtle/detail/singleton.hpp index 2080750..c8f42d6 100644 --- a/include/turtle/detail/singleton.hpp +++ b/include/turtle/detail/singleton.hpp @@ -38,7 +38,7 @@ protected: #define MOCK_SINGLETON_CONS( type ) \ private: \ friend class mock::detail::singleton< type >; \ -type() {} +type() = default #define MOCK_SINGLETON_INST( inst ) \ static BOOST_JOIN( inst, _t )& inst = BOOST_JOIN( inst, _t )::instance(); diff --git a/include/turtle/detail/verifiable.hpp b/include/turtle/detail/verifiable.hpp index 5d85c93..3390ec9 100644 --- a/include/turtle/detail/verifiable.hpp +++ b/include/turtle/detail/verifiable.hpp @@ -10,17 +10,18 @@ #define MOCK_VERIFIABLE_HPP_INCLUDED #include "../config.hpp" -#include namespace mock { namespace detail { - class verifiable : private boost::noncopyable + class verifiable { public: - verifiable() {} - virtual ~verifiable() {} + verifiable() = default; + verifiable(const verifiable&) = delete; + verifiable& operator=(const verifiable&) = delete; + virtual ~verifiable() = default; virtual bool verify() const = 0; diff --git a/include/turtle/object.hpp b/include/turtle/object.hpp index d9f6a47..70f98fa 100644 --- a/include/turtle/object.hpp +++ b/include/turtle/object.hpp @@ -48,8 +48,7 @@ namespace detail : impl_( std::make_shared< detail::object_impl >() ) {} protected: - ~object() - {} + ~object() = default; public: std::shared_ptr< detail::object_impl > impl_; }; diff --git a/include/turtle/stream.hpp b/include/turtle/stream.hpp index d8f3707..3ea47db 100644 --- a/include/turtle/stream.hpp +++ b/include/turtle/stream.hpp @@ -10,7 +10,6 @@ #define MOCK_STREAM_HPP_INCLUDED #include "config.hpp" -#include #include namespace mock @@ -41,10 +40,13 @@ namespace conversion return s << '?'; } - struct holder : boost::noncopyable + struct holder { - virtual ~holder() - {} + holder() = default; + holder(const holder&) = delete; + holder& operator=(const holder&) = delete; + + virtual ~holder() = default; virtual void serialize( std::ostream& s ) const = 0; }; @@ -64,12 +66,14 @@ namespace conversion const T& t_; }; - struct any : boost::noncopyable + struct any { template< typename T > any( const T& t ) : h_( new holder_imp< T >( t ) ) {} + any(const any&) = delete; + any& operator=(const any&) = delete; ~any() { delete h_; diff --git a/test/bench_30_classes_30_methods_30_args_30_max_args.cpp b/test/bench_30_classes_30_methods_30_args_30_max_args.cpp index 7872dc2..d659f6c 100644 --- a/test/bench_30_classes_30_methods_30_args_30_max_args.cpp +++ b/test/bench_30_classes_30_methods_30_args_30_max_args.cpp @@ -17,7 +17,7 @@ namespace class base_class { public: - virtual ~base_class() {} + virtual ~base_class() = default; virtual void f1( int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int ) = 0; diff --git a/test/bench_30_classes_30_methods_9_args.cpp b/test/bench_30_classes_30_methods_9_args.cpp index 67d1b65..beb45bf 100644 --- a/test/bench_30_classes_30_methods_9_args.cpp +++ b/test/bench_30_classes_30_methods_9_args.cpp @@ -16,7 +16,7 @@ namespace class base_class { public: - virtual ~base_class() {} + virtual ~base_class() = default; virtual void f1( int, int, int, int, int, int, int, int, int ) = 0; virtual void f2( int, int, int, int, int, int, int, int, int ) = 0; virtual void f3( int, int, int, int, int, int, int, int, int ) = 0; diff --git a/test/bench_30_classes_30_methods_9_args_10_max_args.cpp b/test/bench_30_classes_30_methods_9_args_10_max_args.cpp index 61a553c..20dad20 100644 --- a/test/bench_30_classes_30_methods_9_args_10_max_args.cpp +++ b/test/bench_30_classes_30_methods_9_args_10_max_args.cpp @@ -17,7 +17,7 @@ namespace class base_class { public: - virtual ~base_class() {} + virtual ~base_class() = default; virtual void f1( int, int, int, int, int, int, int, int, int ) = 0; virtual void f2( int, int, int, int, int, int, int, int, int ) = 0; virtual void f3( int, int, int, int, int, int, int, int, int ) = 0; diff --git a/test/bench_30_classes_30_methods_9_args_20_max_args.cpp b/test/bench_30_classes_30_methods_9_args_20_max_args.cpp index fe442fa..e720691 100644 --- a/test/bench_30_classes_30_methods_9_args_20_max_args.cpp +++ b/test/bench_30_classes_30_methods_9_args_20_max_args.cpp @@ -17,7 +17,7 @@ namespace class base_class { public: - virtual ~base_class() {} + virtual ~base_class() = default; virtual void f1( int, int, int, int, int, int, int, int, int ) = 0; virtual void f2( int, int, int, int, int, int, int, int, int ) = 0; virtual void f3( int, int, int, int, int, int, int, int, int ) = 0; diff --git a/test/bench_30_classes_30_methods_9_args_30_max_args.cpp b/test/bench_30_classes_30_methods_9_args_30_max_args.cpp index 3f6e0af..68096ed 100644 --- a/test/bench_30_classes_30_methods_9_args_30_max_args.cpp +++ b/test/bench_30_classes_30_methods_9_args_30_max_args.cpp @@ -17,7 +17,7 @@ namespace class base_class { public: - virtual ~base_class() {} + virtual ~base_class() = default; virtual void f1( int, int, int, int, int, int, int, int, int ) = 0; virtual void f2( int, int, int, int, int, int, int, int, int ) = 0; virtual void f3( int, int, int, int, int, int, int, int, int ) = 0; diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index bf862f7..95b6d6e 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -289,10 +289,14 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_with_wrong_parameter_value_in namespace { - class my_interface : boost::noncopyable + class my_interface { public: - virtual ~my_interface() {} + my_interface() = default; + my_interface(const my_interface&) = delete; + my_interface& operator=(const my_interface&) = delete; + virtual ~my_interface() = default; + private: virtual void my_method() = 0; }; @@ -493,8 +497,7 @@ namespace { struct base { - virtual ~base() - {} + virtual ~base() = default; virtual void f() = 0; }; struct derived : base diff --git a/test/fail_ambiguous_mock_method.cpp b/test/fail_ambiguous_mock_method.cpp index 08148ce..d1c03de 100644 --- a/test/fail_ambiguous_mock_method.cpp +++ b/test/fail_ambiguous_mock_method.cpp @@ -12,7 +12,7 @@ namespace { struct my_base { - virtual ~my_base() {} + virtual ~my_base() = default; virtual void my_method() = 0; virtual void my_method( int ) = 0; }; diff --git a/test/fail_non_existing_base_class_method_in_mock_method.cpp b/test/fail_non_existing_base_class_method_in_mock_method.cpp index 0e50e73..b30c9ef 100644 --- a/test/fail_non_existing_base_class_method_in_mock_method.cpp +++ b/test/fail_non_existing_base_class_method_in_mock_method.cpp @@ -12,7 +12,7 @@ namespace { struct my_base { - virtual ~my_base() {} + virtual ~my_base() = default; }; MOCK_BASE_CLASS( my_class, my_base ) diff --git a/test/fail_number_of_arguments_greater_than_max_constant.cpp b/test/fail_number_of_arguments_greater_than_max_constant.cpp index 7a71272..4c59c70 100644 --- a/test/fail_number_of_arguments_greater_than_max_constant.cpp +++ b/test/fail_number_of_arguments_greater_than_max_constant.cpp @@ -14,7 +14,7 @@ namespace { struct my_base { - virtual ~my_base() {} + virtual ~my_base() = default; virtual void my_method( int, int, int, int, int, int, int, int, int, int ) = 0; }; diff --git a/test/fail_too_many_arguments_in_mock_method.cpp b/test/fail_too_many_arguments_in_mock_method.cpp index fa4ca01..7c08f7e 100644 --- a/test/fail_too_many_arguments_in_mock_method.cpp +++ b/test/fail_too_many_arguments_in_mock_method.cpp @@ -12,7 +12,7 @@ namespace { struct my_base { - virtual ~my_base() {} + virtual ~my_base() = default; virtual void my_method( int ) = 0; }; diff --git a/test/test_integration.cpp b/test/test_integration.cpp index 15e4a30..e09b99b 100644 --- a/test/test_integration.cpp +++ b/test/test_integration.cpp @@ -10,7 +10,6 @@ #include "undefined.hpp" #include #include -#include #include #include #include @@ -82,11 +81,13 @@ BOOST_FIXTURE_TEST_CASE( basic_mock_object_usage, mock_error_fixture ) namespace { - class my_ambiguited_interface : boost::noncopyable + class my_ambiguited_interface { public: - virtual ~my_ambiguited_interface() - {} + my_ambiguited_interface() = default; + my_ambiguited_interface(const my_ambiguited_interface&) = delete; + my_ambiguited_interface& operator=(const my_ambiguited_interface&) = delete; + virtual ~my_ambiguited_interface() = default; virtual void my_method() = 0; virtual void my_method( int ) = 0; }; @@ -108,11 +109,13 @@ BOOST_FIXTURE_TEST_CASE( mock_object_method_disambiguation, mock_error_fixture ) namespace { - class my_const_ambiguited_interface : boost::noncopyable + class my_const_ambiguited_interface { public: - virtual ~my_const_ambiguited_interface() - {} + my_const_ambiguited_interface() = default; + my_const_ambiguited_interface(const my_const_ambiguited_interface&) = delete; + my_const_ambiguited_interface& operator=(const my_const_ambiguited_interface&) = delete; + virtual ~my_const_ambiguited_interface() = default; virtual void my_method() = 0; virtual void my_method() const = 0; }; @@ -213,8 +216,7 @@ namespace template< typename T > struct my_template_base_class { - virtual ~my_template_base_class() - {} + virtual ~my_template_base_class() = default; virtual void my_method( T ) = 0; virtual void my_other_method() = 0; }; @@ -237,23 +239,27 @@ BOOST_FIXTURE_TEST_CASE( mocking_a_template_base_class_method_is_supported, mock namespace { - class my_observer : boost::noncopyable + class my_observer { public: - virtual ~my_observer() - {} + my_observer() = default; + my_observer(const my_observer&) = delete; + my_observer& operator=(const my_observer&) = delete; + virtual ~my_observer() = default; virtual void notify( int value ) = 0; }; - class my_manager : boost::noncopyable + class my_manager { public: - virtual ~my_manager() - {} + my_manager() = default; + my_manager(const my_manager&) = delete; + my_manager& operator=(const my_manager&) = delete; + virtual ~my_manager() = default; virtual my_observer& get_observer() const = 0; }; - class my_subject : boost::noncopyable + class my_subject { public: explicit my_subject( my_manager& f ) diff --git a/test/test_mock.cpp b/test/test_mock.cpp index 66ae929..516cd9b 100644 --- a/test/test_mock.cpp +++ b/test/test_mock.cpp @@ -360,8 +360,7 @@ namespace { struct base { - virtual ~base() - {} + virtual ~base() = default; virtual void m1() = 0; virtual void m10() const = 0; @@ -417,8 +416,7 @@ namespace stdcall { struct base { - virtual ~base() - {} + virtual ~base() = default; virtual void MOCK_STDCALL m1() = 0; };