Skip to content

Commit f77da1e

Browse files
committed
Undo PR pybind#5718 production code changes only, keep added test.
1 parent f8640da commit f77da1e

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

include/pybind11/detail/init.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class type_caster<value_and_holder> {
3737

3838
PYBIND11_NAMESPACE_BEGIN(initimpl)
3939

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

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

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

0 commit comments

Comments
 (0)