Skip to content

Fail to compile after [419877cf] commit (Added -Wconversion support for C++.) #777

@gviolator

Description

@gviolator

I see there is fixes for correct type cast.

Previously within pack.hpp was declaraion:

void append_buffer(const char* buf, size_t len)
    { m_stream.write(buf, len); }

Now there is couple of compile time overloads to respect valid type cast when len parameter is not size_t. But, what if method ::write has overloads ? In this case &Stream::write will not be compiled (because compiler has ambiguity).

I have class Writer with 'primary' write method

virtual void write(const std::byte*, size_t size) = 0;

and second 'utility' method:

void write(const char* bytes, size_t size)
{
	write(reinterpret_cast<const std::byte*>(bytes), size);
}

Second method introduced especially to using with msgpack-c, but for first parameter compatibility. As temporary solution i remove second 'utility' method from my Writer class and 'fix' pack.hpp as

void append_buffer(const char* buf, size_t len)
{
    append_buffer(m_stream, &Stream::write, buf, len);
}

template<typename S, typename R, typename Ptr, typename Size>
static void append_buffer(S& s, R (S::*) (Ptr, Size), const char* buf, size_t len)
{
  s.write(reinterpret_cast<Ptr>(buf), static_cast<Size>(len));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions