Re: private, undefined copy ctors
Re: private, undefined copy ctors
- Subject: Re: private, undefined copy ctors
- From: Steve Checkoway <email@hidden>
- Date: Mon, 19 Mar 2007 11:54:32 -0700
On Mar 19, 2007, at 10:43 AM, Clark Cox wrote:
On 3/18/07, Steve Checkoway <email@hidden> wrote:
The copy ctor should _not_ be invoked here since Foo takes a constant
reference to a Bar.
The standard allows the compiler to make a judgement call as to
whether or not to call the copy constructor here (When binding a
temporary to a non-const reference). However, the standard does *not*
allow the compiler to not check for the existence of a callable copy
constructor.
I see that now. It's very strange though. Why would it ever need to
copy the temporary to get a reference to it? The standard even has a
footnote to the effect that the copy ctor will eventually need to
just take the reference to prevent an infinite loop.
If you change the code to just pass 5 to Foo,
then the Bar is constructed as would be expected and there is no
problem with the copy ctor.
If you forgo the use of a temporary, it should work:
But that's not forgoing the use of a temporary. It's just using the
fact that I wasn't using the explicit keyword for my ctor and thus
implicitly creating the Bar temporary.
It seems like there are two bugs. One in the standard for requiring
the copy ctor check when taking a reference to a temporary, and one
in gcc for not following the standard when the use of a temporary
isn't explicit.
--
Steve Checkoway
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden