473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VS2005 - question about copy-ctor

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
18 1313
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
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
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
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
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
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
> 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
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
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
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
> 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
....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
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
>> ...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
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
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mike | last post by:
Hi, I have read the Microsoft Product Feature Comparisons page many times over (http://msdn.microsoft.com/vstudio/products/compare/default.aspx), as well as Gregory's blog on the subject...
9
by: Jeff Gaines | last post by:
I have just installed VS 2005 (MSDN version) and I am having problems coping files to the Projects folder while VS2005 is running. The projects folder is on a network share and I have used...
0
by: joey.powell | last post by:
VS2005 Windows Forms App (Native), Tab Control that contains several tab pages. After changing background color off of transparent for a tab page, it always gets "stuck" and will no longer respond...
10
by: musosdev | last post by:
Hi guys I'm trying to migrate to VS2005... I've managed to do that, but realised I'd opened my web projects as file projects, and I'm getting the error about network BIOS command limit. ...
2
by: GW | last post by:
After the conversion and fixing some errs VS2005 threw, project ran OK. Opened xxx.vbproj file after the conversion to VS2005 from VS2003. Changed (usng wordpad) ../msbuild/2003 to 2005...
4
by: WXS | last post by:
In a case you have Project/Assembly A references Project/Assembly B which References Project/Assembly C. Let's say Project A needs be and references it directly. Unknown to A, B needs project C's...
10
by: Frank | last post by:
I've done this a few times. In a solution I have a project, Say P1, and need another project that will contain much code that is similar to that of P1. I hope no one gets hung up on why I...
3
by: rmgalante | last post by:
I have a pretty large web site with about 400 files after I precompile it. When I use the VS2005 Publish tool and publish to an FTP site, which is running IIS, most of the attempts hang after about...
2
by: Jeff | last post by:
Hey In VS2005 I've copied some text to the clipboard, but when I paste it, I get something I previuosly added to the clipboard. I thought a reboot of my computer would help, but it didn''t.......
5
by: Kardon Coupé | last post by:
Dear All, I'm bemused, I'm moving an application I've written from VB6 into VS2005, and I'm getting all the fundamentals over before I delve into the hard part, like getting the forms layout...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.