Controlling C++ Dialect
Only for C++ programs;
Can use most of the GNU compiler options regardless of the language .
For example, to compile a file "firstClass.C" :
g++ -g -frepo -O -c firstClass.C
-frepo is for C++ programs;
-fabi-version=n
Use version n of the C++ ABI. Version 2 is the version of the C++ ABI that first appeared in G++
3.4. Version 1 is the version of the C++ ABI that first appeared in G++ 3.2. Version 0 will
always be the version that conforms most closely to the C++ ABI specification. Therefore, the
ABI obtained using version 0 will change as ABI bugs are fixed.
The default is version 2.
| -fno-access-control Turn off all access checking. 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. This check is normally unnecessary because the C++ standard specifies that
"operator new" will only return 0 if it is declared throw(), in which case the compiler will
always check the return value even without this option. In all other cases, when "operator new"
has a non-empty exception specification, memory exhaustion is signalled by throwing
"std::bad_alloc". 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.
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.
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 *".
| -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.
| -fno-for-scope scope of variables declared in a for-init-statement is limited
to the loop ,
With no-for-scope they extend to the end of the enclosing scope,
Default: follow the standard, give warning for code that would otherwise be invalid, or have different behavior.
| -fno-gnu-keywords
Do not recognize typeof as a keyword, this which can then be used as an identifier.
__typeof__ is still valid. -ansi implies no-gnu-keywords .
| -frepo
Enable automatic template instantiation at link time. Implies no-implicit-templates .
| -fno-implicit-templates
non-inline templates which are instantiated implicitly (i.e. by use.) do not generate code.
| -fno-implicit-inline-templates
In addition to implicit non-inline templets, Don't emit code for implicit instantiations of inline templates.
The default : handle inlines differently so that compiles with and without optimization will need the same set
of explicit instantiations.
| -fno-implement-inlines
Do not emit out-of-line copies of inline functions controlled by #pragma
implementation.
Results in linker errors if these functions are not inlined everywhere they are called.
| -fms-extensions Disable 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. including
ffs, alloca, _exit, index, bzero, conjf and 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 does not require.
Only one is for a name having multiple meanings within a class.
| -fpermissive
Downgrade some diagnostics about nonconformant code from errors to warnings.
| -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).
Exception handling still generates this information.
| -ftemplate-depth-n
Maximum instantiation depth for template classes to detect endless recursions
| -fno-threadsafe-statics
Do not emit the extra code to use the routines specified in the C++ ABI for thread-safe
initialization of local statics.
| -fuse-cxa-atexit
Register destructors for objects with static storage duration with the "__cxa_atexit" function
rather than the "atexit" function. Required for fully standards-compliant
handling of static destructors.
| -fno-use-cxa-get-exception-ptr
Don't use the "__cxa_get_exception_ptr" runtime routine. Causes
"std::uncaught_exception" to be incorrect, but is necessary if the runtime routine is not available.
| -fvisibility-inlines-hidden
Declares that no attempt to compare pointers to inline methods where
the addresses of the two functions were taken in different shared objects.
Mark inline methods with __attribute__ ((visibility ("hidden")))
so that they do not appear in the export table of a DSO and do not
require a PLT indirection when used within the DSO.
Not the same as marking the methods as hidden directly.
Normally if there is a class with default visibility which has a hidden method, the effect of
this is that the method must be defined in only one shared object. This switch does not have
this restriction.
mark a method as having a visibility explicitly to negate the effect of the switch for
that method. For example, to compare pointers to a particular inline method,
mark it as having default visibility.
| -fvisibility-ms-compat
Use visibility settings to make linkage model compatible with Microsoft Visual Studio.
- sets default visibility to
hidden , like -fvisibility=hidden.
- . Types, but not their members, are not hidden by default.
- . The One Definition Rule is relaxed for types without explicit visibility specifications which are defined in more than one different shared object:
those declarations are permitted if they would have been permitted when this option was not used.
Is discouraged, preferable for types to be explicitly exported as
desired on a per-class basis. because Visual Studio can't compare two different
hidden types as unequal for the purposes of type_info and exception handling, users are able to
write code that relies upon this behavior.
consequences are that static data members of the same type with the
same name but defined in different shared objects will be different, so changing one will not
change the other; and that pointers to function members defined in different shared objects will
not compare equal.
It is a violation of the ODR to define types with the same name differently.
| -fno-default-inline
Do not assume inline for functions defined inside a class scope.
these functions will have linkage like inline functions; they won't be inlined by default.
| -Wabi
(C++ only) | Warn when code is not compatible with the vendor-neutral C++ ABI.
Include:
Incorrect handling of tail-padding for bit-fields.
Incorrect handling of tail-padding for virtual bases. G++ does not use tail padding when
Incorrect handling of bit-fields with declared widths greater than that of their underlying
types, when the bit-fields appear in a union.
Empty classes can be placed at incorrect offsets.
Names of template functions whose types involve "typename" or template template parameters
can be mangled incorrectly.
-Wctor-dtor-privacy
(C++ only) |
A class seems unusable because all the constructors or destructors in that class are
private, and it has neither friends nor public static member functions.
| -Wnon-virtual-dtor
(C++ only) |
a class appears to be polymorphic, thereby requiring a virtual destructor, yet it
declares a non-virtual one.
Enabled by all.
| -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.
| Not affected by all .
|
---|
-Weffc++
(C++ only) |
Warn about violations of the following style guidelines from Scott Meyers' Effective C++ book:
- Item 6: Distinguish between prefix and postfix forms of increment and decrement operators.
- Item 7: Never overload
&& , || , or , .
- Item 11: Define a copy constructor and an assignment operator for classes with dynamically allocated memory.
- Item 12: Prefer initialization to assignment in constructors.
- Item 14: Make destructors virtual in base classes.
- Item 15: Have "operator=" return a reference to *this.
- Item 23: Don't try to return a reference when you must return an object.
- Incorrect handling of bit-fields with declared widths greater than that of their underlying
types, when the bit-fields appear in a union.
- Empty classes can be placed at incorrect offsets.
- Names of template functions whose types involve "typename" or template template parameters can be mangled incorrectly.
| -nostdinc++
Do not search for header files in the standard directories specific to C++, search
the other standard directories. used when building the C++ library.
| -Wctor-dtor-privacy
(C++ only) |
a class seems unusable because all the constructors or destructors in that class are
private, and it has neither friends nor public static member functions.
| -Wno-deprecated
(C++ only) | Do not warn about deprecated features.
| -Wstrict-null-sentinel
(C++ only) | uncasted "NULL" as sentinel.
| -Wno-non-template-friend
(C++ only) |
Disable warnings when non-templatized friend functions are declared within a template.
| -Wold-style-cast
(C++ only) | an old-style (C-style) cast to a non-void type is used
| -Woverloaded-virtual
(C++ only) | function declaration hides virtual functions from a 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) |
overload resolution chooses a promotion from unsigned or enumerated type to a signed
type, over a conversion to an unsigned type of the same size.
|
Options Controlling Objective-C and Objective-C++ Dialects
|
---|
gcc -g -fgnu-runtime -O -c some_class.m
Objective-C is an extension of the C language, and compilations may also use
options specific to the C front-end (e.g., -Wtraditional ).
Objective-C++ compilations may use C++-specific options (e.g., -Wabi ).
only for compiling Objective-C and Objective-C++ programs:
| -fconstant-string-class=class-name
Use class-name as the name of the class to instantiate for each literal string specified with the
syntax "@"..."". The default class name is "NXConstantString" if the GNU runtime is being used,
and "NSConstantString"
The -fconstant-cfstrings overrides -fconstant-string-class and cause "@"...""
literals to be laid out as constant CoreFoundation strings.
| -fgnu-runtime
Generate object code compatible with the standard GNU Objective-C runtime. default
for most types of systems.
| -gen-decls
Dump interface declarations for all classes seen in the source file to a file named sourcename.decl.
| -Wno-protocol
If a class is declared to implement a protocol, a warning is issued for every method in the
protocol that is not implemented by the class. The default behavior is to issue a warning for
every method not explicitly implemented in the class, even if a method implementation is
inherited from the superclass. If you use the -Wno-protocol option, then methods inherited from
the superclass are considered to be implemented, and no warning is issued for them.
| -Wselector
multiple methods of different types for the same selector are found during compilation.
The check is performed on the list of methods in the final stage of compilation. Additionally, a
check is performed for each selector appearing in a "@selector(...)" expression, and a
corresponding method for that selector has been found during compilation. Because these checks
scan the method table only at the end of compilation, these warnings are not produced if the
final stage of compilation is not reached, for example because an error is found during
compilation, or because the -fsyntax-only option is being used.
| -Wstrict-selector-match
multiple methods with differing argument and/or return types are found for a given
selector when attempting to send a message using this selector to a receiver of type "id" or
"Class". When this flag is off (which is the default behavior), the compiler will omit such
warnings if any differences found are confined to types which share the same size and alignment.
| -Wundeclared-selector
a "@selector(...)" expression referring to an undeclared selector is found. A selector
is considered undeclared if no method with that name has been declared before the
"@selector(...)" expression, either explicitly in an @interface or @protocol declaration, or
implicitly in an @implementation section. This option always performs its checks as soon as a
"@selector(...)" expression is found, while -Wselector only performs its checks in the final
stage of compilation. This also enforces the coding style convention that methods and selectors
must be declared before being used.
| -print-objc-runtime-info
Generate C header describing the largest structure that is passed by value, if any.
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Control Diagnostic Messages Formatting
formatting algorithm, e.g. how many characters per line, how often source location information should
be reported.
-fmessage-length=n
Format error messages so that they fit on lines of about n characters. default 72
characters for g++ and 0 for the rest of the front ends supported by GCC.
If n is zero, no line-wrapping will be done; each error message will appear on a single line.
| -fdiagnostics-show-location=once
Only meaningful in line-wrapping mode.
Emit once source location information; that is, in case the message is too long to fit on a single physical
line and has to be wrapped, the source location won't be emitted (as prefix) again, over and
over, in subsequent continuation lines. default behavior.
| -fdiagnostics-show-location=every-line
Only meaningful in line-wrapping mode. Instructs the diagnostic messages reporter to emit the
same source location information (as prefix) for physical lines that result from the process of
breaking a message which is too long to fit on a single line.
| | | |
Include or Suppress Warnings
In addition to errors, constructions which are risky or suggest there may be an error are reported.
Request specific warnings with options beginning -W . For example -Wimplicit to request
warnings on implicit declarations. Most have a negative form
beginning -Wno- to turn off warnings. For example, -Wno-implicit.
The default option is shown.
Options rendered like this are included in -Wall .
-fsyntax-only Check the code for syntax errors only.
| -pedantic Issue all the warnings demanded by strict ISO C and ISO C++;
| -pedantic-errors Like -pedantic, except that errors are produced rather than warnings.
| -Wno-import Inhibit warning messages about the use of #import.
| -Wno-#warnings Inhibit messages issued by #warning .
| -Wextra-tokens extra tokens at the end of prepreprocessor directives.
| -Wnewline-eof files missing a newline at the end of the file.
| -Wno-altivec-long-deprecated
Do not warn about the use of the deprecated long keyword in AltiVec data types.
| -Wchar-subscripts
an array subscript has type "char".
enabled by -Wall.
|
| | | | | | | | | | |