• Ben North's avatar
    Fix wrapper's 'value' and 'owned' if ctor missing · 24a2054d
    Ben North authored
    type_caster_generic::cast(): The values of
    
        wrapper->value
        wrapper->owned
    
    are incorrect in the case that a return value policy of 'copy' is
    requested but there is no copy-constructor.  (Similarly 'move'.)  In
    particular, if the source object is a static instance, the destructor of
    the 'object' 'inst' leads to class_::dealloc() which incorrectly
    attempts to 'delete' the static instance.
    
    This commit re-arranges the code to be clearer as to what the values of
    'value' and 'owned' should be in the various cases.  Behaviour is
    different to previous code only in two situations:
    
    policy = copy but no copy-ctor: Old code leaves 'value = src, owned =
    true', which leads to trouble.  New code leaves 'value = nullptr, owned
    = false', which is correct.
    
    policy = move but no move- or copy-ctor: old code leaves 'value = src,
    owned = true', which leads to trouble.  New code leaves 'value =
    nullptr, owned = false', which is correct.
    24a2054d
cast.h 52.4 KB