Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Please read this: Is there a bug in std::unique_ptr? (Repost, thecode in old post is wrong)

Reply
Thread Tools

Please read this: Is there a bug in std::unique_ptr? (Repost, thecode in old post is wrong)

 
 
Jayden Shui
Guest
Posts: n/a
 
      12-16-2011
Hi All,

I accidently find that the following code works with Visual C++
compilation

#include <memory>
#include <iostream>
using namespace std;

int main()
{
unique_ptr<int> const p(new int(1));
unique_ptr<int>& q = p; // assign a constant to a non-constant
reference
q.reset(new int(2));
cout << *p; // output 2
return 0;
}

My question is from the 2nd statement of assigning a constant to a non-
constant reference. I think the compiler should report an compilation
error, but it doesn't. Is there a bug in the code of unique_ptr in the
std template library?

Thanks a lot!

Jayden
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      12-16-2011
On 16.12.2011 15:54, Jayden Shui wrote:
> Hi All,
>
> I accidently find that the following code works with Visual C++
> compilation
>
> #include<memory>
> #include<iostream>
> using namespace std;
>
> int main()
> {
> unique_ptr<int> const p(new int(1));
> unique_ptr<int>& q = p; // assign a constant to a non-constant
> reference
> q.reset(new int(2));
> cout<< *p; // output 2
> return 0;
> }
>
> My question is from the 2nd statement of assigning a constant to a non-
> constant reference. I think the compiler should report an compilation
> error, but it doesn't. Is there a bug in the code of unique_ptr in the
> std template library?


What did you fail to understand about my answer?

It does not compile with Visual C++ 10.0, and it does not compile with
MinGW g++ 4.4.1.

Show your compilation that works, stop spamming/trolling.


 
Reply With Quote
 
 
 
 
Jayden Shui
Guest
Posts: n/a
 
      12-16-2011
On Dec 16, 10:45*am, "Alf P. Steinbach" <alf.p.steinbach
(E-Mail Removed)> wrote:
> On 16.12.2011 15:54, Jayden Shui wrote:
>
>
>
>
>
>
>
>
>
> > Hi All,

>
> > I accidently find that the following code works with Visual C++
> > compilation

>
> > #include<memory>
> > #include<iostream>
> > using namespace std;

>
> > int main()
> > {
> > * * unique_ptr<int> *const p(new int(1));
> > * * unique_ptr<int>& *q = p; // assign a constant to a non-constant
> > reference
> > * * q.reset(new int(2));
> > * * cout<< **p; *// output 2
> > * * return 0;
> > }

>
> > My question is from the 2nd statement of assigning a constant to a non-
> > constant reference. I think the compiler should report an compilation
> > error, but it doesn't. Is there a bug in the code of unique_ptr in the
> > std template library?

>
> What did you fail to understand about my answer?
>
> It does not compile with Visual C++ 10.0, and it does not compile with
> MinGW g++ 4.4.1.
>
> Show your compilation that works, stop spamming/trolling.


Sorry for disturbing. I found the problem. I am in fact using intel c+
+ in visual studio. Intel c++ compiler passes it by treating it as
only a warning.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help old VBasic programmer with simple file read , Please :) marks542004@yahoo.com C++ 17 06-17-2007 01:11 PM
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
Remember my old Adobe Acrobat post about file://etc being on top of each page? Here's a final post Edmonton_Guy@usenet.com Computer Support 0 09-13-2005 08:23 PM
wlftg17 modelsim temp file beeing too big (corret post, ignore the old post) Oleg VHDL 0 04-05-2004 03:31 AM
Post post post. Shel-hed Computer Support 2 11-08-2003 07:41 AM



Advertisments