Boost logo

Boost Users :

Subject: Re: [Boost-users] fatal error C1001 with VS2010, boost 1.49, and shared_ptr.hpp
From: Phillip Hellewell (sshock_at_[hidden])
Date: 2012-04-30 13:56:26


On Mon, Apr 30, 2012 at 11:14 AM, Phillip Hellewell <sshock_at_[hidden]> wrote:
>
> Good news.  Luckily I was able to pinpoint the exact line of code
> causing VS to crash, and two different workarounds:
>
> Crashes VS:
>        return Foo_ptr(new Foo());
>
> Workaround 1:
>        return boost::shared_ptr<Foo>(new Foo());
>
> Workaround 2:
>        Foo_ptr ret(new Foo());
>        return ret;

Oops, I didn't even notice this but the return type on my function is
Foo_const_ptr (boost::shared_ptr<const Foo>), not Foo_ptr.

So this is the right fix:
        return Foo_const_ptr(new Foo());

I guess VS gets all flustered when:
1. Converting an r-value shared_ptr to a non-const object, to a
shared_ptr to a const object,
2. when typedefs are involved,
3. in Debug x64 (other configurations weren't crashing).

There must be some other factors too because when I wrote up a sample
10-line program to illustrate the problem, it didn't crash.

Phillip


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net