billyquith / ponder

C++ reflection library with Lua binding, and JSON and XML serialisation.
http://billyquith.github.io/ponder/
Other
642 stars 95 forks source link

static_cast causes runtime exception when using virtual inheritance #20

Closed Weeena closed 8 years ago

Weeena commented 8 years ago

If some class B is virtually derived from some class A

    class B : public virtual A

and class B is declared for ponder like

    ponder::Class::declare<B>("B")
        .base<A>()
        ...

a runtime exception is caused. It is caused in classbuilder.inl, where the offset to apply for pointer conversions is computed. There, the value (1) is tried to be cast to the base class. In our environment, this leads at runtime to an "access violation reading location 0x00000001". Our environment: MS VS2015. Code line where the exception occurs:

U* asBase = static_cast<U*>(asDerived);

As a side note: Actually, we do not need virtual inheritence. Hence, the above problem fortunately does not really affect us. Once we recognized the problem, we just omitted the virtual inheritence.

billyquith commented 8 years ago

Hmm. Now only fails on Windows debug 32/64.

billyquith commented 8 years ago

Currently choosing not to support virtual inheritance since it is used so infrequently. This is a tricky problem to solve and may be revisited should the need arise.