https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66893
Bug ID: 66893 Summary: disallowed initialization of reference with user-defined conversion function Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- Consider the following: struct B {}; struct S { explicit operator B(); }; int main() { B const &t(S{}); } According to [over.match.ref]: Those non-explicit conversion functions that are not hidden within S and yield type “lvalue reference to cv2 T2” (when initializing an lvalue reference or an rvalue reference to function) or “cv2 T2” or “rvalue reference to cv2 T2” (when initializing an rvalue reference or an lvalue reference to function), where “cv1 T” is reference-compatible (8.5.3) with “cv2 T2”, are candidate functions. In this case, B const (cv1 T) is reference-compatible with B (cv2 T2), so the operator should be a candidate function. However, gcc rejects it: main.cpp: In function 'int main()': main.cpp:5:19: error: invalid initialization of reference of type 'const B&' from expression of type 'S' B const &t(S{}); ^