This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/55437] Non-const copy constructor causes error - even if not called
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 22 Nov 2012 12:48:09 +0000
- Subject: [Bug c++/55437] Non-const copy constructor causes error - even if not called
- Auto-submitted: auto-generated
- References: <bug-55437-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55437
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-22 12:48:09 UTC ---
The program is ill-formed.
String S = (char*)"Test";
is equivalent to
String S = String((char*)"Test");
which requires an accessible copy constructor (or in C++11 move constructor)
that takes an rvalue argument (i.e. temporary). A non-const reference cannot
bind to a temporary, so your copy constructor is not viable.
The copy constructor must be accessible and viable even if the copy is elided
and the copy constructor is not used.
You'll get the same error from any conforming C++ compiler.