Skip to content

Experiment: Undo PR #5718 production code changes only, keep added test. #5724

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions include/pybind11/detail/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class type_caster<value_and_holder> {

PYBIND11_NAMESPACE_BEGIN(initimpl)

inline void no_nullptr(const void *ptr) {
inline void no_nullptr(void *ptr) {
if (!ptr) {
throw type_error("pybind11::init(): factory function returned nullptr");
}
Expand All @@ -61,7 +61,7 @@ bool is_alias(Cpp<Class> *ptr) {
}
// Failing fallback version of the above for a no-alias class (always returns false)
template <typename /*Class*/>
constexpr bool is_alias(const void *) {
constexpr bool is_alias(void *) {
return false;
}

Expand Down Expand Up @@ -167,12 +167,7 @@ void construct(value_and_holder &v_h, Holder<Class> holder, bool need_alias) {
"is not an alias instance");
}

// Cast away constness to store in void* storage.
// The value_and_holder storage is fundamentally untyped (void**), so we lose
// const-correctness here by design. The const qualifier will be restored
// when the pointer is later retrieved and cast back to the original type.
// This explicit const_cast makes the const-removal clearly visible.
v_h.value_ptr() = const_cast<void *>(static_cast<const void *>(ptr));
v_h.value_ptr() = ptr;
v_h.type->init_instance(v_h.inst, &holder);
}

Expand Down
Loading