mercredi 29 novembre 2017

Does std::is_constructible work with arguments that are convertible to parameters?

Does std::is_constructible<T, Arg1> work if Arg1 is a type that is convertible to a valid one-parameter constructor for T? It appears to work when the type has a non-templated conversion operator, but does not work (under some compilers) if the conversion operator is templated.

In the below example, the final static_assert fails under GCC 7.2 and clang 5.0, but passes under MSVC 19. Is there undefined behavior in here, or is one of the compilers misbehaving?

#include <type_traits>

struct foo
{
    foo(int) {}
    foo(int, int) {}
};

struct converts
{
    template <class T>
    operator T(){}
};

int main()
{
    // These compile
    foo f1(converts());
    foo f2(converts(), converts());
    static_assert(std::is_constructible<foo, converts, converts>::value, "foo(converts(), converts())");
    // This line doesn't
    static_assert(std::is_constructible<foo, converts>::value, "foo(converts())");
}

Live example: http://ift.tt/2AISDrp

Aucun commentaire:

Enregistrer un commentaire