By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

VS2005 - question about copy-ctor

P: n/a
Hello all,

find below an example which IMO should refuse to compile. It compiles fine
with VS2005.

What happens in the call?
What is your opinion?

Kind regards,
Patrick

class noncopyable
{
protected:
noncopyable() {}
~noncopyable() {}
private:
// hide the copy-ctor and assignment
noncopyable( noncopyable const & );
const noncopyable& operator=( noncopyable const & );
};
class A : public noncopyable // inherit to avoid copying
{
noncopyable copy_protection; // make member to avoid copying
};
int main()
{
//A a;
//A b = a; // this fails to compile

A c = A(); // this compiles fine

return 0;
}
Mar 24 '06 #1
Share this Question
Share on Google+
18 Replies


P: n/a
Patrick Kowalzick wrote:
Hello all,

find below an example which IMO should refuse to compile. It compiles fine
with VS2005.

What happens in the call?
What is your opinion?
I agree that it shouldn't compile, and for 2 separate reasons:

1: A's default constructor cannot access the default constructor for the
member copy_protection - remember that protected access only gives you
access to protected members of bases through pointers, references and
objects of the derived class, not the base class (this is to prevent one
derived class from breaking objects of other derived classes derived
from the same base). As a result, A doesn't have a well-formed default
constructor, so even "A a;" shouldn't compile. This is covered in 11.5/1
of the standard.

Delete the member copy_protection to get around this, and try a
different compiler to get the error in the first place.

2: In the call, "c" is copy initialized from a default constructed A.
The compiler is allowed to optimize out the copy, but according to the
standard it must check that the copy could be made (e.g. that there is
an accessible copy constructor). This is covered in 12.2/1 of the standard.

Again, use a different compiler to get the error.
class A : public noncopyable // inherit to avoid copying
{
noncopyable copy_protection; // make member to avoid copying
};
Should be:

class A : noncopyable // no need for public inheritance
{
};


int main()
{
//A a;
//A b = a; // this fails to compile

A c = A(); // this compiles fine

return 0;
}


You may want to report the bugs to MS.

Tom
Mar 24 '06 #2

P: n/a
Hello Tom,

I agree that it shouldn't compile, and for 2 separate reasons:

1: A's default constructor cannot access the default constructor for the
member copy_protection - remember that protected access only gives you
access to protected members of bases through pointers, references and
objects of the derived class, not the base class (this is to prevent one
derived class from breaking objects of other derived classes derived from
the same base). As a result, A doesn't have a well-formed default
constructor, so even "A a;" shouldn't compile. This is covered in 11.5/1
of the standard.

Delete the member copy_protection to get around this, and try a different
compiler to get the error in the first place.
Normally, I do not use a member copy_protection. It was just to test VS2005
:).
2: In the call, "c" is copy initialized from a default constructed A. The
compiler is allowed to optimize out the copy, but according to the
standard it must check that the copy could be made (e.g. that there is an
accessible copy constructor). This is covered in 12.2/1 of the standard.

Again, use a different compiler to get the error.
VS2005 is the first, where I do not get the error. I was a little bit
surprised, as this is quite basic stuff. But perhaps MS will launch a 8.1
soon :). 8.0 is a little bit annoying sometimes.
class A : public noncopyable // inherit to avoid copying
{
noncopyable copy_protection; // make member to avoid copying
};


Should be:

class A : noncopyable // no need for public inheritance
{
};


True.
You may want to report the bugs to MS.


Yes, I want. There is antoherone I want to report, but I do not know how. I
googled a little bit, but was not successful, yet.

Regards,
Patrick
Mar 24 '06 #3

P: n/a
You may want to report the bugs to MS.


Yes, I want. There is antoherone I want to report, but I do not know how.
I googled a little bit, but was not successful, yet.


You can do that here:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Then, after you did that you can post the url here so that we can validate
it and vote for it.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Mar 24 '06 #4

P: n/a
Hello all,
You may want to report the bugs to MS.


Yes, I want. There is antoherone I want to report, but I do not know how.
I googled a little bit, but was not successful, yet.


You can do that here:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Then, after you did that you can post the url here so that we can validate
it and vote for it.


I posted it here:
http://lab.msdn.microsoft.com/Produc...ckid=FDBK47765

I wanted to refer to
http://lab.msdn.microsoft.com/produc...ckid=FDBK18668

but I did not manage it. I opened a new one, because the latter one refers
to the beta-version.

Regards,
Patrick
Mar 24 '06 #5

P: n/a
Patrick Kowalzick wrote:
Hello all,

You may want to report the bugs to MS.

Yes, I want. There is antoherone I want to report, but I do not know how.
I googled a little bit, but was not successful, yet.


You can do that here:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Then, after you did that you can post the url here so that we can validate
it and vote for it.

I posted it here:
http://lab.msdn.microsoft.com/Produc...ckid=FDBK47765

I wanted to refer to
http://lab.msdn.microsoft.com/produc...ckid=FDBK18668

but I did not manage it. I opened a new one, because the latter one refers
to the beta-version.


Just to clarify, the following program should *not* compile - if it does
in VS2005 (which I don't have handy), it's another bug which should be
reported:

class Foo
{
protected:
Foo(){}
};

class Bar: public Foo
{
Foo f;
};

int main()
{
Bar b;
}

Tom
Mar 24 '06 #6

P: n/a
Tom Widmer [VC++ MVP] wrote:
Just to clarify, the following program should *not* compile - if it
does in VS2005 (which I don't have handy), it's another bug which should
be
reported:

class Foo
{
protected:
Foo(){}
};

class Bar: public Foo
{
Foo f;
};

int main()
{
Bar b;
}


It does compile with VC8. Looks like another bug is needed.

-cd
Mar 24 '06 #7

P: n/a
> Just to clarify, the following program should *not* compile - if it does
in VS2005 (which I don't have handy), it's another bug which should be
reported:

class Foo
{
protected:
Foo(){}
};

class Bar: public Foo
{
Foo f;
};

int main()
{
Bar b;
}


I posted it here:

http://lab.msdn.microsoft.com/Produc...ckId=FDBK47867

I messed up the class namig, but it should be understandable :).

Regards,
Patrick
Mar 27 '06 #8

P: n/a
Patrick Kowalzick wrote:
Just to clarify, the following program should *not* compile - if it does
in VS2005 (which I don't have handy), it's another bug which should be
reported:

class Foo
{
protected:
Foo(){}
};

class Bar: public Foo
{
Foo f;
};

int main()
{
Bar b;
}

I posted it here:

http://lab.msdn.microsoft.com/Produc...ckId=FDBK47867

I messed up the class namig, but it should be understandable :).


Great. It's about time I installed VC8 I think, then I could at least
validate the bug.

Tom
Mar 28 '06 #9

P: n/a
Hello all,
>You may want to report the bugs to MS.

Yes, I want. There is antoherone I want to report, but I do not know
how. I googled a little bit, but was not successful, yet.

You can do that here:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Then, after you did that you can post the url here so that we can
validate it and vote for it.

I posted it here:
http://lab.msdn.microsoft.com/Produc...ckid=FDBK47765

I wanted to refer to
http://lab.msdn.microsoft.com/produc...ckid=FDBK18668

but I did not manage it. I opened a new one, because the latter one
refers to the beta-version.


MS marked the bug as resolved with the note that
A a = A();

is a direct initialization. As I wondered what the difference between this
and
A a;

shall be, I just posted in comp.lang.c++.moderated.

Regards,
Patrick
Apr 3 '06 #10

P: n/a
Patrick Kowalzick wrote:
Hello all,


Hello.
I posted it here:
http://lab.msdn.microsoft.com/Produc...ckid=FDBK47765

I wanted to refer to
http://lab.msdn.microsoft.com/produc...ckid=FDBK18668

but I did not manage it. I opened a new one, because the latter one
refers to the beta-version.

MS marked the bug as resolved with the note that
A a = A();

is a direct initialization. As I wondered what the difference between this
and
A a;

shall be, I just posted in comp.lang.c++.moderated.


A a = A();
is a copy-initialization; it is however equivalent to a
direct-initialization, since the type of the initializer is the same as
that of "a". The copy constructor is required to be accessible, but it
is implementation defined whether a temporary will be created or not.
The above is semantically equivalent to:
A a((A())); //extra parens to prevent it being a function prototype.

A a;
is a default-initilazation (assuming A is non-POD). No temporary is created.

I've posted a comment to the bug suggesting that the resolution is
incorrect.

Tom
Apr 3 '06 #11

P: n/a
> I've posted a comment to the bug suggesting that the resolution is
incorrect.


I added a comment and tried with Comeau (they seem to agree with us). So I
reopened it. Hope thats not inpolite ;).

Regards,
Patrick
Apr 3 '06 #12

P: n/a
....now playing the bouncing reopen-close game :(. If they just close it
another time without argueing, I'll drop it.

No real fun with MS product feedback.

Regards
Patrick

"Patrick Kowalzick" <pa***************@mapandguide.de> schrieb im
Newsbeitrag news:ne********************@proxy.mapandguide.de.. .
I've posted a comment to the bug suggesting that the resolution is
incorrect.


I added a comment and tried with Comeau (they seem to agree with us). So I
reopened it. Hope thats not inpolite ;).

Regards,
Patrick

Apr 21 '06 #13

P: n/a
Patrick Kowalzick wrote:
...now playing the bouncing reopen-close game :(. If they just close it
another time without argueing, I'll drop it.

No real fun with MS product feedback.


Looks like they can be spoilsports! You could post a link to your clc++m
thread, in particular to the post where Daveed Vandevoorde (of EDG)
admits that the EDG front end has a bug with this (which obviously
invalidates Caves' comment about Comeau C++ compiling the example fine).

Tom
Apr 21 '06 #14

P: n/a
>> ...now playing the bouncing reopen-close game :(. If they just close it
another time without argueing, I'll drop it.

No real fun with MS product feedback.


Looks like they can be spoilsports! You could post a link to your clc++m
thread, in particular to the post where Daveed Vandevoorde (of EDG) admits
that the EDG front end has a bug with this (which obviously invalidates
Caves' comment about Comeau C++ compiling the example fine).


LOL - closed again. I am starting to feel that discussing via a
feedback-portal is annoying. Even if he would be right, it is unpolite to
just close the bug....

Regards,
Patrick

P.S.: IMO the new answer does not fit to the problem :).
Apr 24 '06 #15

P: n/a
Patrick Kowalzick wrote:
...now playing the bouncing reopen-close game :(. If they just close it
another time without argueing, I'll drop it.

No real fun with MS product feedback.


Looks like they can be spoilsports! You could post a link to your clc++m
thread, in particular to the post where Daveed Vandevoorde (of EDG) admits
that the EDG front end has a bug with this (which obviously invalidates
Caves' comment about Comeau C++ compiling the example fine).

LOL - closed again. I am starting to feel that discussing via a
feedback-portal is annoying. Even if he would be right, it is unpolite to
just close the bug....


I've raised this with MS directly, so hopefully it will be resolved
properly this time...

Tom
Apr 25 '06 #16

P: n/a
> I've raised this with MS directly, so hopefully it will be resolved
properly this time...


And I reopened and added another point of view ;).

Patrick
Apr 25 '06 #17

P: n/a
Juhu, confirmed as a bug.

Is there a feedback portal for the feedback portal?

I would like to know how to format the comments, and how I can send a
private message to the responsible developer.

Regards,
Patrick

"Tom Widmer [VC++ MVP]" <to********@hotmail.com> schrieb im Newsbeitrag
news:u8**************@TK2MSFTNGP05.phx.gbl...
Patrick Kowalzick wrote:
...now playing the bouncing reopen-close game :(. If they just close it
another time without argueing, I'll drop it.

No real fun with MS product feedback.

Looks like they can be spoilsports! You could post a link to your clc++m
thread, in particular to the post where Daveed Vandevoorde (of EDG)
admits that the EDG front end has a bug with this (which obviously
invalidates Caves' comment about Comeau C++ compiling the example fine).

LOL - closed again. I am starting to feel that discussing via a
feedback-portal is annoying. Even if he would be right, it is unpolite to
just close the bug....


I've raised this with MS directly, so hopefully it will be resolved
properly this time...

Tom

Apr 27 '06 #18

P: n/a
Patrick Kowalzick wrote:
Juhu, confirmed as a bug.
Hurrah!
Is there a feedback portal for the feedback portal?

I would like to know how to format the comments, and how I can send a
private message to the responsible developer.


You could try the "Contact Us" button at the bottom left of the page - I
suppose it probably counts as MSDN site feedback.

Tom
Apr 28 '06 #19

This discussion thread is closed

Replies have been disabled for this discussion.