This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/67631] New: brace initialization bug
- From: "howard.hinnant at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 18 Sep 2015 20:51:59 +0000
- Subject: [Bug c++/67631] New: brace initialization bug
- Auto-submitted: auto-generated
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};
^