Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

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

@biocomp

Description

@biocomp

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
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions