xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/doc/xml/manual/diagnostics.xml (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1<chapter xmlns="http://docbook.org/ns/docbook" version="5.0"
2	 xml:id="std.diagnostics" xreflabel="Diagnostics">
3<?dbhtml filename="diagnostics.html"?>
4
5<info><title>
6  Diagnostics
7  <indexterm><primary>Diagnostics</primary></indexterm>
8</title>
9  <keywordset>
10    <keyword>ISO C++</keyword>
11    <keyword>library</keyword>
12  </keywordset>
13</info>
14
15
16
17<section xml:id="std.diagnostics.exceptions" xreflabel="Exceptions"><info><title>Exceptions</title></info>
18  <?dbhtml filename="exceptions.html"?>
19
20
21  <section xml:id="std.diagnostics.exceptions.api"><info><title>API Reference</title></info>
22
23    <para>
24      All exception objects are defined in one of the standard header
25      files: <filename>exception</filename>,
26      <filename>stdexcept</filename>, <filename>new</filename>, and
27      <filename>typeinfo</filename>.
28    </para>
29
30    <para>
31      The base exception object is <classname>exception</classname>,
32      located in <filename>exception</filename>. This object has no
33      <classname>string</classname> member.
34    </para>
35
36    <para>
37      Derived from this are several classes that may have a
38      <classname>string</classname> member: a full hierarchy can be
39      found in the source documentation.
40    </para>
41
42    <para>
43      Full API details.
44    </para>
45
46    <!-- Doxygen XML: api/group__exceptions.xml -->
47
48  </section>
49  <section xml:id="std.diagnostics.exceptions.data" xreflabel="Adding Data to Exceptions"><info><title>Adding Data to <classname>exception</classname></title></info>
50
51    <para>
52      The standard exception classes carry with them a single string as
53      data (usually describing what went wrong or where the 'throw' took
54    place).  It's good to remember that you can add your own data to
55    these exceptions when extending the hierarchy:
56   </para>
57   <programlisting>
58   struct My_Exception : public std::runtime_error
59   {
60     public:
61       My_Exception (const string&amp; whatarg)
62	   : std::runtime_error(whatarg), e(errno), id(GetDataBaseID()) { }
63       int  errno_at_time_of_throw() const { return e; }
64       DBID id_of_thing_that_threw() const { return id; }
65     protected:
66       int    e;
67       DBID   id;     // some user-defined type
68   };
69   </programlisting>
70
71  </section>
72</section>
73
74<section xml:id="std.diagnostics.concept_checking" xreflabel="Concept Checking"><info><title>Concept Checking</title></info>
75  <?dbhtml filename="concept_checking.html"?>
76
77  <para>
78    In 1999, SGI added <quote>concept checkers</quote> to their
79    implementation of the STL: code which checked the template
80    parameters of instantiated pieces of the STL, in order to insure
81    that the parameters being used met the requirements of the
82    standard.  For example, the Standard requires that types passed as
83    template parameters to <classname>vector</classname> be
84    "Assignable" (which means what you think it means).  The
85    checking was done during compilation, and none of the code was
86    executed at runtime.
87   </para>
88   <para>
89     Unfortunately, the size of the compiler files grew significantly
90     as a result.  The checking code itself was cumbersome.  And bugs
91     were found in it on more than one occasion.
92   </para>
93   <para>
94     The primary author of the checking code, Jeremy Siek, had already
95     started work on a replacement implementation.  The new code was
96     formally reviewed and accepted into
97   <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.boost.org/libs/concept_check/concept_check.htm">the
98   Boost libraries</link>, and we are pleased to incorporate it into the
99   GNU C++ library.
100 </para>
101 <para>
102   The new version imposes a much smaller space overhead on the generated
103   object file.  The checks are also cleaner and easier to read and
104   understand.
105 </para>
106
107 <para>
108   They are off by default for all versions of GCC.
109   They can be enabled at configure time with
110   <link linkend="manual.intro.setup.configure"><literal>--enable-concept-checks</literal></link>.
111   You can enable them on a per-translation-unit basis with
112     <literal>-D_GLIBCXX_CONCEPT_CHECKS</literal>.
113 </para>
114
115 <para>
116   Please note that the checks are based on the requirements in the original
117   C++ standard, some of which have changed in the new C++11 revision.
118   Additionally, some correct code might be rejected by the concept checks,
119   for example template argument types may need to be complete when used in
120   a template definition, rather than at the point of instantiation.
121   There are no plans to address these shortcomings.
122 </para>
123
124</section>
125
126</chapter>
127