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++/55437] Non-const copy constructor causes error - even if not called


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.


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