shared_ptr branch: every OuterClass<InnerClass> is threated as Shared_pointer_class

Issue #1 resolved
Renan Inácio
created an issue

I understand shared_ptr is still a work in progress, but I found no tests, emails or documentation about this issue, so maybe nobody is yet aware of this.

There is a situation where the code seems to assume that every struct with 1 template argument is a shared pointer, for instance:

template <typename T>
struct NotSharedPtr {};

namespace OOLUA { 
    typedef NotSharedPtr<int> NotSharedPtrInt;
}

struct Foo {
    OOLUA::NotSharedPtrInt* f() { return 0; }
    OOLUA::NotSharedPtrInt& g() { return *(OOLUA::NotSharedPtrInt*)0; }
    OOLUA::NotSharedPtrInt h() { return OOLUA::NotSharedPtrInt(); }
};

OOLUA_PROXY(NotSharedPtrInt)
OOLUA_PROXY_END

OOLUA_PROXY(Foo)
    OOLUA_MFUNC(f) // FAIL
    OOLUA_MFUNC(g) // FAIL
    OOLUA_MFUNC(h) // OK
OOLUA_PROXY_END

Apparently the error is caused by fixup_pointer, because it matches the following declaration:

Ptr_type* fixup_pointer(Lua_ud* ud, Shared_pointer_class<Ptr_type> const* shared) 

I'm not sure if this is the correct way to fix this issue, but I'm attaching a patch that seems to work for me. It uses C++11's std::enable_if, but it's trivial to implement it for C++98 (see http://en.cppreference.com/w/cpp/types/enable_if)

Comments (4)

  1. Liam Devine repo owner

    Thanks for reporting this and the proposed patch. I am a little hesitant to apply the patch until I have looked at where else this problem may be present.

  2. Log in to comment