mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250)
* Adding google-explicit-constructor to .clang-tidy * clang-tidy explicit attr.h (all automatic) * clang-tidy explicit cast.h (all automatic) * clang-tidy detail/init.h (1 NOLINT) * clang-tidy detail/type_caster_base.h (2 NOLINT) * clang-tidy pybind11.h (7 NOLINT) * clang-tidy detail/common.h (3 NOLINT) * clang-tidy detail/descr.h (2 NOLINT) * clang-tidy pytypes.h (23 NOLINT, only 1 explicit) * clang-tidy eigen.h (7 NOLINT, 0 explicit) * Adding 2 explicit in functional.h * Adding 4 explicit in iostream.h * clang-tidy numpy.h (1 NOLINT, 1 explicit) * clang-tidy embed.h (0 NOLINT, 1 explicit) * clang-tidy tests/local_bindings.h (0 NOLINT, 4 explicit) * clang-tidy tests/pybind11_cross_module_tests.cpp (0 NOLINT, 1 explicit) * clang-tidy tests/pybind11_tests.h (0 NOLINT, 2 explicit) * clang-tidy tests/test_buffers.cpp (0 NOLINT, 2 explicit) * clang-tidy tests/test_builtin_casters.cpp (0 NOLINT, 4 explicit) * clang-tidy tests/test_class.cpp (0 NOLINT, 6 explicit) * clang-tidy tests/test_copy_move.cpp (0 NOLINT, 7 explicit) * clang-tidy tests/test_embed/external_module.cpp (0 NOLINT, 1 explicit) * clang-tidy tests/test_embed/test_interpreter.cpp (0 NOLINT, 1 explicit) * clang-tidy tests/object.h (0 NOLINT, 2 explicit) * clang-tidy batch of fully automatic fixes. * Workaround for MSVC 19.16.27045.0 C++17 Python 2 C++ syntax error.
This commit is contained in:
committed by
GitHub
parent
39a0aac88e
commit
6abf2baa62
@@ -24,7 +24,7 @@ template <typename T> class huge_unique_ptr {
|
||||
std::unique_ptr<T> ptr;
|
||||
uint64_t padding[10];
|
||||
public:
|
||||
huge_unique_ptr(T *p) : ptr(p) {}
|
||||
explicit huge_unique_ptr(T *p) : ptr(p) {}
|
||||
T *get() { return ptr.get(); }
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ template <typename T>
|
||||
class custom_unique_ptr {
|
||||
std::unique_ptr<T> impl;
|
||||
public:
|
||||
custom_unique_ptr(T* p) : impl(p) { }
|
||||
explicit custom_unique_ptr(T *p) : impl(p) {}
|
||||
T* get() const { return impl.get(); }
|
||||
T* release_ptr() { return impl.release(); }
|
||||
};
|
||||
@@ -46,7 +46,7 @@ class shared_ptr_with_addressof_operator {
|
||||
std::shared_ptr<T> impl;
|
||||
public:
|
||||
shared_ptr_with_addressof_operator( ) = default;
|
||||
shared_ptr_with_addressof_operator(T* p) : impl(p) { }
|
||||
explicit shared_ptr_with_addressof_operator(T *p) : impl(p) {}
|
||||
T* get() const { return impl.get(); }
|
||||
T** operator&() { throw std::logic_error("Call of overloaded operator& is not expected"); }
|
||||
};
|
||||
@@ -59,7 +59,7 @@ class unique_ptr_with_addressof_operator {
|
||||
std::unique_ptr<T> impl;
|
||||
public:
|
||||
unique_ptr_with_addressof_operator() = default;
|
||||
unique_ptr_with_addressof_operator(T* p) : impl(p) { }
|
||||
explicit unique_ptr_with_addressof_operator(T *p) : impl(p) {}
|
||||
T* get() const { return impl.get(); }
|
||||
T* release_ptr() { return impl.release(); }
|
||||
T** operator&() { throw std::logic_error("Call of overloaded operator& is not expected"); }
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
// Custom object with builtin reference counting (see 'object.h' for the implementation)
|
||||
class MyObject1 : public Object {
|
||||
public:
|
||||
MyObject1(int value) : value(value) { print_created(this, toString()); }
|
||||
explicit MyObject1(int value) : value(value) { print_created(this, toString()); }
|
||||
std::string toString() const override { return "MyObject1[" + std::to_string(value) + "]"; }
|
||||
protected:
|
||||
~MyObject1() override { print_destroyed(this); }
|
||||
@@ -80,7 +80,7 @@ private:
|
||||
class MyObject2 {
|
||||
public:
|
||||
MyObject2(const MyObject2 &) = default;
|
||||
MyObject2(int value) : value(value) { print_created(this, toString()); }
|
||||
explicit MyObject2(int value) : value(value) { print_created(this, toString()); }
|
||||
std::string toString() const { return "MyObject2[" + std::to_string(value) + "]"; }
|
||||
virtual ~MyObject2() { print_destroyed(this); }
|
||||
private:
|
||||
@@ -91,7 +91,7 @@ private:
|
||||
class MyObject3 : public std::enable_shared_from_this<MyObject3> {
|
||||
public:
|
||||
MyObject3(const MyObject3 &) = default;
|
||||
MyObject3(int value) : value(value) { print_created(this, toString()); }
|
||||
explicit MyObject3(int value) : value(value) { print_created(this, toString()); }
|
||||
std::string toString() const { return "MyObject3[" + std::to_string(value) + "]"; }
|
||||
virtual ~MyObject3() { print_destroyed(this); }
|
||||
private:
|
||||
@@ -104,7 +104,7 @@ class MyObject4;
|
||||
std::unordered_set<MyObject4 *> myobject4_instances;
|
||||
class MyObject4 {
|
||||
public:
|
||||
MyObject4(int value) : value{value} {
|
||||
explicit MyObject4(int value) : value{value} {
|
||||
print_created(this);
|
||||
myobject4_instances.insert(this);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class MyObject4a;
|
||||
std::unordered_set<MyObject4a *> myobject4a_instances;
|
||||
class MyObject4a {
|
||||
public:
|
||||
MyObject4a(int i) {
|
||||
explicit MyObject4a(int i) {
|
||||
value = i;
|
||||
print_created(this);
|
||||
myobject4a_instances.insert(this);
|
||||
@@ -153,14 +153,14 @@ protected:
|
||||
// Object derived but with public destructor and no Deleter in default holder
|
||||
class MyObject4b : public MyObject4a {
|
||||
public:
|
||||
MyObject4b(int i) : MyObject4a(i) { print_created(this); }
|
||||
explicit MyObject4b(int i) : MyObject4a(i) { print_created(this); }
|
||||
~MyObject4b() override { print_destroyed(this); }
|
||||
};
|
||||
|
||||
// test_large_holder
|
||||
class MyObject5 { // managed by huge_unique_ptr
|
||||
public:
|
||||
MyObject5(int value) : value{value} { print_created(this); }
|
||||
explicit MyObject5(int value) : value{value} { print_created(this); }
|
||||
~MyObject5() { print_destroyed(this); }
|
||||
int value;
|
||||
};
|
||||
@@ -222,7 +222,7 @@ struct TypeForHolderWithAddressOf {
|
||||
|
||||
// test_move_only_holder_with_addressof_operator
|
||||
struct TypeForMoveOnlyHolderWithAddressOf {
|
||||
TypeForMoveOnlyHolderWithAddressOf(int value) : value{value} { print_created(this); }
|
||||
explicit TypeForMoveOnlyHolderWithAddressOf(int value) : value{value} { print_created(this); }
|
||||
~TypeForMoveOnlyHolderWithAddressOf() { print_destroyed(this); }
|
||||
std::string toString() const {
|
||||
return "MoveOnlyHolderWithAddressOf[" + std::to_string(value) + "]";
|
||||
@@ -242,7 +242,7 @@ struct ElementBase {
|
||||
};
|
||||
|
||||
struct ElementA : ElementBase {
|
||||
ElementA(int v) : v(v) { }
|
||||
explicit ElementA(int v) : v(v) {}
|
||||
int value() const { return v; }
|
||||
int v;
|
||||
};
|
||||
@@ -291,9 +291,9 @@ TEST_SUBMODULE(smart_ptr, m) {
|
||||
py::implicitly_convertible<py::int_, MyObject1>();
|
||||
|
||||
m.def("make_object_1", []() -> Object * { return new MyObject1(1); });
|
||||
m.def("make_object_2", []() -> ref<Object> { return new MyObject1(2); });
|
||||
m.def("make_object_2", []() -> ref<Object> { return ref<Object>(new MyObject1(2)); });
|
||||
m.def("make_myobject1_1", []() -> MyObject1 * { return new MyObject1(4); });
|
||||
m.def("make_myobject1_2", []() -> ref<MyObject1> { return new MyObject1(5); });
|
||||
m.def("make_myobject1_2", []() -> ref<MyObject1> { return ref<MyObject1>(new MyObject1(5)); });
|
||||
m.def("print_object_1", [](const Object *obj) { py::print(obj->toString()); });
|
||||
m.def("print_object_2", [](ref<Object> obj) { py::print(obj->toString()); });
|
||||
m.def("print_object_3", [](const ref<Object> &obj) { py::print(obj->toString()); });
|
||||
@@ -328,7 +328,7 @@ TEST_SUBMODULE(smart_ptr, m) {
|
||||
|
||||
// test_smart_ptr_refcounting
|
||||
m.def("test_object1_refcounting", []() {
|
||||
ref<MyObject1> o = new MyObject1(0);
|
||||
auto o = ref<MyObject1>(new MyObject1(0));
|
||||
bool good = o->getRefCount() == 1;
|
||||
py::object o2 = py::cast(o, py::return_value_policy::reference);
|
||||
// always request (partial) ownership for objects with intrusive
|
||||
|
||||
Reference in New Issue
Block a user