Movatterモバイル変換


[0]ホーム

URL:


GCC Bugs

Table of Contents


Reporting Bugs

A good bug report, which is complete and self-contained, enables usto fix the bug.

Before you report a bug, please check thelist of well-known bugs and,if possible,try a current release or development snapshot.

Before reporting that GCC compiles your code incorrectly, compile itwithgcc -Wall -Wextra and see whether this shows anythingwrong with your code. Similarly, if compiling with-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizationsmakes a difference, or if compiling with-fsanitize=address,undefinedproduces any run-time errors, then your code is probably not correct.

We also ask that for C++ code, users test their programs with-D_GLIBCXX_ASSERTIONS. If you're able to rebuild the entireprogram (including any libraries it uses, because it changes ABI), please do trylibstdc++'sdebug mode(-D_GLIBCXX_DEBUG) which enables more thorough checking in parts ofthe C++ standard library. If either of these fail, this is a strong indicatorof an error in your code.

Summarized bug reporting instructions

After this summary, you'll find detailed instructions that explainhow to obtain some of the information requested in this summary.

What we need

Please include all of the following items, the firstthree of which can be obtained from the output ofgcc -v:

What we donot want

Where to post it

Please submit your bug report directly to theGCC bug tracker.

The GCC bug tracker requires you to create an account with a valide-mail address. This is not merely to be annoying. It's because inthe past spammers have filed fake bug reports, and fake attachments toreal bug reports, to distribute malware and to add links to their spamweb sites. Requiring a valid e-mail address is a partial deterrent tothis. We apologize for the inconvenience.

Detailed bug reporting instructions

Please refer to thenext section when reportingbugs in GNAT, the Ada compiler, or to theone afterthat when reporting bugs that appear when using a precompiled header.

In general, all the information we need can be obtained bycollecting the command line below, as well as its output and thepreprocessed file it generates.

gcc -v -save-tempsall-your-optionssource-file

The preprocessed source is thebasic requirement to fix abug. However, providing aminimal testcaseincreases the chances of getting your bug fixed. Theonlyexcuses to not send us the preprocessed sources are (i) if you'vefound a bug in the preprocessor, (ii) if you've reduced the testcase to asmall file that doesn't include any other file or (iii) if the bugappears only when using precompiled headers. If you can't post thepreprocessed sources because they're proprietary code, then try tocreate 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 includeit in the bug report, although you may want to post parts of it topoint out assembly code you 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/.f preprocessedfile), and, by storing it in an archive, you're just making ourvolunteers' jobs harder. Only when your bug report requires multiplesource files to be reproduced should you use an archive. This is, for example,the case if you are usingINCLUDE directives in Fortran code,which are not processed by the preprocessor, but the compiler. In that case,we need the main file and allINCLUDEd files. In any case,make sure the compiler version, error message, etc, are included inthe body of your bug report as plain text, even if needlesslyduplicated as part of an archive.

Detailed bug reporting instructions for GNAT

See theprevious section for bug reportinginstructions for GCC language implementations other than Ada.

Bug reports have to contain at least the following information inorder to be useful:

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 tognatchop,i.e. contains no non-Ada text. If the compilation terminatednormally, you can usually obtain a list of dependencies using the"gnatls -dmain_unit" command, wheremain_unit is the file name of the main compilationunit (which is also passed togcc).

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 usegnatprep, be sure to send in preprocessedsources (unless you have to report a bug ingnatprep).

When you have checked that your report meets these criteria, pleasesubmit it according to ourgeneric instructions.(If you use a mailing list for reporting, please include an"[Ada]" tag in the subject.)

Detailed bug reporting instructions when using a precompiledheader

If 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 instructionsabove.

If you've found a bug whilebuilding a precompiled header(for instance, the compiler crashes), follow the usual instructionsabove.

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 theprecompiled header, any other headers that source file includes, andthe command lines that you used to build the precompiled header and touse it.

Pleasedon't send us the actual precompiledheader. It is likely to be very large and we can't use it toreproduce the problem.


Frequently Reported Bugs

There are many reasons why a reported bug doesn't get fixed.It might be difficult to fix, or fixing it might break compatibility.Often, reports get a low priority when there is a simple work-around.In particular, bugs caused by invalid code have a simple work-around:fix the code.


Non-bugs

The following are not actually bugs, but are reported oftenenough to warrant 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 sometimes wereless picky about standard conformance and accepted invalid source code.In addition, programming languages themselves change, rendering codeinvalid that used to be conforming (this holds especially for C++).In either case, you should update your code to match recent languagestandards.


General

Problems with floating point numbers - themost often reported non-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 49 onothers.

This is the result ofrounding: The computer cannotrepresent all real numbers exactly, so it has to useapproximations. When computing with approximation, the computer needsto round to the nearest representable number.

This is an inherent limitation of floating point types, not a bug.See Goldberg'sWhatEvery Computer Scientist Should Know about Floating-Point Arithmeticfor more information.


C

Increment/decrement operator (++/--) notworking as expected - aproblem withmany 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 thei without increment can be evaluated before orafter++i.

The C and C++ standards have the notion of "sequence points". Everythingthat happens between two sequence points happens in an unspecified order,but it has to happen after the first and before the second sequence point.The end of a statement and a function call are examples for sequence points,whereas assignments and the comma between function arguments are not.

Modifying a value twice between two sequence points as shown in thefollowing 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 whenoptimization is turned on.

This is often caused by a violation of aliasing rules, which are partof the ISO C standard. These rules say that a program is invalid if you tryto access a variable through a pointer of an incompatible type. This ishappening in the following example where a short is accessed through apointer to integer (the code assumes 16-bitshorts and 32-bitints):

#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 more aggressiveoptimization. Basically, a compiler can assume that all changes to variableshappen through pointers or references to variables of a type compatible tothe accessed variable. Dereferencing a pointer that violates the aliasingrules results in undefined behavior.

In the case above, the compiler may assume that no access through aninteger pointer can change the arraya, consisting of shorts.Thus,printf may be called with the original values ofa[0] anda[1]. What really happens is up tothe compiler and may 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. Withoutoptimization the executable will generate the "expected" output"2222 2222".

To disable optimizations based on alias-analysis for faulty legacy code,the option-fno-strict-aliasing can be used as a work-around.

The option-Wstrict-aliasing (which is included in-Wall) warns about some - but not all - cases of violationof aliasing rules when-fstrict-aliasing is active.

To fix the code above, you can use aunion instead of acast (note that this is a GCC extension which might not work with othercompilers):

#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 atthisarticle.

Loops do not terminate

This is often caused by out-of-bound array accesses or by signed integeroverflow which both result in undefined behavior according to the ISOC standard. For example

intSATD (int* diff, int use_hadamard){  int k, satd = 0, m[16], dd, d[16];  ...    for (dd=d[k=0]; k<16; dd=d[++k])      satd += (dd < 0 ? -dd : dd);

accessesd[16] before the loop is exited withthek<16 check. This causes the compiler tooptimize away the exit test because the new value ofkmust be in the range[0, 15] according to ISO C.

GCC starting with version 4.8 has a new option-fno-aggressive-loop-optimizations that may help here.If it does, then this is a clear sign that your code is not conformingto ISO C and it is not a GCC bug.

Cannot use preprocessor directive in macro arguments.

Let me guess... you used an older version of GCC to compile codethat looks something like this:

  memcpy(dest, src,#ifdef PLATFORM1 12#else 24#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 # directive

This is because your C library's<string.h> happensto definememcpy as a macro - which is perfectly legitimate.In recent versions of glibc, for example,printf is among thosefunctions which 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 a macro. Thecode 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 the manual fordetailed semantics.

However, this kind of code is not portable. It is "undefined behavior"according to the C standard; that means different compilers may dodifferent things with it. It is always possible to rewrite code whichuses conditionals inside macros so that it doesn't. You could writethe above example

#ifdef PLATFORM1   memcpy(dest, src, 12);#else   memcpy(dest, src, 24);#endif

This is a bit more typing, but I personally think it's better stylein addition to being more portable.

Cannot initialize a static variable withstdin.

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, becausestdin is not aconstant. This was done deliberately, to make it easier to maintainbinary compatibility when the typeFILE needs to be changed.It is surprising for people used to traditional Unix C libraries, but itis permitted by the C standard.

This construct commonly occurs in code generated by old versions oflex or yacc. We suggest you try regenerating the parser with acurrent version of flex or bison, respectively. In your own code, theappropriate fix is to move the initialization to the beginning ofmain.

There is a common misconception that the GCC developers areresponsible for GNU libc. These are in fact two entirely separateprojects; please check theGNU libc web pagesfor details.


C++

Functions can be called without qualifying them with their namespace.

Argument Dependent Lookup (ADL) means that functions can be found in namespacesassociated with their arguments. This means thatmove(arg) cancallstd::move ifarg is a type defined in namespacestd, such asstd::string orstd::vector.Ifstd::move is not the function you intended to call, use aqualified name such as::move(arg) orfoo::move(arg).

Nested classes can access private members and types of the containingclass.

Defect report 45 clarifies that nested classes are members of theclass they are nested in, and so are granted access to private members ofthat class.

G++ emits two copies of constructors and destructors.

In general there arethree 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 are involved.

Global destructors are not run in the correct order.

Global destructors should be run in the reverse order of theirconstructorscompleting. In most cases this is the same asthe reverse order of constructorsstarting, but sometimes itis different, and that is important. You need to compile and link yourprograms with--use-cxa-atexit. We have not turned thisswitch on by default, as it requires acxa 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 thancv void *) inan exception specification.

Exceptions don't work in multithreaded applications.

You need to rebuild g++ and libstdc++ with--enable-threads. Remember, C++ exceptions are not likehardware interrupts. You cannot throw an exception in one thread andcatch it in another. You cannot throw an exception from a signalhandler and catch it in the main thread.

Templates, scoping, and digraphs.

If you have a class in the global namespace, say namedX,and want to give it as a template argument to some other class, saystd::vector, thenstd::vector<::X>fails with a parser error in C++98/C++03 mode.

The reason is that the C++98 standard mandates that the sequence<: is treated as if it were the token[.(There are several such combinations of characters - they are calleddigraphs.) Depending on the version, the compiler then reportsa parse error before the character: (the colon beforeX) or a missing closing bracket].

The simplest way to avoid this is to writestd::vector<::X>, i.e. place a space between the opening angle bracketand the scope operator, or compile using C++11 or later. Defect report 1104changed the parser rules so that<:: works as expected.

Common problems when upgrading the compiler

GCC maintains a 'Porting to' resource for new versions:GCC 15 |GCC 14 |GCC 13 |GCC 12 |GCC 11 |GCC 10 |GCC 9 |GCC 8 |GCC 7 |GCC 6 |GCC 5 |GCC 4.9 |GCC 4.8 |GCC 4.7 |GCC 4.6 |GCC 4.4 |GCC 4.3.

ABI changes

The C++ application binary interface (ABI) consists of twocomponents: the first defines how the elements of classes are laidout, how functions are called, how function names are mangled, etc;the second part deals with the internals of the objects in libstdc++.For C++ standards marked asexperimental,stable ABI is not guaranteed: for these, if you change your compiler to adifferent major releaseyou must recompile any libraries that were builtusing a C++ -std= flag that was still experimental. If you failto do so, you risk getting linker errors or malfunctioning programs.It should not be necessary to recompile for C++ standards supported fullyby GCC, such as the default standard. See also thecompatibilitysection of the GCC manual.

Standard conformance

With each release, we try to make G++ conform closer to theISO C++ standard.

Non-conforming legacy code that worked with older versions of GCC may berejected by more recent compilers. There is no command-line switch to ensurecompatibility in general, because trying to parse standard-conforming andold-style code at the same time would render the C++ front end unmaintainable.However, some non-conforming constructs are allowed when the command-lineoption-fpermissive is used.

The manual contains a section onCommon Misunderstandings with GNU C++.

For questions related to the use of GCC,please consult these web pages and theGCC manuals. If that fails,thegcc-help@gcc.gnu.orgmailing list might help.Comments on these web pages and the development of GCC are welcome on ourdeveloper list atgcc@gcc.gnu.org.All ofour listshave public archives.

Copyright (C)Free Software Foundation, Inc.Verbatim copying and distribution of this entire article ispermitted in any medium, provided this notice is preserved.

These pages aremaintained by the GCC team.Last modified 2025-05-01.


[8]ページ先頭

©2009-2026 Movatter.jp