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++/67631] New: brace initialization bug


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

            Bug ID: 67631
           Summary: brace initialization bug
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: howard.hinnant at gmail dot com
  Target Milestone: ---

I expect this program to compile and not assert when run:

#include <cassert>

template <class T, class U>
void
test(const U& uo)
{
    T t{uo};
    U u{t};
    assert(u == uo);
    t = T{uo};
    u = U{t};
    assert(u == uo);
}

class X
{
    unsigned char data_;
public:
    explicit X(unsigned data)
        : data_(data)
        {}

    explicit operator unsigned() const {return data_;}

    friend bool operator==(const X& x, const X& y)
    {
        return x.data_ == y.data_;
    }
};

int
main()
{
    test<unsigned>(X{3});
}

I get:

prog.cc: In instantiation of 'void test(const U&) [with T = unsigned int; U =
X]':
prog.cc:34:24:   required from here
prog.cc:10:7: error: cannot convert 'const X' to 'unsigned int' in
initialization
     t = T{uo};
       ^


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