C_002b_002b-Dialect-Options.html 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): C++ Dialect Options</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): C++ Dialect Options">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): C++ Dialect Options">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Invoking-GCC.html#Invoking-GCC" rel="up" title="Invoking GCC">
  30. <link href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options" rel="next" title="Objective-C and Objective-C++ Dialect Options">
  31. <link href="C-Dialect-Options.html#C-Dialect-Options" rel="prev" title="C Dialect Options">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="C_002b_002b-Dialect-Options"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options" accesskey="n" rel="next">Objective-C and Objective-C++ Dialect Options</a>, Previous: <a href="C-Dialect-Options.html#C-Dialect-Options" accesskey="p" rel="prev">C Dialect Options</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Options-Controlling-C_002b_002b-Dialect"></a>
  69. <h3 class="section">3.5 Options Controlling C++ Dialect</h3>
  70. <a name="index-compiler-options_002c-C_002b_002b"></a>
  71. <a name="index-C_002b_002b-options_002c-command_002dline"></a>
  72. <a name="index-options_002c-C_002b_002b"></a>
  73. <p>This section describes the command-line options that are only meaningful
  74. for C++ programs. You can also use most of the GNU compiler options
  75. regardless of what language your program is in. For example, you
  76. might compile a file <samp>firstClass.C</samp> like this:
  77. </p>
  78. <div class="smallexample">
  79. <pre class="smallexample">g++ -g -fstrict-enums -O -c firstClass.C
  80. </pre></div>
  81. <p>In this example, only <samp>-fstrict-enums</samp> is an option meant
  82. only for C++ programs; you can use the other options with any
  83. language supported by GCC.
  84. </p>
  85. <p>Some options for compiling C programs, such as <samp>-std</samp>, are also
  86. relevant for C++ programs.
  87. See <a href="C-Dialect-Options.html#C-Dialect-Options">Options Controlling C Dialect</a>.
  88. </p>
  89. <p>Here is a list of options that are <em>only</em> for compiling C++ programs:
  90. </p>
  91. <dl compact="compact">
  92. <dt><code>-fabi-version=<var>n</var></code></dt>
  93. <dd><a name="index-fabi_002dversion"></a>
  94. <p>Use version <var>n</var> of the C++ ABI. The default is version 0.
  95. </p>
  96. <p>Version 0 refers to the version conforming most closely to
  97. the C++ ABI specification. Therefore, the ABI obtained using version 0
  98. will change in different versions of G++ as ABI bugs are fixed.
  99. </p>
  100. <p>Version 1 is the version of the C++ ABI that first appeared in G++ 3.2.
  101. </p>
  102. <p>Version 2 is the version of the C++ ABI that first appeared in G++
  103. 3.4, and was the default through G++ 4.9.
  104. </p>
  105. <p>Version 3 corrects an error in mangling a constant address as a
  106. template argument.
  107. </p>
  108. <p>Version 4, which first appeared in G++ 4.5, implements a standard
  109. mangling for vector types.
  110. </p>
  111. <p>Version 5, which first appeared in G++ 4.6, corrects the mangling of
  112. attribute const/volatile on function pointer types, decltype of a
  113. plain decl, and use of a function parameter in the declaration of
  114. another parameter.
  115. </p>
  116. <p>Version 6, which first appeared in G++ 4.7, corrects the promotion
  117. behavior of C++11 scoped enums and the mangling of template argument
  118. packs, const/static_cast, prefix ++ and &ndash;, and a class scope function
  119. used as a template argument.
  120. </p>
  121. <p>Version 7, which first appeared in G++ 4.8, that treats nullptr_t as a
  122. builtin type and corrects the mangling of lambdas in default argument
  123. scope.
  124. </p>
  125. <p>Version 8, which first appeared in G++ 4.9, corrects the substitution
  126. behavior of function types with function-cv-qualifiers.
  127. </p>
  128. <p>Version 9, which first appeared in G++ 5.2, corrects the alignment of
  129. <code>nullptr_t</code>.
  130. </p>
  131. <p>Version 10, which first appeared in G++ 6.1, adds mangling of
  132. attributes that affect type identity, such as ia32 calling convention
  133. attributes (e.g. &lsquo;<samp>stdcall</samp>&rsquo;).
  134. </p>
  135. <p>Version 11, which first appeared in G++ 7, corrects the mangling of
  136. sizeof... expressions and operator names. For multiple entities with
  137. the same name within a function, that are declared in different scopes,
  138. the mangling now changes starting with the twelfth occurrence. It also
  139. implies <samp>-fnew-inheriting-ctors</samp>.
  140. </p>
  141. <p>See also <samp>-Wabi</samp>.
  142. </p>
  143. </dd>
  144. <dt><code>-fabi-compat-version=<var>n</var></code></dt>
  145. <dd><a name="index-fabi_002dcompat_002dversion"></a>
  146. <p>On targets that support strong aliases, G++
  147. works around mangling changes by creating an alias with the correct
  148. mangled name when defining a symbol with an incorrect mangled name.
  149. This switch specifies which ABI version to use for the alias.
  150. </p>
  151. <p>With <samp>-fabi-version=0</samp> (the default), this defaults to 8 (GCC 5
  152. compatibility). If another ABI version is explicitly selected, this
  153. defaults to 0. For compatibility with GCC versions 3.2 through 4.9,
  154. use <samp>-fabi-compat-version=2</samp>.
  155. </p>
  156. <p>If this option is not provided but <samp>-Wabi=<var>n</var></samp> is, that
  157. version is used for compatibility aliases. If this option is provided
  158. along with <samp>-Wabi</samp> (without the version), the version from this
  159. option is used for the warning.
  160. </p>
  161. </dd>
  162. <dt><code>-fno-access-control</code></dt>
  163. <dd><a name="index-fno_002daccess_002dcontrol"></a>
  164. <p>Turn off all access checking. This switch is mainly useful for working
  165. around bugs in the access control code.
  166. </p>
  167. </dd>
  168. <dt><code>-faligned-new</code></dt>
  169. <dd><a name="index-faligned_002dnew"></a>
  170. <p>Enable support for C++17 <code>new</code> of types that require more
  171. alignment than <code>void* ::operator new(std::size_t)</code> provides. A
  172. numeric argument such as <code>-faligned-new=32</code> can be used to
  173. specify how much alignment (in bytes) is provided by that function,
  174. but few users will need to override the default of
  175. <code>alignof(std::max_align_t)</code>.
  176. </p>
  177. </dd>
  178. <dt><code>-fcheck-new</code></dt>
  179. <dd><a name="index-fcheck_002dnew"></a>
  180. <p>Check that the pointer returned by <code>operator new</code> is non-null
  181. before attempting to modify the storage allocated. This check is
  182. normally unnecessary because the C++ standard specifies that
  183. <code>operator new</code> only returns <code>0</code> if it is declared
  184. <code>throw()</code>, in which case the compiler always checks the
  185. return value even without this option. In all other cases, when
  186. <code>operator new</code> has a non-empty exception specification, memory
  187. exhaustion is signalled by throwing <code>std::bad_alloc</code>. See also
  188. &lsquo;<samp>new (nothrow)</samp>&rsquo;.
  189. </p>
  190. </dd>
  191. <dt><code>-fconcepts</code></dt>
  192. <dd><a name="index-fconcepts"></a>
  193. <p>Enable support for the C++ Extensions for Concepts Technical
  194. Specification, ISO 19217 (2015), which allows code like
  195. </p>
  196. <div class="smallexample">
  197. <pre class="smallexample">template &lt;class T&gt; concept bool Addable = requires (T t) { t + t; };
  198. template &lt;Addable T&gt; T add (T a, T b) { return a + b; }
  199. </pre></div>
  200. </dd>
  201. <dt><code>-fconstexpr-depth=<var>n</var></code></dt>
  202. <dd><a name="index-fconstexpr_002ddepth"></a>
  203. <p>Set the maximum nested evaluation depth for C++11 constexpr functions
  204. to <var>n</var>. A limit is needed to detect endless recursion during
  205. constant expression evaluation. The minimum specified by the standard
  206. is 512.
  207. </p>
  208. </dd>
  209. <dt><code>-fconstexpr-loop-limit=<var>n</var></code></dt>
  210. <dd><a name="index-fconstexpr_002dloop_002dlimit"></a>
  211. <p>Set the maximum number of iterations for a loop in C++14 constexpr functions
  212. to <var>n</var>. A limit is needed to detect infinite loops during
  213. constant expression evaluation. The default is 262144 (1&lt;&lt;18).
  214. </p>
  215. </dd>
  216. <dt><code>-fdeduce-init-list</code></dt>
  217. <dd><a name="index-fdeduce_002dinit_002dlist"></a>
  218. <p>Enable deduction of a template type parameter as
  219. <code>std::initializer_list</code> from a brace-enclosed initializer list, i.e.
  220. </p>
  221. <div class="smallexample">
  222. <pre class="smallexample">template &lt;class T&gt; auto forward(T t) -&gt; decltype (realfn (t))
  223. {
  224. return realfn (t);
  225. }
  226. void f()
  227. {
  228. forward({1,2}); // call forward&lt;std::initializer_list&lt;int&gt;&gt;
  229. }
  230. </pre></div>
  231. <p>This deduction was implemented as a possible extension to the
  232. originally proposed semantics for the C++11 standard, but was not part
  233. of the final standard, so it is disabled by default. This option is
  234. deprecated, and may be removed in a future version of G++.
  235. </p>
  236. </dd>
  237. <dt><code>-ffriend-injection</code></dt>
  238. <dd><a name="index-ffriend_002dinjection"></a>
  239. <p>Inject friend functions into the enclosing namespace, so that they are
  240. visible outside the scope of the class in which they are declared.
  241. Friend functions were documented to work this way in the old Annotated
  242. C++ Reference Manual.
  243. However, in ISO C++ a friend function that is not declared
  244. in an enclosing scope can only be found using argument dependent
  245. lookup. GCC defaults to the standard behavior.
  246. </p>
  247. <p>This option is for compatibility, and may be removed in a future
  248. release of G++.
  249. </p>
  250. </dd>
  251. <dt><code>-fno-elide-constructors</code></dt>
  252. <dd><a name="index-fno_002delide_002dconstructors"></a>
  253. <p>The C++ standard allows an implementation to omit creating a temporary
  254. that is only used to initialize another object of the same type.
  255. Specifying this option disables that optimization, and forces G++ to
  256. call the copy constructor in all cases. This option also causes G++
  257. to call trivial member functions which otherwise would be expanded inline.
  258. </p>
  259. <p>In C++17, the compiler is required to omit these temporaries, but this
  260. option still affects trivial member functions.
  261. </p>
  262. </dd>
  263. <dt><code>-fno-enforce-eh-specs</code></dt>
  264. <dd><a name="index-fno_002denforce_002deh_002dspecs"></a>
  265. <p>Don&rsquo;t generate code to check for violation of exception specifications
  266. at run time. This option violates the C++ standard, but may be useful
  267. for reducing code size in production builds, much like defining
  268. <code>NDEBUG</code>. This does not give user code permission to throw
  269. exceptions in violation of the exception specifications; the compiler
  270. still optimizes based on the specifications, so throwing an
  271. unexpected exception results in undefined behavior at run time.
  272. </p>
  273. </dd>
  274. <dt><code>-fextern-tls-init</code></dt>
  275. <dt><code>-fno-extern-tls-init</code></dt>
  276. <dd><a name="index-fextern_002dtls_002dinit"></a>
  277. <a name="index-fno_002dextern_002dtls_002dinit"></a>
  278. <p>The C++11 and OpenMP standards allow <code>thread_local</code> and
  279. <code>threadprivate</code> variables to have dynamic (runtime)
  280. initialization. To support this, any use of such a variable goes
  281. through a wrapper function that performs any necessary initialization.
  282. When the use and definition of the variable are in the same
  283. translation unit, this overhead can be optimized away, but when the
  284. use is in a different translation unit there is significant overhead
  285. even if the variable doesn&rsquo;t actually need dynamic initialization. If
  286. the programmer can be sure that no use of the variable in a
  287. non-defining TU needs to trigger dynamic initialization (either
  288. because the variable is statically initialized, or a use of the
  289. variable in the defining TU will be executed before any uses in
  290. another TU), they can avoid this overhead with the
  291. <samp>-fno-extern-tls-init</samp> option.
  292. </p>
  293. <p>On targets that support symbol aliases, the default is
  294. <samp>-fextern-tls-init</samp>. On targets that do not support symbol
  295. aliases, the default is <samp>-fno-extern-tls-init</samp>.
  296. </p>
  297. </dd>
  298. <dt><code>-ffor-scope</code></dt>
  299. <dt><code>-fno-for-scope</code></dt>
  300. <dd><a name="index-ffor_002dscope"></a>
  301. <a name="index-fno_002dfor_002dscope"></a>
  302. <p>If <samp>-ffor-scope</samp> is specified, the scope of variables declared in
  303. a <i>for-init-statement</i> is limited to the <code>for</code> loop itself,
  304. as specified by the C++ standard.
  305. If <samp>-fno-for-scope</samp> is specified, the scope of variables declared in
  306. a <i>for-init-statement</i> extends to the end of the enclosing scope,
  307. as was the case in old versions of G++, and other (traditional)
  308. implementations of C++.
  309. </p>
  310. <p>If neither flag is given, the default is to follow the standard,
  311. but to allow and give a warning for old-style code that would
  312. otherwise be invalid, or have different behavior.
  313. </p>
  314. </dd>
  315. <dt><code>-fno-gnu-keywords</code></dt>
  316. <dd><a name="index-fno_002dgnu_002dkeywords"></a>
  317. <p>Do not recognize <code>typeof</code> as a keyword, so that code can use this
  318. word as an identifier. You can use the keyword <code>__typeof__</code> instead.
  319. This option is implied by the strict ISO C++ dialects: <samp>-ansi</samp>,
  320. <samp>-std=c++98</samp>, <samp>-std=c++11</samp>, etc.
  321. </p>
  322. </dd>
  323. <dt><code>-fno-implicit-templates</code></dt>
  324. <dd><a name="index-fno_002dimplicit_002dtemplates"></a>
  325. <p>Never emit code for non-inline templates that are instantiated
  326. implicitly (i.e. by use); only emit code for explicit instantiations.
  327. See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>, for more information.
  328. </p>
  329. </dd>
  330. <dt><code>-fno-implicit-inline-templates</code></dt>
  331. <dd><a name="index-fno_002dimplicit_002dinline_002dtemplates"></a>
  332. <p>Don&rsquo;t emit code for implicit instantiations of inline templates, either.
  333. The default is to handle inlines differently so that compiles with and
  334. without optimization need the same set of explicit instantiations.
  335. </p>
  336. </dd>
  337. <dt><code>-fno-implement-inlines</code></dt>
  338. <dd><a name="index-fno_002dimplement_002dinlines"></a>
  339. <p>To save space, do not emit out-of-line copies of inline functions
  340. controlled by <code>#pragma implementation</code>. This causes linker
  341. errors if these functions are not inlined everywhere they are called.
  342. </p>
  343. </dd>
  344. <dt><code>-fms-extensions</code></dt>
  345. <dd><a name="index-fms_002dextensions-1"></a>
  346. <p>Disable Wpedantic warnings about constructs used in MFC, such as implicit
  347. int and getting a pointer to member function via non-standard syntax.
  348. </p>
  349. </dd>
  350. <dt><code>-fnew-inheriting-ctors</code></dt>
  351. <dd><a name="index-fnew_002dinheriting_002dctors"></a>
  352. <p>Enable the P0136 adjustment to the semantics of C++11 constructor
  353. inheritance. This is part of C++17 but also considered to be a Defect
  354. Report against C++11 and C++14. This flag is enabled by default
  355. unless <samp>-fabi-version=10</samp> or lower is specified.
  356. </p>
  357. </dd>
  358. <dt><code>-fnew-ttp-matching</code></dt>
  359. <dd><a name="index-fnew_002dttp_002dmatching"></a>
  360. <p>Enable the P0522 resolution to Core issue 150, template template
  361. parameters and default arguments: this allows a template with default
  362. template arguments as an argument for a template template parameter
  363. with fewer template parameters. This flag is enabled by default for
  364. <samp>-std=c++1z</samp>.
  365. </p>
  366. </dd>
  367. <dt><code>-fno-nonansi-builtins</code></dt>
  368. <dd><a name="index-fno_002dnonansi_002dbuiltins"></a>
  369. <p>Disable built-in declarations of functions that are not mandated by
  370. ANSI/ISO C. These include <code>ffs</code>, <code>alloca</code>, <code>_exit</code>,
  371. <code>index</code>, <code>bzero</code>, <code>conjf</code>, and other related functions.
  372. </p>
  373. </dd>
  374. <dt><code>-fnothrow-opt</code></dt>
  375. <dd><a name="index-fnothrow_002dopt"></a>
  376. <p>Treat a <code>throw()</code> exception specification as if it were a
  377. <code>noexcept</code> specification to reduce or eliminate the text size
  378. overhead relative to a function with no exception specification. If
  379. the function has local variables of types with non-trivial
  380. destructors, the exception specification actually makes the
  381. function smaller because the EH cleanups for those variables can be
  382. optimized away. The semantic effect is that an exception thrown out of
  383. a function with such an exception specification results in a call
  384. to <code>terminate</code> rather than <code>unexpected</code>.
  385. </p>
  386. </dd>
  387. <dt><code>-fno-operator-names</code></dt>
  388. <dd><a name="index-fno_002doperator_002dnames"></a>
  389. <p>Do not treat the operator name keywords <code>and</code>, <code>bitand</code>,
  390. <code>bitor</code>, <code>compl</code>, <code>not</code>, <code>or</code> and <code>xor</code> as
  391. synonyms as keywords.
  392. </p>
  393. </dd>
  394. <dt><code>-fno-optional-diags</code></dt>
  395. <dd><a name="index-fno_002doptional_002ddiags"></a>
  396. <p>Disable diagnostics that the standard says a compiler does not need to
  397. issue. Currently, the only such diagnostic issued by G++ is the one for
  398. a name having multiple meanings within a class.
  399. </p>
  400. </dd>
  401. <dt><code>-fpermissive</code></dt>
  402. <dd><a name="index-fpermissive"></a>
  403. <p>Downgrade some diagnostics about nonconformant code from errors to
  404. warnings. Thus, using <samp>-fpermissive</samp> allows some
  405. nonconforming code to compile.
  406. </p>
  407. </dd>
  408. <dt><code>-fno-pretty-templates</code></dt>
  409. <dd><a name="index-fno_002dpretty_002dtemplates"></a>
  410. <p>When an error message refers to a specialization of a function
  411. template, the compiler normally prints the signature of the
  412. template followed by the template arguments and any typedefs or
  413. typenames in the signature (e.g. <code>void f(T) [with T = int]</code>
  414. rather than <code>void f(int)</code>) so that it&rsquo;s clear which template is
  415. involved. When an error message refers to a specialization of a class
  416. template, the compiler omits any template arguments that match
  417. the default template arguments for that template. If either of these
  418. behaviors make it harder to understand the error message rather than
  419. easier, you can use <samp>-fno-pretty-templates</samp> to disable them.
  420. </p>
  421. </dd>
  422. <dt><code>-frepo</code></dt>
  423. <dd><a name="index-frepo"></a>
  424. <p>Enable automatic template instantiation at link time. This option also
  425. implies <samp>-fno-implicit-templates</samp>. See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>, for more information.
  426. </p>
  427. </dd>
  428. <dt><code>-fno-rtti</code></dt>
  429. <dd><a name="index-fno_002drtti"></a>
  430. <p>Disable generation of information about every class with virtual
  431. functions for use by the C++ run-time type identification features
  432. (<code>dynamic_cast</code> and <code>typeid</code>). If you don&rsquo;t use those parts
  433. of the language, you can save some space by using this flag. Note that
  434. exception handling uses the same information, but G++ generates it as
  435. needed. The <code>dynamic_cast</code> operator can still be used for casts that
  436. do not require run-time type information, i.e. casts to <code>void *</code> or to
  437. unambiguous base classes.
  438. </p>
  439. </dd>
  440. <dt><code>-fsized-deallocation</code></dt>
  441. <dd><a name="index-fsized_002ddeallocation"></a>
  442. <p>Enable the built-in global declarations
  443. </p><div class="smallexample">
  444. <pre class="smallexample">void operator delete (void *, std::size_t) noexcept;
  445. void operator delete[] (void *, std::size_t) noexcept;
  446. </pre></div>
  447. <p>as introduced in C++14. This is useful for user-defined replacement
  448. deallocation functions that, for example, use the size of the object
  449. to make deallocation faster. Enabled by default under
  450. <samp>-std=c++14</samp> and above. The flag <samp>-Wsized-deallocation</samp>
  451. warns about places that might want to add a definition.
  452. </p>
  453. </dd>
  454. <dt><code>-fstrict-enums</code></dt>
  455. <dd><a name="index-fstrict_002denums"></a>
  456. <p>Allow the compiler to optimize using the assumption that a value of
  457. enumerated type can only be one of the values of the enumeration (as
  458. defined in the C++ standard; basically, a value that can be
  459. represented in the minimum number of bits needed to represent all the
  460. enumerators). This assumption may not be valid if the program uses a
  461. cast to convert an arbitrary integer value to the enumerated type.
  462. </p>
  463. </dd>
  464. <dt><code>-fstrong-eval-order</code></dt>
  465. <dd><a name="index-fstrong_002deval_002dorder"></a>
  466. <p>Evaluate member access, array subscripting, and shift expressions in
  467. left-to-right order, and evaluate assignment in right-to-left order,
  468. as adopted for C++17. Enabled by default with <samp>-std=c++1z</samp>.
  469. <samp>-fstrong-eval-order=some</samp> enables just the ordering of member
  470. access and shift expressions, and is the default without
  471. <samp>-std=c++1z</samp>.
  472. </p>
  473. </dd>
  474. <dt><code>-ftemplate-backtrace-limit=<var>n</var></code></dt>
  475. <dd><a name="index-ftemplate_002dbacktrace_002dlimit"></a>
  476. <p>Set the maximum number of template instantiation notes for a single
  477. warning or error to <var>n</var>. The default value is 10.
  478. </p>
  479. </dd>
  480. <dt><code>-ftemplate-depth=<var>n</var></code></dt>
  481. <dd><a name="index-ftemplate_002ddepth"></a>
  482. <p>Set the maximum instantiation depth for template classes to <var>n</var>.
  483. A limit on the template instantiation depth is needed to detect
  484. endless recursions during template class instantiation. ANSI/ISO C++
  485. conforming programs must not rely on a maximum depth greater than 17
  486. (changed to 1024 in C++11). The default value is 900, as the compiler
  487. can run out of stack space before hitting 1024 in some situations.
  488. </p>
  489. </dd>
  490. <dt><code>-fno-threadsafe-statics</code></dt>
  491. <dd><a name="index-fno_002dthreadsafe_002dstatics"></a>
  492. <p>Do not emit the extra code to use the routines specified in the C++
  493. ABI for thread-safe initialization of local statics. You can use this
  494. option to reduce code size slightly in code that doesn&rsquo;t need to be
  495. thread-safe.
  496. </p>
  497. </dd>
  498. <dt><code>-fuse-cxa-atexit</code></dt>
  499. <dd><a name="index-fuse_002dcxa_002datexit"></a>
  500. <p>Register destructors for objects with static storage duration with the
  501. <code>__cxa_atexit</code> function rather than the <code>atexit</code> function.
  502. This option is required for fully standards-compliant handling of static
  503. destructors, but only works if your C library supports
  504. <code>__cxa_atexit</code>.
  505. </p>
  506. </dd>
  507. <dt><code>-fno-use-cxa-get-exception-ptr</code></dt>
  508. <dd><a name="index-fno_002duse_002dcxa_002dget_002dexception_002dptr"></a>
  509. <p>Don&rsquo;t use the <code>__cxa_get_exception_ptr</code> runtime routine. This
  510. causes <code>std::uncaught_exception</code> to be incorrect, but is necessary
  511. if the runtime routine is not available.
  512. </p>
  513. </dd>
  514. <dt><code>-fvisibility-inlines-hidden</code></dt>
  515. <dd><a name="index-fvisibility_002dinlines_002dhidden"></a>
  516. <p>This switch declares that the user does not attempt to compare
  517. pointers to inline functions or methods where the addresses of the two functions
  518. are taken in different shared objects.
  519. </p>
  520. <p>The effect of this is that GCC may, effectively, mark inline methods with
  521. <code>__attribute__ ((visibility (&quot;hidden&quot;)))</code> so that they do not
  522. appear in the export table of a DSO and do not require a PLT indirection
  523. when used within the DSO. Enabling this option can have a dramatic effect
  524. on load and link times of a DSO as it massively reduces the size of the
  525. dynamic export table when the library makes heavy use of templates.
  526. </p>
  527. <p>The behavior of this switch is not quite the same as marking the
  528. methods as hidden directly, because it does not affect static variables
  529. local to the function or cause the compiler to deduce that
  530. the function is defined in only one shared object.
  531. </p>
  532. <p>You may mark a method as having a visibility explicitly to negate the
  533. effect of the switch for that method. For example, if you do want to
  534. compare pointers to a particular inline method, you might mark it as
  535. having default visibility. Marking the enclosing class with explicit
  536. visibility has no effect.
  537. </p>
  538. <p>Explicitly instantiated inline methods are unaffected by this option
  539. as their linkage might otherwise cross a shared library boundary.
  540. See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>.
  541. </p>
  542. </dd>
  543. <dt><code>-fvisibility-ms-compat</code></dt>
  544. <dd><a name="index-fvisibility_002dms_002dcompat"></a>
  545. <p>This flag attempts to use visibility settings to make GCC&rsquo;s C++
  546. linkage model compatible with that of Microsoft Visual Studio.
  547. </p>
  548. <p>The flag makes these changes to GCC&rsquo;s linkage model:
  549. </p>
  550. <ol>
  551. <li> It sets the default visibility to <code>hidden</code>, like
  552. <samp>-fvisibility=hidden</samp>.
  553. </li><li> Types, but not their members, are not hidden by default.
  554. </li><li> The One Definition Rule is relaxed for types without explicit
  555. visibility specifications that are defined in more than one
  556. shared object: those declarations are permitted if they are
  557. permitted when this option is not used.
  558. </li></ol>
  559. <p>In new code it is better to use <samp>-fvisibility=hidden</samp> and
  560. export those classes that are intended to be externally visible.
  561. Unfortunately it is possible for code to rely, perhaps accidentally,
  562. on the Visual Studio behavior.
  563. </p>
  564. <p>Among the consequences of these changes are that static data members
  565. of the same type with the same name but defined in different shared
  566. objects are different, so changing one does not change the other;
  567. and that pointers to function members defined in different shared
  568. objects may not compare equal. When this flag is given, it is a
  569. violation of the ODR to define types with the same name differently.
  570. </p>
  571. </dd>
  572. <dt><code>-fno-weak</code></dt>
  573. <dd><a name="index-fno_002dweak"></a>
  574. <p>Do not use weak symbol support, even if it is provided by the linker.
  575. By default, G++ uses weak symbols if they are available. This
  576. option exists only for testing, and should not be used by end-users;
  577. it results in inferior code and has no benefits. This option may
  578. be removed in a future release of G++.
  579. </p>
  580. </dd>
  581. <dt><code>-nostdinc++</code></dt>
  582. <dd><a name="index-nostdinc_002b_002b"></a>
  583. <p>Do not search for header files in the standard directories specific to
  584. C++, but do still search the other standard directories. (This option
  585. is used when building the C++ library.)
  586. </p></dd>
  587. </dl>
  588. <p>In addition, these optimization, warning, and code generation options
  589. have meanings only for C++ programs:
  590. </p>
  591. <dl compact="compact">
  592. <dt><code>-Wabi <span class="roman">(C, Objective-C, C++ and Objective-C++ only)</span></code></dt>
  593. <dd><a name="index-Wabi"></a>
  594. <a name="index-Wno_002dabi"></a>
  595. <p>Warn when G++ it generates code that is probably not compatible with
  596. the vendor-neutral C++ ABI. Since G++ now defaults to updating the
  597. ABI with each major release, normally <samp>-Wabi</samp> will warn only if
  598. there is a check added later in a release series for an ABI issue
  599. discovered since the initial release. <samp>-Wabi</samp> will warn about
  600. more things if an older ABI version is selected (with
  601. <samp>-fabi-version=<var>n</var></samp>).
  602. </p>
  603. <p><samp>-Wabi</samp> can also be used with an explicit version number to
  604. warn about compatibility with a particular <samp>-fabi-version</samp>
  605. level, e.g. <samp>-Wabi=2</samp> to warn about changes relative to
  606. <samp>-fabi-version=2</samp>.
  607. </p>
  608. <p>If an explicit version number is provided and
  609. <samp>-fabi-compat-version</samp> is not specified, the version number
  610. from this option is used for compatibility aliases. If no explicit
  611. version number is provided with this option, but
  612. <samp>-fabi-compat-version</samp> is specified, that version number is
  613. used for ABI warnings.
  614. </p>
  615. <p>Although an effort has been made to warn about
  616. all such cases, there are probably some cases that are not warned about,
  617. even though G++ is generating incompatible code. There may also be
  618. cases where warnings are emitted even though the code that is generated
  619. is compatible.
  620. </p>
  621. <p>You should rewrite your code to avoid these warnings if you are
  622. concerned about the fact that code generated by G++ may not be binary
  623. compatible with code generated by other compilers.
  624. </p>
  625. <p>Known incompatibilities in <samp>-fabi-version=2</samp> (which was the
  626. default from GCC 3.4 to 4.9) include:
  627. </p>
  628. <ul>
  629. <li> A template with a non-type template parameter of reference type was
  630. mangled incorrectly:
  631. <div class="smallexample">
  632. <pre class="smallexample">extern int N;
  633. template &lt;int &amp;&gt; struct S {};
  634. void n (S&lt;N&gt;) {2}
  635. </pre></div>
  636. <p>This was fixed in <samp>-fabi-version=3</samp>.
  637. </p>
  638. </li><li> SIMD vector types declared using <code>__attribute ((vector_size))</code> were
  639. mangled in a non-standard way that does not allow for overloading of
  640. functions taking vectors of different sizes.
  641. <p>The mangling was changed in <samp>-fabi-version=4</samp>.
  642. </p>
  643. </li><li> <code>__attribute ((const))</code> and <code>noreturn</code> were mangled as type
  644. qualifiers, and <code>decltype</code> of a plain declaration was folded away.
  645. <p>These mangling issues were fixed in <samp>-fabi-version=5</samp>.
  646. </p>
  647. </li><li> Scoped enumerators passed as arguments to a variadic function are
  648. promoted like unscoped enumerators, causing <code>va_arg</code> to complain.
  649. On most targets this does not actually affect the parameter passing
  650. ABI, as there is no way to pass an argument smaller than <code>int</code>.
  651. <p>Also, the ABI changed the mangling of template argument packs,
  652. <code>const_cast</code>, <code>static_cast</code>, prefix increment/decrement, and
  653. a class scope function used as a template argument.
  654. </p>
  655. <p>These issues were corrected in <samp>-fabi-version=6</samp>.
  656. </p>
  657. </li><li> Lambdas in default argument scope were mangled incorrectly, and the
  658. ABI changed the mangling of <code>nullptr_t</code>.
  659. <p>These issues were corrected in <samp>-fabi-version=7</samp>.
  660. </p>
  661. </li><li> When mangling a function type with function-cv-qualifiers, the
  662. un-qualified function type was incorrectly treated as a substitution
  663. candidate.
  664. <p>This was fixed in <samp>-fabi-version=8</samp>, the default for GCC 5.1.
  665. </p>
  666. </li><li> <code>decltype(nullptr)</code> incorrectly had an alignment of 1, leading to
  667. unaligned accesses. Note that this did not affect the ABI of a
  668. function with a <code>nullptr_t</code> parameter, as parameters have a
  669. minimum alignment.
  670. <p>This was fixed in <samp>-fabi-version=9</samp>, the default for GCC 5.2.
  671. </p>
  672. </li><li> Target-specific attributes that affect the identity of a type, such as
  673. ia32 calling conventions on a function type (stdcall, regparm, etc.),
  674. did not affect the mangled name, leading to name collisions when
  675. function pointers were used as template arguments.
  676. <p>This was fixed in <samp>-fabi-version=10</samp>, the default for GCC 6.1.
  677. </p>
  678. </li></ul>
  679. <p>It also warns about psABI-related changes. The known psABI changes at this
  680. point include:
  681. </p>
  682. <ul>
  683. <li> For SysV/x86-64, unions with <code>long double</code> members are
  684. passed in memory as specified in psABI. For example:
  685. <div class="smallexample">
  686. <pre class="smallexample">union U {
  687. long double ld;
  688. int i;
  689. };
  690. </pre></div>
  691. <p><code>union U</code> is always passed in memory.
  692. </p>
  693. </li></ul>
  694. </dd>
  695. <dt><code>-Wabi-tag <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  696. <dd><a name="index-Wabi_002dtag"></a>
  697. <a name="index-_002dWabi_002dtag"></a>
  698. <p>Warn when a type with an ABI tag is used in a context that does not
  699. have that ABI tag. See <a href="C_002b_002b-Attributes.html#C_002b_002b-Attributes">C++ Attributes</a> for more information
  700. about ABI tags.
  701. </p>
  702. </dd>
  703. <dt><code>-Wctor-dtor-privacy <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  704. <dd><a name="index-Wctor_002ddtor_002dprivacy"></a>
  705. <a name="index-Wno_002dctor_002ddtor_002dprivacy"></a>
  706. <p>Warn when a class seems unusable because all the constructors or
  707. destructors in that class are private, and it has neither friends nor
  708. public static member functions. Also warn if there are no non-private
  709. methods, and there&rsquo;s at least one private member function that isn&rsquo;t
  710. a constructor or destructor.
  711. </p>
  712. </dd>
  713. <dt><code>-Wdelete-non-virtual-dtor <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  714. <dd><a name="index-Wdelete_002dnon_002dvirtual_002ddtor"></a>
  715. <a name="index-Wno_002ddelete_002dnon_002dvirtual_002ddtor"></a>
  716. <p>Warn when <code>delete</code> is used to destroy an instance of a class that
  717. has virtual functions and non-virtual destructor. It is unsafe to delete
  718. an instance of a derived class through a pointer to a base class if the
  719. base class does not have a virtual destructor. This warning is enabled
  720. by <samp>-Wall</samp>.
  721. </p>
  722. </dd>
  723. <dt><code>-Wliteral-suffix <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  724. <dd><a name="index-Wliteral_002dsuffix"></a>
  725. <a name="index-Wno_002dliteral_002dsuffix"></a>
  726. <p>Warn when a string or character literal is followed by a ud-suffix which does
  727. not begin with an underscore. As a conforming extension, GCC treats such
  728. suffixes as separate preprocessing tokens in order to maintain backwards
  729. compatibility with code that uses formatting macros from <code>&lt;inttypes.h&gt;</code>.
  730. For example:
  731. </p>
  732. <div class="smallexample">
  733. <pre class="smallexample">#define __STDC_FORMAT_MACROS
  734. #include &lt;inttypes.h&gt;
  735. #include &lt;stdio.h&gt;
  736. int main() {
  737. int64_t i64 = 123;
  738. printf(&quot;My int64: %&quot; PRId64&quot;\n&quot;, i64);
  739. }
  740. </pre></div>
  741. <p>In this case, <code>PRId64</code> is treated as a separate preprocessing token.
  742. </p>
  743. <p>Additionally, warn when a user-defined literal operator is declared with
  744. a literal suffix identifier that doesn&rsquo;t begin with an underscore. Literal
  745. suffix identifiers that don&rsquo;t begin with an underscore are reserved for
  746. future standardization.
  747. </p>
  748. <p>This warning is enabled by default.
  749. </p>
  750. </dd>
  751. <dt><code>-Wlto-type-mismatch</code></dt>
  752. <dd><a name="index-Wlto_002dtype_002dmismatch"></a>
  753. <a name="index-Wno_002dlto_002dtype_002dmismatch"></a>
  754. <p>During the link-time optimization warn about type mismatches in
  755. global declarations from different compilation units.
  756. Requires <samp>-flto</samp> to be enabled. Enabled by default.
  757. </p>
  758. </dd>
  759. <dt><code>-Wno-narrowing <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  760. <dd><a name="index-Wnarrowing"></a>
  761. <a name="index-Wno_002dnarrowing"></a>
  762. <p>For C++11 and later standards, narrowing conversions are diagnosed by default,
  763. as required by the standard. A narrowing conversion from a constant produces
  764. an error, and a narrowing conversion from a non-constant produces a warning,
  765. but <samp>-Wno-narrowing</samp> suppresses the diagnostic.
  766. Note that this does not affect the meaning of well-formed code;
  767. narrowing conversions are still considered ill-formed in SFINAE contexts.
  768. </p>
  769. <p>With <samp>-Wnarrowing</samp> in C++98, warn when a narrowing
  770. conversion prohibited by C++11 occurs within
  771. &lsquo;<samp>{ }</samp>&rsquo;, e.g.
  772. </p>
  773. <div class="smallexample">
  774. <pre class="smallexample">int i = { 2.2 }; // error: narrowing from double to int
  775. </pre></div>
  776. <p>This flag is included in <samp>-Wall</samp> and <samp>-Wc++11-compat</samp>.
  777. </p>
  778. </dd>
  779. <dt><code>-Wnoexcept <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  780. <dd><a name="index-Wnoexcept"></a>
  781. <a name="index-Wno_002dnoexcept"></a>
  782. <p>Warn when a noexcept-expression evaluates to false because of a call
  783. to a function that does not have a non-throwing exception
  784. specification (i.e. <code>throw()</code> or <code>noexcept</code>) but is known by
  785. the compiler to never throw an exception.
  786. </p>
  787. </dd>
  788. <dt><code>-Wnoexcept-type <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  789. <dd><a name="index-Wnoexcept_002dtype"></a>
  790. <a name="index-Wno_002dnoexcept_002dtype"></a>
  791. <p>Warn if the C++1z feature making <code>noexcept</code> part of a function
  792. type changes the mangled name of a symbol relative to C++14. Enabled
  793. by <samp>-Wabi</samp> and <samp>-Wc++1z-compat</samp>.
  794. </p>
  795. <div class="smallexample">
  796. <pre class="smallexample">template &lt;class T&gt; void f(T t) { t(); };
  797. void g() noexcept;
  798. void h() { f(g); } // in C++14 calls f&lt;void(*)()&gt;, in C++1z calls f&lt;void(*)()noexcept&gt;
  799. </pre></div>
  800. </dd>
  801. <dt><code>-Wnon-virtual-dtor <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  802. <dd><a name="index-Wnon_002dvirtual_002ddtor"></a>
  803. <a name="index-Wno_002dnon_002dvirtual_002ddtor"></a>
  804. <p>Warn when a class has virtual functions and an accessible non-virtual
  805. destructor itself or in an accessible polymorphic base class, in which
  806. case it is possible but unsafe to delete an instance of a derived
  807. class through a pointer to the class itself or base class. This
  808. warning is automatically enabled if <samp>-Weffc++</samp> is specified.
  809. </p>
  810. </dd>
  811. <dt><code>-Wregister <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  812. <dd><a name="index-Wregister"></a>
  813. <a name="index-Wno_002dregister"></a>
  814. <p>Warn on uses of the <code>register</code> storage class specifier, except
  815. when it is part of the GNU <a href="Explicit-Register-Variables.html#Explicit-Register-Variables">Explicit Register Variables</a> extension.
  816. The use of the <code>register</code> keyword as storage class specifier has
  817. been deprecated in C++11 and removed in C++17.
  818. Enabled by default with <samp>-std=c++1z</samp>.
  819. </p>
  820. </dd>
  821. <dt><code>-Wreorder <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  822. <dd><a name="index-Wreorder"></a>
  823. <a name="index-Wno_002dreorder"></a>
  824. <a name="index-reordering_002c-warning"></a>
  825. <a name="index-warning-for-reordering-of-member-initializers"></a>
  826. <p>Warn when the order of member initializers given in the code does not
  827. match the order in which they must be executed. For instance:
  828. </p>
  829. <div class="smallexample">
  830. <pre class="smallexample">struct A {
  831. int i;
  832. int j;
  833. A(): j (0), i (1) { }
  834. };
  835. </pre></div>
  836. <p>The compiler rearranges the member initializers for <code>i</code>
  837. and <code>j</code> to match the declaration order of the members, emitting
  838. a warning to that effect. This warning is enabled by <samp>-Wall</samp>.
  839. </p>
  840. </dd>
  841. <dt><code>-fext-numeric-literals <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  842. <dd><a name="index-fext_002dnumeric_002dliterals"></a>
  843. <a name="index-fno_002dext_002dnumeric_002dliterals"></a>
  844. <p>Accept imaginary, fixed-point, or machine-defined
  845. literal number suffixes as GNU extensions.
  846. When this option is turned off these suffixes are treated
  847. as C++11 user-defined literal numeric suffixes.
  848. This is on by default for all pre-C++11 dialects and all GNU dialects:
  849. <samp>-std=c++98</samp>, <samp>-std=gnu++98</samp>, <samp>-std=gnu++11</samp>,
  850. <samp>-std=gnu++14</samp>.
  851. This option is off by default
  852. for ISO C++11 onwards (<samp>-std=c++11</samp>, ...).
  853. </p></dd>
  854. </dl>
  855. <p>The following <samp>-W&hellip;</samp> options are not affected by <samp>-Wall</samp>.
  856. </p>
  857. <dl compact="compact">
  858. <dt><code>-Weffc++ <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  859. <dd><a name="index-Weffc_002b_002b"></a>
  860. <a name="index-Wno_002deffc_002b_002b"></a>
  861. <p>Warn about violations of the following style guidelines from Scott Meyers&rsquo;
  862. <cite>Effective C++</cite> series of books:
  863. </p>
  864. <ul>
  865. <li> Define a copy constructor and an assignment operator for classes
  866. with dynamically-allocated memory.
  867. </li><li> Prefer initialization to assignment in constructors.
  868. </li><li> Have <code>operator=</code> return a reference to <code>*this</code>.
  869. </li><li> Don&rsquo;t try to return a reference when you must return an object.
  870. </li><li> Distinguish between prefix and postfix forms of increment and
  871. decrement operators.
  872. </li><li> Never overload <code>&amp;&amp;</code>, <code>||</code>, or <code>,</code>.
  873. </li></ul>
  874. <p>This option also enables <samp>-Wnon-virtual-dtor</samp>, which is also
  875. one of the effective C++ recommendations. However, the check is
  876. extended to warn about the lack of virtual destructor in accessible
  877. non-polymorphic bases classes too.
  878. </p>
  879. <p>When selecting this option, be aware that the standard library
  880. headers do not obey all of these guidelines; use &lsquo;<samp>grep -v</samp>&rsquo;
  881. to filter out those warnings.
  882. </p>
  883. </dd>
  884. <dt><code>-Wstrict-null-sentinel <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  885. <dd><a name="index-Wstrict_002dnull_002dsentinel"></a>
  886. <a name="index-Wno_002dstrict_002dnull_002dsentinel"></a>
  887. <p>Warn about the use of an uncasted <code>NULL</code> as sentinel. When
  888. compiling only with GCC this is a valid sentinel, as <code>NULL</code> is defined
  889. to <code>__null</code>. Although it is a null pointer constant rather than a
  890. null pointer, it is guaranteed to be of the same size as a pointer.
  891. But this use is not portable across different compilers.
  892. </p>
  893. </dd>
  894. <dt><code>-Wno-non-template-friend <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  895. <dd><a name="index-Wno_002dnon_002dtemplate_002dfriend"></a>
  896. <a name="index-Wnon_002dtemplate_002dfriend"></a>
  897. <p>Disable warnings when non-template friend functions are declared
  898. within a template. In very old versions of GCC that predate implementation
  899. of the ISO standard, declarations such as
  900. &lsquo;<samp>friend int foo(int)</samp>&rsquo;, where the name of the friend is an unqualified-id,
  901. could be interpreted as a particular specialization of a template
  902. function; the warning exists to diagnose compatibility problems,
  903. and is enabled by default.
  904. </p>
  905. </dd>
  906. <dt><code>-Wold-style-cast <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  907. <dd><a name="index-Wold_002dstyle_002dcast"></a>
  908. <a name="index-Wno_002dold_002dstyle_002dcast"></a>
  909. <p>Warn if an old-style (C-style) cast to a non-void type is used within
  910. a C++ program. The new-style casts (<code>dynamic_cast</code>,
  911. <code>static_cast</code>, <code>reinterpret_cast</code>, and <code>const_cast</code>) are
  912. less vulnerable to unintended effects and much easier to search for.
  913. </p>
  914. </dd>
  915. <dt><code>-Woverloaded-virtual <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  916. <dd><a name="index-Woverloaded_002dvirtual"></a>
  917. <a name="index-Wno_002doverloaded_002dvirtual"></a>
  918. <a name="index-overloaded-virtual-function_002c-warning"></a>
  919. <a name="index-warning-for-overloaded-virtual-function"></a>
  920. <p>Warn when a function declaration hides virtual functions from a
  921. base class. For example, in:
  922. </p>
  923. <div class="smallexample">
  924. <pre class="smallexample">struct A {
  925. virtual void f();
  926. };
  927. struct B: public A {
  928. void f(int);
  929. };
  930. </pre></div>
  931. <p>the <code>A</code> class version of <code>f</code> is hidden in <code>B</code>, and code
  932. like:
  933. </p>
  934. <div class="smallexample">
  935. <pre class="smallexample">B* b;
  936. b-&gt;f();
  937. </pre></div>
  938. <p>fails to compile.
  939. </p>
  940. </dd>
  941. <dt><code>-Wno-pmf-conversions <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  942. <dd><a name="index-Wno_002dpmf_002dconversions"></a>
  943. <a name="index-Wpmf_002dconversions"></a>
  944. <p>Disable the diagnostic for converting a bound pointer to member function
  945. to a plain pointer.
  946. </p>
  947. </dd>
  948. <dt><code>-Wsign-promo <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  949. <dd><a name="index-Wsign_002dpromo"></a>
  950. <a name="index-Wno_002dsign_002dpromo"></a>
  951. <p>Warn when overload resolution chooses a promotion from unsigned or
  952. enumerated type to a signed type, over a conversion to an unsigned type of
  953. the same size. Previous versions of G++ tried to preserve
  954. unsignedness, but the standard mandates the current behavior.
  955. </p>
  956. </dd>
  957. <dt><code>-Wtemplates <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  958. <dd><a name="index-Wtemplates"></a>
  959. <p>Warn when a primary template declaration is encountered. Some coding
  960. rules disallow templates, and this may be used to enforce that rule.
  961. The warning is inactive inside a system header file, such as the STL, so
  962. one can still use the STL. One may also instantiate or specialize
  963. templates.
  964. </p>
  965. </dd>
  966. <dt><code>-Wmultiple-inheritance <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  967. <dd><a name="index-Wmultiple_002dinheritance"></a>
  968. <p>Warn when a class is defined with multiple direct base classes. Some
  969. coding rules disallow multiple inheritance, and this may be used to
  970. enforce that rule. The warning is inactive inside a system header file,
  971. such as the STL, so one can still use the STL. One may also define
  972. classes that indirectly use multiple inheritance.
  973. </p>
  974. </dd>
  975. <dt><code>-Wvirtual-inheritance</code></dt>
  976. <dd><a name="index-Wvirtual_002dinheritance"></a>
  977. <p>Warn when a class is defined with a virtual direct base class. Some
  978. coding rules disallow multiple inheritance, and this may be used to
  979. enforce that rule. The warning is inactive inside a system header file,
  980. such as the STL, so one can still use the STL. One may also define
  981. classes that indirectly use virtual inheritance.
  982. </p>
  983. </dd>
  984. <dt><code>-Wnamespaces</code></dt>
  985. <dd><a name="index-Wnamespaces"></a>
  986. <p>Warn when a namespace definition is opened. Some coding rules disallow
  987. namespaces, and this may be used to enforce that rule. The warning is
  988. inactive inside a system header file, such as the STL, so one can still
  989. use the STL. One may also use using directives and qualified names.
  990. </p>
  991. </dd>
  992. <dt><code>-Wno-terminate <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  993. <dd><a name="index-Wterminate"></a>
  994. <a name="index-Wno_002dterminate"></a>
  995. <p>Disable the warning about a throw-expression that will immediately
  996. result in a call to <code>terminate</code>.
  997. </p></dd>
  998. </dl>
  999. <hr>
  1000. <div class="header">
  1001. <p>
  1002. Next: <a href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options" accesskey="n" rel="next">Objective-C and Objective-C++ Dialect Options</a>, Previous: <a href="C-Dialect-Options.html#C-Dialect-Options" accesskey="p" rel="prev">C Dialect Options</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  1003. </div>
  1004. </body>
  1005. </html>