vendredi 26 août 2016

tuple of references with conversion operators, g++ 5.x vs g++ 6.x

Given the following minimal example, g++ 5.4 compiles without complaining, but g++ 6.1 doesn't find a matching constructor for the tuple. Which compiler is correct?

#include <tuple>
#include <utility>

struct derived;
struct base
{
    operator derived & () &;
    operator derived const & () const &;
    operator derived && () &&;
};

struct derived : base {};

base::operator derived & () & { return *static_cast<derived *>(this); }
base::operator derived const & () const & { return *static_cast<derived const *>(this); }
base::operator derived && () && { return std::move(*static_cast<derived *>(this)); }

std::tuple<derived &&> test(base && b)
{
    return std::tuple<derived &&>(std::move(b));
}

int main(int,char**)
{
    auto d = test(derived{});
    return 0;
}

The base class provides an implicit conversion operator, so it should work as far as I can tell. If I change test to the following, neither compiler complains:

std::tuple<derived &&> test(base && b)
{
    return std::tuple<derived &&>(static_cast<derived &&>(std::move(b)));
}

Aucun commentaire:

Enregistrer un commentaire