Boost logo

Boost Users :

From: Alan M. Carroll, CodeSlinger (yg-boost-users_at_[hidden])
Date: 2002-09-25 15:23:51


"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:019701c264b3$8af21640$1d00a8c0_at_pdimov2...
> From: "Alan M. Carroll, CodeSlinger" <yg-boost-users_at_[hidden]>
> > operator void const * () const { return px; }
> delete ptr; // ;-)
>
> In the general case unwanted comparisons are a problem, too.

According to (an admittedly old) spec (Annotated C++), 5.3.4 says "A pointer
to constant cannot be deleted" in reference to the delete operator. Since
the value returned by this operator is a pointer to constant void, the
statement you have should generate a compiler error. I've tested in on MS-VC
6 (SP5) and it does not compile.

int main(int argc, char **argv)
{
 void const * ptr;
 delete ptr;
 return 0;
}

yields

    error C2664: 'delete' : cannot convert parameter 1 from 'const void *'
to 'void *'

What kind of unwanted comparisons can occur? The ability to compare directly
to a raw pointer seems like a feature. It would seem that this just allows
the same comparisons one would get with a raw pointer, which makes
shared_ptr easier to drop in as a replacement.


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