GCC BugsThe latest version of this document is always available at[1]http://gcc.gnu.org/bugs.html._________________________________________________________________Table of Contents* [2]Reporting Bugs+ [3]What we need+ [4]What we DON'T want+ [5]Where to post it+ [6]Detailed bug reporting instructions+ [7]Detailed bug reporting instructions for GNAT+ [8]Detailed bug reporting instructions when using aprecompiled header* [9]Frequently Reported Bugs in GCC+ [10]C++o [11]Missing featureso [12]Bugs fixed in the 3.4 series+ [13]Fortran* [14]Non-bugs+ [15]General+ [16]C+ [17]C++o [18]Common problems when upgrading the compiler_________________________________________________________________Reporting BugsThe main purpose of a bug report is to enable us to fix the bug. Themost important prerequisite for this is that the report must becomplete and self-contained.Before you report a bug, please check the [19]list of well-known bugsand, if possible, try a current development snapshot. If you want toreport a bug with versions of GCC before 3.4 we strongly recommendupgrading to the current release first.Before reporting that GCC compiles your code incorrectly, pleasecompile it with gcc -Wall and see whether this shows anything wrongwith your code that could be the cause instead of a bug in GCC.Summarized bug reporting instructionsAfter this summary, you'll find detailed bug reporting instructions,that explain how to obtain some of the information requested in thissummary.What we needPlease include in your bug report all of the following items, thefirst three of which can be obtained from the output of gcc -v:* the exact version of GCC;* the system type;* the options given when GCC was configured/built;* the complete command line that triggers the bug;* the compiler output (error messages, warnings, etc.); and* the preprocessed file (*.i*) that triggers the bug, generated byadding -save-temps to the complete compilation command, or, in thecase of a bug report for the GNAT front end, a complete set ofsource files (see below).What we do not want* A source file that #includes header files that are left out of thebug report (see above)* That source file and a collection of header files.* An attached archive (tar, zip, shar, whatever) containing all (orsome :-) of the above.* A code snippet that won't cause the compiler to produce the exactoutput mentioned in the bug report (e.g., a snippet with just afew lines around the one that apparently triggers the bug, withsome pieces replaced with ellipses or comments for extraobfuscation :-)* The location (URL) of the package that failed to build (we won'tdownload it, anyway, since you've already given us what we need toduplicate the bug, haven't you? :-)* An error that occurs only some of the times a certain file iscompiled, such that retrying a sufficient number of times resultsin a successful compilation; this is a symptom of a hardwareproblem, not of a compiler bug (sorry)* Assembly files (*.s) produced by the compiler, or any binaryfiles, such as object files, executables, core files, orprecompiled header files* Duplicate bug reports, or reports of bugs already fixed in thedevelopment tree, especially those that have already been reportedas fixed last week :-)* Bugs in the assembler, the linker or the C library. These areseparate projects, with separate mailing lists and different bugreporting procedures* Bugs in releases or snapshots of GCC not issued by the GNUProject. Report them to whoever provided you with the release* Questions about the correctness or the expected behavior ofcertain constructs that are not GCC extensions. Ask them in forumsdedicated to the discussion of the programming languageWhere to post itPlease submit your bug report directly to the [20]GCC bug database.Alternatively, you can use the gccbug script that mails your bugreport to the bug database.Only if all this is absolutely impossible, mail all information to[21]gcc-bugs@gcc.gnu.org.Detailed bug reporting instructionsPlease refer to the [22]next section when reporting bugs in GNAT, theAda compiler, or to the [23]one after that when reporting bugs thatappear when using a precompiled header.In general, all the information we need can be obtained by collectingthe command line below, as well as its output and the preprocessedfile it generates.gcc -v -save-temps all-your-options source-fileThe only excuses to not send us the preprocessed sources are (i) ifyou've found a bug in the preprocessor, (ii) if you've reduced thetestcase to a small file that doesn't include any other file or (iii)if the bug appears only when using precompiled headers. If you can'tpost the preprocessed sources because they're proprietary code, thentry to create a small file that triggers the same problem.Since we're supposed to be able to re-create the assembly output(extension .s), you usually should not include it in the bug report,although you may want to post parts of it to point out assembly codeyou consider to be wrong.Please avoid posting an archive (.tar, .shar or .zip); we generallyneed just a single file to reproduce the bug (the .i/.ii/.fpreprocessed file), and, by storing it in an archive, you're justmaking our volunteers' jobs harder. Only when your bug report requiresmultiple source files to be reproduced should you use an archive. Thisis, for example, the case if you are using INCLUDE directives inFortran code, which are not processed by the preprocessor, but thecompiler. In that case, we need the main file and all INCLUDEd files.In any case, make sure the compiler version, error message, etc, areincluded in the body of your bug report as plain text, even ifneedlessly duplicated as part of an archive.Detailed bug reporting instructions for GNATSee the [24]previous section for bug reporting instructions for GCClanguage implementations other than Ada.Bug reports have to contain at least the following information inorder to be useful:* the exact version of GCC, as shown by "gcc -v";* the system type;* the options when GCC was configured/built;* the exact command line passed to the gcc program triggering thebug (not just the flags passed to gnatmake, but gnatmake printsthe parameters it passed to gcc)* a collection of source files for reproducing the bug, preferably aminimal set (see below);* a description of the expected behavior;* a description of actual behavior.If your code depends on additional source files (usually packagespecifications), submit the source code for these compilation units ina single file that is acceptable input to gnatchop, i.e. contains nonon-Ada text. If the compilation terminated normally, you can usuallyobtain a list of dependencies using the "gnatls -d main_unit" command,where main_unit is the file name of the main compilation unit (whichis also passed to gcc).If you report a bug which causes the compiler to print a bug box,include that bug box in your report, and do not forget to send all thesource files listed after the bug box along with your report.If you use gnatprep, be sure to send in preprocessed sources (unlessyou have to report a bug in gnatprep).When you have checked that your report meets these criteria, pleasesubmit it according to our [25]generic instructions. (If you use amailing list for reporting, please include an "[Ada]" tag in thesubject.)Detailed bug reporting instructions when using a precompiled headerIf you're encountering a bug when using a precompiled header, thefirst thing to do is to delete the precompiled header, and try runningthe same GCC command again. If the bug happens again, the bug doesn'treally involve precompiled headers, please report it without usingthem by following the instructions [26]above.If you've found a bug while building a precompiled header (forinstance, the compiler crashes), follow the usual instructions[27]above.If you've found a real precompiled header bug, what we'll need toreproduce it is the sources to build the precompiled header (as asingle .i file), the source file that uses the precompiled header, anyother headers that source file includes, and the command lines thatyou used to build the precompiled header and to use it.Please don't send us the actual precompiled header. It is likely to bevery large and we can't use it to reproduce the problem._________________________________________________________________Frequently Reported Bugs in GCCThis is a list of bugs in GCC that are reported very often, but notyet fixed. While it is certainly better to fix bugs instead ofdocumenting them, this document might save people the effort ofwriting a bug report when the bug is already well-known.There are many reasons why a reported bug doesn't get fixed. It mightbe difficult to fix, or fixing it might break compatibility. Often,reports get a low priority when there is a simple work-around. Inparticular, bugs caused by invalid code have a simple work-around: fixthe code._________________________________________________________________C++Missing featuresThe export keyword is not implemented.Most C++ compilers (G++ included) do not yet implement export,which is necessary for separate compilation of templatedeclarations and definitions. Without export, a templatedefinition must be in scope to be used. The obvious workaroundis simply to place all definitions in the header itself.Alternatively, the compilation unit containing templatedefinitions may be included from the header.Bugs fixed in the 3.4 seriesThe following bugs are present up to (and including) GCC 3.3.x. Theyhave been fixed in 3.4.0.Two-stage name-lookup.GCC did not implement two-stage name-lookup (also see[28]below).Covariant return types.GCC did not implement non-trivial covariant returns.Parse errors for "simple" code.GCC gave parse errors for seemingly simple code, such asstruct A{A();A(int);};struct B{B(A);B(A,A);void foo();};A bar(){B b(A(),A(1)); // Variable b, initialized with two temporariesB(A(2)).foo(); // B temporary, initialized with A temporaryreturn (A()); // return A temporary}Although being valid code, each of the three lines with acomment was rejected by GCC. The work-arounds for oldercompiler versions proposed below do not change the semantics ofthe programs at all.The problem in the first case was that GCC started to parse thedeclaration of b as a function called b returning B, taking afunction returning A as an argument. When it encountered the 1,it was too late. To show the compiler that this should bereally an expression, a comma operator with a dummy argumentcould be used:B b((0,A()),A(1));The work-around for simpler cases like the second one was toadd additional parentheses around the expressions that weremistaken as declarations:(B(A(2))).foo();In the third case, however, additional parentheses were causingthe problems: The compiler interpreted A() as a function(taking no arguments, returning A), and (A()) as a cast lackingan expression to be casted, hence the parse error. Thework-around was to omit the parentheses:return A();This problem occurred in a number of variants; in throwstatements, people also frequently put the object inparentheses._________________________________________________________________FortranG77 bugs are documented in the G77 manual rather than explicitlylisted here. Please see [29]Known Causes of Trouble with GNU Fortranin the G77 manual._________________________________________________________________Non-bugsThe following are not actually bugs, but are reported often enough towarrant a mention here.It is not always a bug in the compiler, if code which "worked" in aprevious version, is now rejected. Earlier versions of GCC sometimeswere less picky about standard conformance and accepted invalid sourcecode. In addition, programming languages themselves change, renderingcode invalid that used to be conforming (this holds especially forC++). In either case, you should update your code to match recentlanguage standards._________________________________________________________________GeneralProblems with floating point numbers - the [30]most often reportednon-bug.In a number of cases, GCC appears to perform floating pointcomputations incorrectly. For example, the C++ program#include <iostream>int main(){double a = 0.5;double b = 0.01;std::cout << (int)(a / b) << std::endl;return 0;}might print 50 on some systems and optimization levels, and 49on others.This is the result of rounding: The computer cannot representall real numbers exactly, so it has to use approximations. Whencomputing with approximation, the computer needs to round tothe nearest representable number.This is not a bug in the compiler, but an inherent limitationof the floating point types. Please study [31]this paper formore information._________________________________________________________________CIncrement/decrement operator (++/--) not working as expected - a[32]problem with many variations.The following expressions have unpredictable results:x[i]=++ifoo(i,++i)i*(++i) /* special case with foo=="operator*" */std::cout << i << ++i /* foo(foo(std::cout,i),++i) */since the i without increment can be evaluated before or after++i.The C and C++ standards have the notion of "sequence points".Everything that happens between two sequence points happens inan unspecified order, but it has to happen after the first andbefore the second sequence point. The end of a statement and afunction call are examples for sequence points, whereasassignments and the comma between function arguments are not.Modifying a value twice between two sequence points as shown inthe following examples is even worse:i=++ifoo(++i,++i)(++i)*(++i) /* special case with foo=="operator*" */std::cout << ++i << ++i /* foo(foo(std::cout,++i),++i) */This leads to undefined behavior (i.e. the compiler can doanything).Casting does not work as expected when optimization is turned on.This is often caused by a violation of aliasing rules, whichare part of the ISO C standard. These rules say that a programis invalid if you try to access a variable through a pointer ofan incompatible type. This is happening in the followingexample where a short is accessed through a pointer to integer(the code assumes 16-bit shorts and 32-bit ints):#include <stdio.h>int main(){short a[2];a[0]=0x1111;a[1]=0x1111;*(int *)a = 0x22222222; /* violation of aliasing rules */printf("%x %x\n", a[0], a[1]);return 0;}The aliasing rules were designed to allow compilers moreaggressive optimization. Basically, a compiler can assume thatall changes to variables happen through pointers or referencesto variables of a type compatible to the accessed variable.Dereferencing a pointer that violates the aliasing rulesresults in undefined behavior.In the case above, the compiler may assume that no accessthrough an integer pointer can change the array a, consistingof shorts. Thus, printf may be called with the original valuesof a[0] and a[1]. What really happens is up to the compiler andmay change with architecture and optimization level.Recent versions of GCC turn on the option -fstrict-aliasing(which allows alias-based optimizations) by default with -O2.And some architectures then really print "1111 1111" as result.Without optimization the executable will generate the"expected" output "2222 2222".To disable optimizations based on alias-analysis for faultylegacy code, the option -fno-strict-aliasing can be used as awork-around.The option -Wstrict-aliasing (which is included in -Wall) warnsabout some - but not all - cases of violation of aliasing ruleswhen -fstrict-aliasing is active.To fix the code above, you can use a union instead of a cast(note that this is a GCC extension which might not work withother compilers):#include <stdio.h>int main(){union{short a[2];int i;} u;u.a[0]=0x1111;u.a[1]=0x1111;u.i = 0x22222222;printf("%x %x\n", u.a[0], u.a[1]);return 0;}Now the result will always be "2222 2222".For some more insight into the subject, please have a look at[33]this article.Cannot use preprocessor directive in macro arguments.Let me guess... you used an older version of GCC to compilecode that looks something like this:memcpy(dest, src,#ifdef PLATFORM112#else24#endif);and you got a whole pile of error messages:test.c:11: warning: preprocessing directive not recognized within macro argtest.c:11: warning: preprocessing directive not recognized within macro argtest.c:11: warning: preprocessing directive not recognized within macro argtest.c: In function `foo':test.c:6: undefined or invalid # directivetest.c:8: undefined or invalid # directivetest.c:9: parse error before `24'test.c:10: undefined or invalid # directiveThis is because your C library's <string.h> happens to definememcpy as a macro - which is perfectly legitimate. In recentversions of glibc, for example, printf is among those functionswhich are implemented as macros.Versions of GCC prior to 3.3 did not allow you to put #ifdef(or any other preprocessor directive) inside the arguments of amacro. The code therefore would not compile.As of GCC 3.3 this kind of construct is always accepted and thepreprocessor will probably do what you expect, but see themanual for detailed semantics.However, this kind of code is not portable. It is "undefinedbehavior" according to the C standard; that means differentcompilers may do different things with it. It is alwayspossible to rewrite code which uses conditionals inside macrosso that it doesn't. You could write the above example#ifdef PLATFORM1memcpy(dest, src, 12);#elsememcpy(dest, src, 24);#endifThis is a bit more typing, but I personally think it's betterstyle in addition to being more portable.Cannot initialize a static variable with stdin.This has nothing to do with GCC, but people ask us about it alot. Code like this:#include <stdio.h>FILE *yyin = stdin;will not compile with GNU libc, because stdin is not aconstant. This was done deliberately, to make it easier tomaintain binary compatibility when the type FILE needs to bechanged. It is surprising for people used to traditional Unix Clibraries, but it is permitted by the C standard.This construct commonly occurs in code generated by oldversions of lex or yacc. We suggest you try regenerating theparser with a current version of flex or bison, respectively.In your own code, the appropriate fix is to move theinitialization to the beginning of main.There is a common misconception that the GCC developers areresponsible for GNU libc. These are in fact two entirelyseparate projects; please check the [34]GNU libc web pages fordetails._________________________________________________________________C++Nested classes can access private members and types of the containingclass.Defect report 45 clarifies that nested classes are members ofthe class they are nested in, and so are granted access toprivate members of that class.G++ emits two copies of constructors and destructors.In general there are three types of constructors (anddestructors).1. The complete object constructor/destructor.2. The base object constructor/destructor.3. The allocating constructor/deallocating destructor.The first two are different, when virtual base classes areinvolved.Global destructors are not run in the correct order.Global destructors should be run in the reverse order of theirconstructors completing. In most cases this is the same as thereverse order of constructors starting, but sometimes it isdifferent, and that is important. You need to compile and linkyour programs with --use-cxa-atexit. We have not turned thisswitch on by default, as it requires a cxa aware runtimelibrary (libc, glibc, or equivalent).Classes in exception specifiers must be complete types.[15.4]/1 tells you that you cannot have an incomplete type, orpointer to incomplete (other than cv void *) in an exceptionspecification.Exceptions don't work in multithreaded applications.You need to rebuild g++ and libstdc++ with --enable-threads.Remember, C++ exceptions are not like hardware interrupts. Youcannot throw an exception in one thread and catch it inanother. You cannot throw an exception from a signal handlerand catch it in the main thread.Templates, scoping, and digraphs.If you have a class in the global namespace, say named X, andwant to give it as a template argument to some other class, saystd::vector, then std::vector<::X> fails with a parser error.The reason is that the standard mandates that the sequence <:is treated as if it were the token [. (There are several suchcombinations of characters - they are called digraphs.)Depending on the version, the compiler then reports a parseerror before the character : (the colon before X) or a missingclosing bracket ].The simplest way to avoid this is to write std::vector< ::X>,i.e. place a space between the opening angle bracket and thescope operator.Copy constructor access check while initializing a reference.Consider this code:class A{public:A();private:A(const A&); // private copy ctor};A makeA(void);void foo(const A&);void bar(void){foo(A()); // error, copy ctor is not accessiblefoo(makeA()); // error, copy ctor is not accessibleA a1;foo(a1); // OK, a1 is a lvalue}Starting with GCC 3.4.0, binding an rvalue to a const referencerequires an accessible copy constructor. This might besurprising at first sight, especially since most popularcompilers do not correctly implement this rule.The C++ Standard says that a temporary object should be createdin this context and its contents filled with a copy of theobject we are trying to bind to the reference; it also saysthat the temporary copy can be elided, but the semanticconstraints (eg. accessibility) of the copy constructor stillhave to be checked.For further information, you can consult the followingparagraphs of the C++ standard: [dcl.init.ref]/5, bullet 2,sub-bullet 1, and [class.temporary]/2.Common problems when upgrading the compilerABI changesThe C++ application binary interface (ABI) consists of two components:the first defines how the elements of classes are laid out, howfunctions are called, how function names are mangled, etc; the secondpart deals with the internals of the objects in libstdc++. Although westrive for a non-changing ABI, so far we have had to modify it witheach major release. If you change your compiler to a different majorrelease you must recompile all libraries that contain C++ code. If youfail to do so you risk getting linker errors or malfunctioningprograms. Some of our Java support libraries also contain C++ code, soyou might want to recompile all libraries to be safe. It should not benecessary to recompile if you have changed to a bug-fix release of thesame version of the compiler; bug-fix releases are careful to avoidABI changes. See also the [35]compatibility section of the GCC manual.Remark: A major release is designated by a change to the first orsecond component of the two- or three-part version number. A minor(bug-fix) release is designated by a change to the third componentonly. Thus GCC 3.2 and 3.3 are major releases, while 3.3.1 and 3.3.2are bug-fix releases for GCC 3.3. With the 3.4 series we areintroducing a new naming scheme; the first release of this series is3.4.0 instead of just 3.4.Standard conformanceWith each release, we try to make G++ conform closer to the ISO C++standard (available at [36]http://www.ncits.org/cplusplus.htm). Wehave also implemented some of the core and library defect reports(available at[37]http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html &[38]http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.htmlrespectively).Non-conforming legacy code that worked with older versions of GCC maybe rejected by more recent compilers. There is no command-line switchto ensure compatibility in general, because trying to parsestandard-conforming and old-style code at the same time would renderthe C++ frontend unmaintainable. However, some non-conformingconstructs are allowed when the command-line option -fpermissive isused.Two milestones in standard conformance are GCC 3.0 (including a majoroverhaul of the standard library) and the 3.4.0 version (with its newC++ parser).New in GCC 3.0* The standard library is much more conformant, and uses the std::namespace (which is now a real namespace, not an alias for ::).* The standard header files for the c library don't end with .h, butbegin with c (i.e. <cstdlib> rather than <stdlib.h>). The .h namesare still available, but are deprecated.* <strstream> is deprecated, use <sstream> instead.* streambuf::seekoff & streambuf::seekpos are private, instead usestreambuf::pubseekoff & streambuf::pubseekpos respectively.* If std::operator << (std::ostream &, long long) doesn't exist, youneed to recompile libstdc++ with --enable-long-long.If you get lots of errors about things like cout not being found,you've most likely forgotten to tell the compiler to look in the std::namespace. There are several ways to do this:* Say std::cout at the call. This is the most explicit way of sayingwhat you mean.* Say using std::cout; somewhere before the call. You will need todo this for each function or type you wish to use from thestandard library.* Say using namespace std; somewhere before the call. This is thequick-but-dirty fix. This brings the whole of the std:: namespaceinto scope. Never do this in a header file, as every user of yourheader file will be affected by this decision.New in GCC 3.4.0The new parser brings a lot of improvements, especially concerningname-lookup.* The "implicit typename" extension got removed (it was alreadydeprecated since GCC 3.1), so that the following code is nowrejected, see [14.6]:template <typename> struct A{typedef int X;};template <typename T> struct B{A<T>::X x; // errortypename A<T>::X y; // OK};B<void> b;* For similar reasons, the following code now requires the templatekeyword, see [14.2]:template <typename> struct A{template <int> struct X {};};template <typename T> struct B{typename A<T>::X<0> x; // errortypename A<T>::template X<0> y; // OK};B<void> b;* We now have two-stage name-lookup, so that the following code isrejected, see [14.6]/9:template <typename T> int foo(){return i; // error}* This also affects members of base classes, see [14.6.2]:template <typename> struct A{int i, j;};template <typename T> struct B : A<T>{int foo1() { return i; } // errorint foo2() { return this->i; } // OKint foo3() { return B<T>::i; } // OKint foo4() { return A<T>::i; } // OKusing A<T>::j;int foo5() { return j; } // OK};In addition to the problems listed above, the manual contains asection on [39]Common Misunderstandings with GNU C++.References1. http://gcc.gnu.org/bugs.html2. http://gcc.gnu.org/bugs.html#report3. http://gcc.gnu.org/bugs.html#need4. http://gcc.gnu.org/bugs.html#dontwant5. http://gcc.gnu.org/bugs.html#where6. http://gcc.gnu.org/bugs.html#detailed7. http://gcc.gnu.org/bugs.html#gnat8. http://gcc.gnu.org/bugs.html#pch9. http://gcc.gnu.org/bugs.html#known10. http://gcc.gnu.org/bugs.html#cxx11. http://gcc.gnu.org/bugs.html#missing12. http://gcc.gnu.org/bugs.html#fixed3413. http://gcc.gnu.org/bugs.html#fortran14. http://gcc.gnu.org/bugs.html#nonbugs15. http://gcc.gnu.org/bugs.html#nonbugs_general16. http://gcc.gnu.org/bugs.html#nonbugs_c17. http://gcc.gnu.org/bugs.html#nonbugs_cxx18. http://gcc.gnu.org/bugs.html#upgrading19. http://gcc.gnu.org/bugs.html#known20. http://gcc.gnu.org/bugzilla/21. mailto:gcc-bugs@gcc.gnu.org22. http://gcc.gnu.org/bugs.html#gnat23. http://gcc.gnu.org/bugs.html#pch24. http://gcc.gnu.org/bugs.html#detailed25. http://gcc.gnu.org/bugs.html#where26. http://gcc.gnu.org/bugs.html#detailed27. http://gcc.gnu.org/bugs.html#detailed28. http://gcc.gnu.org/bugs.html#new3429. http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Trouble.html30. http://gcc.gnu.org/PR32331. http://www.validlab.com/goldberg/paper.ps32. http://gcc.gnu.org/PR1175133. http://mail-index.NetBSD.org/tech-kern/2003/08/11/0001.html34. http://www.gnu.org/software/libc/35. http://gcc.gnu.org/onlinedocs/gcc/Compatibility.html36. http://www.ncits.org/cplusplus.htm37. http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html38. http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html39. http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Misunderstandings.html