OSDN Git Service

2010-01-05 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / doc / html / manual / bk01pt12ch30s02.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Semantics</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><meta name="keywords" content="&#10;      C++&#10;    , &#10;      library&#10;    , &#10;      debug&#10;    " /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><link rel="home" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="debug_mode.html" title="Chapter 30. Debug Mode" /><link rel="prev" href="debug_mode.html" title="Chapter 30. Debug Mode" /><link rel="next" href="bk01pt12ch30s03.html" title="Using" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Semantics</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="debug_mode.html">Prev</a> </td><th width="60%" align="center">Chapter 30. Debug Mode</th><td width="20%" align="right"> <a accesskey="n" href="bk01pt12ch30s03.html">Next</a></td></tr></table><hr /></div><div class="sect1" title="Semantics"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="manual.ext.debug_mode.semantics"></a>Semantics</h2></div></div></div><p>
4   </p><p>A program that uses the C++ standard library correctly
5   will maintain the same semantics under debug mode as it had with
6   the normal (release) library. All functional and exception-handling
7   guarantees made by the normal library also hold for the debug mode
8   library, with one exception: performance guarantees made by the
9   normal library may not hold in the debug mode library. For
10   instance, erasing an element in a <code class="code">std::list</code> is a
11   constant-time operation in normal library, but in debug mode it is
12   linear in the number of iterators that reference that particular
13   list. So while your (correct) program won't change its results, it 
14   is likely to execute more slowly.</p><p>libstdc++ includes many extensions to the C++ standard library. In
15   some cases the extensions are obvious, such as the hashed
16   associative containers, whereas other extensions give predictable
17   results to behavior that would otherwise be undefined, such as
18   throwing an exception when a <code class="code">std::basic_string</code> is
19   constructed from a NULL character pointer. This latter category also
20   includes implementation-defined and unspecified semantics, such as
21   the growth rate of a vector. Use of these extensions is not
22   considered incorrect, so code that relies on them will not be
23   rejected by debug mode. However, use of these extensions may affect
24   the portability of code to other implementations of the C++ standard
25   library, and is therefore somewhat hazardous. For this reason, the
26   libstdc++ debug mode offers a "pedantic" mode (similar to
27   GCC's <code class="code">-pedantic</code> compiler flag) that attempts to emulate
28   the semantics guaranteed by the C++ standard. For
29   instance, constructing a <code class="code">std::basic_string</code> with a NULL
30   character pointer would result in an exception under normal mode or
31   non-pedantic debug mode (this is a libstdc++ extension), whereas
32   under pedantic debug mode libstdc++ would signal an error. To enable
33   the pedantic debug mode, compile your program with
34   both <code class="code">-D_GLIBCXX_DEBUG</code>
35   and <code class="code">-D_GLIBCXX_DEBUG_PEDANTIC</code> .
36   (N.B. In GCC 3.4.x and 4.0.0, due to a bug,
37   <code class="code">-D_GLIBXX_DEBUG_PEDANTIC</code> was also needed. The problem has
38   been fixed in GCC 4.0.1 and later versions.) </p><p>The following library components provide extra debugging
39   capabilities in debug mode:</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p><code class="code">std::basic_string</code> (no safe iterators and see note below)</p></li><li class="listitem"><p><code class="code">std::bitset</code></p></li><li class="listitem"><p><code class="code">std::deque</code></p></li><li class="listitem"><p><code class="code">std::list</code></p></li><li class="listitem"><p><code class="code">std::map</code></p></li><li class="listitem"><p><code class="code">std::multimap</code></p></li><li class="listitem"><p><code class="code">std::multiset</code></p></li><li class="listitem"><p><code class="code">std::set</code></p></li><li class="listitem"><p><code class="code">std::vector</code></p></li><li class="listitem"><p><code class="code">std::unordered_map</code></p></li><li class="listitem"><p><code class="code">std::unordered_multimap</code></p></li><li class="listitem"><p><code class="code">std::unordered_set</code></p></li><li class="listitem"><p><code class="code">std::unordered_multiset</code></p></li></ul></div><p>N.B. although there are precondition checks for some string operations,
40 e.g.  <code class="code">operator[]</code>,
41 they will not always be run when using the <code class="code">char</code> and
42 <code class="code">wchar_t</code> specialisations (<code class="code">std::string</code> and
43 <code class="code">std::wstring</code>).  This is because libstdc++ uses GCC's
44 <code class="code">extern template</code> extension to provide explicit instantiations
45 of <code class="code">std::string</code> and <code class="code">std::wstring</code>, and those
46 explicit instantiations don't include the debug-mode checks.  If the
47 containing functions are inlined then the checks will run, so compiling
48 with <code class="code">-O1</code> might be enough to enable them.  Alternatively
49 <code class="code">-D_GLIBCXX_EXTERN_TEMPLATE=0</code> will suppress the declarations
50 of the explicit instantiations and cause the functions to be instantiated
51 with the debug-mode checks included, but this is unsupported and not
52 guaranteed to work.  For full debug-mode support you can use the
53 <code class="code">__gnu_debug::basic_string</code> debugging container directly,
54 which always works correctly.
55 </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="debug_mode.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="debug_mode.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt12ch30s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 30. Debug Mode </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> Using</td></tr></table></div></body></html>