Mayur Pandey
2013-Sep-24 06:43 UTC
[LLVMdev] initialization list with conversion operator dont work properly and report error
for the following code: struct X { X(); }; struct Y { operator X() const; }; X a = { Y() }; // reports error: no matching constructor for initialization of 'X' X aa = Y(); // works fine clang when compiled with std=c++11 gives compilation errors as: testfile.C:11:3: error: no matching constructor for initialization of 'X' X a = { Y() }; // reports error: no matching constructor for initialization of 'X' ^ ~~~~~~~ testfile.C:1:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'Y' to 'const X &' for 1st argument struct X ^ testfile.C:1:8: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'Y' to 'X &&' for 1st argument struct X ^ testfile.C:3:3: note: candidate constructor not viable: requires 0 arguments, but 1 was provided X(); ^ 1 error generated. -- Thanx & Regards *Mayur Pandey * +91-9742959541 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130924/86017a0b/attachment.html>
Eli Friedman
2013-Sep-24 23:59 UTC
[LLVMdev] initialization list with conversion operator dont work properly and report error
On Mon, Sep 23, 2013 at 11:43 PM, Mayur Pandey <mayurthebond at gmail.com>wrote:> for the following code: > > struct X > { > X(); > }; > > struct Y > { > operator X() const; > }; > > X a = { Y() }; // reports error: no matching constructor for > initialization of 'X' > X aa = Y(); // works fine > > > clang when compiled with std=c++11 gives compilation errors as: > > > testfile.C:11:3: error: no matching constructor for initialization of 'X' > X a = { Y() }; // reports error: no matching constructor for > initialization of 'X' > ^ ~~~~~~~ > testfile.C:1:8: note: candidate constructor (the implicit copy > constructor) not viable: no known conversion from 'Y' to 'const X &' for 1st > argument > struct X > ^ > testfile.C:1:8: note: candidate constructor (the implicit move > constructor) not viable: no known conversion from 'Y' to 'X &&' for 1st > argument > struct X > ^ > testfile.C:3:3: note: candidate constructor not viable: requires 0 > arguments, but 1 was provided > X(); > ^ > 1 error generated. > >See C++11 [over.best.ics]p4. We could probably improve the diagnostic here, though; please file a bug. -Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130924/1477a542/attachment.html>
Mayur Pandey
2013-Sep-25 13:34 UTC
[LLVMdev] initialization list with conversion operator dont work properly and report error
Actually it should have not thrown error at all. it works fine with gcc. And the part of code which you mentioned is not getting hit at all. Maybe some difference in parsing is there. On Wed, Sep 25, 2013 at 5:29 AM, Eli Friedman <eli.friedman at gmail.com>wrote:> On Mon, Sep 23, 2013 at 11:43 PM, Mayur Pandey <mayurthebond at gmail.com>wrote: > >> for the following code: >> >> struct X >> { >> X(); >> }; >> >> struct Y >> { >> operator X() const; >> }; >> >> X a = { Y() }; // reports error: no matching constructor for >> initialization of 'X' >> X aa = Y(); // works fine >> >> >> clang when compiled with std=c++11 gives compilation errors as: >> >> >> testfile.C:11:3: error: no matching constructor for initialization of 'X' >> X a = { Y() }; // reports error: no matching constructor for >> initialization of 'X' >> ^ ~~~~~~~ >> testfile.C:1:8: note: candidate constructor (the implicit copy >> constructor) not viable: no known conversion from 'Y' to 'const X &' for 1st >> argument >> struct X >> ^ >> testfile.C:1:8: note: candidate constructor (the implicit move >> constructor) not viable: no known conversion from 'Y' to 'X &&' for 1st >> argument >> struct X >> ^ >> testfile.C:3:3: note: candidate constructor not viable: requires 0 >> arguments, but 1 was provided >> X(); >> ^ >> 1 error generated. >> >> > See C++11 [over.best.ics]p4. We could probably improve the diagnostic > here, though; please file a bug. > > -Eli >-- Thanx & Regards *Mayur Pandey * Senior Software Engineer Samsung India Software Operations Bangalore +91-9742959541 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130925/86e180b8/attachment.html>
Seemingly Similar Threads
- [LLVMdev] initialization list with conversion operator dont work properly and report error
- [LLVMdev] initialization list with conversion operator dont work properly and report error
- [LLVMdev] initialization list with conversion operator dont work properly and report error
- [LLVMdev] operator overloading fails while debugging with gdb for i386
- [LLVMdev] bx instruction getting generated in arm assembly for O1