Using and Porting the GNU Compiler Collection (GCC)
This section describes the command-line options that are only meaningful
for C++ programs; but you can also use most of the GNU compiler options
regardless of what language your program is in. For example, you
might compile a file firstClass.C
like this:
g++ -g -frepo -O -c firstClass.C
In this example, only `-frepo
' is an option meant
only for C++ programs; you can use the other options with any
language supported by GCC.
Here is a list of options that are only for compiling C++ programs:
-fno-access-control
-fcheck-new
operator new
is non-null
before attempting to modify the storage allocated. The current Working
Paper requires that operator new
never return a null pointer, so
this check is normally unnecessary.
An alternative to using this option is to specify that your
operator new
does not throw any exceptions; if you declare it
`throw()
', g++ will check the return value. See also `new (nothrow)
'.
-fconserve-space
main()
has
completed, you may have an object that is being destroyed twice because
two definitions were merged.
This option is no longer useful on most targets, now that support has been added for putting variables into BSS without making them common.
-fdollars-in-identifiers
$
' in identifiers. You can also explicitly prohibit use of
`$
' with the option `-fno-dollars-in-identifiers
'. (GNU C allows
`$
' by default on most target systems, but there are a few exceptions.)
Traditional C allowed the character `$
' to form part of
identifiers. However, ANSI C and C++ forbid `$
' in identifiers.
-fno-elide-constructors
-fexternal-templates
#pragma interface
' and
`implementation
'; template instances are emitted or not according
to the location of the template definition. See Template Instantiation, for more information.
This option is deprecated.
-falt-external-templates
This option is deprecated.
-ffor-scope
-fno-for-scope
for
' loop itself,
as specified by the draft C++ standard.
If -fno-for-scope is specified, the scope of variables declared in
a for-init-statement extends to the end of the enclosing scope,
as was the case in old versions of gcc, and other (traditional)
implementations of C++.
The default if neither flag is given to follow the standard, but to allow and give a warning for old-style code that would otherwise be invalid, or have different behavior.
-fno-gnu-keywords
classof
, headof
, signature
,
sigof
or typeof
as a keyword, so that code can use these
words as identifiers. You can use the keywords __classof__
,
__headof__
, __signature__
, __sigof__
, and
__typeof__
instead. `-ansi
' implies
`-fno-gnu-keywords
'.
-fguiding-decls
This option implies `-fname-mangling-version-0
', and will not work
with other name mangling versions. Like all options that change the
ABI, all C++ code, including libgcc.a must be built with the same
setting of this option.
-fhandle-signatures
signature
and sigof
keywords for specifying
abstract types. The default (`-fno-handle-signatures
') is not to
recognize them. See Type Abstraction using Signatures.
-fhonor-std
namespace std
as a namespace, instead of ignoring
it. For compatibility with earlier versions of g++, the compiler will,
by default, ignore namespace-declarations
,
using-declarations
, using-directives
, and
namespace-names
, if they involve std
.
-fhuge-objects
short int
'. Users should not use this flag by
default; if you need to use it, the compiler will tell you so.
This flag is not useful when compiling with -fvtable-thunks.
Like all options that change the ABI, all C++ code, including libgcc must be built with the same setting of this option.
-fno-implicit-templates
-fno-implicit-inline-templates
-finit-priority
__attribute__ ((init_priority (n)))
' for controlling the
order of initialization of file-scope objects. On ELF targets, this
requires GNU ld 2.10 or later.
-fno-implement-inlines
#pragma implementation
'. This will cause linker
errors if these functions are not inlined everywhere they are called.
-fname-mangling-version-n
template <class T, class U> void foo(T t);
Like all options that change the ABI, all C++ code, including libgcc must be built with the same setting of this option.
-foperator-names
and
, bitand
,
bitor
, compl
, not
, or
and xor
as
synonyms for the symbols they refer to. `-ansi
' implies
`-foperator-names
'.
-fno-optional-diags
-fpermissive
-pedantic-errors
' without
`-pedantic
'; this option reverses that. This behavior and this
option are superceded by `-pedantic
', which works as it does for GNU C.
-frepo
-fno-implicit-templates
'. See Template Instantiation, for more
information.
-fno-rtti
dynamic_cast
' and `typeid
'). If you
don't use those parts of the language (or exception handling, which uses
`dynamic_cast
' internally), you can save some space by using this
flag.
-fstrict-prototype
extern "C"
' linkage specification, treat a function
declaration with no arguments, such as `int foo ();
', as declaring
the function to take no arguments. Normally, such a declaration means
that the function foo
can take any combination of arguments, as
in C. `-pedantic
' implies `-fstrict-prototype
' unless
overridden with `-fno-strict-prototype
'.
Specifying this option will also suppress implicit declarations of functions.
This flag no longer affects declarations with C++ linkage.
-fsquangle
-fno-squangle
-fsquangle
' will enable a compressed form of name mangling for
identifiers. In particular, it helps to shorten very long names by recognizing
types and class names which occur more than once, replacing them with special
short ID codes. This option also requires any C++ libraries being used to
be compiled with this option as well. The compiler has this disabled (the
equivalent of `-fno-squangle
') by default.
Like all options that change the ABI, all C++ code, including libgcc.a must be built with the same setting of this option.
-ftemplate-depth-n
-fthis-is-variable
this
. The incorporation of user-defined
free store management into C++ has made assignment to `this
' an
anachronism. Therefore, by default it is invalid to assign to
this
within a class member function; that is, GNU C++ treats
`this
' in a member function of class X
as a non-lvalue of
type `X *
'. However, for backwards compatibility, you can make it
valid with `-fthis-is-variable
'.
-fvtable-thunks=thunks-version
thunks
' to implement the virtual function dispatch table
(`vtable
'). The traditional (cfront-style) approach to
implementing vtables was to store a pointer to the function and two
offsets for adjusting the `this
' pointer at the call site. Newer
implementations store a single pointer to a `thunk
' function which
does any necessary adjustment and then calls the target function.
The original implementation of thunks (version 1) had a bug regarding virtual base classes; this bug is fixed with version 2 of the thunks implementation. With setting the version to 2, compatibility to the version 1 thunks is provided, at the cost of extra machine code. Version 3 does not include this compatibility.
This option also enables a heuristic for controlling emission of vtables; if a class has any non-inline virtual functions, the vtable will be emitted in the translation unit containing the first one of those.
Like all options that change the ABI, all C++ code, including libgcc.a must be built with the same setting of this option. Since version 1 and version 2 are also incompatible (for classes with virtual bases defining virtual functions), all code must also be compiled with the same version.
In this version of gcc, there are no targets for which version 2 thunks are the default. On all targets, not giving the option will use the traditional implementation, and -fvtable-thunks will produce version 2 thunks.
-nostdinc++
In addition, these optimization, warning, and code generation options have meanings only for C++ programs:
-fno-default-inline
inline
' for functions defined inside a class scope.
See Optimize Options. Note that these
functions will have linkage like inline functions; they just won't be
inlined by default.
-Wctor-dtor-privacy (C++ only)
-Wnon-virtual-dtor (C++ only)
-Wreorder (C++ only)
struct A { int i; int j; A(): j (0), i (1) { } };
Here the compiler will warn that the member initializers for `i
'
and `j
' will be rearranged to match the declaration order of the
members.
The following `-W...
' options are not affected by `-Wall
'.
-Weffc++ (C++ only)
grep -v
' to filter out those warnings.
-Wno-deprecated (C++ only)
-Wno-non-template-friend (C++ only)
friend foo(int)
'), the C++ language specification demands that the
friend declare or define an ordinary, nontemplate function. (Section
14.5.3). Before g++ implemented explicit specification, unqualified-ids
could be interpreted as a particular specialization of a templatized
function. Because this non-conforming behavior is no longer the default
behavior for g++, `-Wnon-template-friend
' allows the compiler to
check existing code for potential trouble spots, and is on by default.
This new compiler behavior can also be turned off with the flag
`-fguiding-decls
', which activates the older, non-specification
compiler code, or with `-Wno-non-template-friend
' which keeps the
conformant compiler code but disables the helpful warning.
-Wold-style-cast (C++ only)
static_cast
', `reinterpret_cast
', and
`const_cast
') are less vulnerable to unintended effects.
-Woverloaded-virtual (C++ only)
-Wno-pmf-conversions (C++ only)
-Wsign-promo (C++ only)
-Wsynth (C++ only)
struct A { operator int (); A& operator = (int); }; main () { A a,b; a = b; }
In this example, g++ will synthesize a default `A& operator = (const A&);
', while cfront will use the user-defined `operator =
'.
Using and Porting the GNU Compiler Collection (GCC)
Packaging copyright © 1988-2000 OAR Corporation
Context copyright by each document's author. See Free Software Foundation for information.