3.5 Options Controlling C++ Dialect
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
-
Turn off all access checking. This switch is mainly useful for working
around bugs in the access control code.
-fcheck-new
-
Check that the pointer returned by
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
-
Put uninitialized or runtime-initialized global variables into the
common segment, as C does. This saves space in the executable at the
cost of not diagnosing duplicate definitions. If you compile with this
flag and your program mysteriously crashes after
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.
-fno-const-strings
-
Give string constants type
char *
instead of type const
char *
. By default, G++ uses type const char *
as required by
the standard. Even if you use `-fno-const-strings', you cannot
actually modify the value of a string constant, unless you also use
`-fwritable-strings'.
This option might be removed in a future release of G++. For maximum
portability, you should structure your code so that it works with
string constants that have type const char *
.
-fdollars-in-identifiers
-
Accept `$' 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, ISO C and C++ forbid `$' in identifiers.
-fno-elide-constructors
-
The C++ standard allows an implementation to omit creating a temporary
which is only used to initialize another object of the same type.
Specifying this option disables that optimization, and forces g++ to
call the copy constructor in all cases.
-fno-enforce-eh-specs
-
Don't check for violation of exception specifications at runtime. This
option violates the C++ standard, but may be useful for reducing code
size in production builds, much like defining `NDEBUG'. The compiler
will still optimize based on the exception specifications.
-fexternal-templates
-
Cause template instantiations to obey `#pragma interface' and
`implementation'; template instances are emitted or not according
to the location of the template definition. See section 6.6 Where's the Template?, for more information.
This option is deprecated.
-falt-external-templates
-
Similar to `-fexternal-templates', but template instances are emitted or
not according to the place where they are first instantiated.
See section 6.6 Where's the Template?, for more information.
This option is deprecated.
-ffor-scope
-fno-for-scope
-
If `-ffor-scope' is specified, the scope of variables declared in
a for-init-statement is limited to the `for' loop itself,
as specified by the 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
-
Do not recognize
typeof
as a keyword, so that code can use this
word as an identifier. You can use the keyword __typeof__
instead.
`-ansi' implies `-fno-gnu-keywords'.
-fno-honor-std
-
Ignore
namespace std
, instead of treating it as a real namespace.
With this switch, the compiler will ignore
namespace-declarations
, using-declarations
,
using-directives
, and namespace-names
, if they involve
std
.
This option is only useful if you have manually compiled the C++
run-time library with the same switch. Otherwise, your programs will
not link. The use of this option is not recommended, and the option may
be removed from a future version of G++.
-fno-implicit-templates
-
Never emit code for non-inline templates which are instantiated
implicitly (i.e. by use); only emit code for explicit instantiations.
See section 6.6 Where's the Template?, for more information.
-fno-implicit-inline-templates
-
Don't emit code for implicit instantiations of inline templates, either.
The default is to handle inlines differently so that compiles with and
without optimization will need the same set of explicit instantiations.
-fno-implement-inlines
-
To save space, do not emit out-of-line copies of inline functions
controlled by `#pragma implementation'. This will cause linker
errors if these functions are not inlined everywhere they are called.
-fms-extensions
-
Disable pedantic warnings about constructs used in MFC, such as implicit
int and getting a pointer to member function via non-standard syntax.
-fno-nonansi-builtins
-
Disable built-in declarations of functions that are not mandated by
ANSI/ISO C. These include
ffs
, alloca
, _exit
,
index
, bzero
, conjf
, and other related functions.
-fno-operator-names
-
Do not treat the operator name keywords
and
, bitand
,
bitor
, compl
, not
, or
and xor
as
synonyms as keywords.
-fno-optional-diags
-
Disable diagnostics that the standard says a compiler does not need to
issue. Currently, the only such diagnostic issued by g++ is the one for
a name having multiple meanings within a class.
-fpermissive
-
Downgrade messages about nonconformant code from errors to warnings. By
default, g++ effectively sets `-pedantic-errors' without
`-pedantic'; this option reverses that. This behavior and this
option are superseded by `-pedantic', which works as it does for GNU C.
-frepo
-
Enable automatic template instantiation. This option also implies
`-fno-implicit-templates'. See section 6.6 Where's the Template?, for more
information.
-fno-rtti
-
Disable generation of information about every class with virtual
functions for use by the C++ runtime type identification features
(`dynamic_cast' and `typeid'). If you don't use those parts
of the language, you can save some space by using this flag. Note that
exception handling uses the same information, but it will generate it as
needed.
-fstats
-
Emit statistics about front-end processing at the end of the compilation.
This information is generally only useful to the G++ development team.
-ftemplate-depth-n
-
Set the maximum instantiation depth for template classes to n.
A limit on the template instantiation depth is needed to detect
endless recursions during template class instantiation. ANSI/ISO C++
conforming programs must not rely on a maximum depth greater than 17.
-fuse-cxa-atexit
-
Register destructors for objects with static storage duration with the
__cxa_atexit
function rather than the atexit
function.
This option is required for fully standards-compliant handling of static
destructors, but will only work if your C library supports
__cxa_atexit
.
-fno-weak
-
Do not use weak symbol support, even if it is provided by the linker.
By default, G++ will use weak symbols if they are available. This
option exists only for testing, and should not be used by end-users;
it will result in inferior code and has no benefits. This option may
be removed in a future release of G++.
-nostdinc++
-
Do not search for header files in the standard directories specific to
C++, but do still search the other standard directories. (This option
is used when building the C++ library.)
In addition, these optimization, warning, and code generation options
have meanings only for C++ programs:
-fno-default-inline
-
Do not assume `inline' for functions defined inside a class scope.
See section Options That Control Optimization. Note that these
functions will have linkage like inline functions; they just won't be
inlined by default.
-Wctor-dtor-privacy (C++ only)
-
Warn when a class seems unusable, because all the constructors or
destructors in a class are private and the class has no friends or
public static member functions.
-Wnon-virtual-dtor (C++ only)
-
Warn when a class declares a non-virtual destructor that should probably
be virtual, because it looks like the class will be used polymorphically.
-Wreorder (C++ only)
-
Warn when the order of member initializers given in the code does not
match the order in which they must be executed. For instance:
| 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)
-
Warn about violations of various style guidelines from Scott Meyers'
Effective C++ books. If you use this option, you should be aware
that the standard library headers do not obey all of these guidelines;
you can use `grep -v' to filter out those warnings.
-Wno-deprecated (C++ only)
-
Do not warn about usage of deprecated features. See section 6.10 Deprecated Features.
-Wno-non-template-friend (C++ only)
-
Disable warnings when non-templatized friend functions are declared
within a template. With the advent of explicit template specification
support in g++, if the name of the friend is an unqualified-id (i.e.,
`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 be turned off with
`-Wno-non-template-friend' which keeps the conformant compiler code
but disables the helpful warning.
-Wold-style-cast (C++ only)
-
Warn if an old-style (C-style) cast is used within a C++ program. The
new-style casts (`static_cast', `reinterpret_cast', and
`const_cast') are less vulnerable to unintended effects, and much
easier to grep for.
-Woverloaded-virtual (C++ only)
-
Warn when a derived class function declaration may be an error in
defining a virtual function. In a derived class, the
definitions of virtual functions must match the type signature of a
virtual function declared in the base class. With this option, the
compiler warns when you define a function with the same name as a
virtual function, but with a type signature that does not match any
declarations from the base class.
-Wno-pmf-conversions (C++ only)
-
Disable the diagnostic for converting a bound pointer to member function
to a plain pointer.
-Wsign-promo (C++ only)
-
Warn when overload resolution chooses a promotion from unsigned or
enumeral type to a signed type over a conversion to an unsigned type of
the same size. Previous versions of g++ would try to preserve
unsignedness, but the standard mandates the current behavior.
-Wsynth (C++ only)
-
Warn when g++'s synthesis behavior does not match that of cfront. For
instance:
| 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 ='.
This document was generated
by Vincent Chung on June, 26 2001
using texi2html