public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/6340: copy constructor vs non-default constructor
@ 2002-04-17 12:16 swhite
0 siblings, 0 replies; 2+ messages in thread
From: swhite @ 2002-04-17 12:16 UTC (permalink / raw)
To: gcc-gnats
>Number: 6340
>Category: c++
>Synopsis: copy constructor vs non-default constructor
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Apr 17 12:16:02 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: stephen white
>Release: 3.02
>Organization:
>Environment:
red hat linux 7.1
kernel 2.4.2-2
>Description:
the attached code generates the following error:
foo.cpp: In function `int main (int, char **)':
foo.cpp:16: `Thing2::Thing2 (const Thing2 &)' is private
foo.cpp:25: within this context
while the copy constructor is private, it should never
be called. in fact, if it is made public, it *is*
never called. it seems as if g++ just wants there to be
a public copy constructor to give it a warm fuzzy feeling.
the workaround is to use:
Thing2 b( a );
>How-To-Repeat:
g++ -lstdc++ foo.cpp
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="foo.cpp"
Content-Disposition: inline; filename="foo.cpp"
#include <iostream.h>
class Thing1
{
};
class Thing2
{
public:
Thing2( const Thing1& r ) {
cout << "constructing Thing2 from const Thing1&\n";
}
private:
Thing2( const Thing2& r ) {
cout << "copy constructor (PROHIBITED)\n";
}
};
int
main(int argc, char **argv)
{
Thing1 a;
Thing2 b = a;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c++/6340: copy constructor vs non-default constructor
@ 2002-04-18 0:58 nathan
0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-04-18 0:58 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, swhite
Synopsis: copy constructor vs non-default constructor
State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Thu Apr 18 00:58:37 2002
State-Changed-Why:
not a bug.
Thing2 b = a;
is formally
Thing2 b(Thing2 (a));
i.e. convert a to Thing2 then copy construct b with
that. [8.5]/14 class copy initialization case.
But we are allowed to elide that temporary Thing2.
See [12.8]/15 of the std. The copy ctor must
exist and be accessible though.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6340
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-04-18 7:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-17 12:16 c++/6340: copy constructor vs non-default constructor swhite
2002-04-18 0:58 nathan
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).