Changeset 1391 for branches/GNU/src/gcc/bugs.html
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (21 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 dir.info 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/bugs.html
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r1390 r1391 9 9 10 10 <p>The latest version of this document is always available at 11 <a href="http:// www.gnu.org/software/gcc/bugs.html">http://www.gnu.org/software/gcc/bugs.html</a>.</p>11 <a href="http://gcc.gnu.org/bugs.html">http://gcc.gnu.org/bugs.html</a>.</p> 12 12 13 13 <hr /> … … 16 16 <ul> 17 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>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 26 </li> 27 <li><a href="#manage">Managing Bugs (GNATS and the test-suite)</a></li>28 27 <li><a href="#known">Frequently Reported Bugs in GCC</a> 29 <ul>30 <li><a href="#general">General</a></li>31 <li><a href="#fortran">Fortran</a></li>32 <li><a href="#c">C</a></li>33 <li><a href="#cplusplus">C++</a>34 28 <ul> 35 <li><a href="# updating">Common problems updating from G++ 2.95 to36 G++ 3.0</a></li>37 <li><a href="#nonbugs">Non-bugs</a></li>38 <li><a href="#missing">Missing features</a></li>39 <li><a href="#parsing">Parse errors for "simple" code</a></li>40 < li><a href="#-O3">Optimization at <code>-O3</code> takes a41 very long time</a></li>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 upcoming 3.4 series</a></li> 33 </ul> 34 </li> 35 <li><a href="#fortran">Fortran</a></li> 42 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> 43 46 </li> 44 </ul>45 47 </ul> 48 </li> 46 49 </ul> 47 50 … … 50 53 <h1><a name="report">Reporting Bugs</a></h1> 51 54 52 <p>Our preferred way of receiving bugs is via the 53 <a href="gnats.html">GCC GNATS bug reporting system</a>.</p> 55 <p>The main purpose of a bug report is to enable us to fix the bug. The 56 most important prerequisite for this is that the report must be complete and 57 self-contained, which we explain in detail below.</p> 54 58 55 59 <p>Before you report a bug, please check the … … 72 76 <h3><a name="need">What we need</a></h3> 73 77 74 Please include in your bug report all of the following items, the first75 three of which can be obtained from the output of <code>gcc -v</code>: 78 <p>Please include in your bug report all of the following items, the first 79 three of which can be obtained from the output of <code>gcc -v</code>:</p> 76 80 77 81 <ul> … … 140 144 141 145 <p>Please submit your bug report directly to the 142 <a href="gnats.html">GCC GNATS bug database</a>. 143 Only if this is not possible, mail all information to 144 <a href="mailto:bug-gcc@gnu.org">bug-gcc@gnu.org</a> or 146 <a href="http://gcc.gnu.org/bugzilla/">GCC bug database</a>. 147 Alternatively, you can use the <code>gccbug</code> script that mails your bug 148 report to the bug database. 149 <br /> 150 Only if all this is absolutely impossible, mail all information to 145 151 <a href="mailto:gcc-bugs@gcc.gnu.org">gcc-bugs@gcc.gnu.org</a>.</p> 146 147 <p>The GCC lists have message size limits (200 kbytes) and bug reports148 over those limits will currently be bounced. If your bug is larger149 than that, please post it using the <a href="gnats.html">GCC GNATS bug150 database</a>.</p>151 152 152 153 <h2><a name="detailed">Detailed bug reporting instructions</a></h2> … … 160 161 preprocessed file it generates.</p> 161 162 162 <blockquote>< code>gcc -v -save-temps <i>all-your-options163 source-file</i></code></ blockquote>163 <blockquote><p><code>gcc -v -save-temps <i>all-your-options 164 source-file</i></code></p></blockquote> 164 165 165 166 <p>Typically the preprocessed file (extension <code>.i</code> for C or 166 <code>.ii</code> for C++) will be large, so please compress the 167 <code>.ii</code> for C++, and <code>.f</code> if the preprocessor is used on 168 Fortran files) will be large, so please compress the 167 169 resulting file with one of the popular compression programs such as 168 170 bzip2, gzip, zip or compress (in … … 192 194 193 195 <p>Please avoid posting an archive (.tar, .shar or .zip); we generally 194 need just a single file to reproduce the bug (the .i/.ii preprocessed196 need just a single file to reproduce the bug (the .i/.ii/.f preprocessed 195 197 file), and, by storing it in an archive, you're just making our 196 198 volunteers' jobs harder. Only when your bug report requires multiple 197 source files to be reproduced should you use an archive. In any case, 199 source files to be reproduced should you use an archive. This is, for example, 200 the case if you are using <code>INCLUDE</code> directives in Fortran code, 201 which are not processed by the preprocessor, but the compiler. In that case, 202 we need the main file and all <code>INCLUDE</code>d files. In any case, 198 203 make sure the compiler version, error message, etc, are included in 199 204 the body of your bug report as plain text, even if needlessly … … 277 282 reproduce the problem.</p> 278 283 279 <h1><a name="manage">Managing Bugs (GNATS and the test-suite)</a></h1>280 281 <p>This section contains information mostly intended for GCC282 contributors.</p>283 284 <p>If you find a bug, but you are not fixing it (yet):</p>285 <ol>286 <li>Create a (minimal) test-case.</li>287 <li>Add the test-case to our test-suite, marking it as XFAIL unless288 the bug is a regression.</li>289 <li>Add a bug report referencing the test-case to GNATS.</li>290 </ol>291 292 <p>If you fix a bug for which there is already a GNATS entry:</p>293 <ol>294 <li>Remove the XFAIL on the test-case.</li>295 <li>Close the bug report in GNATS.</li>296 </ol>297 298 <p>If you find a bug, and you are fixing it right then:</p>299 <ol>300 <li>Create a (minimal) test-case.</li>301 <li>Add the test-case to our test-suite, marking it as PASS.</li>302 <li>Check in your fixes.</li>303 </ol>304 305 284 <hr /> 306 285 307 286 <h1><a name="known">Frequently Reported Bugs in GCC</a></h1> 308 287 309 <h2><a name="fortran">Fortran</a></h2> 310 311 <p>Fortran bugs are documented in the G77 manual rather than 312 explicitly listed here. Please see 313 <a href="http://gcc.gnu.org/onlinedocs/g77/Trouble.html">Known Causes of 314 Trouble with GNU Fortran</a> in the G77 manual.</p> 288 <p>This is a list of bugs in GCC that are reported very often, but not 289 yet fixed. While it is certainly better to fix bugs instead of documenting 290 them, this document might save people the effort of writing a bug report 291 when the bug is already well-known.</p> 292 293 <p>There are many reasons why a reported bug doesn't get fixed. 294 It might be difficult to fix, or fixing it might break compatibility. 295 Often, reports get a low priority when there is a simple work-around. 296 In particular, bugs caused by invalid code have a simple work-around: 297 <em>fix the code</em>.</p> 315 298 316 299 <hr /> 317 300 318 <h2><a name="c">C</a></h2> 319 320 <p>The following are not bugs in the C compiler, but are reported 321 often enough to warrant a mention here.</p> 322 323 <dl> 324 <dt>Cannot initialize a static variable with <code>stdin</code>.</dt> 325 <dd><p>This has nothing to do with GCC, but people ask us about it a 326 lot. Code like this:</p> 327 328 <blockquote><pre> 329 #include <stdio.h> 330 331 FILE *yyin = stdin; 332 </pre></blockquote> 333 334 <p>will not compile with GNU libc (GNU/Linux libc6), because 335 <code>stdin</code> is not a constant. This was done deliberately, to make 336 it easier to maintain binary compatibility when the type <code>FILE</code> 337 needs to be changed. It is surprising for people used to traditional Unix 338 C libraries, but it is permitted by the C standard.</p> 339 340 <p>This construct commonly occurs in code generated by old versions of 341 lex or yacc. We suggest you try regenerating the parser with a 342 current version of flex or bison, respectively. In your own code, the 343 appropriate fix is to move the initialization to the beginning of 344 main.</p> 345 346 <p>There is a common misconception that the GCC developers are 347 responsible for GNU libc. These are in fact two entirely separate 348 projects; please check the 349 <a href="http://www.gnu.org/software/glibc/">GNU libc web pages</a> 350 for details. 351 </p></dd> 352 353 <dt>Cannot use preprocessor directive in macro arguments.</dt> 354 <dd><p>Let me guess... you wrote code that looks something like this:</p> 355 <blockquote><pre> 356 memcpy(dest, src, 357 #ifdef PLATFORM1 358 12 359 #else 360 24 361 #endif 362 ); 363 </pre></blockquote> 364 <p>and you got a whole pile of error messages:</p> 365 <blockquote><code> 366 367 test.c:11: warning: preprocessing directive not recognized within 368 macro arg<br /> 369 test.c:11: warning: preprocessing directive not recognized within 370 macro arg<br /> 371 test.c:11: warning: preprocessing directive not recognized within 372 macro arg<br /> 373 test.c: In function `foo':<br /> 374 test.c:6: undefined or invalid # directive<br /> 375 test.c:8: undefined or invalid # directive<br /> 376 test.c:9: parse error before `24'<br /> 377 test.c:10: undefined or invalid # directive<br /> 378 test.c:11: parse error before `#'<br /> 379 </code></blockquote> 380 381 <p><strong>Update:</strong> As of GCC 3.2 this kind of construct is 382 always accepted and CPP will probably do what you expect, but see the 383 manual for detailed semantics.</p> 384 385 <p>However, versions of GCC prior to 3.2 did not allow you to put 386 <code>#ifdef</code> (or any other directive) inside the arguments of a 387 macro. Your C library's <code><string.h></code> happens to 388 define <code>memcpy</code> as a macro - this is perfectly legitimate. 389 The code therefore would not compile.</p> 390 391 <p>This kind of code is not portable. It is "undefined behavior" 392 according to the C standard; that means different compilers will do 393 different things with it. It is always possible to rewrite code which 394 uses conditionals inside macros so that it doesn't. You could write 395 the above example</p> 396 <blockquote><pre> 397 #ifdef PLATFORM1 398 memcpy(dest, src, 12); 399 #else 400 memcpy(dest, src, 24); 401 #endif 402 </pre></blockquote> 403 <p>This is a bit more typing, but I personally think it's better style 404 in addition to being more portable.</p> 405 406 <p>In recent versions of glibc, <code>printf</code> is among the 407 functions which are implemented as macros.</p></dd> 408 </dl> 409 410 <hr /> 411 412 <h2><a name="cplusplus">C++</a></h2> 413 414 <p>This is the list of bugs (and non-bugs) in g++ (aka GNU C++) that 415 are reported very often, but not yet fixed. While it is certainly 416 better to fix bugs instead of documenting them, this document might 417 save people the effort of writing a bug report when the bug is already 418 well-known. <a href="#report">How to report bugs</a> tells you how to 419 report a bug.</p> 420 421 <p>There are many reasons why reported bugs don't get fixed. It might 422 be difficult to fix, or fixing it might break compatibility. Often, 423 reports get a low priority when there is a simple work-around. In 424 particular, bugs caused by invalid C++ code have a simple work-around, 425 <em>fix the code</em>. Now that there is an agreed ISO/ANSI standard 426 for C++, the compiler has a definitive document to adhere to. Earlier 427 versions might have accepted source code that is <em>no longer</em> 428 C++. This means that code which might have `worked' in a previous 429 version, is now rejected. You should update your code to be C++.</p> 430 431 <p>You should try to use the latest stable release of the GNU C++ 432 compiler.</p> 433 434 <h3><a name="updating">Common problems updating from G++ 2.95 to G++ 435 3.0</a></h3> 436 437 <p>G++ 3.0 conforms much closer to the ISO C++ standard (available at 438 <a href="http://www.ncits.org/cplusplus.htm">http://www.ncits.org/cplusplus.htm</a>).</p> 439 440 <p>We have also implemented some of the core and library defect reports 441 (available at 442 <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html">http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html</a> 443 & 444 <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html"> 445 http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html</a> 446 respectively).</p> 447 448 <ul> 449 450 <li>The ABI has changed. This means that both class layout and name 451 mangling is different. You <em>must</em> recompile all c++ libraries (if 452 you don't you will get link errors).</li> 453 454 <li>The standard library is much more conformant, and uses the 455 <code>std::</code> namespace.</li> 456 457 <li><code>std::</code> is now a real namespace, not an alias for 458 <code>::</code>.</li> 459 460 <li>The standard header files for the c library don't end with 461 <code>.h</code>, but begin with <code>c</code> (i.e. 462 <code><cstdlib></code> rather than <code><stdlib.h></code>). 463 The <code>.h</code> names are still available, but are deprecated.</li> 464 465 <li><code><strstream></code> is deprecated, use 466 <code><sstream></code> instead.</li> 467 468 <li><code>streambuf::seekoff</code> & 469 <code>streambuf::seekpos</code> are private, instead use 470 <code>streambuf::pubseekoff</code> & 471 <code>streambuf::pubseekpos</code> respectively.</li> 472 473 <li>If <code>std::operator << (std::ostream &, long long)</code> 474 doesn't exist, you need to recompile libstdc++ with 475 <code>--enable-long-long</code>.</li> 476 477 </ul> 478 479 This means you may get lots of errors about things like 480 <code>strcmp</code> not being found. You've most likely forgotten to 481 tell the compiler to look in the <code>std::</code> namespace. There are 482 several ways to do this, 483 484 <ul> 485 486 <li>Say, <code>std::strcmp</code> at the call. This is the most explicit 487 way of saying what you mean.</li> 488 489 <li>Say, <code>using std::strcmp;</code> somewhere before the call. You 490 will need to do this for each function or type you wish to use from the 491 standard library.</li> 492 493 <li>Say, <code>using namespace std;</code> somewhere before the call. 494 This is the quick-but-dirty fix. This brings the <em>whole</em> of the 495 <code>std::</code> namespace into scope. <em>Never</em> do this in a 496 header file, as you will be forcing users of your header file to do the 497 same.</li> 498 499 </ul> 500 501 <h3><a name="abi">ABI bugs</a></h3> 502 503 <p>3.0 had a new ABI, which affected class layout, function mangling and 504 calling conventions. We had intended it to be complete, unfortunately 505 some issues came to light, too late to fix in the 3.0 series. 506 The ABI should not change in dot releases, so we addressed most issues 507 in GCC 3.1. 508 </p> 509 510 <dl> 511 512 <dt>Covariant return types</dt> 513 514 <dd>We do not implement non-trivial covariant returns. We also generate 515 incorrect virtual function tables for trivial covariance. Although 516 trivial covariance will work, it is incompatible with the ABI. GNATS PR 517 3706 tracks this problem.</dd> 518 519 </dl> 520 521 <h3><a name="nonbugs">Non-bugs</a></h3> 522 523 <p>Here are some features that have been reported as bugs, but are 524 not.</p> 525 526 <dl> 527 528 <dt>Nested classes can access private types of the containing 529 class.</dt> 530 <dd><p>G++ now implements type access control on member types. Defect 531 report 45 clarifies that nested classes are members of the class they 532 are nested in, and so are granted access to private members of that 533 class.</p></dd> 534 535 <dt>Classes in exception specifiers must be complete types.</dt> 536 <dd><p>[15.4]/1 tells you that you cannot have an incomplete type, or 537 pointer to incomplete (other than <code><i>cv</i> void *</code>) in 538 an exception specification.</p></dd> 539 540 <dt>G++ emits two copies of constructors and destructors.</dt> 541 542 <dd><p>In general there are <em>three</em> types of constructors (and 543 destructors).</p> 544 <ol> 545 <li>The complete object constructor/destructor.</li> 546 <li>The base object constructor/destructor.</li> 547 <li>The allocating destructor/deallocating destructor.</li> 548 </ol> 549 <p>The first two are different, when virtual base classes are involved. 550 In some cases we can do better, and this is logged in GNATS.</p></dd> 551 552 <dt>Exceptions don't work in multithreaded applications.</dt> 553 554 <dd><p>You need to rebuild g++ and libstdc++ with 555 <code>--enable-threads</code>. Remember, c++ exceptions are not like 556 hardware interrupts. You cannot throw an exception in one thread and 557 catch it in another. You cannot throw an exception from a signal 558 handler, and catch it in the main thread.</p></dd> 559 560 <dt>Global destructors are not run in the correct order.</dt> 561 562 <dd><p>Global destructors should be run in the reverse order of their 563 constructors <em>completing</em>. In most cases this is the same as 564 the reverse order of constructors <em>starting</em>, but sometimes it 565 is different, and that is important. You need to compile and link your 566 programs with <code>--use-cxa-atexit</code>. We have not turned this 567 switch on by default, as it requires a <code>cxa</code> aware runtime 568 library (<code>libc</code>, <code>glibc</code>, or 569 equivalent).</p></dd> 570 571 <dt>Problems with floating point computations.</dt> 572 <dd><p>In a number of cases, GCC appears to perform floating point 573 computations incorrectly. For example, the program</p> 574 <blockquote><code> 575 #include <iostream><br /> 576 <br /> 577 int main() {<br /> 578 <br /> 579 double min = 0.0;<br /> 580 double max = 0.5;<br /> 581 double width = 0.01;<br /> 582 std::cout << (int)(((max - min) / width) - 1) << 583 std::endl;<br /> 584 <br /> 585 }<br /> 586 </code></blockquote> 587 <p>might print 49 on some systems and optimization levels, and 48 on 588 others.</p> 589 590 <p>The is the result of <em>rounding</em>: The computer cannot 591 represent all real numbers exactly, so it has to use 592 approximations. When computing with approximation, the computer needs 593 to round to the nearest representable number.</p> 594 595 <p>This is not a bug in the compiler, but an inherent limitation of 596 the float and double types. Please study 597 <a href="http://www.validlab.com/goldberg/paper.ps">this paper</a> 598 for more information.</p></dd> 599 600 <dt>Templates, scoping, and digraphs.</dt> 601 602 <dd><p>If you have a class in global namespace, say named 603 <code>X</code>, and want to give it as a template argument to some 604 other class, say <code>std::vector</code>, then this here fails with a 605 parser error: <code>std::vector<::X></code>. 606 </p> 607 608 <p> 609 The reason is that the standard mandates that the sequence 610 <code><:</code> is treated as if it were the token 611 <code>[</code>, and the parser then reports a parse error before the 612 character <code>:</code> (by which it means the second 613 colon). There are several such combinations of characters, and 614 they are called <em>digraphs</em>. 615 </p> 616 617 <p> 618 The simplest way to avoid this is to write <code>std::vector< 619 ::X></code>, i.e. place a space between the opening angle bracket 620 and the scope operator. 621 </p></dd> 622 623 624 </dl> 301 <h2><a name="cxx">C++</a></h2> 625 302 626 303 <h3><a name="missing">Missing features</a></h3> 627 <p>We know some things are missing from G++.</p>628 304 629 305 <dl> … … 638 314 definitions may be included from the header.</p></dd> 639 315 640 <dt>Two stage lookup in templates is not implemented.</dt>641 <dd><p>[14.6] specifies how names are looked up inside a template. G++642 does not do this correctly, but for most templates this will not be643 noticeable.</p></dd>644 645 316 </dl> 646 317 647 <h3><a name="parsing">Parse errors for "simple" code</a></h3> 648 649 Up to and including GCC 3.0, the compiler will give "parse error" for 650 seemingly simple code, such as 651 652 <pre> 653 struct A{ 318 <h3><a name="fixed34">Bugs fixed in the upcoming 3.4 series</a></h3> 319 320 <p>The following bugs are present up to (and including) GCC 3.3.x. 321 They 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> 339 struct A 340 { 654 341 A(); 655 342 A(int); 656 void func();657 343 }; 658 344 659 struct B{ 345 struct B 346 { 660 347 B(A); 661 348 B(A,A); 662 void f unc();349 void foo(); 663 350 }; 664 351 665 void foo(){ 666 B b(A(),A(1)); //Variable b, initialized with two temporaries 667 B(A(2)).func(); //B temporary, initialized with A temporary 352 A 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 668 357 } 669 </pre> 670 The problem is that GCC starts to parse the declaration of 671 <code>b</code> as a function <code>b</code> returning <code>B</code>, 672 taking a function returning <code>A</code> as an argument. When it 673 sees the 1, it is too late. The work-around in these cases is to add 674 additional parentheses around the expressions that are mistaken as 675 declarations: 676 <pre> 677 (B(A(2))).func(); 678 </pre> 679 Sometimes, even that is not enough; to show the compiler that this 680 should be really an expression, a comma operator with a dummy argument 681 can be used: 682 <pre> 683 B b((0,A()),A(1)); 684 </pre> 685 <p> 686 Another example is the parse error for the <code>return</code> 687 statement in</p> 688 <pre> 689 struct A{}; 690 691 struct B{ 692 A a; 693 A f1(bool); 358 </pre></blockquote> 359 360 <p>Although being valid code, each of the three lines with a comment was 361 rejected by GCC. The work-arounds for older compiler versions proposed 362 below 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 365 declaration 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. 367 When it encountered the <code>1</code>, it was too late. To show the 368 compiler that this should be really an expression, a comma operator with 369 a dummy argument could be used:</p> 370 371 <blockquote><pre> 372 B b((0,A()),A(1)); 373 </pre></blockquote> 374 375 <p>The work-around for simpler cases like the second one was to add 376 additional parentheses around the expressions that were mistaken as 377 declarations:</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 384 the problems: The compiler interpreted <code>A()</code> as a function 385 (taking no arguments, returning <code>A</code>), and <code>(A())</code> 386 as a cast lacking an expression to be casted, hence the parse error. 387 The work-around was to omit the parentheses:</p> 388 389 <blockquote><pre> 390 return A(); 391 </pre></blockquote> 392 393 <p>This problem occured in a number of variants; in <code>throw</code> 394 statements, 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 403 explicitly listed here. Please see 404 <a href="http://gcc.gnu.org/onlinedocs/g77/Trouble.html">Known Causes of 405 Trouble 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 412 enough to warrant a mention here.</p> 413 414 <p>It is not always a bug in the compiler, if code which "worked" in a 415 previous version, is now rejected. Earlier versions of GCC sometimes were 416 less picky about standard conformance and accepted invalid source code. 417 In addition, programming languages themselves change, rendering code 418 invalid that used to be conforming (this holds especially for C++). 419 In either case, you should update your code to match recent language 420 standards.</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 430 computations incorrectly. For example, the C++ program</p> 431 <blockquote><pre> 432 #include <iostream> 433 434 int main() 435 { 436 double a = 0.5; 437 double b = 0.01; 438 std::cout << (int)(a / b) << std::endl; 439 return 0; 440 } 441 </pre></blockquote> 442 <p>might print 50 on some systems and optimization levels, and 49 on 443 others.</p> 444 445 <p>The is the result of <em>rounding</em>: The computer cannot 446 represent all real numbers exactly, so it has to use 447 approximations. When computing with approximation, the computer needs 448 to round to the nearest representable number.</p> 449 450 <p>This is not a bug in the compiler, but an inherent limitation of 451 the floating point types. Please study 452 <a href="http://www.validlab.com/goldberg/paper.ps">this paper</a> 453 for 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 464 of the ISO C standard. These rules say that a program is invalid if you try 465 to access a variable through a pointer of an incompatible type. This is 466 happening in the following example where a short is accessed through a 467 pointer 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 <stdio.h> 471 472 int 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 486 optimization. Basically, a compiler can assume that all changes to variables 487 happen through pointers or references to variables of a type compatible to 488 the accessed variable. Dereferencing a pointer that violates the aliasing 489 rules results in undefined behavior.</p> 490 491 <p>In the case above, the compiler may assume that no access through an 492 integer pointer can change the array <code>a</code>, consisting of shorts. 493 Thus, <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 495 the 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>. 499 And some architectures then really print "1111 1111" as result. Without 500 optimization 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, 504 the 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 508 of 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 511 cast (note that this is a GCC extension which might not work with other 512 compilers):</p> 513 <blockquote><pre> 514 #include <stdio.h> 515 516 int 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 537 article</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 542 that 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> 554 test.c:11: warning: preprocessing directive not recognized within macro arg 555 test.c:11: warning: preprocessing directive not recognized within macro arg 556 test.c:11: warning: preprocessing directive not recognized within macro arg 557 test.c: In function `foo': 558 test.c:6: undefined or invalid # directive 559 test.c:8: undefined or invalid # directive 560 test.c:9: parse error before `24' 561 test.c:10: undefined or invalid # directive 562 </pre></blockquote> 563 564 <p>This is because your C library's <code><string.h></code> happens 565 to define <code>memcpy</code> as a macro - which is perfectly legitimate. 566 In recent versions of glibc, for example, <code>printf</code> is among those 567 functions 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 571 code therefore would not compile.</p> 572 573 <p>As of GCC 3.3 this kind of construct is always accepted and the 574 preprocessor will probably do what you expect, but see the manual for 575 detailed semantics.</p> 576 577 <p>However, this kind of code is not portable. It is "undefined behavior" 578 according to the C standard; that means different compilers may do 579 different things with it. It is always possible to rewrite code which 580 uses conditionals inside macros so that it doesn't. You could write 581 the 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 590 in 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 595 lot. Code like this:</p> 596 597 <blockquote><pre> 598 #include <stdio.h> 599 600 FILE *yyin = stdin; 601 </pre></blockquote> 602 603 <p>will not compile with GNU libc, because <code>stdin</code> is not a 604 constant. This was done deliberately, to make it easier to maintain 605 binary compatibility when the type <code>FILE</code> needs to be changed. 606 It is surprising for people used to traditional Unix C libraries, but it 607 is permitted by the C standard.</p> 608 609 <p>This construct commonly occurs in code generated by old versions of 610 lex or yacc. We suggest you try regenerating the parser with a 611 current version of flex or bison, respectively. In your own code, the 612 appropriate fix is to move the initialization to the beginning of 613 main.</p> 614 615 <p>There is a common misconception that the GCC developers are 616 responsible for GNU libc. These are in fact two entirely separate 617 projects; please check the 618 <a href="http://www.gnu.org/software/libc/">GNU libc web pages</a> 619 for 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 629 class.</dt> 630 631 <dd><p>Defect report 45 clarifies that nested classes are members of the 632 class they are nested in, and so are granted access to private members of 633 that 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 638 destructors).</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 650 constructors <em>completing</em>. In most cases this is the same as 651 the reverse order of constructors <em>starting</em>, but sometimes it 652 is different, and that is important. You need to compile and link your 653 programs with <code>--use-cxa-atexit</code>. We have not turned this 654 switch on by default, as it requires a <code>cxa</code> aware runtime 655 library (<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 660 pointer to incomplete (other than <code><i>cv</i> void *</code>) in 661 an 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 667 hardware interrupts. You cannot throw an exception in one thread and 668 catch it in another. You cannot throw an exception from a signal 669 handler 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>, 674 and want to give it as a template argument to some other class, say 675 <code>std::vector</code>, then <code>std::vector<::X></code> 676 fails with a parser error.</p> 677 678 <p>The reason is that the standard mandates that the sequence 679 <code><:</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 682 a 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< 686 ::X></code>, i.e. place a space between the opening angle bracket 687 and the scope operator.</p></dd> 688 </dl> 689 690 <h3><a name="upgrading">Common problems when upgrading the compiler</a></h3> 691 692 <h4>ABI changes</h4> 693 694 <p>The application binary interface (ABI) defines how the elements of 695 classes are laid out, how functions are called, how function names are 696 mangled etc. It usually changes with each major release (i.e. when the 697 first or second part of the version number changes). You <em>must</em> 698 recompile all C++ libraries, or you risk linker errors or malfunctioning 699 programs. However, the ABI is not changed with bug-fix releases (i.e. 700 when the third part of the version number changes). The code should be 701 binary compatible among these versions.</p> 702 703 <h4>Standard conformance</h4> 704 705 <p>With each release, we try to make G++ conform closer to the ISO C++ standard 706 (available at 707 <a href="http://www.ncits.org/cplusplus.htm">http://www.ncits.org/cplusplus.htm</a>). 708 We have also implemented some of the core and library defect reports 709 (available at 710 <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html">http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html</a> 711 & 712 <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html">http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html</a> 713 respectively).</p> 714 715 <p>Non-conforming legacy code that worked with older versions of GCC may be 716 rejected by more recent compilers. There is no command-line switch to ensure 717 compatibility in general, because trying to parse standard-conforming and 718 old-style code at the same time would render the C++ frontend unmaintainable. 719 However, some non-conforming constructs are allowed when the command-line 720 option <code>-fpermissive</code> is used.</p> 721 722 <p>Two milestones in standard conformance are GCC 3.0 (including a major 723 overhaul of the standard library) and the upcoming 3.4.0 version (with its 724 new C++ parser).</p> 725 726 <h4>New in GCC 3.0</h4> 727 728 <ul> 729 730 <li>The standard library is much more conformant, and uses the 731 <code>std::</code> namespace (which is now a real namespace, not an 732 alias for <code>::</code>).</li> 733 734 <li>The standard header files for the c library don't end with 735 <code>.h</code>, but begin with <code>c</code> (i.e. 736 <code><cstdlib></code> rather than <code><stdlib.h></code>). 737 The <code>.h</code> names are still available, but are deprecated.</li> 738 739 <li><code><strstream></code> is deprecated, use 740 <code><sstream></code> instead.</li> 741 742 <li><code>streambuf::seekoff</code> & 743 <code>streambuf::seekpos</code> are private, instead use 744 <code>streambuf::pubseekoff</code> & 745 <code>streambuf::pubseekpos</code> respectively.</li> 746 747 <li>If <code>std::operator << (std::ostream &, long long)</code> 748 doesn't exist, you need to recompile libstdc++ with 749 <code>--enable-long-long</code>.</li> 750 751 </ul> 752 753 <p>If you get lots of errors about things like <code>cout</code> not being 754 found, you've most likely forgotten to tell the compiler to look in the 755 <code>std::</code> namespace. There are several ways to do this:</p> 756 757 <ul> 758 759 <li>Say <code>std::cout</code> at the call. This is the most explicit 760 way of saying what you mean.</li> 761 762 <li>Say <code>using std::cout;</code> somewhere before the call. You 763 will need to do this for each function or type you wish to use from the 764 standard library.</li> 765 766 <li>Say <code>using namespace std;</code> somewhere before the call. 767 This is the quick-but-dirty fix. This brings the <em>whole</em> of the 768 <code>std::</code> namespace into scope. <em>Never</em> do this in a 769 header file, as every user of your header file will be affected by this 770 decision.</li> 771 772 </ul> 773 774 <h4><a name="new34">New in GCC 3.4.0</a></h4> 775 776 <p>The new parser brings a lot of improvements, especially concerning 777 name-lookup.</p> 778 779 <ul> 780 781 <li>The "implicit typename" extension got removed (it was already deprecated 782 since GCC 3.1), so that the following code is now rejected, see [14.6]: 783 <blockquote><pre> 784 template <typename> struct A 785 { 786 typedef int X; 694 787 }; 695 788 696 A B::f1(bool b) 697 { 698 if (b) 699 return (A()); 700 return a; 789 template <typename T> struct B 790 { 791 A<T>::X x; // error 792 typename A<T>::X y; // OK 793 }; 794 795 B<void> b; 796 </pre></blockquote></li> 797 798 <li>For similar reasons, the following code now requires the 799 <code>template</code> keyword, see [14.2]: 800 <blockquote><pre> 801 template <typename> struct A 802 { 803 template <int> struct X {}; 804 }; 805 806 template <typename T> struct B 807 { 808 typename A<T>::X<0> x; // error 809 typename A<T>::template X<0> y; // OK 810 }; 811 812 B<void> b; 813 </pre></blockquote></li> 814 815 <li>We now have two-stage name-lookup, so that the following code is 816 rejected, see [14.6]/9: 817 <blockquote><pre> 818 template <typename T> int foo() 819 { 820 return i; // error 701 821 } 702 </pre> 703 <p>The problem is that the compiler interprets <code>A()</code> as a 704 function (taking no arguments, returning <code>A</code>), and 705 <code>(A()</code>) as a cast - with a missing expression, hence the 706 parse error. The work-around is to omit the parentheses:</p> 707 <pre> 708 if (b) 709 return A(); 710 </pre> 711 <p>This problem occurs in a number of variants; in <code>throw</code> 712 statements, people also frequently put the object in parentheses. The 713 exact error also somewhat varies with the compiler version. The 714 work-arounds proposed do not change the semantics of the program at 715 all; they make them perhaps less readable.</p> 716 717 <h3><a name="-O3">Optimization at <code>-O3</code> takes a 718 very long time</a></h3> 719 <p>At <code>-O3</code>, all functions are candidates for inlining. The 720 heuristic used has some deficiencies which show up when allowed such 721 freedom. This is g++ specific, as it has an earlier inliner than 722 gcc.</p> 822 </pre></blockquote></li> 823 824 <li>This also affects members of base classes, see [14.6.2]: 825 <blockquote><pre> 826 template <typename> struct A 827 { 828 int i, j; 829 }; 830 831 template <typename T> struct B : A<T> 832 { 833 int foo1() { return i; } // error 834 int foo2() { return this->i; } // OK 835 int foo3() { return B<T>::i; } // OK 836 int foo4() { return A<T>::i; } // OK 837 838 using A<T>::j; 839 int foo5() { return j; } // OK 840 }; 841 </pre></blockquote></li> 842 843 </ul> 844 845 <p>In addition to the problems listed above, the manual contains a section on 846 <a href="http://gcc.gnu.org/onlinedocs/gcc/C---Misunderstandings.html">Common 847 Misunderstandings with GNU C++</a>.</p> 723 848 724 849 </body> -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.