blob: ebbfd81f654c07d260df04dda8ba15e3106d3eba [file] [log] [blame]
<html lang="en">
<head>
<title>C++ Dialect Options - Using the GNU Compiler Collection (GCC)</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using the GNU Compiler Collection (GCC)">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Invoking-GCC.html#Invoking-GCC" title="Invoking GCC">
<link rel="prev" href="C-Dialect-Options.html#C-Dialect-Options" title="C Dialect Options">
<link rel="next" href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options" title="Objective-C and Objective-C++ Dialect Options">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
2008 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Funding Free Software'', the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below). A copy of the license is included in the section entitled
``GNU Free Documentation License''.
(a) The FSF's Front-Cover Text is:
A GNU Manual
(b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development.-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="C++-Dialect-Options"></a>
<a name="C_002b_002b-Dialect-Options"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options">Objective-C and Objective-C++ Dialect Options</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="C-Dialect-Options.html#C-Dialect-Options">C Dialect Options</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Invoking-GCC.html#Invoking-GCC">Invoking GCC</a>
<hr>
</div>
<h3 class="section">3.5 Options Controlling C++ Dialect</h3>
<p><a name="index-compiler-options_002c-C_002b_002b-126"></a><a name="index-C_002b_002b-options_002c-command-line-127"></a><a name="index-options_002c-C_002b_002b-128"></a>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 <code>firstClass.C</code> like this:
<pre class="smallexample"> g++ -g -frepo -O -c firstClass.C
</pre>
<p class="noindent">In this example, only <samp><span class="option">-frepo</span></samp> is an option meant
only for C++ programs; you can use the other options with any
language supported by GCC.
<p>Here is a list of options that are <em>only</em> for compiling C++ programs:
<dl>
<dt><code>-fabi-version=</code><var>n</var><dd><a name="index-fabi_002dversion-129"></a>Use version <var>n</var> 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.
<p>The default is version 2.
<p>Version 3 corrects an error in mangling a constant address as a
template argument.
<p>Version 4 implements a standard mangling for vector types.
<p>See also <samp><span class="option">-Wabi</span></samp>.
<br><dt><code>-fno-access-control</code><dd><a name="index-fno_002daccess_002dcontrol-130"></a>Turn off all access checking. This switch is mainly useful for working
around bugs in the access control code.
<br><dt><code>-fcheck-new</code><dd><a name="index-fcheck_002dnew-131"></a>Check that the pointer returned by <code>operator new</code> is non-null
before attempting to modify the storage allocated. This check is
normally unnecessary because the C++ standard specifies that
<code>operator new</code> will only return <code>0</code> if it is declared
&lsquo;<samp><span class="samp">throw()</span></samp>&rsquo;, in which case the compiler will always check the
return value even without this option. In all other cases, when
<code>operator new</code> has a non-empty exception specification, memory
exhaustion is signalled by throwing <code>std::bad_alloc</code>. See also
&lsquo;<samp><span class="samp">new (nothrow)</span></samp>&rsquo;.
<br><dt><code>-fconserve-space</code><dd><a name="index-fconserve_002dspace-132"></a>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 <code>main()</code> has
completed, you may have an object that is being destroyed twice because
two definitions were merged.
<p>This option is no longer useful on most targets, now that support has
been added for putting variables into BSS without making them common.
<br><dt><code>-fno-deduce-init-list</code><dd><a name="index-fno_002ddeduce_002dinit_002dlist-133"></a>Disable deduction of a template type parameter as
std::initializer_list from a brace-enclosed initializer list, i.e.
<pre class="smallexample"> template &lt;class T&gt; auto forward(T t) -&gt; decltype (realfn (t))
{
return realfn (t);
}
void f()
{
forward({1,2}); // call forward&lt;std::initializer_list&lt;int&gt;&gt;
}
</pre>
<p>This option is present because this deduction is an extension to the
current specification in the C++0x working draft, and there was
some concern about potential overload resolution problems.
<br><dt><code>-ffriend-injection</code><dd><a name="index-ffriend_002dinjection-134"></a>Inject friend functions into the enclosing namespace, so that they are
visible outside the scope of the class in which they are declared.
Friend functions were documented to work this way in the old Annotated
C++ Reference Manual, and versions of G++ before 4.1 always worked
that way. However, in ISO C++ a friend function which is not declared
in an enclosing scope can only be found using argument dependent
lookup. This option causes friends to be injected as they were in
earlier releases.
<p>This option is for compatibility, and may be removed in a future
release of G++.
<br><dt><code>-fno-elide-constructors</code><dd><a name="index-fno_002delide_002dconstructors-135"></a>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.
<br><dt><code>-fno-enforce-eh-specs</code><dd><a name="index-fno_002denforce_002deh_002dspecs-136"></a>Don't generate code to 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
&lsquo;<samp><span class="samp">NDEBUG</span></samp>&rsquo;. This does not give user code permission to throw
exceptions in violation of the exception specifications; the compiler
will still optimize based on the specifications, so throwing an
unexpected exception will result in undefined behavior.
<br><dt><code>-ffor-scope</code><dt><code>-fno-for-scope</code><dd><a name="index-ffor_002dscope-137"></a><a name="index-fno_002dfor_002dscope-138"></a>If <samp><span class="option">-ffor-scope</span></samp> is specified, the scope of variables declared in
a <i>for-init-statement</i> is limited to the &lsquo;<samp><span class="samp">for</span></samp>&rsquo; loop itself,
as specified by the C++ standard.
If <samp><span class="option">-fno-for-scope</span></samp> is specified, the scope of variables declared in
a <i>for-init-statement</i> extends to the end of the enclosing scope,
as was the case in old versions of G++, and other (traditional)
implementations of C++.
<p>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.
<br><dt><code>-fno-gnu-keywords</code><dd><a name="index-fno_002dgnu_002dkeywords-139"></a>Do not recognize <code>typeof</code> as a keyword, so that code can use this
word as an identifier. You can use the keyword <code>__typeof__</code> instead.
<samp><span class="option">-ansi</span></samp> implies <samp><span class="option">-fno-gnu-keywords</span></samp>.
<br><dt><code>-fno-implicit-templates</code><dd><a name="index-fno_002dimplicit_002dtemplates-140"></a>Never emit code for non-inline templates which are instantiated
implicitly (i.e. by use); only emit code for explicit instantiations.
See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>, for more information.
<br><dt><code>-fno-implicit-inline-templates</code><dd><a name="index-fno_002dimplicit_002dinline_002dtemplates-141"></a>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.
<br><dt><code>-fno-implement-inlines</code><dd><a name="index-fno_002dimplement_002dinlines-142"></a>To save space, do not emit out-of-line copies of inline functions
controlled by &lsquo;<samp><span class="samp">#pragma implementation</span></samp>&rsquo;. This will cause linker
errors if these functions are not inlined everywhere they are called.
<br><dt><code>-fms-extensions</code><dd><a name="index-fms_002dextensions-143"></a>Disable pedantic warnings about constructs used in MFC, such as implicit
int and getting a pointer to member function via non-standard syntax.
<br><dt><code>-fno-nonansi-builtins</code><dd><a name="index-fno_002dnonansi_002dbuiltins-144"></a>Disable built-in declarations of functions that are not mandated by
ANSI/ISO C. These include <code>ffs</code>, <code>alloca</code>, <code>_exit</code>,
<code>index</code>, <code>bzero</code>, <code>conjf</code>, and other related functions.
<br><dt><code>-fno-operator-names</code><dd><a name="index-fno_002doperator_002dnames-145"></a>Do not treat the operator name keywords <code>and</code>, <code>bitand</code>,
<code>bitor</code>, <code>compl</code>, <code>not</code>, <code>or</code> and <code>xor</code> as
synonyms as keywords.
<br><dt><code>-fno-optional-diags</code><dd><a name="index-fno_002doptional_002ddiags-146"></a>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.
<br><dt><code>-fpermissive</code><dd><a name="index-fpermissive-147"></a>Downgrade some diagnostics about nonconformant code from errors to
warnings. Thus, using <samp><span class="option">-fpermissive</span></samp> will allow some
nonconforming code to compile.
<br><dt><code>-fno-pretty-templates</code><dd><a name="index-fno_002dpretty_002dtemplates-148"></a>When an error message refers to a specialization of a function
template, the compiler will normally print the signature of the
template followed by the template arguments and any typedefs or
typenames in the signature (e.g. <code>void f(T) [with T = int]</code>
rather than <code>void f(int)</code>) so that it's clear which template is
involved. When an error message refers to a specialization of a class
template, the compiler will omit any template arguments which match
the default template arguments for that template. If either of these
behaviors make it harder to understand the error message rather than
easier, using <samp><span class="option">-fno-pretty-templates</span></samp> will disable them.
<br><dt><code>-frepo</code><dd><a name="index-frepo-149"></a>Enable automatic template instantiation at link time. This option also
implies <samp><span class="option">-fno-implicit-templates</span></samp>. See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>, for more information.
<br><dt><code>-fno-rtti</code><dd><a name="index-fno_002drtti-150"></a>Disable generation of information about every class with virtual
functions for use by the C++ runtime type identification features
(&lsquo;<samp><span class="samp">dynamic_cast</span></samp>&rsquo; and &lsquo;<samp><span class="samp">typeid</span></samp>&rsquo;). 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. The &lsquo;<samp><span class="samp">dynamic_cast</span></samp>&rsquo; operator can still be used for casts that
do not require runtime type information, i.e. casts to <code>void *</code> or to
unambiguous base classes.
<br><dt><code>-fstats</code><dd><a name="index-fstats-151"></a>Emit statistics about front-end processing at the end of the compilation.
This information is generally only useful to the G++ development team.
<br><dt><code>-ftemplate-depth=</code><var>n</var><dd><a name="index-ftemplate_002ddepth-152"></a>Set the maximum instantiation depth for template classes to <var>n</var>.
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
(changed to 1024 in C++0x).
<br><dt><code>-fno-threadsafe-statics</code><dd><a name="index-fno_002dthreadsafe_002dstatics-153"></a>Do not emit the extra code to use the routines specified in the C++
ABI for thread-safe initialization of local statics. You can use this
option to reduce code size slightly in code that doesn't need to be
thread-safe.
<br><dt><code>-fuse-cxa-atexit</code><dd><a name="index-fuse_002dcxa_002datexit-154"></a>Register destructors for objects with static storage duration with the
<code>__cxa_atexit</code> function rather than the <code>atexit</code> function.
This option is required for fully standards-compliant handling of static
destructors, but will only work if your C library supports
<code>__cxa_atexit</code>.
<br><dt><code>-fno-use-cxa-get-exception-ptr</code><dd><a name="index-fno_002duse_002dcxa_002dget_002dexception_002dptr-155"></a>Don't use the <code>__cxa_get_exception_ptr</code> runtime routine. This
will cause <code>std::uncaught_exception</code> to be incorrect, but is necessary
if the runtime routine is not available.
<br><dt><code>-fvisibility-inlines-hidden</code><dd><a name="index-fvisibility_002dinlines_002dhidden-156"></a>This switch declares that the user does not attempt to compare
pointers to inline methods where the addresses of the two functions
were taken in different shared objects.
<p>The effect of this is that GCC may, effectively, mark inline methods with
<code>__attribute__ ((visibility ("hidden")))</code> 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. Enabling this option can have a dramatic effect
on load and link times of a DSO as it massively reduces the size of the
dynamic export table when the library makes heavy use of templates.
<p>The behavior of this switch is not quite the same as marking the
methods as hidden directly, because it does not affect static variables
local to the function or cause the compiler to deduce that
the function is defined in only one shared object.
<p>You may mark a method as having a visibility explicitly to negate the
effect of the switch for that method. For example, if you do want to
compare pointers to a particular inline method, you might mark it as
having default visibility. Marking the enclosing class with explicit
visibility will have no effect.
<p>Explicitly instantiated inline methods are unaffected by this option
as their linkage might otherwise cross a shared library boundary.
See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>.
<br><dt><code>-fvisibility-ms-compat</code><dd><a name="index-fvisibility_002dms_002dcompat-157"></a>This flag attempts to use visibility settings to make GCC's C++
linkage model compatible with that of Microsoft Visual Studio.
<p>The flag makes these changes to GCC's linkage model:
<ol type=1 start=1>
<li>It sets the default visibility to <code>hidden</code>, like
<samp><span class="option">-fvisibility=hidden</span></samp>.
<li>Types, but not their members, are not hidden by default.
<li>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.
</ol>
<p>In new code it is better to use <samp><span class="option">-fvisibility=hidden</span></samp> and
export those classes which are intended to be externally visible.
Unfortunately it is possible for code to rely, perhaps accidentally,
on the Visual Studio behavior.
<p>Among the consequences of these changes 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 may not compare equal. When this flag is given, it is a
violation of the ODR to define types with the same name differently.
<br><dt><code>-fno-weak</code><dd><a name="index-fno_002dweak-158"></a>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++.
<br><dt><code>-nostdinc++</code><dd><a name="index-nostdinc_002b_002b-159"></a>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.)
</dl>
<p>In addition, these optimization, warning, and code generation options
have meanings only for C++ programs:
<dl>
<dt><code>-fno-default-inline</code><dd><a name="index-fno_002ddefault_002dinline-160"></a>Do not assume &lsquo;<samp><span class="samp">inline</span></samp>&rsquo; for functions defined inside a class scope.
See <a href="Optimize-Options.html#Optimize-Options">Options That Control Optimization</a>. Note that these
functions will have linkage like inline functions; they just won't be
inlined by default.
<br><dt><code>-Wabi </code><span class="roman">(C, Objective-C, C++ and Objective-C++ only)</span><dd><a name="index-Wabi-161"></a><a name="index-Wno_002dabi-162"></a>Warn when G++ generates code that is probably not compatible with the
vendor-neutral C++ ABI. Although an effort has been made to warn about
all such cases, there are probably some cases that are not warned about,
even though G++ is generating incompatible code. There may also be
cases where warnings are emitted even though the code that is generated
will be compatible.
<p>You should rewrite your code to avoid these warnings if you are
concerned about the fact that code generated by G++ may not be binary
compatible with code generated by other compilers.
<p>The known incompatibilities in <samp><span class="option">-fabi-version=2</span></samp> (the default) include:
<ul>
<li>A template with a non-type template parameter of reference type is
mangled incorrectly:
<pre class="smallexample"> extern int N;
template &lt;int &amp;&gt; struct S {};
void n (S&lt;N&gt;) {2}
</pre>
<p>This is fixed in <samp><span class="option">-fabi-version=3</span></samp>.
<li>SIMD vector types declared using <code>__attribute ((vector_size))</code> are
mangled in a non-standard way that does not allow for overloading of
functions taking vectors of different sizes.
<p>The mangling is changed in <samp><span class="option">-fabi-version=4</span></samp>.
</ul>
<p>The known incompatibilities in <samp><span class="option">-fabi-version=1</span></samp> include:
<ul>
<li>Incorrect handling of tail-padding for bit-fields. G++ may attempt to
pack data into the same byte as a base class. For example:
<pre class="smallexample"> struct A { virtual void f(); int f1 : 1; };
struct B : public A { int f2 : 1; };
</pre>
<p class="noindent">In this case, G++ will place <code>B::f2</code> into the same byte
as<code>A::f1</code>; other compilers will not. You can avoid this problem
by explicitly padding <code>A</code> so that its size is a multiple of the
byte size on your platform; that will cause G++ and other compilers to
layout <code>B</code> identically.
<li>Incorrect handling of tail-padding for virtual bases. G++ does not use
tail padding when laying out virtual bases. For example:
<pre class="smallexample"> struct A { virtual void f(); char c1; };
struct B { B(); char c2; };
struct C : public A, public virtual B {};
</pre>
<p class="noindent">In this case, G++ will not place <code>B</code> into the tail-padding for
<code>A</code>; other compilers will. You can avoid this problem by
explicitly padding <code>A</code> so that its size is a multiple of its
alignment (ignoring virtual base classes); that will cause G++ and other
compilers to layout <code>C</code> identically.
<li>Incorrect handling of bit-fields with declared widths greater than that
of their underlying types, when the bit-fields appear in a union. For
example:
<pre class="smallexample"> union U { int i : 4096; };
</pre>
<p class="noindent">Assuming that an <code>int</code> does not have 4096 bits, G++ will make the
union too small by the number of bits in an <code>int</code>.
<li>Empty classes can be placed at incorrect offsets. For example:
<pre class="smallexample"> struct A {};
struct B {
A a;
virtual void f ();
};
struct C : public B, public A {};
</pre>
<p class="noindent">G++ will place the <code>A</code> base class of <code>C</code> at a nonzero offset;
it should be placed at offset zero. G++ mistakenly believes that the
<code>A</code> data member of <code>B</code> is already at offset zero.
<li>Names of template functions whose types involve <code>typename</code> or
template template parameters can be mangled incorrectly.
<pre class="smallexample"> template &lt;typename Q&gt;
void f(typename Q::X) {}
template &lt;template &lt;typename&gt; class Q&gt;
void f(typename Q&lt;int&gt;::X) {}
</pre>
<p class="noindent">Instantiations of these templates may be mangled incorrectly.
</ul>
<p>It also warns psABI related changes. The known psABI changes at this
point include:
<ul>
<li>For SYSV/x86-64, when passing union with long double, it is changed to
pass in memory as specified in psABI. For example:
<pre class="smallexample"> union U {
long double ld;
int i;
};
</pre>
<p class="noindent"><code>union U</code> will always be passed in memory.
</ul>
<br><dt><code>-Wctor-dtor-privacy </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wctor_002ddtor_002dprivacy-163"></a><a name="index-Wno_002dctor_002ddtor_002dprivacy-164"></a>Warn when 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.
<br><dt><code>-Wnon-virtual-dtor </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wnon_002dvirtual_002ddtor-165"></a><a name="index-Wno_002dnon_002dvirtual_002ddtor-166"></a>Warn when a class has virtual functions and accessible non-virtual
destructor, in which case it would be possible but unsafe to delete
an instance of a derived class through a pointer to the base class.
This warning is also enabled if -Weffc++ is specified.
<br><dt><code>-Wreorder </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wreorder-167"></a><a name="index-Wno_002dreorder-168"></a><a name="index-reordering_002c-warning-169"></a><a name="index-warning-for-reordering-of-member-initializers-170"></a>Warn when the order of member initializers given in the code does not
match the order in which they must be executed. For instance:
<pre class="smallexample"> struct A {
int i;
int j;
A(): j (0), i (1) { }
};
</pre>
<p>The compiler will rearrange the member initializers for &lsquo;<samp><span class="samp">i</span></samp>&rsquo;
and &lsquo;<samp><span class="samp">j</span></samp>&rsquo; to match the declaration order of the members, emitting
a warning to that effect. This warning is enabled by <samp><span class="option">-Wall</span></samp>.
</dl>
<p>The following <samp><span class="option">-W...</span></samp> options are not affected by <samp><span class="option">-Wall</span></samp>.
<dl>
<dt><code>-Weffc++ </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Weffc_002b_002b-171"></a><a name="index-Wno_002deffc_002b_002b-172"></a>Warn about violations of the following style guidelines from Scott Meyers'
<cite>Effective C++</cite> book:
<ul>
<li>Item 11: Define a copy constructor and an assignment operator for classes
with dynamically allocated memory.
<li>Item 12: Prefer initialization to assignment in constructors.
<li>Item 14: Make destructors virtual in base classes.
<li>Item 15: Have <code>operator=</code> return a reference to <code>*this</code>.
<li>Item 23: Don't try to return a reference when you must return an object.
</ul>
<p>Also warn about violations of the following style guidelines from
Scott Meyers' <cite>More Effective C++</cite> book:
<ul>
<li>Item 6: Distinguish between prefix and postfix forms of increment and
decrement operators.
<li>Item 7: Never overload <code>&amp;&amp;</code>, <code>||</code>, or <code>,</code>.
</ul>
<p>When selecting this option, be aware that the standard library
headers do not obey all of these guidelines; use &lsquo;<samp><span class="samp">grep -v</span></samp>&rsquo;
to filter out those warnings.
<br><dt><code>-Wstrict-null-sentinel </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wstrict_002dnull_002dsentinel-173"></a><a name="index-Wno_002dstrict_002dnull_002dsentinel-174"></a>Warn also about the use of an uncasted <code>NULL</code> as sentinel. When
compiling only with GCC this is a valid sentinel, as <code>NULL</code> is defined
to <code>__null</code>. Although it is a null pointer constant not a null pointer,
it is guaranteed to be of the same size as a pointer. But this use is
not portable across different compilers.
<br><dt><code>-Wno-non-template-friend </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wno_002dnon_002dtemplate_002dfriend-175"></a><a name="index-Wnon_002dtemplate_002dfriend-176"></a>Disable warnings when non-templatized friend functions are declared
within a template. Since the advent of explicit template specification
support in G++, if the name of the friend is an unqualified-id (i.e.,
&lsquo;<samp><span class="samp">friend foo(int)</span></samp>&rsquo;), 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++, <samp><span class="option">-Wnon-template-friend</span></samp> 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
<samp><span class="option">-Wno-non-template-friend</span></samp> which keeps the conformant compiler code
but disables the helpful warning.
<br><dt><code>-Wold-style-cast </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wold_002dstyle_002dcast-177"></a><a name="index-Wno_002dold_002dstyle_002dcast-178"></a>Warn if an old-style (C-style) cast to a non-void type is used within
a C++ program. The new-style casts (&lsquo;<samp><span class="samp">dynamic_cast</span></samp>&rsquo;,
&lsquo;<samp><span class="samp">static_cast</span></samp>&rsquo;, &lsquo;<samp><span class="samp">reinterpret_cast</span></samp>&rsquo;, and &lsquo;<samp><span class="samp">const_cast</span></samp>&rsquo;) are
less vulnerable to unintended effects and much easier to search for.
<br><dt><code>-Woverloaded-virtual </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Woverloaded_002dvirtual-179"></a><a name="index-Wno_002doverloaded_002dvirtual-180"></a><a name="index-overloaded-virtual-fn_002c-warning-181"></a><a name="index-warning-for-overloaded-virtual-fn-182"></a>Warn when a function declaration hides virtual functions from a
base class. For example, in:
<pre class="smallexample"> struct A {
virtual void f();
};
struct B: public A {
void f(int);
};
</pre>
<p>the <code>A</code> class version of <code>f</code> is hidden in <code>B</code>, and code
like:
<pre class="smallexample"> B* b;
b-&gt;f();
</pre>
<p>will fail to compile.
<br><dt><code>-Wno-pmf-conversions </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wno_002dpmf_002dconversions-183"></a><a name="index-Wpmf_002dconversions-184"></a>Disable the diagnostic for converting a bound pointer to member function
to a plain pointer.
<br><dt><code>-Wsign-promo </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wsign_002dpromo-185"></a><a name="index-Wno_002dsign_002dpromo-186"></a>Warn when 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. Previous versions of G++ would try to preserve
unsignedness, but the standard mandates the current behavior.
<pre class="smallexample"> struct A {
operator int ();
A&amp; operator = (int);
};
main ()
{
A a,b;
a = b;
}
</pre>
<p>In this example, G++ will synthesize a default &lsquo;<samp><span class="samp">A&amp; operator =
(const A&amp;);</span></samp>&rsquo;, while cfront will use the user-defined &lsquo;<samp><span class="samp">operator =</span></samp>&rsquo;.
</dl>
</body></html>