This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[PATCH] Miscellaneous debug mode fixes
- From: Douglas Gregor <gregod at cs dot rpi dot edu>
- To: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 13 Nov 2003 18:34:12 -0500
- Subject: [PATCH] Miscellaneous debug mode fixes
- Organization: Rensselaer Polytechnic Institute
Here are the (minor) debug mode fixes I promised. I know of no other bugs in
the implementation, but I'm sure we'll find some :)
Tested on i686-pc-linux-gnu; no regressions in the libstdc++ test suite in
either debug or release mode. The new test case bits falied before, but pass
now.
Doug
2003-11-13 Douglas Gregor <gregod@cs.rpi.edu>
* docs/html/debug.html: Users are allowed to specialize in
namespace __gnu_debug, unlike in the Apple version of the debug
mode. Clear up a confusing double-negative. Note that
std::basic_string does provide extra debugging capabilities, but
not safe iterators.
* include/bits/basic_string.tcc: Make sure there's never an
ambiguity when calling __is_null_pointer.
* include/debug/deque: (deque::erase) Properly handle invalidation
when erasing at the end of the deque.
* include/debug/vector: (vector::swap): Swap _M_guaranteed_capacity.
(vector::clear): Set the guaranteed capacity to 0.
* testsuite/23_containers/deque/invalidation/4.cc: (test04): Test
iterator invalidation when erasing at the end of the deque.
Index: docs/html/debug.html
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/docs/html/debug.html,v
retrieving revision 1.5
diff -u -b -B -r1.5 debug.html
--- docs/html/debug.html 11 Nov 2003 20:09:06 -0000 1.5
+++ docs/html/debug.html 13 Nov 2003 23:21:18 -0000
@@ -145,8 +145,7 @@
functionally equivalent to the standard drop-in containers used in
debug mode, but they are available in a separate namespace as GNU
extensions and may be used in programs compiled with either release
- mode or with debug mode. However, unlike the containers in namespace
- <code>std</code>, these containers may not be specialized. The
+ mode or with debug mode. The
following table provides the names and headers of the debugging
containers:
@@ -250,7 +249,7 @@
</table>
<h4 class="left">Debug mode semantics</h4>
-<p>A program that does not use the C++ standard library incorrectly
+<p>A program that uses the C++ standard library correctly
will maintain the same semantics under debug mode as it had with
the normal (release) library. All functional and exception-handling
guarantees made by the normal library also hold for the debug mode
@@ -276,7 +275,7 @@
library, and is therefore somewhat hazardous. For this reason, the
libstdc++ debug mode offers a "pedantic" mode (similar to
GCC's <code>-pedantic</code> compiler flag) that attempts to emulate
- the semantics guaranteed by the C++ standard. In pedantic mode, for
+ the semantics guaranteed by the C++ standard. For
instance, constructing a <code>std::basic_string</code> with a NULL
character pointer would result in an exception under normal mode or
non-pedantic debug mode (this is a libstdc++ extension), whereas
@@ -288,6 +287,7 @@
<p>The following library components provide extra debugging
capabilities in debug mode:</p>
<ul>
+ <li><code>std::basic_string</code> (no safe iterators)</li>
<li><code>std::bitset</code></li>
<li><code>std::deque</code></li>
<li><code>__gnu_cxx::hash_map</code></li>
Index: include/bits/basic_string.tcc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/basic_string.tcc,v
retrieving revision 1.43
diff -u -b -B -r1.43 basic_string.tcc
--- include/bits/basic_string.tcc 11 Nov 2003 20:09:07 -0000 1.43
+++ include/bits/basic_string.tcc 13 Nov 2003 23:21:19 -0000
@@ -52,7 +52,7 @@
template<typename _Type>
inline bool
- __is_null_pointer(const _Type&)
+ __is_null_pointer(_Type)
{ return false; }
template<typename _CharT, typename _Traits, typename _Alloc>
Index: include/debug/deque
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/debug/deque,v
retrieving revision 1.1
diff -u -b -B -r1.1 deque
--- include/debug/deque 11 Nov 2003 20:09:09 -0000 1.1
+++ include/debug/deque 13 Nov 2003 23:21:19 -0000
@@ -294,7 +294,7 @@
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 151. can't currently clear() empty container
__glibcxx_check_erase_range(__first, __last);
- if (__first == begin() || __last == end()-1)
+ if (__first == begin() || __last == end())
{
this->_M_detach_singular();
for (iterator __position = __first; __position != __last; )
Index: include/debug/vector
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/debug/vector,v
retrieving revision 1.1
diff -u -b -B -r1.1 vector
--- include/debug/vector 11 Nov 2003 20:09:09 -0000 1.1
+++ include/debug/vector 13 Nov 2003 23:21:20 -0000
@@ -34,6 +34,7 @@
#include <vector>
#include <debug/safe_sequence.h>
#include <debug/safe_iterator.h>
+#include <utility>
namespace __gnu_debug_def
{
@@ -328,6 +329,7 @@
{
_Base::swap(__x);
this->_M_swap(__x);
+ std::swap(_M_guaranteed_capacity, __x._M_guaranteed_capacity);
}
void
@@ -335,6 +337,7 @@
{
_Base::clear();
this->_M_invalidate_all();
+ _M_guaranteed_capacity = 0;
}
_Base&
Index: testsuite/23_containers/deque/invalidation/4.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/testsuite/23_containers/deque/invalidation/4.cc,v
retrieving revision 1.1
diff -u -b -B -r1.1 4.cc
--- testsuite/23_containers/deque/invalidation/4.cc 11 Nov 2003 20:09:14 -0000 1.1
+++ testsuite/23_containers/deque/invalidation/4.cc 13 Nov 2003 23:21:22 -0000
@@ -55,6 +55,12 @@
VERIFY(before._M_singular());
VERIFY(at._M_singular());
+ // Multiple element erase at end
+ before = v.begin();
+ at = before + 3;
+ v.erase(at, v.end());
+ *before;
+
// clear()
before = v.begin();
VERIFY(before._M_dereferenceable());