mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-12 01:10:34 +00:00
Use std::addressof to obtain holder address instead of operator&
This commit is contained in:
committed by
Jason Rhinelander
parent
9b02856293
commit
e3cb2a674a
@@ -1423,7 +1423,7 @@ public:
|
||||
|
||||
explicit operator type*() { return this->value; }
|
||||
explicit operator type&() { return *(this->value); }
|
||||
explicit operator holder_type*() { return &holder; }
|
||||
explicit operator holder_type*() { return std::addressof(holder); }
|
||||
|
||||
// Workaround for Intel compiler bug
|
||||
// see pybind11 issue 94
|
||||
@@ -1493,7 +1493,7 @@ struct move_only_holder_caster {
|
||||
|
||||
static handle cast(holder_type &&src, return_value_policy, handle) {
|
||||
auto *ptr = holder_helper<holder_type>::get(src);
|
||||
return type_caster_base<type>::cast_holder(ptr, &src);
|
||||
return type_caster_base<type>::cast_holder(ptr, std::addressof(src));
|
||||
}
|
||||
static constexpr auto name = type_caster_base<type>::name;
|
||||
};
|
||||
|
||||
@@ -1271,25 +1271,25 @@ private:
|
||||
auto sh = std::dynamic_pointer_cast<typename holder_type::element_type>(
|
||||
v_h.value_ptr<type>()->shared_from_this());
|
||||
if (sh) {
|
||||
new (&v_h.holder<holder_type>()) holder_type(std::move(sh));
|
||||
new (std::addressof(v_h.holder<holder_type>())) holder_type(std::move(sh));
|
||||
v_h.set_holder_constructed();
|
||||
}
|
||||
} catch (const std::bad_weak_ptr &) {}
|
||||
|
||||
if (!v_h.holder_constructed() && inst->owned) {
|
||||
new (&v_h.holder<holder_type>()) holder_type(v_h.value_ptr<type>());
|
||||
new (std::addressof(v_h.holder<holder_type>())) holder_type(v_h.value_ptr<type>());
|
||||
v_h.set_holder_constructed();
|
||||
}
|
||||
}
|
||||
|
||||
static void init_holder_from_existing(const detail::value_and_holder &v_h,
|
||||
const holder_type *holder_ptr, std::true_type /*is_copy_constructible*/) {
|
||||
new (&v_h.holder<holder_type>()) holder_type(*reinterpret_cast<const holder_type *>(holder_ptr));
|
||||
new (std::addressof(v_h.holder<holder_type>())) holder_type(*reinterpret_cast<const holder_type *>(holder_ptr));
|
||||
}
|
||||
|
||||
static void init_holder_from_existing(const detail::value_and_holder &v_h,
|
||||
const holder_type *holder_ptr, std::false_type /*is_copy_constructible*/) {
|
||||
new (&v_h.holder<holder_type>()) holder_type(std::move(*const_cast<holder_type *>(holder_ptr)));
|
||||
new (std::addressof(v_h.holder<holder_type>())) holder_type(std::move(*const_cast<holder_type *>(holder_ptr)));
|
||||
}
|
||||
|
||||
/// Initialize holder object, variant 2: try to construct from existing holder object, if possible
|
||||
@@ -1299,7 +1299,7 @@ private:
|
||||
init_holder_from_existing(v_h, holder_ptr, std::is_copy_constructible<holder_type>());
|
||||
v_h.set_holder_constructed();
|
||||
} else if (inst->owned || detail::always_construct_holder<holder_type>::value) {
|
||||
new (&v_h.holder<holder_type>()) holder_type(v_h.value_ptr<type>());
|
||||
new (std::addressof(v_h.holder<holder_type>())) holder_type(v_h.value_ptr<type>());
|
||||
v_h.set_holder_constructed();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user