public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55437] New: Non-const copy constructor causes error - even if not called
@ 2012-11-22 5:17 rockydowns0485 at msn dot com
2012-11-22 12:48 ` [Bug c++/55437] " redi at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: rockydowns0485 at msn dot com @ 2012-11-22 5:17 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55437
Bug #: 55437
Summary: Non-const copy constructor causes error - even if not
called
Classification: Unclassified
Product: gcc
Version: 4.4.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: rockydowns0485@msn.com
I believe the error below should not occur. The copy constructor in question
is not exercised. Moreover, making the copy constructor const also makes the
error not occur.
class String{
public:
String(String& s){} // No error if this line is removed
String(const char* s){}
};
int main(){
String S = (char*)"Test";
return 0;
}
test2.cpp: In function ‘int main()’:
test2.cpp:9: error: no matching function for call to ‘String::String(String)’
test2.cpp:5: note: candidates are: String::String(const char*)
test2.cpp:4: note: String::String(String&)
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/55437] Non-const copy constructor causes error - even if not called
2012-11-22 5:17 [Bug c++/55437] New: Non-const copy constructor causes error - even if not called rockydowns0485 at msn dot com
@ 2012-11-22 12:48 ` redi at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-22 12:48 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-11-22 12:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-22 5:17 [Bug c++/55437] New: Non-const copy constructor causes error - even if not called rockydowns0485 at msn dot com
2012-11-22 12:48 ` [Bug c++/55437] " redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).