Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

bond::is_writer does not work for derived types if they don't implement WriteStructBegin #896

Closed
biocomp opened this issue May 14, 2018 · 3 comments
Assignees
Labels

Comments

@biocomp
Copy link
Contributor

biocomp commented May 14, 2018

Repro (I copied check_method and is_writer from bond's headers): https://godbolt.org/g/2F76N9

The way is_writer works - it tries to assign member function pointer from T::WriteStructBegin. When derived class relies on base's WriteStructBegin, this fails because it tries to assign base's pointer to member function to derived one.

I'm also guessing is_writer is not the only problem.

Copy of repro above:

#include <type_traits>
#include <boost/type_traits.hpp>

struct Metadata
{};

struct Base
{
    void WriteStructBegin(const Metadata&, bool) {}
};

struct Derived : Base {};

template <typename T, T> struct 
check_method
    : std::true_type {};

template <typename T, typename Enable = void> struct
is_writer
    : std::false_type {};

template <typename T> struct
is_writer<T, typename boost::enable_if<check_method<void (T::*)(const Metadata&, bool), &T::WriteStructBegin>>::type>
     : std::true_type {};

int main()
{
    static_assert(is_writer<Base>::value, "!Base is writer");
    static_assert(is_writer<Derived>::value, "!Derived is writer"); // Fails
}
@ara-ayvazyan ara-ayvazyan self-assigned this May 14, 2018
@chwarr
Copy link
Member

chwarr commented May 14, 2018

Is there a deeper problem that this is causing? We need to know that to make sure that the fix addresses the core problem too.

Are you, for example, hitting the static assert in the Serialization transform?

As a work around, try adding an explicit specialization of is_writer for your derived type:

template <> struct
is_writer<Derived> : std::true_type {};

@biocomp
Copy link
Contributor Author

biocomp commented May 14, 2018

Yes, this was exaclty the issue - I hit that assert. And yes, I did figure out this workaround, or I can just implement the method in derived class too. I just filed the issue that future users won't have to suffer :)

@chwarr
Copy link
Member

chwarr commented May 14, 2018

Thanks for confirming it was the static assert. We'll make sure the fix actually fixes that case.

chwarr pushed a commit that referenced this issue May 16, 2018
The use of `bond::check_method` has been replaced with less restricting expression
SFINAE checks on supported compilers. 

Fixes #896
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants