This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: debug/vector anomalous behaviour
- From: Stefano Soffia <soffia at cs dot unipr dot it>
- To: Paolo Carlini <paolo dot carlini at oracle dot com>
- Cc: libstdc++ at gcc dot gnu dot org, Douglas Gregor <doug dot gregor at gmail dot com>, Enea Zaffanella <zaffanella at cs dot unipr dot it>, bagnara at cs dot unipr dot it
- Date: Sat, 10 May 2008 15:21:15 +0200 (CEST)
- Subject: Re: debug/vector anomalous behaviour
- References: <Pine.LNX.4.63.0805101033570.6100@spartacus.cs.unipr.it> <4825771F.7020407@oracle.com>
On Sat, 10 May 2008, Paolo Carlini wrote:
The latter behavior, by itself, seems right to me: in pedantic mode, when the
correctness according to the strict letter of standard counts, debug mode is
indeed able to figure out that no reallocation is happening and the code is
safe.
Exactly.
My note was referred to the above snippet of code where the pedantic
behaviour seems to be safe whereas the non-pedantic behaviour isn't so.
However, I'm puzzled by the default, which uses the _M_guaranteed_capacity
idea, trying to flag potentially dangerous situations. Now that I look a bit
into it, frankly I'm not sure it's worth such kind of false positives...
Maybe Doug (the author of these bits, a long time ago, if I remember
correctly...), wants to clarify the rationale.
I have spoken about this with my colleagues Enea Zaffanella and Roberto
Bagnara and our guess is that the intended meaning for the pedantic mode is
to provide the user with the minimal capacity() necessary satisfy the
requirements of the C++ Standard (for example, this would mean that when a
push_back() requires a reallocation, instead of doubling the current
capacity(), the capacity is increased only by 1.)
While the non-pedantic behaviour simply provides the capacity of the
underlying implementation, allowing the user to make assumptions about
implementation-defined aspects of the standard.
Stefano Soffia
Applied Formal Methods Laboratory
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/afmlab/