[Bug c++/80691] Narrowing conversion in {} allowed in a SFINAE context

griwes at griwes dot info gcc-bugzilla@gcc.gnu.org
Tue May 9 15:13:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80691

--- Comment #1 from Michał Dominiak <griwes at griwes dot info> ---
This bug makes it seem (in SFINAE contexts) that std::string is constructible
from double with an initializer-list constructor, without narrowing:

#include <string>
#include <type_traits>

using std::void_t;

template<typename T, typename U, typename = void>
struct is_nonnarrowing_conversion : std::false_type {};

template<typename T, typename U>
struct is_nonnarrowing_conversion<T, U,
    void_t<decltype(T{ std::declval<U>() })>> : std::true_type {};

static_assert(!is_nonnarrowing_conversion<std::string, double>());


More information about the Gcc-bugs mailing list