Boost logo

Boost :

From: Moore, Dave (dmoore_at_[hidden])
Date: 2002-04-10 08:20:51


Ok, my first reply to this had a braindead example (need coffee), but the
part of no code generation still held.

Below is a better example of the problem.

I have a simple minded workaround for MSVC, haven't given much thought to
what else might break, but how about adding an overloaded assignment
operator:

        shared_ptr & operator=(T *p)
        {
                this_type(p).swap(*this);
                return *this;
        }

Broken example, fixed by above workaround on MSVC6SP5

#include <boost/shared_ptr.hpp>

boost::shared_ptr<int> p_i;
int i=5;

int testa()
{
        i = 5;
        p_i = new int(i); // No code generated!!?!?!
        *p_i = 0;
        return i;
}

int testb()
{
        boost::shared_ptr<int> _temp(new int(i));
        p_i = _temp;
        *p_i = 0;
        return i;
}

int main()
{
        testa();
        testb();

        return i;
}

> -----Original Message-----
> From: Markus Schöpflin [mailto:markus.schoepflin_at_[hidden]]
> Sent: Wednesday, April 10, 2002 8:25 AM
> To: boost_at_[hidden]
> Subject: [boost] Current shared_ptr and MSVC6SP5 is really dangerous
>
>
> Boosters,
>
> the current implementation of shared_ptr allows the following
> program to compile with MSVC6SP5.
>
> #include <boost/shared_ptr.hpp>
> boost::shared_ptr<int> p_i;
> int main()
> {
> p_i = 42;
> return 0;
> }
>
> The line p_i = 42; generates no assembly instructions at all, it
> is simply ignored.
>
> This is especially dangerous as the compiler belives this to be
> the same as p_i = new int(0) which also doesn't generate any
> assembly instructions.
>
> I think this is a serious problem and should be addressed.
>
> Markus
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk