Next: compiling standard libraries Prev: documentation Up: User Problems Top: Top

3.11. What are the differences between g++ and the ARM specification of C++?

The chief thing missing from g++ that is in the ARM is exceptions. There are bits and pieces of exception code present, but it is not presently usable.

The template implementation is still new. The implementation in 2.4.1 represents a considerable improvement over that of previous releases, but it has a long way to go. This continues to improve from release to release.

g++ does not implement a separate pass to instantiate template functions and classes at this point; for this reason, it will not work, for the most part, to declare your template functions in one file and define them in another. The compiler will need to see the entire definition of the function, and will generate a static copy of the function in each file in which it is used. For 2.5.0, however, a new switch -fexternal-templates was added; this makes it possible to have only one globally visible copy of a given template expansion in your executable. See the gcc manual for details.

Some features that the ANSI/ISO standardization committee has voted in that don't appear in the ARM are supported, notably the mutable keyword, in version 2.5.x.

As with any beta-test compiler, there are bugs. You can help improve the compiler by submitting detailed bug reports.

One of the weakest areas of g++ other than templates is the resolution of overloaded functions and operators in complex cases. The usual symptom is that in a case where the ARM says that it is ambiguous which function should be chosen, g++ chooses one (often the first one declared). This is usually not a problem when porting C++ code from other compilers to g++, but shows up as errors when code developed under g++ is ported to other compilers.

As of 2.5.0, the overloading code has been rewritten. For now, you must specify the option -fansi-overloading to get the new code, since there were some important users actually depending on g++'s incorrect resolution of ambiguities. This switch should disappear in the future. If a program that compiled under previous g++ versions now reports that a use of an overloaded function is ambiguous, it is likely that the old g++ was letting you write buggy code and the new one is detecting the problem. If in doubt, consult the ARM.

[A full bug list would be very long indeed, so I won't put one here. I may add a list of frequently-reported bugs and "non-bugs" like the static class members issue mentioned above].