This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] stl_vector.h
On Tue, 2004-10-12 at 20:52, Paolo Carlini wrote:
> Dhruv Matani wrote:
>
> >Hello,
> > Here is the patch for the bug that I had mentioned earlier on.
> >
> >I ahve also attached a test-case for replicating the bug.
> >
> >This bug actually helped me fix a totally unralated error in some other
> >part of my program!
> >
> >
> I don't think we have a bug, neither I think your testcase is correct.
> Why you have an assert( n != 0) in the allocator? According to the
> standard, the return value of allocate when n == 0 is unspecified,
Exactly, so a standard compliant allocator (user defined though) may do
weird stuff if n==0! We may not rely on such behaviour.
Strictly, speaking then we *MUST* call deallocate for every such
allocate(0) call or it will be a faulty library(memory leak).
> indeed, but is anyway perfectly legal to call allocate with n == 0. What
> happens then in std::vector is that all of the _M_impl pointers become
> equal and the various algorithms do not iterate at all, no problem.
About the alogoirthms working, no doubt they do work perfeclty.
> In
> fact all of our allocators + vector accept std::vector vv(0, 1) and are
> able to deal with it correctly subsequently. To summarize, I think that
> the testcase (the allocator part of it) is wrong, not our vector class.
>
> Paolo.
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
The price of freedom is responsibility, but it's a bargain, because
freedom is priceless. ~ Hugh Downs