source: vendor/gcc/3.3.4/bugs.html@ 3315

Last change on this file since 3315 was 1464, checked in by bird, 21 years ago

GCC v3.3.4 - official sources.

  • Property cvs2svn:cvs-rev set to 1.1.1.3
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 32.7 KB
Line 
1<html>
2
3<head>
4<title>GCC Bugs</title>
5</head>
6
7<body>
8<h1>GCC Bugs</h1>
9
10<p>The latest version of this document is always available at
11<a href="http://gcc.gnu.org/bugs.html">http://gcc.gnu.org/bugs.html</a>.</p>
12
13<hr />
14
15<h2>Table of Contents</h2>
16<ul>
17<li><a href="#report">Reporting Bugs</a>
18 <ul>
19 <li><a href="#need">What we need</a></li>
20 <li><a href="#dontwant">What we DON'T want</a></li>
21 <li><a href="#where">Where to post it</a></li>
22 <li><a href="#detailed">Detailed bug reporting instructions</a></li>
23 <li><a href="#gnat">Detailed bug reporting instructions for GNAT</a></li>
24 <li><a href="#pch">Detailed bug reporting instructions when using a precompiled header</a></li>
25 </ul>
26</li>
27<li><a href="#known">Frequently Reported Bugs in GCC</a>
28 <ul>
29 <li><a href="#cxx">C++</a>
30 <ul>
31 <li><a href="#missing">Missing features</a></li>
32 <li><a href="#fixed34">Bugs fixed in the 3.4 series</a></li>
33 </ul>
34 </li>
35 <li><a href="#fortran">Fortran</a></li>
36 </ul>
37</li>
38<li><a href="#nonbugs">Non-bugs</a>
39 <ul>
40 <li><a href="#nonbugs_general">General</a></li>
41 <li><a href="#nonbugs_c">C</a></li>
42 <li><a href="#nonbugs_cxx">C++</a>
43 <ul>
44 <li><a href="#upgrading">Common problems when upgrading the compiler</a></li>
45 </ul>
46 </li>
47 </ul>
48</li>
49</ul>
50
51<hr />
52
53<h1><a name="report">Reporting Bugs</a></h1>
54
55<p>The main purpose of a bug report is to enable us to fix the bug. The
56most important prerequisite for this is that the report must be complete and
57self-contained, which we explain in detail below.</p>
58
59<p>Before you report a bug, please check the
60<a href="#known">list of well-known bugs</a> and, <strong>if possible
61in any way, try a current development snapshot</strong>.
62If you want to report a bug with versions of GCC before 3.1 we strongly
63recommend upgrading to the current release first.</p>
64
65<p>Before reporting that GCC compiles your code incorrectly, please
66compile it with <code>gcc -Wall</code> and see whether this shows
67anything wrong with your code that could be the cause instead of a bug
68in GCC.</p>
69
70<h2>Summarized bug reporting instructions</h2>
71
72<p>After this summary, you'll find detailed bug reporting
73instructions, that explain how to obtain some of the information
74requested in this summary.</p>
75
76<h3><a name="need">What we need</a></h3>
77
78<p>Please include in your bug report all of the following items, the first
79three of which can be obtained from the output of <code>gcc -v</code>:</p>
80
81<ul>
82 <li>the exact version of GCC;</li>
83 <li>the system type;</li>
84 <li>the options given when GCC was configured/built;</li>
85 <li>the complete command line that triggers the bug;</li>
86 <li>the compiler output (error messages, warnings, etc.); and</li>
87 <li>the <em>preprocessed</em> file (<code>*.i*</code>) that triggers the
88 bug, generated by adding <code>-save-temps</code> to the complete
89 compilation command, or, in the case of a bug report for the GNAT front end,
90 a complete set of source files (see below).</li>
91</ul>
92
93<h3><a name="dontwant">What we do <strong>not</strong> want</a></h3>
94
95<ul>
96 <li>A source file that <code>#include</code>s header files that are left
97 out of the bug report (see above)</li>
98
99 <li>That source file and a collection of header files.</li>
100
101 <li>An attached archive (tar, zip, shar, whatever) containing all
102 (or some :-) of the above.</li>
103
104 <li>A code snippet that won't cause the compiler to produce the
105 exact output mentioned in the bug report (e.g., a snippet with just
106 a few lines around the one that <b>apparently</b> triggers the bug,
107 with some pieces replaced with ellipses or comments for extra
108 obfuscation :-)</li>
109
110 <li>The location (URL) of the package that failed to build (we won't
111 download it, anyway, since you've already given us what we need to
112 duplicate the bug, haven't you? :-)</li>
113
114 <li>An error that occurs only some of the times a certain file is
115 compiled, such that retrying a sufficient number of times results in
116 a successful compilation; this is a symptom of a hardware problem,
117 not of a compiler bug (sorry)</li>
118
119 <li>E-mail messages that complement previous, incomplete bug
120 reports. Post a new, self-contained, full bug report instead, if
121 possible as a follow-up to the original bug report</li>
122
123 <li>Assembly files (<code>*.s</code>) produced by the compiler, or any
124 binary files, such as object files, executables, core files, or
125 precompiled header files</li>
126
127 <li>Duplicate bug reports, or reports of bugs already fixed in the
128 development tree, especially those that have already been reported
129 as fixed last week :-)</li>
130
131 <li>Bugs in the assembler, the linker or the C library. These are
132 separate projects, with separate mailing lists and different bug
133 reporting procedures</li>
134
135 <li>Bugs in releases or snapshots of GCC not issued by the GNU
136 Project. Report them to whoever provided you with the release</li>
137
138 <li>Questions about the correctness or the expected behavior of
139 certain constructs that are not GCC extensions. Ask them in forums
140 dedicated to the discussion of the programming language</li>
141</ul>
142
143<h3><a name="where">Where to post it</a></h3>
144
145<p>Please submit your bug report directly to the
146<a href="http://gcc.gnu.org/bugzilla/">GCC bug database</a>.
147Alternatively, you can use the <code>gccbug</code> script that mails your bug
148report to the bug database.
149<br />
150Only if all this is absolutely impossible, mail all information to
151<a href="mailto:gcc-bugs@gcc.gnu.org">gcc-bugs@gcc.gnu.org</a>.</p>
152
153<h2><a name="detailed">Detailed bug reporting instructions</a></h2>
154
155<p>Please refer to the <a href="#gnat">next section</a> when reporting
156bugs in GNAT, the Ada compiler, or to the <a href="#pch">one after
157that</a> when reporting bugs that appear when using a precompiled header.</p>
158
159<p>In general, all the information we need can be obtained by
160collecting the command line below, as well as its output and the
161preprocessed file it generates.</p>
162
163<blockquote><p><code>gcc -v -save-temps <i>all-your-options
164source-file</i></code></p></blockquote>
165
166<p>Typically the preprocessed file (extension <code>.i</code> for C or
167<code>.ii</code> for C++, and <code>.f</code> if the preprocessor is used on
168Fortran files) will be large, so please compress the
169resulting file with one of the popular compression programs such as
170bzip2, gzip, zip or compress (in
171decreasing order of preference). Use maximum compression
172(<code>-9</code>) if available. Please include the compressed
173preprocessor output in your bug report, even if the source code is
174freely available elsewhere; it makes the job of our volunteer testers
175much easier.</p>
176
177<p>The <b>only</b> excuses to not send us the preprocessed sources are
178(i) if you've found a bug in the preprocessor, (ii) if you've reduced
179the testcase to a small file that doesn't include any other file or
180(iii) if the bug appears only when using precompiled headers. If you
181can't post the preprocessed sources because they're proprietary code,
182then try to create a small file that triggers the same problem.</p>
183
184<p>Since we're supposed to be able to re-create the assembly output
185(extension <code>.s</code>), you usually should not include
186it in the bug report, although you may want to post parts of it to
187point out assembly code you consider to be wrong.</p>
188
189<p>Whether to use MIME attachments or <code>uuencode</code> is up to
190you. In any case, make sure the compiler command line, version and
191error output are in plain text, so that we don't have to decode the
192bug report in order to tell who should take care of it. A meaningful
193subject indicating language and platform also helps.</p>
194
195<p>Please avoid posting an archive (.tar, .shar or .zip); we generally
196need just a single file to reproduce the bug (the .i/.ii/.f preprocessed
197file), and, by storing it in an archive, you're just making our
198volunteers' jobs harder. Only when your bug report requires multiple
199source files to be reproduced should you use an archive. This is, for example,
200the case if you are using <code>INCLUDE</code> directives in Fortran code,
201which are not processed by the preprocessor, but the compiler. In that case,
202we need the main file and all <code>INCLUDE</code>d files. In any case,
203make sure the compiler version, error message, etc, are included in
204the body of your bug report as plain text, even if needlessly
205duplicated as part of an archive.</p>
206
207<p>If you fail to supply enough information for a bug report to be
208reproduced, someone will probably ask you to post additional
209information (or just ignore your bug report, if they're in a bad day,
210so try to get it right on the first posting :-). In this case, please
211post the additional information to the bug reporting mailing list, not
212just to the person who requested it, unless explicitly told so. If
213possible, please include in this follow-up all the information you had
214supplied in the incomplete bug report (including the preprocessor
215output), so that the new bug report is self-contained.</p>
216
217<h2><a name="gnat">Detailed bug reporting instructions for GNAT</a></h2>
218
219<p>See the <a href="#detailed">previous section</a> for bug reporting
220instructions for GCC language implementations other than Ada.</p>
221
222<p>Bug reports have to contain at least the following information in
223order to be useful:</p>
224
225<ul>
226<li>the exact version of GCC, as shown by "<code>gcc -v</code>";</li>
227<li>the system type;</li>
228<li>the options when GCC was configured/built;</li>
229<li>the exact command line passed to the <code>gcc</code> program
230triggering the bug
231(not just the flags passed to <code>gnatmake</code>, but
232<code>gnatmake</code> prints the parameters it passed to <code>gcc</code>)</li>
233<li>a collection of source files for reproducing the bug,
234preferably a minimal set (see below);</li>
235<li>a description of the expected behavior;</li>
236<li>a description of actual behavior.</li>
237</ul>
238
239<p>If your code depends on additional source files (usually package
240specifications), submit the source code for these compilation units in
241a single file that is acceptable input to <code>gnatchop</code>,
242i.e. contains no non-Ada text. If the compilation terminated
243normally, you can usually obtain a list of dependencies using the
244"<code>gnatls -d <i>main_unit</i></code>" command, where
245<code><i>main_unit</i></code> is the file name of the main compilation
246unit (which is also passed to <code>gcc</code>).</p>
247
248<p>If you report a bug which causes the compiler to print a bug box,
249include that bug box in your report, and do not forget to send all the
250source files listed after the bug box along with your report.</p>
251
252<p>If you use <code>gnatprep</code>, be sure to send in preprocessed
253sources (unless you have to report a bug in <code>gnatprep</code>).</p>
254
255<p>When you have checked that your report meets these criteria, please
256submit it according to our <a href="#where">generic instructions</a>.
257(If you use a mailing list for reporting, please include an
258"<code>[Ada]</code>" tag in the subject.)</p>
259
260<h2><a name="pch">Detailed bug reporting instructions when using a
261precompiled header</a></h2>
262
263<p>If you're encountering a bug when using a precompiled header, the
264first thing to do is to delete the precompiled header, and try running
265the same GCC command again. If the bug happens again, the bug doesn't
266really involve precompiled headers, please report it without using
267them by following the instructions <a href="#detailed">above</a>.</p>
268
269<p>If you've found a bug while <i>building</i> a precompiled header
270(for instance, the compiler crashes), follow the usual instructions
271<a href="#detailed">above</a>.</p>
272
273<p>If you've found a real precompiled header bug, what we'll need to
274reproduce it is the sources to build the precompiled header (as a
275single <code>.i</code> file), the source file that uses the
276precompiled header, any other headers that source file includes, and
277the command lines that you used to build the precompiled header and to
278use it.</p>
279
280<p>Please <strong>don't</strong> send us the actual precompiled
281header. It is likely to be very large and we can't use it to
282reproduce the problem.</p>
283
284<hr />
285
286<h1><a name="known">Frequently Reported Bugs in GCC</a></h1>
287
288<p>This is a list of bugs in GCC that are reported very often, but not
289yet fixed. While it is certainly better to fix bugs instead of documenting
290them, this document might save people the effort of writing a bug report
291when the bug is already well-known.</p>
292
293<p>There are many reasons why a reported bug doesn't get fixed.
294It might be difficult to fix, or fixing it might break compatibility.
295Often, reports get a low priority when there is a simple work-around.
296In particular, bugs caused by invalid code have a simple work-around:
297<em>fix the code</em>.</p>
298
299<hr />
300
301<h2><a name="cxx">C++</a></h2>
302
303<h3><a name="missing">Missing features</a></h3>
304
305<dl>
306
307<dt>The <code>export</code> keyword is not implemented.</dt>
308<dd><p>Most C++ compilers (G++ included) do not yet implement
309<code>export</code>, which is necessary for separate compilation of
310template declarations and definitions. Without <code>export</code>, a
311template definition must be in scope to be used. The obvious
312workaround is simply to place all definitions in the header
313itself. Alternatively, the compilation unit containing template
314definitions may be included from the header.</p></dd>
315
316</dl>
317
318<h3><a name="fixed34">Bugs fixed in the 3.4 series</a></h3>
319
320<p>The following bugs are present up to (and including) GCC 3.3.x.
321They have been fixed in 3.4.0.</p>
322
323<dl>
324
325<dt>Two-stage name-lookup.</dt>
326
327<dd><p>GCC did not implement two-stage name-lookup (also see
328<a href="#new34">below</a>).</p></dd>
329
330<dt>Covariant return types.</dt>
331
332<dd><p>GCC did not implement non-trivial covariant returns.</p></dd>
333
334<dt>Parse errors for "simple" code.</dt>
335
336<dd><p>GCC gave parse errors for seemingly simple code, such as</p>
337
338<blockquote><pre>
339struct A
340{
341 A();
342 A(int);
343};
344
345struct B
346{
347 B(A);
348 B(A,A);
349 void foo();
350};
351
352A bar()
353{
354 B b(A(),A(1)); // Variable b, initialized with two temporaries
355 B(A(2)).foo(); // B temporary, initialized with A temporary
356 return (A()); // return A temporary
357}
358</pre></blockquote>
359
360<p>Although being valid code, each of the three lines with a comment was
361rejected by GCC. The work-arounds for older compiler versions proposed
362below do not change the semantics of the programs at all.</p>
363
364<p>The problem in the first case was that GCC started to parse the
365declaration of <code>b</code> as a function called <code>b</code> returning
366<code>B</code>, taking a function returning <code>A</code> as an argument.
367When it encountered the <code>1</code>, it was too late. To show the
368compiler that this should be really an expression, a comma operator with
369a dummy argument could be used:</p>
370
371<blockquote><pre>
372B b((0,A()),A(1));
373</pre></blockquote>
374
375<p>The work-around for simpler cases like the second one was to add
376additional parentheses around the expressions that were mistaken as
377declarations:</p>
378
379<blockquote><pre>
380(B(A(2))).foo();
381</pre></blockquote>
382
383<p>In the third case, however, additional parentheses were causing
384the problems: The compiler interpreted <code>A()</code> as a function
385(taking no arguments, returning <code>A</code>), and <code>(A())</code>
386as a cast lacking an expression to be casted, hence the parse error.
387The work-around was to omit the parentheses:</p>
388
389<blockquote><pre>
390return A();
391</pre></blockquote>
392
393<p>This problem occured in a number of variants; in <code>throw</code>
394statements, people also frequently put the object in parentheses.</p></dd>
395
396</dl>
397
398<hr />
399
400<h2><a name="fortran">Fortran</a></h2>
401
402<p>Fortran bugs are documented in the G77 manual rather than
403explicitly listed here. Please see
404<a href="http://gcc.gnu.org/onlinedocs/g77/Trouble.html">Known Causes of
405Trouble with GNU Fortran</a> in the G77 manual.</p>
406
407<hr />
408
409<h1><a name="nonbugs">Non-bugs</a></h1>
410
411<p>The following are not actually bugs, but are reported often
412enough to warrant a mention here.</p>
413
414<p>It is not always a bug in the compiler, if code which "worked" in a
415previous version, is now rejected. Earlier versions of GCC sometimes were
416less picky about standard conformance and accepted invalid source code.
417In addition, programming languages themselves change, rendering code
418invalid that used to be conforming (this holds especially for C++).
419In either case, you should update your code to match recent language
420standards.</p>
421
422<hr />
423
424<h2><a name="nonbugs_general">General</a></h2>
425
426<dl>
427<dt>Problems with floating point numbers - the
428<a href="http://gcc.gnu.org/PR323">most often reported non-bug</a>.</dt>
429<dd><p>In a number of cases, GCC appears to perform floating point
430computations incorrectly. For example, the C++ program</p>
431<blockquote><pre>
432#include &lt;iostream&gt;
433
434int main()
435{
436 double a = 0.5;
437 double b = 0.01;
438 std::cout &lt;&lt; (int)(a / b) &lt;&lt; std::endl;
439 return 0;
440}
441</pre></blockquote>
442<p>might print 50 on some systems and optimization levels, and 49 on
443others.</p>
444
445<p>This is the result of <em>rounding</em>: The computer cannot
446represent all real numbers exactly, so it has to use
447approximations. When computing with approximation, the computer needs
448to round to the nearest representable number.</p>
449
450<p>This is not a bug in the compiler, but an inherent limitation of
451the floating point types. Please study
452<a href="http://www.validlab.com/goldberg/paper.ps">this paper</a>
453for more information.</p></dd>
454</dl>
455
456<hr />
457
458<h2><a name="nonbugs_c">C</a></h2>
459
460<dl>
461<dt>Casting does not work as expected when optimization is turned on.</dt>
462
463<dd><p>This is often caused by a violation of aliasing rules, which are part
464of the ISO C standard. These rules say that a program is invalid if you try
465to access a variable through a pointer of an incompatible type. This is
466happening in the following example where a short is accessed through a
467pointer to integer (the code assumes 16-bit <code>short</code>s and 32-bit
468<code>int</code>s):</p>
469<blockquote><pre>
470#include &lt;stdio.h&gt;
471
472int main()
473{
474 short a[2];
475
476 a[0]=0x1111;
477 a[1]=0x1111;
478
479 *(int *)a = 0x22222222; /* violation of aliasing rules */
480
481 printf("%x %x\n", a[0], a[1]);
482 return 0;
483}
484</pre></blockquote>
485<p>The aliasing rules were designed to allow compilers more aggressive
486optimization. Basically, a compiler can assume that all changes to variables
487happen through pointers or references to variables of a type compatible to
488the accessed variable. Dereferencing a pointer that violates the aliasing
489rules results in undefined behavior.</p>
490
491<p>In the case above, the compiler may assume that no access through an
492integer pointer can change the array <code>a</code>, consisting of shorts.
493Thus, <code>printf</code> may be called with the original values of
494<code>a[0]</code> and <code>a[1]</code>. What really happens is up to
495the compiler and may change with architecture and optimization level.</p>
496
497<p>Recent versions of GCC turn on the option <code>-fstrict-aliasing</code>
498(which allows alias-based optimizations) by default with <code>-O2</code>.
499And some architectures then really print "1111 1111" as result. Without
500optimization the executable will generate the "expected" output
501"2222 2222".</p>
502
503<p>To disable optimizations based on alias-analysis for faulty legacy code,
504the option <code>-fno-strict-aliasing</code> can be used as a work-around.</p>
505
506<p>The option <code>-Wstrict-aliasing</code> (which is included in
507<code>-Wall</code>) warns about some - but not all - cases of violation
508of aliasing rules when <code>-fstrict-aliasing</code> is active.</p>
509
510<p>To fix the code above, you can use a <code>union</code> instead of a
511cast (note that this is a GCC extension which might not work with other
512compilers):</p>
513<blockquote><pre>
514#include &lt;stdio.h&gt;
515
516int main()
517{
518 union
519 {
520 short a[2];
521 int i;
522 } u;
523
524 u.a[0]=0x1111;
525 u.a[1]=0x1111;
526
527 u.i = 0x22222222;
528
529 printf("%x %x\n", u.a[0], u.a[1]);
530 return 0;
531}
532</pre></blockquote>
533<p>Now the result will always be "2222 2222".</p>
534
535<p>For some more insight into the subject, please have a look at
536<a href="http://mail-index.NetBSD.org/tech-kern/2003/08/11/0001.html">this
537article</a>.</p></dd>
538
539
540<dt>Cannot use preprocessor directive in macro arguments.</dt>
541<dd><p>Let me guess... you used an older version of GCC to compile code
542that looks something like this:</p>
543<blockquote><pre>
544 memcpy(dest, src,
545#ifdef PLATFORM1
546 12
547#else
548 24
549#endif
550 );
551</pre></blockquote>
552<p>and you got a whole pile of error messages:</p>
553<blockquote><pre>
554test.c:11: warning: preprocessing directive not recognized within macro arg
555test.c:11: warning: preprocessing directive not recognized within macro arg
556test.c:11: warning: preprocessing directive not recognized within macro arg
557test.c: In function `foo':
558test.c:6: undefined or invalid # directive
559test.c:8: undefined or invalid # directive
560test.c:9: parse error before `24'
561test.c:10: undefined or invalid # directive
562</pre></blockquote>
563
564<p>This is because your C library's <code>&lt;string.h&gt;</code> happens
565to define <code>memcpy</code> as a macro - which is perfectly legitimate.
566In recent versions of glibc, for example, <code>printf</code> is among those
567functions which are implemented as macros.</p>
568
569<p>Versions of GCC prior to 3.3 did not allow you to put <code>#ifdef</code>
570(or any other preprocessor directive) inside the arguments of a macro. The
571code therefore would not compile.</p>
572
573<p>As of GCC 3.3 this kind of construct is always accepted and the
574preprocessor will probably do what you expect, but see the manual for
575detailed semantics.</p>
576
577<p>However, this kind of code is not portable. It is "undefined behavior"
578according to the C standard; that means different compilers may do
579different things with it. It is always possible to rewrite code which
580uses conditionals inside macros so that it doesn't. You could write
581the above example</p>
582<blockquote><pre>
583#ifdef PLATFORM1
584 memcpy(dest, src, 12);
585#else
586 memcpy(dest, src, 24);
587#endif
588</pre></blockquote>
589<p>This is a bit more typing, but I personally think it's better style
590in addition to being more portable.</p></dd>
591
592
593<dt>Cannot initialize a static variable with <code>stdin</code>.</dt>
594<dd><p>This has nothing to do with GCC, but people ask us about it a
595lot. Code like this:</p>
596
597<blockquote><pre>
598#include &lt;stdio.h&gt;
599
600FILE *yyin = stdin;
601</pre></blockquote>
602
603<p>will not compile with GNU libc, because <code>stdin</code> is not a
604constant. This was done deliberately, to make it easier to maintain
605binary compatibility when the type <code>FILE</code> needs to be changed.
606It is surprising for people used to traditional Unix C libraries, but it
607is permitted by the C standard.</p>
608
609<p>This construct commonly occurs in code generated by old versions of
610lex or yacc. We suggest you try regenerating the parser with a
611current version of flex or bison, respectively. In your own code, the
612appropriate fix is to move the initialization to the beginning of
613main.</p>
614
615<p>There is a common misconception that the GCC developers are
616responsible for GNU libc. These are in fact two entirely separate
617projects; please check the
618<a href="http://www.gnu.org/software/libc/">GNU libc web pages</a>
619for details.
620</p></dd>
621</dl>
622
623<hr />
624
625<h2><a name="nonbugs_cxx">C++</a></h2>
626
627<dl>
628<dt>Nested classes can access private members and types of the containing
629class.</dt>
630
631<dd><p>Defect report 45 clarifies that nested classes are members of the
632class they are nested in, and so are granted access to private members of
633that class.</p></dd>
634
635<dt>G++ emits two copies of constructors and destructors.</dt>
636
637<dd><p>In general there are <em>three</em> types of constructors (and
638destructors).</p>
639<ol>
640<li>The complete object constructor/destructor.</li>
641<li>The base object constructor/destructor.</li>
642<li>The allocating constructor/deallocating destructor.</li>
643</ol>
644<p>The first two are different, when virtual base classes are involved.
645</p></dd>
646
647<dt>Global destructors are not run in the correct order.</dt>
648
649<dd><p>Global destructors should be run in the reverse order of their
650constructors <em>completing</em>. In most cases this is the same as
651the reverse order of constructors <em>starting</em>, but sometimes it
652is different, and that is important. You need to compile and link your
653programs with <code>--use-cxa-atexit</code>. We have not turned this
654switch on by default, as it requires a <code>cxa</code> aware runtime
655library (<code>libc</code>, <code>glibc</code>, or equivalent).</p></dd>
656
657<dt>Classes in exception specifiers must be complete types.</dt>
658
659<dd><p>[15.4]/1 tells you that you cannot have an incomplete type, or
660pointer to incomplete (other than <code><i>cv</i> void *</code>) in
661an exception specification.</p></dd>
662
663<dt>Exceptions don't work in multithreaded applications.</dt>
664
665<dd><p>You need to rebuild g++ and libstdc++ with
666<code>--enable-threads</code>. Remember, C++ exceptions are not like
667hardware interrupts. You cannot throw an exception in one thread and
668catch it in another. You cannot throw an exception from a signal
669handler and catch it in the main thread.</p></dd>
670
671<dt>Templates, scoping, and digraphs.</dt>
672
673<dd><p>If you have a class in the global namespace, say named <code>X</code>,
674and want to give it as a template argument to some other class, say
675<code>std::vector</code>, then <code>std::vector&lt;::X&gt;</code>
676fails with a parser error.</p>
677
678<p>The reason is that the standard mandates that the sequence
679<code>&lt;:</code> is treated as if it were the token <code>[</code>.
680(There are several such combinations of characters - they are called
681<em>digraphs</em>.) Depending on the version, the compiler then reports
682a parse error before the character <code>:</code> (the colon before
683<code>X</code>) or a missing closing bracket <code>]</code>.</p>
684
685<p>The simplest way to avoid this is to write <code>std::vector&lt;
686::X&gt;</code>, i.e. place a space between the opening angle bracket
687and the scope operator.</p></dd>
688
689
690<dt><a name="cxx_rvalbind">Copy constructor access check while
691initializing a reference.</a></dt>
692
693<dd><p>Consider this code:</p>
694
695<blockquote><pre>
696class A
697{
698public:
699 A();
700
701private:
702 A(const A&amp;); // private copy ctor
703};
704
705A makeA(void);
706void foo(const A&amp;);
707
708void bar(void)
709{
710 foo(A()); // error, copy ctor is not accessible
711 foo(makeA()); // error, copy ctor is not accessible
712
713 A a1;
714 foo(a1); // OK, a1 is a lvalue
715}</pre></blockquote>
716
717<p>Starting with GCC 3.4.0, binding an rvalue to a const reference requires
718an accessible copy constructor. This might be surprising at first sight,
719especially since most popular compilers do not correctly implement this
720rule.</p>
721
722<p>The C++ Standard says that a temporary object should be created in
723this context and its contents filled with a copy of the object we are
724trying to bind to the reference; it also says that the temporary copy
725can be elided, but the semantic constraints (eg. accessibility) of the
726copy constructor still have to be checked.</p>
727
728<p>For further information, you can consult the following paragraphs of
729the C++ standard: [dcl.init.ref]/5, bullet 2, sub-bullet 1, and
730[class.temporary]/2.</p></dd>
731</dl>
732
733<h3><a name="upgrading">Common problems when upgrading the compiler</a></h3>
734
735<h4>ABI changes</h4>
736
737<p>The C++ application binary interface (ABI) consists of two
738components: the first defines how the elements of classes are laid
739out, how functions are called, how function names are mangled, etc;
740the second part deals with the internals of the objects in libstdc++.
741Although we strive for a non-changing ABI, so far we have had to
742modify it with each major release. If you change your compiler to a
743different major release <em>you must recompile all libraries that
744contain C++ code</em>. If you fail to do so you risk getting linker
745errors or malfunctioning programs. Some of our Java support libraries
746also contain C++ code, so you might want to recompile all libraries to
747be safe. It should not be necessary to recompile if you have changed
748to a bug-fix release of the same version of the compiler; bug-fix
749releases are careful to avoid ABI changes. See also the
750<a href="onlinedocs/gcc/Compatibility.html">compatibility section</a>
751of the GCC manual.</p>
752
753<p>Remark: A major release is designated by a change to the first or second
754component of the two- or three-part version number. A minor (bug-fix)
755release is designated by a change to the third component only. Thus GCC
7563.2 and 3.3 are major releases, while 3.3.1 and 3.3.2 are bug-fix releases
757for GCC 3.3. With the 3.4 series we are introducing a new naming scheme;
758the first release of this series is 3.4.0 instead of just 3.4.</p>
759
760<h4>Standard conformance</h4>
761
762<p>With each release, we try to make G++ conform closer to the ISO C++ standard
763(available at
764<a href="http://www.ncits.org/cplusplus.htm">http://www.ncits.org/cplusplus.htm</a>).
765We have also implemented some of the core and library defect reports
766(available at
767<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html">http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html</a>
768&amp;
769<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html">http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html</a>
770respectively).</p>
771
772<p>Non-conforming legacy code that worked with older versions of GCC may be
773rejected by more recent compilers. There is no command-line switch to ensure
774compatibility in general, because trying to parse standard-conforming and
775old-style code at the same time would render the C++ frontend unmaintainable.
776However, some non-conforming constructs are allowed when the command-line
777option <code>-fpermissive</code> is used.</p>
778
779<p>Two milestones in standard conformance are GCC 3.0 (including a major
780overhaul of the standard library) and the 3.4.0 version (with its new C++
781parser).</p>
782
783<h4>New in GCC 3.0</h4>
784
785<ul>
786
787<li>The standard library is much more conformant, and uses the
788<code>std::</code> namespace (which is now a real namespace, not an
789alias for <code>::</code>).</li>
790
791<li>The standard header files for the c library don't end with
792<code>.h</code>, but begin with <code>c</code> (i.e.
793<code>&lt;cstdlib&gt;</code> rather than <code>&lt;stdlib.h&gt;</code>).
794The <code>.h</code> names are still available, but are deprecated.</li>
795
796<li><code>&lt;strstream&gt;</code> is deprecated, use
797<code>&lt;sstream&gt;</code> instead.</li>
798
799<li><code>streambuf::seekoff</code> &amp;
800<code>streambuf::seekpos</code> are private, instead use
801<code>streambuf::pubseekoff</code> &amp;
802<code>streambuf::pubseekpos</code> respectively.</li>
803
804<li>If <code>std::operator &lt;&lt; (std::ostream &amp;, long long)</code>
805doesn't exist, you need to recompile libstdc++ with
806<code>--enable-long-long</code>.</li>
807
808</ul>
809
810<p>If you get lots of errors about things like <code>cout</code> not being
811found, you've most likely forgotten to tell the compiler to look in the
812<code>std::</code> namespace. There are several ways to do this:</p>
813
814<ul>
815
816<li>Say <code>std::cout</code> at the call. This is the most explicit
817way of saying what you mean.</li>
818
819<li>Say <code>using std::cout;</code> somewhere before the call. You
820will need to do this for each function or type you wish to use from the
821standard library.</li>
822
823<li>Say <code>using namespace std;</code> somewhere before the call.
824This is the quick-but-dirty fix. This brings the <em>whole</em> of the
825<code>std::</code> namespace into scope. <em>Never</em> do this in a
826header file, as every user of your header file will be affected by this
827decision.</li>
828
829</ul>
830
831<h4><a name="new34">New in GCC 3.4.0</a></h4>
832
833<p>The new parser brings a lot of improvements, especially concerning
834name-lookup.</p>
835
836<ul>
837
838<li>The "implicit typename" extension got removed (it was already deprecated
839since GCC 3.1), so that the following code is now rejected, see [14.6]:
840<blockquote><pre>
841template &lt;typename&gt; struct A
842{
843 typedef int X;
844};
845
846template &lt;typename T&gt; struct B
847{
848 A&lt;T&gt;::X x; // error
849 typename A&lt;T&gt;::X y; // OK
850};
851
852B&lt;void&gt; b;
853</pre></blockquote></li>
854
855<li>For similar reasons, the following code now requires the
856<code>template</code> keyword, see [14.2]:
857<blockquote><pre>
858template &lt;typename&gt; struct A
859{
860 template &lt;int&gt; struct X {};
861};
862
863template &lt;typename T&gt; struct B
864{
865 typename A&lt;T&gt;::X&lt;0&gt; x; // error
866 typename A&lt;T&gt;::template X&lt;0&gt; y; // OK
867};
868
869B&lt;void&gt; b;
870</pre></blockquote></li>
871
872<li>We now have two-stage name-lookup, so that the following code is
873rejected, see [14.6]/9:
874<blockquote><pre>
875template &lt;typename T&gt; int foo()
876{
877 return i; // error
878}
879</pre></blockquote></li>
880
881<li>This also affects members of base classes, see [14.6.2]:
882<blockquote><pre>
883template &lt;typename&gt; struct A
884{
885 int i, j;
886};
887
888template &lt;typename T&gt; struct B : A&lt;T&gt;
889{
890 int foo1() { return i; } // error
891 int foo2() { return this-&gt;i; } // OK
892 int foo3() { return B&lt;T&gt;::i; } // OK
893 int foo4() { return A&lt;T&gt;::i; } // OK
894
895 using A&lt;T&gt;::j;
896 int foo5() { return j; } // OK
897};
898</pre></blockquote></li>
899
900</ul>
901
902<p>In addition to the problems listed above, the manual contains a section on
903<a href="http://gcc.gnu.org/onlinedocs/gcc/C---Misunderstandings.html">Common
904Misunderstandings with GNU C++</a>.</p>
905
906</body>
907</html>
Note: See TracBrowser for help on using the repository browser.