• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-armeabi-2013.11/share/doc/arm-arm-none-eabi/html/gcc/
1<html lang="en">
2<head>
3<title>C++ Dialect Options - Using the GNU Compiler Collection (GCC)</title>
4<meta http-equiv="Content-Type" content="text/html">
5<meta name="description" content="Using the GNU Compiler Collection (GCC)">
6<meta name="generator" content="makeinfo 4.13">
7<link title="Top" rel="start" href="index.html#Top">
8<link rel="up" href="Invoking-GCC.html#Invoking-GCC" title="Invoking GCC">
9<link rel="prev" href="C-Dialect-Options.html#C-Dialect-Options" title="C Dialect Options">
10<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">
11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12<!--
13Copyright (C) 1988-2013 Free Software Foundation, Inc.
14
15Permission is granted to copy, distribute and/or modify this document
16under the terms of the GNU Free Documentation License, Version 1.3 or
17any later version published by the Free Software Foundation; with the
18Invariant Sections being ``Funding Free Software'', the Front-Cover
19Texts being (a) (see below), and with the Back-Cover Texts being (b)
20(see below).  A copy of the license is included in the section entitled
21``GNU Free Documentation License''.
22
23(a) The FSF's Front-Cover Text is:
24
25     A GNU Manual
26
27(b) The FSF's Back-Cover Text is:
28
29     You have freedom to copy and modify this GNU Manual, like GNU
30     software.  Copies published by the Free Software Foundation raise
31     funds for GNU development.-->
32<meta http-equiv="Content-Style-Type" content="text/css">
33<style type="text/css"><!--
34  pre.display { font-family:inherit }
35  pre.format  { font-family:inherit }
36  pre.smalldisplay { font-family:inherit; font-size:smaller }
37  pre.smallformat  { font-family:inherit; font-size:smaller }
38  pre.smallexample { font-size:smaller }
39  pre.smalllisp    { font-size:smaller }
40  span.sc    { font-variant:small-caps }
41  span.roman { font-family:serif; font-weight:normal; } 
42  span.sansserif { font-family:sans-serif; font-weight:normal; } 
43--></style>
44<link rel="stylesheet" type="text/css" href="../cs.css">
45</head>
46<body>
47<div class="node">
48<a name="C++-Dialect-Options"></a>
49<a name="C_002b_002b-Dialect-Options"></a>
50<p>
51Next:&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>,
52Previous:&nbsp;<a rel="previous" accesskey="p" href="C-Dialect-Options.html#C-Dialect-Options">C Dialect Options</a>,
53Up:&nbsp;<a rel="up" accesskey="u" href="Invoking-GCC.html#Invoking-GCC">Invoking GCC</a>
54<hr>
55</div>
56
57<h3 class="section">3.5 Options Controlling C++ Dialect</h3>
58
59<p><a name="index-compiler-options_002c-C_002b_002b-130"></a><a name="index-C_002b_002b-options_002c-command_002dline-131"></a><a name="index-options_002c-C_002b_002b-132"></a>This section describes the command-line options that are only meaningful
60for C++ programs.  You can also use most of the GNU compiler options
61regardless of what language your program is in.  For example, you
62might compile a file <code>firstClass.C</code> like this:
63
64<pre class="smallexample">     g++ -g -frepo -O -c firstClass.C
65</pre>
66 <p class="noindent">In this example, only <samp><span class="option">-frepo</span></samp> is an option meant
67only for C++ programs; you can use the other options with any
68language supported by GCC.
69
70 <p>Here is a list of options that are <em>only</em> for compiling C++ programs:
71
72     <dl>
73<dt><code>-fabi-version=</code><var>n</var><dd><a name="index-fabi_002dversion-133"></a>Use version <var>n</var> of the C++ ABI.  The default is version 2.
74
75     <p>Version 0 refers to the version conforming most closely to
76the C++ ABI specification.  Therefore, the ABI obtained using version 0
77will change in different versions of G++ as ABI bugs are fixed.
78
79     <p>Version 1 is the version of the C++ ABI that first appeared in G++ 3.2.
80
81     <p>Version 2 is the version of the C++ ABI that first appeared in G++ 3.4.
82
83     <p>Version 3 corrects an error in mangling a constant address as a
84template argument.
85
86     <p>Version 4, which first appeared in G++ 4.5, implements a standard
87mangling for vector types.
88
89     <p>Version 5, which first appeared in G++ 4.6, corrects the mangling of
90attribute const/volatile on function pointer types, decltype of a
91plain decl, and use of a function parameter in the declaration of
92another parameter.
93
94     <p>Version 6, which first appeared in G++ 4.7, corrects the promotion
95behavior of C++11 scoped enums and the mangling of template argument
96packs, const/static_cast, prefix ++ and &ndash;, and a class scope function
97used as a template argument.
98
99     <p>See also <samp><span class="option">-Wabi</span></samp>.
100
101     <br><dt><code>-fno-access-control</code><dd><a name="index-fno_002daccess_002dcontrol-134"></a>Turn off all access checking.  This switch is mainly useful for working
102around bugs in the access control code.
103
104     <br><dt><code>-fcheck-new</code><dd><a name="index-fcheck_002dnew-135"></a>Check that the pointer returned by <code>operator new</code> is non-null
105before attempting to modify the storage allocated.  This check is
106normally unnecessary because the C++ standard specifies that
107<code>operator new</code> only returns <code>0</code> if it is declared
108&lsquo;<samp><span class="samp">throw()</span></samp>&rsquo;, in which case the compiler always checks the
109return value even without this option.  In all other cases, when
110<code>operator new</code> has a non-empty exception specification, memory
111exhaustion is signalled by throwing <code>std::bad_alloc</code>.  See also
112&lsquo;<samp><span class="samp">new (nothrow)</span></samp>&rsquo;.
113
114     <br><dt><code>-fconstexpr-depth=</code><var>n</var><dd><a name="index-fconstexpr_002ddepth-136"></a>Set the maximum nested evaluation depth for C++11 constexpr functions
115to <var>n</var>.  A limit is needed to detect endless recursion during
116constant expression evaluation.  The minimum specified by the standard
117is 512.
118
119     <br><dt><code>-fdeduce-init-list</code><dd><a name="index-fdeduce_002dinit_002dlist-137"></a>Enable deduction of a template type parameter as
120<code>std::initializer_list</code> from a brace-enclosed initializer list, i.e.
121
122     <pre class="smallexample">          template &lt;class T&gt; auto forward(T t) -&gt; decltype (realfn (t))
123          {
124            return realfn (t);
125          }
126          
127          void f()
128          {
129            forward({1,2}); // call forward&lt;std::initializer_list&lt;int&gt;&gt;
130          }
131</pre>
132     <p>This deduction was implemented as a possible extension to the
133originally proposed semantics for the C++11 standard, but was not part
134of the final standard, so it is disabled by default.  This option is
135deprecated, and may be removed in a future version of G++.
136
137     <br><dt><code>-ffriend-injection</code><dd><a name="index-ffriend_002dinjection-138"></a>Inject friend functions into the enclosing namespace, so that they are
138visible outside the scope of the class in which they are declared. 
139Friend functions were documented to work this way in the old Annotated
140C++ Reference Manual, and versions of G++ before 4.1 always worked
141that way.  However, in ISO C++ a friend function that is not declared
142in an enclosing scope can only be found using argument dependent
143lookup.  This option causes friends to be injected as they were in
144earlier releases.
145
146     <p>This option is for compatibility, and may be removed in a future
147release of G++.
148
149     <br><dt><code>-fno-elide-constructors</code><dd><a name="index-fno_002delide_002dconstructors-139"></a>The C++ standard allows an implementation to omit creating a temporary
150that is only used to initialize another object of the same type. 
151Specifying this option disables that optimization, and forces G++ to
152call the copy constructor in all cases.
153
154     <br><dt><code>-fno-enforce-eh-specs</code><dd><a name="index-fno_002denforce_002deh_002dspecs-140"></a>Don't generate code to check for violation of exception specifications
155at run time.  This option violates the C++ standard, but may be useful
156for reducing code size in production builds, much like defining
157&lsquo;<samp><span class="samp">NDEBUG</span></samp>&rsquo;.  This does not give user code permission to throw
158exceptions in violation of the exception specifications; the compiler
159still optimizes based on the specifications, so throwing an
160unexpected exception results in undefined behavior at run time.
161
162     <br><dt><code>-fextern-tls-init</code><dt><code>-fno-extern-tls-init</code><dd><a name="index-fextern_002dtls_002dinit-141"></a><a name="index-fno_002dextern_002dtls_002dinit-142"></a>The C++11 and OpenMP standards allow &lsquo;<samp><span class="samp">thread_local</span></samp>&rsquo; and
163&lsquo;<samp><span class="samp">threadprivate</span></samp>&rsquo; variables to have dynamic (runtime)
164initialization.  To support this, any use of such a variable goes
165through a wrapper function that performs any necessary initialization. 
166When the use and definition of the variable are in the same
167translation unit, this overhead can be optimized away, but when the
168use is in a different translation unit there is significant overhead
169even if the variable doesn't actually need dynamic initialization.  If
170the programmer can be sure that no use of the variable in a
171non-defining TU needs to trigger dynamic initialization (either
172because the variable is statically initialized, or a use of the
173variable in the defining TU will be executed before any uses in
174another TU), they can avoid this overhead with the
175<samp><span class="option">-fno-extern-tls-init</span></samp> option.
176
177     <p>On targets that support symbol aliases, the default is
178<samp><span class="option">-fextern-tls-init</span></samp>.  On targets that do not support symbol
179aliases, the default is <samp><span class="option">-fno-extern-tls-init</span></samp>.
180
181     <br><dt><code>-ffor-scope</code><dt><code>-fno-for-scope</code><dd><a name="index-ffor_002dscope-143"></a><a name="index-fno_002dfor_002dscope-144"></a>If <samp><span class="option">-ffor-scope</span></samp> is specified, the scope of variables declared in
182a <i>for-init-statement</i> is limited to the &lsquo;<samp><span class="samp">for</span></samp>&rsquo; loop itself,
183as specified by the C++ standard. 
184If <samp><span class="option">-fno-for-scope</span></samp> is specified, the scope of variables declared in
185a <i>for-init-statement</i> extends to the end of the enclosing scope,
186as was the case in old versions of G++, and other (traditional)
187implementations of C++.
188
189     <p>If neither flag is given, the default is to follow the standard,
190but to allow and give a warning for old-style code that would
191otherwise be invalid, or have different behavior.
192
193     <br><dt><code>-fno-gnu-keywords</code><dd><a name="index-fno_002dgnu_002dkeywords-145"></a>Do not recognize <code>typeof</code> as a keyword, so that code can use this
194word as an identifier.  You can use the keyword <code>__typeof__</code> instead. 
195<samp><span class="option">-ansi</span></samp> implies <samp><span class="option">-fno-gnu-keywords</span></samp>.
196
197     <br><dt><code>-fno-implicit-templates</code><dd><a name="index-fno_002dimplicit_002dtemplates-146"></a>Never emit code for non-inline templates that are instantiated
198implicitly (i.e. by use); only emit code for explicit instantiations. 
199See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>, for more information.
200
201     <br><dt><code>-fno-implicit-inline-templates</code><dd><a name="index-fno_002dimplicit_002dinline_002dtemplates-147"></a>Don't emit code for implicit instantiations of inline templates, either. 
202The default is to handle inlines differently so that compiles with and
203without optimization need the same set of explicit instantiations.
204
205     <br><dt><code>-fno-implement-inlines</code><dd><a name="index-fno_002dimplement_002dinlines-148"></a>To save space, do not emit out-of-line copies of inline functions
206controlled by &lsquo;<samp><span class="samp">#pragma implementation</span></samp>&rsquo;.  This causes linker
207errors if these functions are not inlined everywhere they are called.
208
209     <br><dt><code>-fms-extensions</code><dd><a name="index-fms_002dextensions-149"></a>Disable Wpedantic warnings about constructs used in MFC, such as implicit
210int and getting a pointer to member function via non-standard syntax.
211
212     <br><dt><code>-fno-nonansi-builtins</code><dd><a name="index-fno_002dnonansi_002dbuiltins-150"></a>Disable built-in declarations of functions that are not mandated by
213ANSI/ISO C.  These include <code>ffs</code>, <code>alloca</code>, <code>_exit</code>,
214<code>index</code>, <code>bzero</code>, <code>conjf</code>, and other related functions.
215
216     <br><dt><code>-fnothrow-opt</code><dd><a name="index-fnothrow_002dopt-151"></a>Treat a <code>throw()</code> exception specification as if it were a
217<code>noexcept</code> specification to reduce or eliminate the text size
218overhead relative to a function with no exception specification.  If
219the function has local variables of types with non-trivial
220destructors, the exception specification actually makes the
221function smaller because the EH cleanups for those variables can be
222optimized away.  The semantic effect is that an exception thrown out of
223a function with such an exception specification results in a call
224to <code>terminate</code> rather than <code>unexpected</code>.
225
226     <br><dt><code>-fno-operator-names</code><dd><a name="index-fno_002doperator_002dnames-152"></a>Do not treat the operator name keywords <code>and</code>, <code>bitand</code>,
227<code>bitor</code>, <code>compl</code>, <code>not</code>, <code>or</code> and <code>xor</code> as
228synonyms as keywords.
229
230     <br><dt><code>-fno-optional-diags</code><dd><a name="index-fno_002doptional_002ddiags-153"></a>Disable diagnostics that the standard says a compiler does not need to
231issue.  Currently, the only such diagnostic issued by G++ is the one for
232a name having multiple meanings within a class.
233
234     <br><dt><code>-fpermissive</code><dd><a name="index-fpermissive-154"></a>Downgrade some diagnostics about nonconformant code from errors to
235warnings.  Thus, using <samp><span class="option">-fpermissive</span></samp> allows some
236nonconforming code to compile.
237
238     <br><dt><code>-fno-pretty-templates</code><dd><a name="index-fno_002dpretty_002dtemplates-155"></a>When an error message refers to a specialization of a function
239template, the compiler normally prints the signature of the
240template followed by the template arguments and any typedefs or
241typenames in the signature (e.g. <code>void f(T) [with T = int]</code>
242rather than <code>void f(int)</code>) so that it's clear which template is
243involved.  When an error message refers to a specialization of a class
244template, the compiler omits any template arguments that match
245the default template arguments for that template.  If either of these
246behaviors make it harder to understand the error message rather than
247easier, you can use <samp><span class="option">-fno-pretty-templates</span></samp> to disable them.
248
249     <br><dt><code>-frepo</code><dd><a name="index-frepo-156"></a>Enable automatic template instantiation at link time.  This option also
250implies <samp><span class="option">-fno-implicit-templates</span></samp>.  See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>, for more information.
251
252     <br><dt><code>-fno-rtti</code><dd><a name="index-fno_002drtti-157"></a>Disable generation of information about every class with virtual
253functions for use by the C++ run-time type identification features
254(&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
255of the language, you can save some space by using this flag.  Note that
256exception handling uses the same information, but G++ generates it as
257needed. The &lsquo;<samp><span class="samp">dynamic_cast</span></samp>&rsquo; operator can still be used for casts that
258do not require run-time type information, i.e. casts to <code>void *</code> or to
259unambiguous base classes.
260
261     <br><dt><code>-fstats</code><dd><a name="index-fstats-158"></a>Emit statistics about front-end processing at the end of the compilation. 
262This information is generally only useful to the G++ development team.
263
264     <br><dt><code>-fstrict-enums</code><dd><a name="index-fstrict_002denums-159"></a>Allow the compiler to optimize using the assumption that a value of
265enumerated type can only be one of the values of the enumeration (as
266defined in the C++ standard; basically, a value that can be
267represented in the minimum number of bits needed to represent all the
268enumerators).  This assumption may not be valid if the program uses a
269cast to convert an arbitrary integer value to the enumerated type.
270
271     <br><dt><code>-ftemplate-backtrace-limit=</code><var>n</var><dd><a name="index-ftemplate_002dbacktrace_002dlimit-160"></a>Set the maximum number of template instantiation notes for a single
272warning or error to <var>n</var>.  The default value is 10.
273
274     <br><dt><code>-ftemplate-depth=</code><var>n</var><dd><a name="index-ftemplate_002ddepth-161"></a>Set the maximum instantiation depth for template classes to <var>n</var>. 
275A limit on the template instantiation depth is needed to detect
276endless recursions during template class instantiation.  ANSI/ISO C++
277conforming programs must not rely on a maximum depth greater than 17
278(changed to 1024 in C++11).  The default value is 900, as the compiler
279can run out of stack space before hitting 1024 in some situations.
280
281     <br><dt><code>-fno-threadsafe-statics</code><dd><a name="index-fno_002dthreadsafe_002dstatics-162"></a>Do not emit the extra code to use the routines specified in the C++
282ABI for thread-safe initialization of local statics.  You can use this
283option to reduce code size slightly in code that doesn't need to be
284thread-safe.
285
286     <br><dt><code>-fuse-cxa-atexit</code><dd><a name="index-fuse_002dcxa_002datexit-163"></a>Register destructors for objects with static storage duration with the
287<code>__cxa_atexit</code> function rather than the <code>atexit</code> function. 
288This option is required for fully standards-compliant handling of static
289destructors, but only works if your C library supports
290<code>__cxa_atexit</code>.
291
292     <br><dt><code>-fno-use-cxa-get-exception-ptr</code><dd><a name="index-fno_002duse_002dcxa_002dget_002dexception_002dptr-164"></a>Don't use the <code>__cxa_get_exception_ptr</code> runtime routine.  This
293causes <code>std::uncaught_exception</code> to be incorrect, but is necessary
294if the runtime routine is not available.
295
296     <br><dt><code>-fvisibility-inlines-hidden</code><dd><a name="index-fvisibility_002dinlines_002dhidden-165"></a>This switch declares that the user does not attempt to compare
297pointers to inline functions or methods where the addresses of the two functions
298are taken in different shared objects.
299
300     <p>The effect of this is that GCC may, effectively, mark inline methods with
301<code>__attribute__ ((visibility ("hidden")))</code> so that they do not
302appear in the export table of a DSO and do not require a PLT indirection
303when used within the DSO.  Enabling this option can have a dramatic effect
304on load and link times of a DSO as it massively reduces the size of the
305dynamic export table when the library makes heavy use of templates.
306
307     <p>The behavior of this switch is not quite the same as marking the
308methods as hidden directly, because it does not affect static variables
309local to the function or cause the compiler to deduce that
310the function is defined in only one shared object.
311
312     <p>You may mark a method as having a visibility explicitly to negate the
313effect of the switch for that method.  For example, if you do want to
314compare pointers to a particular inline method, you might mark it as
315having default visibility.  Marking the enclosing class with explicit
316visibility has no effect.
317
318     <p>Explicitly instantiated inline methods are unaffected by this option
319as their linkage might otherwise cross a shared library boundary. 
320See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>.
321
322     <br><dt><code>-fvisibility-ms-compat</code><dd><a name="index-fvisibility_002dms_002dcompat-166"></a>This flag attempts to use visibility settings to make GCC's C++
323linkage model compatible with that of Microsoft Visual Studio.
324
325     <p>The flag makes these changes to GCC's linkage model:
326
327          <ol type=1 start=1>
328<li>It sets the default visibility to <code>hidden</code>, like
329<samp><span class="option">-fvisibility=hidden</span></samp>.
330
331          <li>Types, but not their members, are not hidden by default.
332
333          <li>The One Definition Rule is relaxed for types without explicit
334visibility specifications that are defined in more than one
335shared object: those declarations are permitted if they are
336permitted when this option is not used.
337          </ol>
338
339     <p>In new code it is better to use <samp><span class="option">-fvisibility=hidden</span></samp> and
340export those classes that are intended to be externally visible. 
341Unfortunately it is possible for code to rely, perhaps accidentally,
342on the Visual Studio behavior.
343
344     <p>Among the consequences of these changes are that static data members
345of the same type with the same name but defined in different shared
346objects are different, so changing one does not change the other;
347and that pointers to function members defined in different shared
348objects may not compare equal.  When this flag is given, it is a
349violation of the ODR to define types with the same name differently.
350
351     <br><dt><code>-fno-weak</code><dd><a name="index-fno_002dweak-167"></a>Do not use weak symbol support, even if it is provided by the linker. 
352By default, G++ uses weak symbols if they are available.  This
353option exists only for testing, and should not be used by end-users;
354it results in inferior code and has no benefits.  This option may
355be removed in a future release of G++.
356
357     <br><dt><code>-nostdinc++</code><dd><a name="index-nostdinc_002b_002b-168"></a>Do not search for header files in the standard directories specific to
358C++, but do still search the other standard directories.  (This option
359is used when building the C++ library.) 
360</dl>
361
362 <p>In addition, these optimization, warning, and code generation options
363have meanings only for C++ programs:
364
365     <dl>
366<dt><code>-fno-default-inline</code><dd><a name="index-fno_002ddefault_002dinline-169"></a>Do not assume &lsquo;<samp><span class="samp">inline</span></samp>&rsquo; for functions defined inside a class scope. 
367See <a href="Optimize-Options.html#Optimize-Options">Options That Control Optimization</a>.  Note that these
368functions have linkage like inline functions; they just aren't
369inlined by default.
370
371     <br><dt><code>-Wabi </code><span class="roman">(C, Objective-C, C++ and Objective-C++ only)</span><dd><a name="index-Wabi-170"></a><a name="index-Wno_002dabi-171"></a>Warn when G++ generates code that is probably not compatible with the
372vendor-neutral C++ ABI.  Although an effort has been made to warn about
373all such cases, there are probably some cases that are not warned about,
374even though G++ is generating incompatible code.  There may also be
375cases where warnings are emitted even though the code that is generated
376is compatible.
377
378     <p>You should rewrite your code to avoid these warnings if you are
379concerned about the fact that code generated by G++ may not be binary
380compatible with code generated by other compilers.
381
382     <p>The known incompatibilities in <samp><span class="option">-fabi-version=2</span></samp> (the default) include:
383
384          <ul>
385<li>A template with a non-type template parameter of reference type is
386mangled incorrectly:
387          <pre class="smallexample">               extern int N;
388               template &lt;int &amp;&gt; struct S {};
389               void n (S&lt;N&gt;) {2}
390</pre>
391          <p>This is fixed in <samp><span class="option">-fabi-version=3</span></samp>.
392
393          <li>SIMD vector types declared using <code>__attribute ((vector_size))</code> are
394mangled in a non-standard way that does not allow for overloading of
395functions taking vectors of different sizes.
396
397          <p>The mangling is changed in <samp><span class="option">-fabi-version=4</span></samp>. 
398</ul>
399
400     <p>The known incompatibilities in <samp><span class="option">-fabi-version=1</span></samp> include:
401
402          <ul>
403<li>Incorrect handling of tail-padding for bit-fields.  G++ may attempt to
404pack data into the same byte as a base class.  For example:
405
406          <pre class="smallexample">               struct A { virtual void f(); int f1 : 1; };
407               struct B : public A { int f2 : 1; };
408</pre>
409          <p class="noindent">In this case, G++ places <code>B::f2</code> into the same byte
410as <code>A::f1</code>; other compilers do not.  You can avoid this problem
411by explicitly padding <code>A</code> so that its size is a multiple of the
412byte size on your platform; that causes G++ and other compilers to
413lay out <code>B</code> identically.
414
415          <li>Incorrect handling of tail-padding for virtual bases.  G++ does not use
416tail padding when laying out virtual bases.  For example:
417
418          <pre class="smallexample">               struct A { virtual void f(); char c1; };
419               struct B { B(); char c2; };
420               struct C : public A, public virtual B {};
421</pre>
422          <p class="noindent">In this case, G++ does not place <code>B</code> into the tail-padding for
423<code>A</code>; other compilers do.  You can avoid this problem by
424explicitly padding <code>A</code> so that its size is a multiple of its
425alignment (ignoring virtual base classes); that causes G++ and other
426compilers to lay out <code>C</code> identically.
427
428          <li>Incorrect handling of bit-fields with declared widths greater than that
429of their underlying types, when the bit-fields appear in a union.  For
430example:
431
432          <pre class="smallexample">               union U { int i : 4096; };
433</pre>
434          <p class="noindent">Assuming that an <code>int</code> does not have 4096 bits, G++ makes the
435union too small by the number of bits in an <code>int</code>.
436
437          <li>Empty classes can be placed at incorrect offsets.  For example:
438
439          <pre class="smallexample">               struct A {};
440               
441               struct B {
442                 A a;
443                 virtual void f ();
444               };
445               
446               struct C : public B, public A {};
447</pre>
448          <p class="noindent">G++ places the <code>A</code> base class of <code>C</code> at a nonzero offset;
449it should be placed at offset zero.  G++ mistakenly believes that the
450<code>A</code> data member of <code>B</code> is already at offset zero.
451
452          <li>Names of template functions whose types involve <code>typename</code> or
453template template parameters can be mangled incorrectly.
454
455          <pre class="smallexample">               template &lt;typename Q&gt;
456               void f(typename Q::X) {}
457               
458               template &lt;template &lt;typename&gt; class Q&gt;
459               void f(typename Q&lt;int&gt;::X) {}
460</pre>
461          <p class="noindent">Instantiations of these templates may be mangled incorrectly.
462
463     </ul>
464
465     <p>It also warns about psABI-related changes.  The known psABI changes at this
466point include:
467
468          <ul>
469<li>For SysV/x86-64, unions with <code>long double</code> members are
470passed in memory as specified in psABI.  For example:
471
472          <pre class="smallexample">               union U {
473                 long double ld;
474                 int i;
475               };
476</pre>
477          <p class="noindent"><code>union U</code> is always passed in memory.
478
479     </ul>
480
481     <br><dt><code>-Wctor-dtor-privacy </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wctor_002ddtor_002dprivacy-172"></a><a name="index-Wno_002dctor_002ddtor_002dprivacy-173"></a>Warn when a class seems unusable because all the constructors or
482destructors in that class are private, and it has neither friends nor
483public static member functions.  Also warn if there are no non-private
484methods, and there's at least one private member function that isn't
485a constructor or destructor.
486
487     <br><dt><code>-Wdelete-non-virtual-dtor </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wdelete_002dnon_002dvirtual_002ddtor-174"></a><a name="index-Wno_002ddelete_002dnon_002dvirtual_002ddtor-175"></a>Warn when &lsquo;<samp><span class="samp">delete</span></samp>&rsquo; is used to destroy an instance of a class that
488has virtual functions and non-virtual destructor. It is unsafe to delete
489an instance of a derived class through a pointer to a base class if the
490base class does not have a virtual destructor.  This warning is enabled
491by <samp><span class="option">-Wall</span></samp>.
492
493     <br><dt><code>-Wliteral-suffix </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wliteral_002dsuffix-176"></a><a name="index-Wno_002dliteral_002dsuffix-177"></a>Warn when a string or character literal is followed by a ud-suffix which does
494not begin with an underscore.  As a conforming extension, GCC treats such
495suffixes as separate preprocessing tokens in order to maintain backwards
496compatibility with code that uses formatting macros from <code>&lt;inttypes.h&gt;</code>. 
497For example:
498
499     <pre class="smallexample">          #define __STDC_FORMAT_MACROS
500          #include &lt;inttypes.h&gt;
501          #include &lt;stdio.h&gt;
502          
503          int main() {
504            int64_t i64 = 123;
505            printf("My int64: %"PRId64"\n", i64);
506          }
507</pre>
508     <p>In this case, <code>PRId64</code> is treated as a separate preprocessing token.
509
510     <p>This warning is enabled by default.
511
512     <br><dt><code>-Wnarrowing </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wnarrowing-178"></a><a name="index-Wno_002dnarrowing-179"></a>Warn when a narrowing conversion prohibited by C++11 occurs within
513&lsquo;<samp><span class="samp">{ }</span></samp>&rsquo;, e.g.
514
515     <pre class="smallexample">          int i = { 2.2 }; // error: narrowing from double to int
516</pre>
517     <p>This flag is included in <samp><span class="option">-Wall</span></samp> and <samp><span class="option">-Wc++11-compat</span></samp>.
518
519     <p>With <samp><span class="option">-std=c++11</span></samp>, <samp><span class="option">-Wno-narrowing</span></samp> suppresses the diagnostic
520required by the standard.  Note that this does not affect the meaning
521of well-formed code; narrowing conversions are still considered
522ill-formed in SFINAE context.
523
524     <br><dt><code>-Wnoexcept </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wnoexcept-180"></a><a name="index-Wno_002dnoexcept-181"></a>Warn when a noexcept-expression evaluates to false because of a call
525to a function that does not have a non-throwing exception
526specification (i.e. &lsquo;<samp><span class="samp">throw()</span></samp>&rsquo; or &lsquo;<samp><span class="samp">noexcept</span></samp>&rsquo;) but is known by
527the compiler to never throw an exception.
528
529     <br><dt><code>-Wnon-virtual-dtor </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wnon_002dvirtual_002ddtor-182"></a><a name="index-Wno_002dnon_002dvirtual_002ddtor-183"></a>Warn when a class has virtual functions and an accessible non-virtual
530destructor, in which case it is possible but unsafe to delete
531an instance of a derived class through a pointer to the base class. 
532This warning is also enabled if <samp><span class="option">-Weffc++</span></samp> is specified.
533
534     <br><dt><code>-Wreorder </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wreorder-184"></a><a name="index-Wno_002dreorder-185"></a><a name="index-reordering_002c-warning-186"></a><a name="index-warning-for-reordering-of-member-initializers-187"></a>Warn when the order of member initializers given in the code does not
535match the order in which they must be executed.  For instance:
536
537     <pre class="smallexample">          struct A {
538            int i;
539            int j;
540            A(): j (0), i (1) { }
541          };
542</pre>
543     <p class="noindent">The compiler rearranges the member initializers for &lsquo;<samp><span class="samp">i</span></samp>&rsquo;
544and &lsquo;<samp><span class="samp">j</span></samp>&rsquo; to match the declaration order of the members, emitting
545a warning to that effect.  This warning is enabled by <samp><span class="option">-Wall</span></samp>.
546
547     <br><dt><code>-fext-numeric-literals </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-fext_002dnumeric_002dliterals-188"></a><a name="index-fno_002dext_002dnumeric_002dliterals-189"></a>Accept imaginary, fixed-point, or machine-defined
548literal number suffixes as GNU extensions. 
549When this option is turned off these suffixes are treated
550as C++11 user-defined literal numeric suffixes. 
551This is on by default for all pre-C++11 dialects and all GNU dialects:
552<samp><span class="option">-std=c++98</span></samp>, <samp><span class="option">-std=gnu++98</span></samp>, <samp><span class="option">-std=gnu++11</span></samp>,
553<samp><span class="option">-std=gnu++1y</span></samp>. 
554This option is off by default
555for ISO C++11 onwards (<samp><span class="option">-std=c++11</span></samp>, ...). 
556</dl>
557
558 <p>The following <samp><span class="option">-W...</span></samp> options are not affected by <samp><span class="option">-Wall</span></samp>.
559
560     <dl>
561<dt><code>-Weffc++ </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Weffc_002b_002b-190"></a><a name="index-Wno_002deffc_002b_002b-191"></a>Warn about violations of the following style guidelines from Scott Meyers'
562<cite>Effective C++, Second Edition</cite> book:
563
564          <ul>
565<li>Item 11:  Define a copy constructor and an assignment operator for classes
566with dynamically-allocated memory.
567
568          <li>Item 12:  Prefer initialization to assignment in constructors.
569
570          <li>Item 14:  Make destructors virtual in base classes.
571
572          <li>Item 15:  Have <code>operator=</code> return a reference to <code>*this</code>.
573
574          <li>Item 23:  Don't try to return a reference when you must return an object.
575
576     </ul>
577
578     <p>Also warn about violations of the following style guidelines from
579Scott Meyers' <cite>More Effective C++</cite> book:
580
581          <ul>
582<li>Item 6:  Distinguish between prefix and postfix forms of increment and
583decrement operators.
584
585          <li>Item 7:  Never overload <code>&amp;&amp;</code>, <code>||</code>, or <code>,</code>.
586
587     </ul>
588
589     <p>When selecting this option, be aware that the standard library
590headers do not obey all of these guidelines; use &lsquo;<samp><span class="samp">grep -v</span></samp>&rsquo;
591to filter out those warnings.
592
593     <br><dt><code>-Wstrict-null-sentinel </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wstrict_002dnull_002dsentinel-192"></a><a name="index-Wno_002dstrict_002dnull_002dsentinel-193"></a>Warn about the use of an uncasted <code>NULL</code> as sentinel.  When
594compiling only with GCC this is a valid sentinel, as <code>NULL</code> is defined
595to <code>__null</code>.  Although it is a null pointer constant rather than a
596null pointer, it is guaranteed to be of the same size as a pointer. 
597But this use is not portable across different compilers.
598
599     <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-194"></a><a name="index-Wnon_002dtemplate_002dfriend-195"></a>Disable warnings when non-templatized friend functions are declared
600within a template.  Since the advent of explicit template specification
601support in G++, if the name of the friend is an unqualified-id (i.e.,
602&lsquo;<samp><span class="samp">friend foo(int)</span></samp>&rsquo;), the C++ language specification demands that the
603friend declare or define an ordinary, nontemplate function.  (Section
60414.5.3).  Before G++ implemented explicit specification, unqualified-ids
605could be interpreted as a particular specialization of a templatized
606function.  Because this non-conforming behavior is no longer the default
607behavior for G++, <samp><span class="option">-Wnon-template-friend</span></samp> allows the compiler to
608check existing code for potential trouble spots and is on by default. 
609This new compiler behavior can be turned off with
610<samp><span class="option">-Wno-non-template-friend</span></samp>, which keeps the conformant compiler code
611but disables the helpful warning.
612
613     <br><dt><code>-Wold-style-cast </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wold_002dstyle_002dcast-196"></a><a name="index-Wno_002dold_002dstyle_002dcast-197"></a>Warn if an old-style (C-style) cast to a non-void type is used within
614a C++ program.  The new-style casts (&lsquo;<samp><span class="samp">dynamic_cast</span></samp>&rsquo;,
615&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
616less vulnerable to unintended effects and much easier to search for.
617
618     <br><dt><code>-Woverloaded-virtual </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Woverloaded_002dvirtual-198"></a><a name="index-Wno_002doverloaded_002dvirtual-199"></a><a name="index-overloaded-virtual-function_002c-warning-200"></a><a name="index-warning-for-overloaded-virtual-function-201"></a>Warn when a function declaration hides virtual functions from a
619base class.  For example, in:
620
621     <pre class="smallexample">          struct A {
622            virtual void f();
623          };
624          
625          struct B: public A {
626            void f(int);
627          };
628</pre>
629     <p>the <code>A</code> class version of <code>f</code> is hidden in <code>B</code>, and code
630like:
631
632     <pre class="smallexample">          B* b;
633          b-&gt;f();
634</pre>
635     <p class="noindent">fails to compile.
636
637     <br><dt><code>-Wno-pmf-conversions </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wno_002dpmf_002dconversions-202"></a><a name="index-Wpmf_002dconversions-203"></a>Disable the diagnostic for converting a bound pointer to member function
638to a plain pointer.
639
640     <br><dt><code>-Wsign-promo </code><span class="roman">(C++ and Objective-C++ only)</span><dd><a name="index-Wsign_002dpromo-204"></a><a name="index-Wno_002dsign_002dpromo-205"></a>Warn when overload resolution chooses a promotion from unsigned or
641enumerated type to a signed type, over a conversion to an unsigned type of
642the same size.  Previous versions of G++ tried to preserve
643unsignedness, but the standard mandates the current behavior. 
644</dl>
645
646 </body></html>
647
648