| 1 |  | 
|---|
| 2 | GCC Bugs | 
|---|
| 3 |  | 
|---|
| 4 | The latest version of this document is always available at | 
|---|
| 5 | [1]http://www.gnu.org/software/gcc/bugs.html. | 
|---|
| 6 | _________________________________________________________________ | 
|---|
| 7 |  | 
|---|
| 8 | Table of Contents | 
|---|
| 9 |  | 
|---|
| 10 | * [2]Reporting Bugs | 
|---|
| 11 | + [3]What we need | 
|---|
| 12 | + [4]What we DON'T want | 
|---|
| 13 | + [5]Where to post it | 
|---|
| 14 | + [6]Detailed bug reporting instructions | 
|---|
| 15 | + [7]Detailed bug reporting instructions for GNAT | 
|---|
| 16 | + [8]Detailed bug reporting instructions when using a | 
|---|
| 17 | precompiled header | 
|---|
| 18 | * [9]Managing Bugs (GNATS and the test-suite) | 
|---|
| 19 | * [10]Frequently Reported Bugs in GCC | 
|---|
| 20 | + [11]General | 
|---|
| 21 | + [12]Fortran | 
|---|
| 22 | + [13]C | 
|---|
| 23 | + [14]C++ | 
|---|
| 24 | o [15]Common problems updating from G++ 2.95 to G++ 3.0 | 
|---|
| 25 | o [16]Non-bugs | 
|---|
| 26 | o [17]Missing features | 
|---|
| 27 | o [18]Parse errors for "simple" code | 
|---|
| 28 | o [19]Optimization at -O3 takes a very long time | 
|---|
| 29 | _________________________________________________________________ | 
|---|
| 30 |  | 
|---|
| 31 | Reporting Bugs | 
|---|
| 32 |  | 
|---|
| 33 | Our preferred way of receiving bugs is via the [20]GCC GNATS bug | 
|---|
| 34 | reporting system. | 
|---|
| 35 |  | 
|---|
| 36 | Before you report a bug, please check the [21]list of well-known bugs | 
|---|
| 37 | and, if possible in any way, try a current development snapshot. If | 
|---|
| 38 | you want to report a bug with versions of GCC before 3.1 we strongly | 
|---|
| 39 | recommend upgrading to the current release first. | 
|---|
| 40 |  | 
|---|
| 41 | Before reporting that GCC compiles your code incorrectly, please | 
|---|
| 42 | compile it with gcc -Wall and see whether this shows anything wrong | 
|---|
| 43 | with your code that could be the cause instead of a bug in GCC. | 
|---|
| 44 |  | 
|---|
| 45 | Summarized bug reporting instructions | 
|---|
| 46 |  | 
|---|
| 47 | After this summary, you'll find detailed bug reporting instructions, | 
|---|
| 48 | that explain how to obtain some of the information requested in this | 
|---|
| 49 | summary. | 
|---|
| 50 |  | 
|---|
| 51 | What we need | 
|---|
| 52 |  | 
|---|
| 53 | Please include in your bug report all of the following items, the | 
|---|
| 54 | first three of which can be obtained from the output of gcc -v: | 
|---|
| 55 | * the exact version of GCC; | 
|---|
| 56 | * the system type; | 
|---|
| 57 | * the options given when GCC was configured/built; | 
|---|
| 58 | * the complete command line that triggers the bug; | 
|---|
| 59 | * the compiler output (error messages, warnings, etc.); and | 
|---|
| 60 | * the preprocessed file (*.i*) that triggers the bug, generated by | 
|---|
| 61 | adding -save-temps to the complete compilation command, or, in the | 
|---|
| 62 | case of a bug report for the GNAT front end, a complete set of | 
|---|
| 63 | source files (see below). | 
|---|
| 64 |  | 
|---|
| 65 | What we do not want | 
|---|
| 66 |  | 
|---|
| 67 | * A source file that #includes header files that are left out of the | 
|---|
| 68 | bug report (see above) | 
|---|
| 69 | * That source file and a collection of header files. | 
|---|
| 70 | * An attached archive (tar, zip, shar, whatever) containing all (or | 
|---|
| 71 | some :-) of the above. | 
|---|
| 72 | * A code snippet that won't cause the compiler to produce the exact | 
|---|
| 73 | output mentioned in the bug report (e.g., a snippet with just a | 
|---|
| 74 | few lines around the one that apparently triggers the bug, with | 
|---|
| 75 | some pieces replaced with ellipses or comments for extra | 
|---|
| 76 | obfuscation :-) | 
|---|
| 77 | * The location (URL) of the package that failed to build (we won't | 
|---|
| 78 | download it, anyway, since you've already given us what we need to | 
|---|
| 79 | duplicate the bug, haven't you? :-) | 
|---|
| 80 | * An error that occurs only some of the times a certain file is | 
|---|
| 81 | compiled, such that retrying a sufficient number of times results | 
|---|
| 82 | in a successful compilation; this is a symptom of a hardware | 
|---|
| 83 | problem, not of a compiler bug (sorry) | 
|---|
| 84 | * E-mail messages that complement previous, incomplete bug reports. | 
|---|
| 85 | Post a new, self-contained, full bug report instead, if possible | 
|---|
| 86 | as a follow-up to the original bug report | 
|---|
| 87 | * Assembly files (*.s) produced by the compiler, or any binary | 
|---|
| 88 | files, such as object files, executables, core files, or | 
|---|
| 89 | precompiled header files | 
|---|
| 90 | * Duplicate bug reports, or reports of bugs already fixed in the | 
|---|
| 91 | development tree, especially those that have already been reported | 
|---|
| 92 | as fixed last week :-) | 
|---|
| 93 | * Bugs in the assembler, the linker or the C library. These are | 
|---|
| 94 | separate projects, with separate mailing lists and different bug | 
|---|
| 95 | reporting procedures | 
|---|
| 96 | * Bugs in releases or snapshots of GCC not issued by the GNU | 
|---|
| 97 | Project. Report them to whoever provided you with the release | 
|---|
| 98 | * Questions about the correctness or the expected behavior of | 
|---|
| 99 | certain constructs that are not GCC extensions. Ask them in forums | 
|---|
| 100 | dedicated to the discussion of the programming language | 
|---|
| 101 |  | 
|---|
| 102 | Where to post it | 
|---|
| 103 |  | 
|---|
| 104 | Please submit your bug report directly to the [22]GCC GNATS bug | 
|---|
| 105 | database. Only if this is not possible, mail all information to | 
|---|
| 106 | [23]bug-gcc@gnu.org or [24]gcc-bugs@gcc.gnu.org. | 
|---|
| 107 |  | 
|---|
| 108 | The GCC lists have message size limits (200 kbytes) and bug reports | 
|---|
| 109 | over those limits will currently be bounced. If your bug is larger | 
|---|
| 110 | than that, please post it using the [25]GCC GNATS bug database. | 
|---|
| 111 |  | 
|---|
| 112 | Detailed bug reporting instructions | 
|---|
| 113 |  | 
|---|
| 114 | Please refer to the [26]next section when reporting bugs in GNAT, the | 
|---|
| 115 | Ada compiler, or to the [27]one after that when reporting bugs that | 
|---|
| 116 | appear when using a precompiled header. | 
|---|
| 117 |  | 
|---|
| 118 | In general, all the information we need can be obtained by collecting | 
|---|
| 119 | the command line below, as well as its output and the preprocessed | 
|---|
| 120 | file it generates. | 
|---|
| 121 |  | 
|---|
| 122 | gcc -v -save-temps all-your-options source-file | 
|---|
| 123 |  | 
|---|
| 124 | Typically the preprocessed file (extension .i for C or .ii for C++) | 
|---|
| 125 | will be large, so please compress the resulting file with one of the | 
|---|
| 126 | popular compression programs such as bzip2, gzip, zip or compress (in | 
|---|
| 127 | decreasing order of preference). Use maximum compression (-9) if | 
|---|
| 128 | available. Please include the compressed preprocessor output in your | 
|---|
| 129 | bug report, even if the source code is freely available elsewhere; it | 
|---|
| 130 | makes the job of our volunteer testers much easier. | 
|---|
| 131 |  | 
|---|
| 132 | The only excuses to not send us the preprocessed sources are (i) if | 
|---|
| 133 | you've found a bug in the preprocessor, (ii) if you've reduced the | 
|---|
| 134 | testcase to a small file that doesn't include any other file or (iii) | 
|---|
| 135 | if the bug appears only when using precompiled headers. If you can't | 
|---|
| 136 | post the preprocessed sources because they're proprietary code, then | 
|---|
| 137 | try to create a small file that triggers the same problem. | 
|---|
| 138 |  | 
|---|
| 139 | Since we're supposed to be able to re-create the assembly output | 
|---|
| 140 | (extension .s), you usually should not include it in the bug report, | 
|---|
| 141 | although you may want to post parts of it to point out assembly code | 
|---|
| 142 | you consider to be wrong. | 
|---|
| 143 |  | 
|---|
| 144 | Whether to use MIME attachments or uuencode is up to you. In any case, | 
|---|
| 145 | make sure the compiler command line, version and error output are in | 
|---|
| 146 | plain text, so that we don't have to decode the bug report in order to | 
|---|
| 147 | tell who should take care of it. A meaningful subject indicating | 
|---|
| 148 | language and platform also helps. | 
|---|
| 149 |  | 
|---|
| 150 | Please avoid posting an archive (.tar, .shar or .zip); we generally | 
|---|
| 151 | need just a single file to reproduce the bug (the .i/.ii preprocessed | 
|---|
| 152 | file), and, by storing it in an archive, you're just making our | 
|---|
| 153 | volunteers' jobs harder. Only when your bug report requires multiple | 
|---|
| 154 | source files to be reproduced should you use an archive. In any case, | 
|---|
| 155 | make sure the compiler version, error message, etc, are included in | 
|---|
| 156 | the body of your bug report as plain text, even if needlessly | 
|---|
| 157 | duplicated as part of an archive. | 
|---|
| 158 |  | 
|---|
| 159 | If you fail to supply enough information for a bug report to be | 
|---|
| 160 | reproduced, someone will probably ask you to post additional | 
|---|
| 161 | information (or just ignore your bug report, if they're in a bad day, | 
|---|
| 162 | so try to get it right on the first posting :-). In this case, please | 
|---|
| 163 | post the additional information to the bug reporting mailing list, not | 
|---|
| 164 | just to the person who requested it, unless explicitly told so. If | 
|---|
| 165 | possible, please include in this follow-up all the information you had | 
|---|
| 166 | supplied in the incomplete bug report (including the preprocessor | 
|---|
| 167 | output), so that the new bug report is self-contained. | 
|---|
| 168 |  | 
|---|
| 169 | Detailed bug reporting instructions for GNAT | 
|---|
| 170 |  | 
|---|
| 171 | See the [28]previous section for bug reporting instructions for GCC | 
|---|
| 172 | language implementations other than Ada. | 
|---|
| 173 |  | 
|---|
| 174 | Bug reports have to contain at least the following information in | 
|---|
| 175 | order to be useful: | 
|---|
| 176 | * the exact version of GCC, as shown by "gcc -v"; | 
|---|
| 177 | * the system type; | 
|---|
| 178 | * the options when GCC was configured/built; | 
|---|
| 179 | * the exact command line passed to the gcc program triggering the | 
|---|
| 180 | bug (not just the flags passed to gnatmake, but gnatmake prints | 
|---|
| 181 | the parameters it passed to gcc) | 
|---|
| 182 | * a collection of source files for reproducing the bug, preferably a | 
|---|
| 183 | minimal set (see below); | 
|---|
| 184 | * a description of the expected behavior; | 
|---|
| 185 | * a description of actual behavior. | 
|---|
| 186 |  | 
|---|
| 187 | If your code depends on additional source files (usually package | 
|---|
| 188 | specifications), submit the source code for these compilation units in | 
|---|
| 189 | a single file that is acceptable input to gnatchop, i.e. contains no | 
|---|
| 190 | non-Ada text. If the compilation terminated normally, you can usually | 
|---|
| 191 | obtain a list of dependencies using the "gnatls -d main_unit" command, | 
|---|
| 192 | where main_unit is the file name of the main compilation unit (which | 
|---|
| 193 | is also passed to gcc). | 
|---|
| 194 |  | 
|---|
| 195 | If you report a bug which causes the compiler to print a bug box, | 
|---|
| 196 | include that bug box in your report, and do not forget to send all the | 
|---|
| 197 | source files listed after the bug box along with your report. | 
|---|
| 198 |  | 
|---|
| 199 | If you use gnatprep, be sure to send in preprocessed sources (unless | 
|---|
| 200 | you have to report a bug in gnatprep). | 
|---|
| 201 |  | 
|---|
| 202 | When you have checked that your report meets these criteria, please | 
|---|
| 203 | submit it according to our [29]generic instructions. (If you use a | 
|---|
| 204 | mailing list for reporting, please include an "[Ada]" tag in the | 
|---|
| 205 | subject.) | 
|---|
| 206 |  | 
|---|
| 207 | Detailed bug reporting instructions when using a precompiled header | 
|---|
| 208 |  | 
|---|
| 209 | If you're encountering a bug when using a precompiled header, the | 
|---|
| 210 | first thing to do is to delete the precompiled header, and try running | 
|---|
| 211 | the same GCC command again. If the bug happens again, the bug doesn't | 
|---|
| 212 | really involve precompiled headers, please report it without using | 
|---|
| 213 | them by following the instructions [30]above. | 
|---|
| 214 |  | 
|---|
| 215 | If you've found a bug while building a precompiled header (for | 
|---|
| 216 | instance, the compiler crashes), follow the usual instructions | 
|---|
| 217 | [31]above. | 
|---|
| 218 |  | 
|---|
| 219 | If you've found a real precompiled header bug, what we'll need to | 
|---|
| 220 | reproduce it is the sources to build the precompiled header (as a | 
|---|
| 221 | single .i file), the source file that uses the precompiled header, any | 
|---|
| 222 | other headers that source file includes, and the command lines that | 
|---|
| 223 | you used to build the precompiled header and to use it. | 
|---|
| 224 |  | 
|---|
| 225 | Please don't send us the actual precompiled header. It is likely to be | 
|---|
| 226 | very large and we can't use it to reproduce the problem. | 
|---|
| 227 |  | 
|---|
| 228 | Managing Bugs (GNATS and the test-suite) | 
|---|
| 229 |  | 
|---|
| 230 | This section contains information mostly intended for GCC | 
|---|
| 231 | contributors. | 
|---|
| 232 |  | 
|---|
| 233 | If you find a bug, but you are not fixing it (yet): | 
|---|
| 234 | 1. Create a (minimal) test-case. | 
|---|
| 235 | 2. Add the test-case to our test-suite, marking it as XFAIL unless | 
|---|
| 236 | the bug is a regression. | 
|---|
| 237 | 3. Add a bug report referencing the test-case to GNATS. | 
|---|
| 238 |  | 
|---|
| 239 | If you fix a bug for which there is already a GNATS entry: | 
|---|
| 240 | 1. Remove the XFAIL on the test-case. | 
|---|
| 241 | 2. Close the bug report in GNATS. | 
|---|
| 242 |  | 
|---|
| 243 | If you find a bug, and you are fixing it right then: | 
|---|
| 244 | 1. Create a (minimal) test-case. | 
|---|
| 245 | 2. Add the test-case to our test-suite, marking it as PASS. | 
|---|
| 246 | 3. Check in your fixes. | 
|---|
| 247 | _________________________________________________________________ | 
|---|
| 248 |  | 
|---|
| 249 | Frequently Reported Bugs in GCC | 
|---|
| 250 |  | 
|---|
| 251 | Fortran | 
|---|
| 252 |  | 
|---|
| 253 | Fortran bugs are documented in the G77 manual rather than explicitly | 
|---|
| 254 | listed here. Please see [32]Known Causes of Trouble with GNU Fortran | 
|---|
| 255 | in the G77 manual. | 
|---|
| 256 | _________________________________________________________________ | 
|---|
| 257 |  | 
|---|
| 258 | C | 
|---|
| 259 |  | 
|---|
| 260 | The following are not bugs in the C compiler, but are reported often | 
|---|
| 261 | enough to warrant a mention here. | 
|---|
| 262 |  | 
|---|
| 263 | Cannot initialize a static variable with stdin. | 
|---|
| 264 | This has nothing to do with GCC, but people ask us about it a | 
|---|
| 265 | lot. Code like this: | 
|---|
| 266 |  | 
|---|
| 267 | #include <stdio.h> | 
|---|
| 268 |  | 
|---|
| 269 | FILE *yyin = stdin; | 
|---|
| 270 |  | 
|---|
| 271 | will not compile with GNU libc (GNU/Linux libc6), because stdin | 
|---|
| 272 | is not a constant. This was done deliberately, to make it | 
|---|
| 273 | easier to maintain binary compatibility when the type FILE | 
|---|
| 274 | needs to be changed. It is surprising for people used to | 
|---|
| 275 | traditional Unix C libraries, but it is permitted by the C | 
|---|
| 276 | standard. | 
|---|
| 277 |  | 
|---|
| 278 | This construct commonly occurs in code generated by old | 
|---|
| 279 | versions of lex or yacc. We suggest you try regenerating the | 
|---|
| 280 | parser with a current version of flex or bison, respectively. | 
|---|
| 281 | In your own code, the appropriate fix is to move the | 
|---|
| 282 | initialization to the beginning of main. | 
|---|
| 283 |  | 
|---|
| 284 | There is a common misconception that the GCC developers are | 
|---|
| 285 | responsible for GNU libc. These are in fact two entirely | 
|---|
| 286 | separate projects; please check the [33]GNU libc web pages for | 
|---|
| 287 | details. | 
|---|
| 288 |  | 
|---|
| 289 | Cannot use preprocessor directive in macro arguments. | 
|---|
| 290 | Let me guess... you wrote code that looks something like this: | 
|---|
| 291 |  | 
|---|
| 292 | memcpy(dest, src, | 
|---|
| 293 | #ifdef PLATFORM1 | 
|---|
| 294 | 12 | 
|---|
| 295 | #else | 
|---|
| 296 | 24 | 
|---|
| 297 | #endif | 
|---|
| 298 | ); | 
|---|
| 299 |  | 
|---|
| 300 | and you got a whole pile of error messages: | 
|---|
| 301 |  | 
|---|
| 302 | test.c:11: warning: preprocessing directive not recognized within | 
|---|
| 303 | macro arg | 
|---|
| 304 | test.c:11: warning: preprocessing directive not recognized within | 
|---|
| 305 | macro arg | 
|---|
| 306 | test.c:11: warning: preprocessing directive not recognized within | 
|---|
| 307 | macro arg | 
|---|
| 308 | test.c: In function `foo': | 
|---|
| 309 | test.c:6: undefined or invalid # directive | 
|---|
| 310 | test.c:8: undefined or invalid # directive | 
|---|
| 311 | test.c:9: parse error before `24' | 
|---|
| 312 | test.c:10: undefined or invalid # directive | 
|---|
| 313 | test.c:11: parse error before `#' | 
|---|
| 314 |  | 
|---|
| 315 | Update: As of GCC 3.2 this kind of construct is always accepted | 
|---|
| 316 | and CPP will probably do what you expect, but see the manual | 
|---|
| 317 | for detailed semantics. | 
|---|
| 318 |  | 
|---|
| 319 | However, versions of GCC prior to 3.2 did not allow you to put | 
|---|
| 320 | #ifdef (or any other directive) inside the arguments of a | 
|---|
| 321 | macro. Your C library's <string.h> happens to define memcpy as | 
|---|
| 322 | a macro - this is perfectly legitimate. The code therefore | 
|---|
| 323 | would not compile. | 
|---|
| 324 |  | 
|---|
| 325 | This kind of code is not portable. It is "undefined behavior" | 
|---|
| 326 | according to the C standard; that means different compilers | 
|---|
| 327 | will do different things with it. It is always possible to | 
|---|
| 328 | rewrite code which uses conditionals inside macros so that it | 
|---|
| 329 | doesn't. You could write the above example | 
|---|
| 330 |  | 
|---|
| 331 | #ifdef PLATFORM1 | 
|---|
| 332 | memcpy(dest, src, 12); | 
|---|
| 333 | #else | 
|---|
| 334 | memcpy(dest, src, 24); | 
|---|
| 335 | #endif | 
|---|
| 336 |  | 
|---|
| 337 | This is a bit more typing, but I personally think it's better | 
|---|
| 338 | style in addition to being more portable. | 
|---|
| 339 |  | 
|---|
| 340 | In recent versions of glibc, printf is among the functions | 
|---|
| 341 | which are implemented as macros. | 
|---|
| 342 | _________________________________________________________________ | 
|---|
| 343 |  | 
|---|
| 344 | C++ | 
|---|
| 345 |  | 
|---|
| 346 | This is the list of bugs (and non-bugs) in g++ (aka GNU C++) that are | 
|---|
| 347 | reported very often, but not yet fixed. While it is certainly better | 
|---|
| 348 | to fix bugs instead of documenting them, this document might save | 
|---|
| 349 | people the effort of writing a bug report when the bug is already | 
|---|
| 350 | well-known. [34]How to report bugs tells you how to report a bug. | 
|---|
| 351 |  | 
|---|
| 352 | There are many reasons why reported bugs don't get fixed. It might be | 
|---|
| 353 | difficult to fix, or fixing it might break compatibility. Often, | 
|---|
| 354 | reports get a low priority when there is a simple work-around. In | 
|---|
| 355 | particular, bugs caused by invalid C++ code have a simple work-around, | 
|---|
| 356 | fix the code. Now that there is an agreed ISO/ANSI standard for C++, | 
|---|
| 357 | the compiler has a definitive document to adhere to. Earlier versions | 
|---|
| 358 | might have accepted source code that is no longer C++. This means that | 
|---|
| 359 | code which might have `worked' in a previous version, is now rejected. | 
|---|
| 360 | You should update your code to be C++. | 
|---|
| 361 |  | 
|---|
| 362 | You should try to use the latest stable release of the GNU C++ | 
|---|
| 363 | compiler. | 
|---|
| 364 |  | 
|---|
| 365 | Common problems updating from G++ 2.95 to G++ 3.0 | 
|---|
| 366 |  | 
|---|
| 367 | G++ 3.0 conforms much closer to the ISO C++ standard (available at | 
|---|
| 368 | [35]http://www.ncits.org/cplusplus.htm). | 
|---|
| 369 |  | 
|---|
| 370 | We have also implemented some of the core and library defect reports | 
|---|
| 371 | (available at | 
|---|
| 372 | [36]http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html & | 
|---|
| 373 | [37]http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html | 
|---|
| 374 | respectively). | 
|---|
| 375 | * The ABI has changed. This means that both class layout and name | 
|---|
| 376 | mangling is different. You must recompile all c++ libraries (if | 
|---|
| 377 | you don't you will get link errors). | 
|---|
| 378 | * The standard library is much more conformant, and uses the std:: | 
|---|
| 379 | namespace. | 
|---|
| 380 | * std:: is now a real namespace, not an alias for ::. | 
|---|
| 381 | * The standard header files for the c library don't end with .h, but | 
|---|
| 382 | begin with c (i.e. <cstdlib> rather than <stdlib.h>). The .h names | 
|---|
| 383 | are still available, but are deprecated. | 
|---|
| 384 | * <strstream> is deprecated, use <sstream> instead. | 
|---|
| 385 | * streambuf::seekoff & streambuf::seekpos are private, instead use | 
|---|
| 386 | streambuf::pubseekoff & streambuf::pubseekpos respectively. | 
|---|
| 387 | * If std::operator << (std::ostream &, long long) doesn't exist, you | 
|---|
| 388 | need to recompile libstdc++ with --enable-long-long. | 
|---|
| 389 |  | 
|---|
| 390 | This means you may get lots of errors about things like strcmp not | 
|---|
| 391 | being found. You've most likely forgotten to tell the compiler to look | 
|---|
| 392 | in the std:: namespace. There are several ways to do this, | 
|---|
| 393 | * Say, std::strcmp at the call. This is the most explicit way of | 
|---|
| 394 | saying what you mean. | 
|---|
| 395 | * Say, using std::strcmp; somewhere before the call. You will need | 
|---|
| 396 | to do this for each function or type you wish to use from the | 
|---|
| 397 | standard library. | 
|---|
| 398 | * Say, using namespace std; somewhere before the call. This is the | 
|---|
| 399 | quick-but-dirty fix. This brings the whole of the std:: namespace | 
|---|
| 400 | into scope. Never do this in a header file, as you will be forcing | 
|---|
| 401 | users of your header file to do the same. | 
|---|
| 402 |  | 
|---|
| 403 | ABI bugs | 
|---|
| 404 |  | 
|---|
| 405 | 3.0 had a new ABI, which affected class layout, function mangling and | 
|---|
| 406 | calling conventions. We had intended it to be complete, unfortunately | 
|---|
| 407 | some issues came to light, too late to fix in the 3.0 series. The ABI | 
|---|
| 408 | should not change in dot releases, so we addressed most issues in GCC | 
|---|
| 409 | 3.1. | 
|---|
| 410 |  | 
|---|
| 411 | Covariant return types | 
|---|
| 412 | We do not implement non-trivial covariant returns. We also | 
|---|
| 413 | generate incorrect virtual function tables for trivial | 
|---|
| 414 | covariance. Although trivial covariance will work, it is | 
|---|
| 415 | incompatible with the ABI. GNATS PR 3706 tracks this problem. | 
|---|
| 416 |  | 
|---|
| 417 | Non-bugs | 
|---|
| 418 |  | 
|---|
| 419 | Here are some features that have been reported as bugs, but are not. | 
|---|
| 420 |  | 
|---|
| 421 | Nested classes can access private types of the containing class. | 
|---|
| 422 | G++ now implements type access control on member types. Defect | 
|---|
| 423 | report 45 clarifies that nested classes are members of the | 
|---|
| 424 | class they are nested in, and so are granted access to private | 
|---|
| 425 | members of that class. | 
|---|
| 426 |  | 
|---|
| 427 | Classes in exception specifiers must be complete types. | 
|---|
| 428 | [15.4]/1 tells you that you cannot have an incomplete type, or | 
|---|
| 429 | pointer to incomplete (other than cv void *) in an exception | 
|---|
| 430 | specification. | 
|---|
| 431 |  | 
|---|
| 432 | G++ emits two copies of constructors and destructors. | 
|---|
| 433 | In general there are three types of constructors (and | 
|---|
| 434 | destructors). | 
|---|
| 435 |  | 
|---|
| 436 | 1. The complete object constructor/destructor. | 
|---|
| 437 | 2. The base object constructor/destructor. | 
|---|
| 438 | 3. The allocating destructor/deallocating destructor. | 
|---|
| 439 |  | 
|---|
| 440 | The first two are different, when virtual base classes are | 
|---|
| 441 | involved. In some cases we can do better, and this is logged in | 
|---|
| 442 | GNATS. | 
|---|
| 443 |  | 
|---|
| 444 | Exceptions don't work in multithreaded applications. | 
|---|
| 445 | You need to rebuild g++ and libstdc++ with --enable-threads. | 
|---|
| 446 | Remember, c++ exceptions are not like hardware interrupts. You | 
|---|
| 447 | cannot throw an exception in one thread and catch it in | 
|---|
| 448 | another. You cannot throw an exception from a signal handler, | 
|---|
| 449 | and catch it in the main thread. | 
|---|
| 450 |  | 
|---|
| 451 | Global destructors are not run in the correct order. | 
|---|
| 452 | Global destructors should be run in the reverse order of their | 
|---|
| 453 | constructors completing. In most cases this is the same as the | 
|---|
| 454 | reverse order of constructors starting, but sometimes it is | 
|---|
| 455 | different, and that is important. You need to compile and link | 
|---|
| 456 | your programs with --use-cxa-atexit. We have not turned this | 
|---|
| 457 | switch on by default, as it requires a cxa aware runtime | 
|---|
| 458 | library (libc, glibc, or equivalent). | 
|---|
| 459 |  | 
|---|
| 460 | Problems with floating point computations. | 
|---|
| 461 | In a number of cases, GCC appears to perform floating point | 
|---|
| 462 | computations incorrectly. For example, the program | 
|---|
| 463 |  | 
|---|
| 464 | #include <iostream> | 
|---|
| 465 | int main() { | 
|---|
| 466 | double min = 0.0; | 
|---|
| 467 | double max = 0.5; | 
|---|
| 468 | double width = 0.01; | 
|---|
| 469 | std::cout << (int)(((max - min) / width) - 1) << std::endl; | 
|---|
| 470 | } | 
|---|
| 471 |  | 
|---|
| 472 | might print 49 on some systems and optimization levels, and 48 | 
|---|
| 473 | on others. | 
|---|
| 474 |  | 
|---|
| 475 | The is the result of rounding: The computer cannot represent | 
|---|
| 476 | all real numbers exactly, so it has to use approximations. When | 
|---|
| 477 | computing with approximation, the computer needs to round to | 
|---|
| 478 | the nearest representable number. | 
|---|
| 479 |  | 
|---|
| 480 | This is not a bug in the compiler, but an inherent limitation | 
|---|
| 481 | of the float and double types. Please study [38]this paper for | 
|---|
| 482 | more information. | 
|---|
| 483 |  | 
|---|
| 484 | Templates, scoping, and digraphs. | 
|---|
| 485 | If you have a class in global namespace, say named X, and want | 
|---|
| 486 | to give it as a template argument to some other class, say | 
|---|
| 487 | std::vector, then this here fails with a parser error: | 
|---|
| 488 | std::vector<::X>. | 
|---|
| 489 |  | 
|---|
| 490 | The reason is that the standard mandates that the sequence <: | 
|---|
| 491 | is treated as if it were the token [, and the parser then | 
|---|
| 492 | reports a parse error before the character : (by which it means | 
|---|
| 493 | the second colon). There are several such combinations of | 
|---|
| 494 | characters, and they are called digraphs. | 
|---|
| 495 |  | 
|---|
| 496 | The simplest way to avoid this is to write std::vector< ::X>, | 
|---|
| 497 | i.e. place a space between the opening angle bracket and the | 
|---|
| 498 | scope operator. | 
|---|
| 499 |  | 
|---|
| 500 | Missing features | 
|---|
| 501 |  | 
|---|
| 502 | We know some things are missing from G++. | 
|---|
| 503 |  | 
|---|
| 504 | The export keyword is not implemented. | 
|---|
| 505 | Most C++ compilers (G++ included) do not yet implement export, | 
|---|
| 506 | which is necessary for separate compilation of template | 
|---|
| 507 | declarations and definitions. Without export, a template | 
|---|
| 508 | definition must be in scope to be used. The obvious workaround | 
|---|
| 509 | is simply to place all definitions in the header itself. | 
|---|
| 510 | Alternatively, the compilation unit containing template | 
|---|
| 511 | definitions may be included from the header. | 
|---|
| 512 |  | 
|---|
| 513 | Two stage lookup in templates is not implemented. | 
|---|
| 514 | [14.6] specifies how names are looked up inside a template. G++ | 
|---|
| 515 | does not do this correctly, but for most templates this will | 
|---|
| 516 | not be noticeable. | 
|---|
| 517 |  | 
|---|
| 518 | Parse errors for "simple" code | 
|---|
| 519 |  | 
|---|
| 520 | Up to and including GCC 3.0, the compiler will give "parse error" for | 
|---|
| 521 | seemingly simple code, such as | 
|---|
| 522 | struct A{ | 
|---|
| 523 | A(); | 
|---|
| 524 | A(int); | 
|---|
| 525 | void func(); | 
|---|
| 526 | }; | 
|---|
| 527 |  | 
|---|
| 528 | struct B{ | 
|---|
| 529 | B(A); | 
|---|
| 530 | B(A,A); | 
|---|
| 531 | void func(); | 
|---|
| 532 | }; | 
|---|
| 533 |  | 
|---|
| 534 | void foo(){ | 
|---|
| 535 | B b(A(),A(1));     //Variable b, initialized with two temporaries | 
|---|
| 536 | B(A(2)).func();    //B temporary, initialized with A temporary | 
|---|
| 537 | } | 
|---|
| 538 |  | 
|---|
| 539 | The problem is that GCC starts to parse the declaration of b as a | 
|---|
| 540 | function b returning B, taking a function returning A as an argument. | 
|---|
| 541 | When it sees the 1, it is too late. The work-around in these cases is | 
|---|
| 542 | to add additional parentheses around the expressions that are mistaken | 
|---|
| 543 | as declarations: | 
|---|
| 544 | (B(A(2))).func(); | 
|---|
| 545 |  | 
|---|
| 546 | Sometimes, even that is not enough; to show the compiler that this | 
|---|
| 547 | should be really an expression, a comma operator with a dummy argument | 
|---|
| 548 | can be used: | 
|---|
| 549 | B b((0,A()),A(1)); | 
|---|
| 550 |  | 
|---|
| 551 | Another example is the parse error for the return statement in | 
|---|
| 552 | struct A{}; | 
|---|
| 553 |  | 
|---|
| 554 | struct B{ | 
|---|
| 555 | A a; | 
|---|
| 556 | A f1(bool); | 
|---|
| 557 | }; | 
|---|
| 558 |  | 
|---|
| 559 | A B::f1(bool b) | 
|---|
| 560 | { | 
|---|
| 561 | if (b) | 
|---|
| 562 | return (A()); | 
|---|
| 563 | return a; | 
|---|
| 564 | } | 
|---|
| 565 |  | 
|---|
| 566 | The problem is that the compiler interprets A() as a function (taking | 
|---|
| 567 | no arguments, returning A), and (A()) as a cast - with a missing | 
|---|
| 568 | expression, hence the parse error. The work-around is to omit the | 
|---|
| 569 | parentheses: | 
|---|
| 570 | if (b) | 
|---|
| 571 | return A(); | 
|---|
| 572 |  | 
|---|
| 573 | This problem occurs in a number of variants; in throw statements, | 
|---|
| 574 | people also frequently put the object in parentheses. The exact error | 
|---|
| 575 | also somewhat varies with the compiler version. The work-arounds | 
|---|
| 576 | proposed do not change the semantics of the program at all; they make | 
|---|
| 577 | them perhaps less readable. | 
|---|
| 578 |  | 
|---|
| 579 | Optimization at -O3 takes a very long time | 
|---|
| 580 |  | 
|---|
| 581 | At -O3, all functions are candidates for inlining. The heuristic used | 
|---|
| 582 | has some deficiencies which show up when allowed such freedom. This is | 
|---|
| 583 | g++ specific, as it has an earlier inliner than gcc. | 
|---|
| 584 |  | 
|---|
| 585 | References | 
|---|
| 586 |  | 
|---|
| 587 | 1. http://www.gnu.org/software/gcc/bugs.html | 
|---|
| 588 | 2. http://gcc.gnu.org/bugs.html#report | 
|---|
| 589 | 3. http://gcc.gnu.org/bugs.html#need | 
|---|
| 590 | 4. http://gcc.gnu.org/bugs.html#dontwant | 
|---|
| 591 | 5. http://gcc.gnu.org/bugs.html#where | 
|---|
| 592 | 6. http://gcc.gnu.org/bugs.html#detailed | 
|---|
| 593 | 7. http://gcc.gnu.org/bugs.html#gnat | 
|---|
| 594 | 8. http://gcc.gnu.org/bugs.html#pch | 
|---|
| 595 | 9. http://gcc.gnu.org/bugs.html#manage | 
|---|
| 596 | 10. http://gcc.gnu.org/bugs.html#known | 
|---|
| 597 | 11. http://gcc.gnu.org/bugs.html#general | 
|---|
| 598 | 12. http://gcc.gnu.org/bugs.html#fortran | 
|---|
| 599 | 13. http://gcc.gnu.org/bugs.html#c | 
|---|
| 600 | 14. http://gcc.gnu.org/bugs.html#cplusplus | 
|---|
| 601 | 15. http://gcc.gnu.org/bugs.html#updating | 
|---|
| 602 | 16. http://gcc.gnu.org/bugs.html#nonbugs | 
|---|
| 603 | 17. http://gcc.gnu.org/bugs.html#missing | 
|---|
| 604 | 18. http://gcc.gnu.org/bugs.html#parsing | 
|---|
| 605 | 19. http://gcc.gnu.org/bugs.html#-O3 | 
|---|
| 606 | 20. http://gcc.gnu.org/gnats.html | 
|---|
| 607 | 21. http://gcc.gnu.org/bugs.html#known | 
|---|
| 608 | 22. http://gcc.gnu.org/gnats.html | 
|---|
| 609 | 23. mailto:bug-gcc@gnu.org | 
|---|
| 610 | 24. mailto:gcc-bugs@gcc.gnu.org | 
|---|
| 611 | 25. http://gcc.gnu.org/gnats.html | 
|---|
| 612 | 26. http://gcc.gnu.org/bugs.html#gnat | 
|---|
| 613 | 27. http://gcc.gnu.org/bugs.html#pch | 
|---|
| 614 | 28. http://gcc.gnu.org/bugs.html#detailed | 
|---|
| 615 | 29. http://gcc.gnu.org/bugs.html#where | 
|---|
| 616 | 30. http://gcc.gnu.org/bugs.html#detailed | 
|---|
| 617 | 31. http://gcc.gnu.org/bugs.html#detailed | 
|---|
| 618 | 32. http://gcc.gnu.org/onlinedocs/g77/Trouble.html | 
|---|
| 619 | 33. http://www.gnu.org/software/glibc/ | 
|---|
| 620 | 34. http://gcc.gnu.org/bugs.html#report | 
|---|
| 621 | 35. http://www.ncits.org/cplusplus.htm | 
|---|
| 622 | 36. http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html | 
|---|
| 623 | 37. http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html | 
|---|
| 624 | 38. http://www.validlab.com/goldberg/paper.ps | 
|---|