From b491b465c7282e039583f6f92e11077cfc378e80 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 10 Sep 2020 23:15:22 -0400 Subject: [PATCH] style: clang-tidy: modernize-use-equals-default --- .clang-tidy | 1 + include/pybind11/attr.h | 5 +++-- include/pybind11/buffer_info.h | 2 +- include/pybind11/cast.h | 2 +- include/pybind11/detail/common.h | 2 +- include/pybind11/pybind11.h | 2 +- tests/test_class.cpp | 6 +++--- tests/test_copy_move.cpp | 4 ++-- tests/test_smart_ptr.cpp | 2 +- tests/test_virtual_functions.cpp | 6 +++--- 10 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 294a1902..75519bb9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -6,6 +6,7 @@ llvm-namespace-comment, modernize-use-override, readability-container-size-empty, modernize-use-using, +modernize-use-equals-default, ' HeaderFilterRegex: 'pybind11/.*h' diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index aedbf62f..d0a8b34b 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -40,8 +40,9 @@ struct sibling { handle value; sibling(const handle &value) : value(value.ptr()) /// Annotation indicating that a class derives from another given type template struct base { + PYBIND11_DEPRECATED("base() was deprecated in favor of specifying 'T' as a template argument to class_") - base() { } + base() { } // NOLINT(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute }; /// Keep patient alive while nurse lives @@ -61,7 +62,7 @@ struct metaclass { handle value; PYBIND11_DEPRECATED("py::metaclass() is no longer required. It's turned on by default now.") - metaclass() {} + metaclass() { } // NOLINT(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute /// Override pybind11's default metaclass explicit metaclass(handle value) : value(value) { } diff --git a/include/pybind11/buffer_info.h b/include/pybind11/buffer_info.h index 8349a46b..308be06a 100644 --- a/include/pybind11/buffer_info.h +++ b/include/pybind11/buffer_info.h @@ -24,7 +24,7 @@ struct buffer_info { std::vector strides; // Number of bytes between adjacent entries (for each per dimension) bool readonly = false; // flag to indicate if the underlying storage may be written to - buffer_info() { } + buffer_info() = default; buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim, detail::any_container shape_in, detail::any_container strides_in, bool readonly=false) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 85875e90..5ee12b82 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -220,7 +220,7 @@ struct value_and_holder { {} // Default constructor (used to signal a value-and-holder not found by get_value_and_holder()) - value_and_holder() {} + value_and_holder() = default; // Used for past-the-end iterator value_and_holder(size_t index) : index{index} {} diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 68036c73..0986521a 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -761,7 +761,7 @@ struct nodelete { template void operator()(T*) { } }; PYBIND11_NAMESPACE_BEGIN(detail) template struct overload_cast_impl { - constexpr overload_cast_impl() {} // MSVC 2015 needs this + constexpr overload_cast_impl() {}; // NOLINT(modernize-use-equals-default): MSVC 2015 needs this template constexpr auto operator()(Return (*pf)(Args...)) const noexcept diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index c6334fbb..5fce339f 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -55,7 +55,7 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) /// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object class cpp_function : public function { public: - cpp_function() { } + cpp_function() = default; cpp_function(std::nullptr_t) { } /// Construct a cpp_function from a vanilla function pointer diff --git a/tests/test_class.cpp b/tests/test_class.cpp index 4dd4941f..b0e3d3a4 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -103,7 +103,7 @@ TEST_SUBMODULE(class_, m) { BaseClass() = default; BaseClass(const BaseClass &) = default; BaseClass(BaseClass &&) = default; - virtual ~BaseClass() {} + virtual ~BaseClass() = default; }; struct DerivedClass1 : BaseClass { }; struct DerivedClass2 : BaseClass { }; @@ -353,7 +353,7 @@ TEST_SUBMODULE(class_, m) { // test_reentrant_implicit_conversion_failure // #1035: issue with runaway reentrant implicit conversion struct BogusImplicitConversion { - BogusImplicitConversion(const BogusImplicitConversion &) { } + BogusImplicitConversion(const BogusImplicitConversion &) = default; }; py::class_(m, "BogusImplicitConversion") @@ -407,7 +407,7 @@ TEST_SUBMODULE(class_, m) { py::class_(m, "IsNonFinalFinal", py::is_final()); struct PyPrintDestructor { - PyPrintDestructor() {} + PyPrintDestructor() = default; ~PyPrintDestructor() { py::print("Print from destructor"); } diff --git a/tests/test_copy_move.cpp b/tests/test_copy_move.cpp index 34f1c618..05d5c476 100644 --- a/tests/test_copy_move.cpp +++ b/tests/test_copy_move.cpp @@ -19,14 +19,14 @@ struct empty { }; struct lacking_copy_ctor : public empty { - lacking_copy_ctor() {} + lacking_copy_ctor() = default; lacking_copy_ctor(const lacking_copy_ctor& other) = delete; }; template <> lacking_copy_ctor empty::instance_ = {}; struct lacking_move_ctor : public empty { - lacking_move_ctor() {} + lacking_move_ctor() = default; lacking_move_ctor(const lacking_move_ctor& other) = delete; lacking_move_ctor(lacking_move_ctor&& other) = delete; }; diff --git a/tests/test_smart_ptr.cpp b/tests/test_smart_ptr.cpp index 512175e9..60c2e692 100644 --- a/tests/test_smart_ptr.cpp +++ b/tests/test_smart_ptr.cpp @@ -339,7 +339,7 @@ TEST_SUBMODULE(smart_ptr, m) { // test_shared_ptr_gc // #187: issue involving std::shared_ptr<> return value policy & garbage collection struct ElementBase { - virtual ~ElementBase() { } /* Force creation of virtual table */ + virtual ~ElementBase() = default; /* Force creation of virtual table */ ElementBase() = default; ElementBase(const ElementBase&) = delete; }; diff --git a/tests/test_virtual_functions.cpp b/tests/test_virtual_functions.cpp index 7a417561..baea1e57 100644 --- a/tests/test_virtual_functions.cpp +++ b/tests/test_virtual_functions.cpp @@ -129,7 +129,7 @@ private: class NCVirt { public: - virtual ~NCVirt() { } + virtual ~NCVirt() = default; NCVirt() = default; NCVirt(const NCVirt&) = delete; virtual NonCopyable get_noncopyable(int a, int b) { return NonCopyable(a, b); } @@ -227,7 +227,7 @@ TEST_SUBMODULE(virtual_functions, m) { struct A { A() = default; A(const A&) = delete; - virtual ~A() {} + virtual ~A() = default; virtual void f() { py::print("A.f()"); } }; @@ -255,7 +255,7 @@ TEST_SUBMODULE(virtual_functions, m) { struct A2 { A2() = default; A2(const A2&) = delete; - virtual ~A2() {} + virtual ~A2() = default; virtual void f() { py::print("A2.f()"); } };