mercredi 12 décembre 2018

c++11 invoke a type conversion while moving moving an object

I have a simple code, I compiled the code on GCC 5, 6, and 8 and deployed it to a physical testbed that uses gcc 4.8.3 for some reason, the code fails to compile on the testbed (ubuntu 14.04), I have been scratching my head to figure out what the problem is, but so far nothing. I copied the code below,

#include <memory>
#include <utility>

struct probe_payload
{
    int id{0};
    int sub_id{0};
    int snd_ts{0};
    int rcv_ts{0};
    int rtt_ms{1000};
    double snd_bw_bps{0};
    bool end_flag{false};
};

struct probe_message
{
  public:
    using buffer_t = typename std::add_pointer<typename std::add_const<void>::type>::type;

    probe_payload info;
    char shim[1280];

};

template<typename Packet>
struct parcel
{
    explicit parcel(Packet&& object, int ts) : item{std::move(object)}
    {
        arrival_time = std::move(ts);
    }

    parcel() = delete;
    parcel(const parcel<Packet>& /* other */) = default;
    parcel<Packet>& operator=(const parcel<Packet>& /* other */) = default;
    parcel(parcel<Packet>&& /* other */) = default;
    parcel<Packet>& operator=(parcel<Packet>&& /* other */) = default;

    Packet item;
    int arrival_time{0};
};


template <typename T>
parcel<T> get_parcel()
{
    T a;
    return parcel<T>{std::move(a), 10};
}


int main()
{
    auto p = get_parcel<probe_message>();
    return p.arrival_time;
}

: In instantiation of 'parcel::parcel(Packet&&, int) [with Packet = probe_message]':

:48:38: required from 'parcel get_parcel() [with T = probe_message]'

:54:40: required from here

:28:67: error: could not convert 'std::move((* & object))' from 'std::remove_reference::type {aka probe_message}' to 'probe_payload'

explicit parcel(Packet&& object, int ts) : item{std::move(object)}

I've attached the link from compiler explorer.

Aucun commentaire:

Enregistrer un commentaire