This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

            Bug ID: 80691
           Summary: Narrowing conversion in {} allowed in a SFINAE context
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: griwes at griwes dot info
  Target Milestone: ---

There seems to be a regression in GCC 7.1 in how the compiler treats narrowing
conversions in braced initialization, when using a user-provided constructor
for a type. The following code compiles with GCC 6.3 and several recent
versions of Clang (and some older too, if you implement void_t yourself), but
the second static_assert fails on GCC 7.1.

#include <utility>
#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 {};

template<typename T>
class wrapper
{
public:
    wrapper(T) {}
};

static_assert(!is_nonnarrowing_conversion<int, float>());
static_assert(!is_nonnarrowing_conversion<wrapper<int>, float>());

As I read it, this explicitly violates [dcl.init.list]3.6
(http://eel.is/c++draft/dcl.init.list#3.6).

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]