diff --git a/tests/test_class_sh_basic.cpp b/tests/test_class_sh_basic.cpp index fb1de946e..4457aa819 100644 --- a/tests/test_class_sh_basic.cpp +++ b/tests/test_class_sh_basic.cpp @@ -14,7 +14,7 @@ struct atyp { // Short for "any type". atyp() : mtxt("DefaultConstructor") {} atyp(const std::string &mtxt_) : mtxt(mtxt_) {} atyp(const atyp &other) { mtxt = other.mtxt + "_CpCtor"; } - atyp(atyp &&other) { mtxt = other.mtxt + "_MvCtor"; } + atyp(atyp &&other) noexcept { mtxt = other.mtxt + "_MvCtor"; } }; struct uconsumer { // unique_ptr consumer @@ -37,7 +37,7 @@ atyp& rtrn_mref() { static atyp obj; obj.mtxt = "rtrn_mref"; return obj; } atyp const* rtrn_cptr() { return new atyp{"rtrn_cptr"}; } atyp* rtrn_mptr() { return new atyp{"rtrn_mptr"}; } -std::string pass_valu(atyp obj) { return "pass_valu:" + obj.mtxt; } +std::string pass_valu(atyp obj) { return "pass_valu:" + obj.mtxt; } // NOLINT std::string pass_cref(atyp const& obj) { return "pass_cref:" + obj.mtxt; } std::string pass_mref(atyp& obj) { return "pass_mref:" + obj.mtxt; } std::string pass_cptr(atyp const* obj) { return "pass_cptr:" + obj->mtxt; } @@ -46,8 +46,8 @@ std::string pass_mptr(atyp* obj) { return "pass_mptr:" + obj->mtxt; } std::shared_ptr rtrn_shmp() { return std::shared_ptr(new atyp{"rtrn_shmp"}); } std::shared_ptr rtrn_shcp() { return std::shared_ptr(new atyp{"rtrn_shcp"}); } -std::string pass_shmp(std::shared_ptr obj) { return "pass_shmp:" + obj->mtxt; } -std::string pass_shcp(std::shared_ptr obj) { return "pass_shcp:" + obj->mtxt; } +std::string pass_shmp(std::shared_ptr obj) { return "pass_shmp:" + obj->mtxt; } // NOLINT +std::string pass_shcp(std::shared_ptr obj) { return "pass_shcp:" + obj->mtxt; } // NOLINT std::unique_ptr rtrn_uqmp() { return std::unique_ptr(new atyp{"rtrn_uqmp"}); } std::unique_ptr rtrn_uqcp() { return std::unique_ptr(new atyp{"rtrn_uqcp"}); } @@ -77,7 +77,7 @@ const std::unique_ptr &unique_ptr_cref_roundtrip(const std::unique_ptr> stash; - void Add(std::shared_ptr obj) { stash.push_back(obj); } + void Add(const std::shared_ptr &obj) { stash.push_back(obj); } }; } // namespace class_sh_basic diff --git a/tests/test_class_sh_inheritance.cpp b/tests/test_class_sh_inheritance.cpp index 1c825d7f0..1ecb991e6 100644 --- a/tests/test_class_sh_inheritance.cpp +++ b/tests/test_class_sh_inheritance.cpp @@ -15,10 +15,10 @@ struct base_template { int base_id; // Some compilers complain about implicitly defined versions of some of the following: - base_template(const base_template &) = default; - base_template(base_template &&) = default; + base_template(const base_template &) = default; + base_template(base_template &&) noexcept = default; base_template &operator=(const base_template &) = default; - base_template &operator=(base_template &&) = default; + base_template &operator=(base_template &&) noexcept = default; }; using base = base_template<100>; @@ -37,8 +37,8 @@ inline int pass_cptr_drvd(drvd const *d) { return d->id() + 12; } inline std::shared_ptr rtrn_shmp_drvd() { return std::shared_ptr(new drvd); } inline std::shared_ptr rtrn_shmp_drvd_up_cast() { return std::shared_ptr(new drvd); } -inline int pass_shcp_base(std::shared_ptr b) { return b->id() + 21; } -inline int pass_shcp_drvd(std::shared_ptr d) { return d->id() + 22; } +inline int pass_shcp_base(const std::shared_ptr& b) { return b->id() + 21; } +inline int pass_shcp_drvd(const std::shared_ptr& d) { return d->id() + 22; } // clang-format on using base1 = base_template<110>; diff --git a/tests/test_class_sh_trampoline_basic.cpp b/tests/test_class_sh_trampoline_basic.cpp index 935dafd94..48351c153 100644 --- a/tests/test_class_sh_trampoline_basic.cpp +++ b/tests/test_class_sh_trampoline_basic.cpp @@ -16,10 +16,10 @@ struct Abase { virtual int Add(int other_val) const = 0; // Some compilers complain about implicitly defined versions of some of the following: - Abase(const Abase &) = default; - Abase(Abase &&) = default; + Abase(const Abase &) = default; + Abase(Abase &&) noexcept = default; Abase &operator=(const Abase &) = default; - Abase &operator=(Abase &&) = default; + Abase &operator=(Abase &&) noexcept = default; }; template diff --git a/tests/test_class_sh_trampoline_self_life_support.cpp b/tests/test_class_sh_trampoline_self_life_support.cpp index ddbceaad4..ffcea710f 100644 --- a/tests/test_class_sh_trampoline_self_life_support.cpp +++ b/tests/test_class_sh_trampoline_self_life_support.cpp @@ -8,24 +8,25 @@ #include #include +#include namespace { struct Big5 { // Also known as "rule of five". std::string history; - explicit Big5(std::string history_start) : history{history_start} {} + explicit Big5(std::string history_start) : history{std::move(history_start)} {} Big5(const Big5 &other) { history = other.history + "_CpCtor"; } - Big5(Big5 &&other) { history = other.history + "_MvCtor"; } + Big5(Big5 &&other) noexcept { history = other.history + "_MvCtor"; } Big5 &operator=(const Big5 &other) { history = other.history + "_OpEqLv"; return *this; } - Big5 &operator=(Big5 &&other) { + Big5 &operator=(Big5 &&other) noexcept { history = other.history + "_OpEqRv"; return *this; } diff --git a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp index b6e2517b4..41dace8e2 100644 --- a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp +++ b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp @@ -2,8 +2,10 @@ // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include "pybind11_tests.h" +#include + #include "pybind11/smart_holder.h" +#include "pybind11_tests.h" namespace { @@ -16,7 +18,7 @@ struct SpBase { // returns true if there's an associated python instance bool has_python_instance() { auto tinfo = py::detail::get_type_info(typeid(SpBase)); - return (bool)py::detail::get_object_handle(this, tinfo); + return (bool) py::detail::get_object_handle(this, tinfo); } SpBase() = default; @@ -30,13 +32,11 @@ struct PySpBase : SpBase { struct SpBaseTester { std::shared_ptr get_object() const { return m_obj; } - void set_object(std::shared_ptr obj) { m_obj = obj; } + void set_object(std::shared_ptr obj) { m_obj = std::move(obj); } bool is_base_used() { return m_obj->is_base_used(); } - bool has_instance() { return (bool)m_obj; } + bool has_instance() { return (bool) m_obj; } bool has_python_instance() { return m_obj && m_obj->has_python_instance(); } - void set_nonpython_instance() { - m_obj = std::make_shared(); - } + void set_nonpython_instance() { m_obj = std::make_shared(); } std::shared_ptr m_obj; };