You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1461 lines
65KB

  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>C++ Dialect Options (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="C++ Dialect Options (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="C++ Dialect Options (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  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.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="C_002b_002b-Dialect-Options"></a>
  62. <div class="header">
  63. <p>
  64. 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>
  65. </div>
  66. <hr>
  67. <a name="Options-Controlling-C_002b_002b-Dialect"></a>
  68. <h3 class="section">3.5 Options Controlling C++ Dialect</h3>
  69. <a name="index-compiler-options_002c-C_002b_002b"></a>
  70. <a name="index-C_002b_002b-options_002c-command_002dline"></a>
  71. <a name="index-options_002c-C_002b_002b"></a>
  72. <p>This section describes the command-line options that are only meaningful
  73. for C++ programs. You can also use most of the GNU compiler options
  74. regardless of what language your program is in. For example, you
  75. might compile a file <samp>firstClass.C</samp> like this:
  76. </p>
  77. <div class="smallexample">
  78. <pre class="smallexample">g++ -g -fstrict-enums -O -c firstClass.C
  79. </pre></div>
  80. <p>In this example, only <samp>-fstrict-enums</samp> is an option meant
  81. only for C++ programs; you can use the other options with any
  82. language supported by GCC.
  83. </p>
  84. <p>Some options for compiling C programs, such as <samp>-std</samp>, are also
  85. relevant for C++ programs.
  86. See <a href="C-Dialect-Options.html#C-Dialect-Options">Options Controlling C Dialect</a>.
  87. </p>
  88. <p>Here is a list of options that are <em>only</em> for compiling C++ programs:
  89. </p>
  90. <dl compact="compact">
  91. <dt><code>-fabi-version=<var>n</var></code></dt>
  92. <dd><a name="index-fabi_002dversion"></a>
  93. <p>Use version <var>n</var> of the C++ ABI. The default is version 0.
  94. </p>
  95. <p>Version 0 refers to the version conforming most closely to
  96. the C++ ABI specification. Therefore, the ABI obtained using version 0
  97. will change in different versions of G++ as ABI bugs are fixed.
  98. </p>
  99. <p>Version 1 is the version of the C++ ABI that first appeared in G++ 3.2.
  100. </p>
  101. <p>Version 2 is the version of the C++ ABI that first appeared in G++
  102. 3.4, and was the default through G++ 4.9.
  103. </p>
  104. <p>Version 3 corrects an error in mangling a constant address as a
  105. template argument.
  106. </p>
  107. <p>Version 4, which first appeared in G++ 4.5, implements a standard
  108. mangling for vector types.
  109. </p>
  110. <p>Version 5, which first appeared in G++ 4.6, corrects the mangling of
  111. attribute const/volatile on function pointer types, decltype of a
  112. plain decl, and use of a function parameter in the declaration of
  113. another parameter.
  114. </p>
  115. <p>Version 6, which first appeared in G++ 4.7, corrects the promotion
  116. behavior of C++11 scoped enums and the mangling of template argument
  117. packs, const/static_cast, prefix ++ and &ndash;, and a class scope function
  118. used as a template argument.
  119. </p>
  120. <p>Version 7, which first appeared in G++ 4.8, that treats nullptr_t as a
  121. builtin type and corrects the mangling of lambdas in default argument
  122. scope.
  123. </p>
  124. <p>Version 8, which first appeared in G++ 4.9, corrects the substitution
  125. behavior of function types with function-cv-qualifiers.
  126. </p>
  127. <p>Version 9, which first appeared in G++ 5.2, corrects the alignment of
  128. <code>nullptr_t</code>.
  129. </p>
  130. <p>Version 10, which first appeared in G++ 6.1, adds mangling of
  131. attributes that affect type identity, such as ia32 calling convention
  132. attributes (e.g. &lsquo;<samp>stdcall</samp>&rsquo;).
  133. </p>
  134. <p>Version 11, which first appeared in G++ 7, corrects the mangling of
  135. sizeof... expressions and operator names. For multiple entities with
  136. the same name within a function, that are declared in different scopes,
  137. the mangling now changes starting with the twelfth occurrence. It also
  138. implies <samp>-fnew-inheriting-ctors</samp>.
  139. </p>
  140. <p>Version 12, which first appeared in G++ 8, corrects the calling
  141. conventions for empty classes on the x86_64 target and for classes
  142. with only deleted copy/move constructors. It accidentally changes the
  143. calling convention for classes with a deleted copy constructor and a
  144. trivial move constructor.
  145. </p>
  146. <p>Version 13, which first appeared in G++ 8.2, fixes the accidental
  147. change in version 12.
  148. </p>
  149. <p>Version 14, which first appeared in G++ 10, corrects the mangling of
  150. the nullptr expression.
  151. </p>
  152. <p>See also <samp>-Wabi</samp>.
  153. </p>
  154. </dd>
  155. <dt><code>-fabi-compat-version=<var>n</var></code></dt>
  156. <dd><a name="index-fabi_002dcompat_002dversion"></a>
  157. <p>On targets that support strong aliases, G++
  158. works around mangling changes by creating an alias with the correct
  159. mangled name when defining a symbol with an incorrect mangled name.
  160. This switch specifies which ABI version to use for the alias.
  161. </p>
  162. <p>With <samp>-fabi-version=0</samp> (the default), this defaults to 11 (GCC 7
  163. compatibility). If another ABI version is explicitly selected, this
  164. defaults to 0. For compatibility with GCC versions 3.2 through 4.9,
  165. use <samp>-fabi-compat-version=2</samp>.
  166. </p>
  167. <p>If this option is not provided but <samp>-Wabi=<var>n</var></samp> is, that
  168. version is used for compatibility aliases. If this option is provided
  169. along with <samp>-Wabi</samp> (without the version), the version from this
  170. option is used for the warning.
  171. </p>
  172. </dd>
  173. <dt><code>-fno-access-control</code></dt>
  174. <dd><a name="index-fno_002daccess_002dcontrol"></a>
  175. <a name="index-faccess_002dcontrol"></a>
  176. <p>Turn off all access checking. This switch is mainly useful for working
  177. around bugs in the access control code.
  178. </p>
  179. </dd>
  180. <dt><code>-faligned-new</code></dt>
  181. <dd><a name="index-faligned_002dnew"></a>
  182. <p>Enable support for C++17 <code>new</code> of types that require more
  183. alignment than <code>void* ::operator new(std::size_t)</code> provides. A
  184. numeric argument such as <code>-faligned-new=32</code> can be used to
  185. specify how much alignment (in bytes) is provided by that function,
  186. but few users will need to override the default of
  187. <code>alignof(std::max_align_t)</code>.
  188. </p>
  189. <p>This flag is enabled by default for <samp>-std=c++17</samp>.
  190. </p>
  191. </dd>
  192. <dt><code>-fchar8_t</code></dt>
  193. <dt><code>-fno-char8_t</code></dt>
  194. <dd><a name="index-fchar8_005ft"></a>
  195. <a name="index-fno_002dchar8_005ft"></a>
  196. <p>Enable support for <code>char8_t</code> as adopted for C++2a. This includes
  197. the addition of a new <code>char8_t</code> fundamental type, changes to the
  198. types of UTF-8 string and character literals, new signatures for
  199. user-defined literals, associated standard library updates, and new
  200. <code>__cpp_char8_t</code> and <code>__cpp_lib_char8_t</code> feature test macros.
  201. </p>
  202. <p>This option enables functions to be overloaded for ordinary and UTF-8
  203. strings:
  204. </p>
  205. <div class="smallexample">
  206. <pre class="smallexample">int f(const char *); // #1
  207. int f(const char8_t *); // #2
  208. int v1 = f(&quot;text&quot;); // Calls #1
  209. int v2 = f(u8&quot;text&quot;); // Calls #2
  210. </pre></div>
  211. <p>and introduces new signatures for user-defined literals:
  212. </p>
  213. <div class="smallexample">
  214. <pre class="smallexample">int operator&quot;&quot;_udl1(char8_t);
  215. int v3 = u8'x'_udl1;
  216. int operator&quot;&quot;_udl2(const char8_t*, std::size_t);
  217. int v4 = u8&quot;text&quot;_udl2;
  218. template&lt;typename T, T...&gt; int operator&quot;&quot;_udl3();
  219. int v5 = u8&quot;text&quot;_udl3;
  220. </pre></div>
  221. <p>The change to the types of UTF-8 string and character literals introduces
  222. incompatibilities with ISO C++11 and later standards. For example, the
  223. following code is well-formed under ISO C++11, but is ill-formed when
  224. <samp>-fchar8_t</samp> is specified.
  225. </p>
  226. <div class="smallexample">
  227. <pre class="smallexample">char ca[] = u8&quot;xx&quot;; // error: char-array initialized from wide
  228. // string
  229. const char *cp = u8&quot;xx&quot;;// error: invalid conversion from
  230. // `const char8_t*' to `const char*'
  231. int f(const char*);
  232. auto v = f(u8&quot;xx&quot;); // error: invalid conversion from
  233. // `const char8_t*' to `const char*'
  234. std::string s{u8&quot;xx&quot;}; // error: no matching function for call to
  235. // `std::basic_string&lt;char&gt;::basic_string()'
  236. using namespace std::literals;
  237. s = u8&quot;xx&quot;s; // error: conversion from
  238. // `basic_string&lt;char8_t&gt;' to non-scalar
  239. // type `basic_string&lt;char&gt;' requested
  240. </pre></div>
  241. </dd>
  242. <dt><code>-fcheck-new</code></dt>
  243. <dd><a name="index-fcheck_002dnew"></a>
  244. <p>Check that the pointer returned by <code>operator new</code> is non-null
  245. before attempting to modify the storage allocated. This check is
  246. normally unnecessary because the C++ standard specifies that
  247. <code>operator new</code> only returns <code>0</code> if it is declared
  248. <code>throw()</code>, in which case the compiler always checks the
  249. return value even without this option. In all other cases, when
  250. <code>operator new</code> has a non-empty exception specification, memory
  251. exhaustion is signalled by throwing <code>std::bad_alloc</code>. See also
  252. &lsquo;<samp>new (nothrow)</samp>&rsquo;.
  253. </p>
  254. </dd>
  255. <dt><code>-fconcepts</code></dt>
  256. <dt><code>-fconcepts-ts</code></dt>
  257. <dd><a name="index-fconcepts"></a>
  258. <a name="index-fconcepts_002dts"></a>
  259. <p>Below <samp>-std=c++2a</samp>, <samp>-fconcepts</samp> enables support for the
  260. C++ Extensions for Concepts Technical Specification, ISO 19217 (2015).
  261. </p>
  262. <p>With <samp>-std=c++2a</samp> and above, Concepts are part of the language
  263. standard, so <samp>-fconcepts</samp> defaults to on. But the standard
  264. specification of Concepts differs significantly from the TS, so some
  265. constructs that were allowed in the TS but didn&rsquo;t make it into the
  266. standard can still be enabled by <samp>-fconcepts-ts</samp>.
  267. </p>
  268. </dd>
  269. <dt><code>-fconstexpr-depth=<var>n</var></code></dt>
  270. <dd><a name="index-fconstexpr_002ddepth"></a>
  271. <p>Set the maximum nested evaluation depth for C++11 constexpr functions
  272. to <var>n</var>. A limit is needed to detect endless recursion during
  273. constant expression evaluation. The minimum specified by the standard
  274. is 512.
  275. </p>
  276. </dd>
  277. <dt><code>-fconstexpr-cache-depth=<var>n</var></code></dt>
  278. <dd><a name="index-fconstexpr_002dcache_002ddepth"></a>
  279. <p>Set the maximum level of nested evaluation depth for C++11 constexpr
  280. functions that will be cached to <var>n</var>. This is a heuristic that
  281. trades off compilation speed (when the cache avoids repeated
  282. calculations) against memory consumption (when the cache grows very
  283. large from highly recursive evaluations). The default is 8. Very few
  284. users are likely to want to adjust it, but if your code does heavy
  285. constexpr calculations you might want to experiment to find which
  286. value works best for you.
  287. </p>
  288. </dd>
  289. <dt><code>-fconstexpr-loop-limit=<var>n</var></code></dt>
  290. <dd><a name="index-fconstexpr_002dloop_002dlimit"></a>
  291. <p>Set the maximum number of iterations for a loop in C++14 constexpr functions
  292. to <var>n</var>. A limit is needed to detect infinite loops during
  293. constant expression evaluation. The default is 262144 (1&lt;&lt;18).
  294. </p>
  295. </dd>
  296. <dt><code>-fconstexpr-ops-limit=<var>n</var></code></dt>
  297. <dd><a name="index-fconstexpr_002dops_002dlimit"></a>
  298. <p>Set the maximum number of operations during a single constexpr evaluation.
  299. Even when number of iterations of a single loop is limited with the above limit,
  300. if there are several nested loops and each of them has many iterations but still
  301. smaller than the above limit, or if in a body of some loop or even outside
  302. of a loop too many expressions need to be evaluated, the resulting constexpr
  303. evaluation might take too long.
  304. The default is 33554432 (1&lt;&lt;25).
  305. </p>
  306. </dd>
  307. <dt><code>-fcoroutines</code></dt>
  308. <dd><a name="index-fcoroutines"></a>
  309. <p>Enable support for the C++ coroutines extension (experimental).
  310. </p>
  311. </dd>
  312. <dt><code>-fno-elide-constructors</code></dt>
  313. <dd><a name="index-fno_002delide_002dconstructors"></a>
  314. <a name="index-felide_002dconstructors"></a>
  315. <p>The C++ standard allows an implementation to omit creating a temporary
  316. that is only used to initialize another object of the same type.
  317. Specifying this option disables that optimization, and forces G++ to
  318. call the copy constructor in all cases. This option also causes G++
  319. to call trivial member functions which otherwise would be expanded inline.
  320. </p>
  321. <p>In C++17, the compiler is required to omit these temporaries, but this
  322. option still affects trivial member functions.
  323. </p>
  324. </dd>
  325. <dt><code>-fno-enforce-eh-specs</code></dt>
  326. <dd><a name="index-fno_002denforce_002deh_002dspecs"></a>
  327. <a name="index-fenforce_002deh_002dspecs"></a>
  328. <p>Don&rsquo;t generate code to check for violation of exception specifications
  329. at run time. This option violates the C++ standard, but may be useful
  330. for reducing code size in production builds, much like defining
  331. <code>NDEBUG</code>. This does not give user code permission to throw
  332. exceptions in violation of the exception specifications; the compiler
  333. still optimizes based on the specifications, so throwing an
  334. unexpected exception results in undefined behavior at run time.
  335. </p>
  336. </dd>
  337. <dt><code>-fextern-tls-init</code></dt>
  338. <dt><code>-fno-extern-tls-init</code></dt>
  339. <dd><a name="index-fextern_002dtls_002dinit"></a>
  340. <a name="index-fno_002dextern_002dtls_002dinit"></a>
  341. <p>The C++11 and OpenMP standards allow <code>thread_local</code> and
  342. <code>threadprivate</code> variables to have dynamic (runtime)
  343. initialization. To support this, any use of such a variable goes
  344. through a wrapper function that performs any necessary initialization.
  345. When the use and definition of the variable are in the same
  346. translation unit, this overhead can be optimized away, but when the
  347. use is in a different translation unit there is significant overhead
  348. even if the variable doesn&rsquo;t actually need dynamic initialization. If
  349. the programmer can be sure that no use of the variable in a
  350. non-defining TU needs to trigger dynamic initialization (either
  351. because the variable is statically initialized, or a use of the
  352. variable in the defining TU will be executed before any uses in
  353. another TU), they can avoid this overhead with the
  354. <samp>-fno-extern-tls-init</samp> option.
  355. </p>
  356. <p>On targets that support symbol aliases, the default is
  357. <samp>-fextern-tls-init</samp>. On targets that do not support symbol
  358. aliases, the default is <samp>-fno-extern-tls-init</samp>.
  359. </p>
  360. </dd>
  361. <dt><code>-fno-gnu-keywords</code></dt>
  362. <dd><a name="index-fno_002dgnu_002dkeywords"></a>
  363. <a name="index-fgnu_002dkeywords"></a>
  364. <p>Do not recognize <code>typeof</code> as a keyword, so that code can use this
  365. word as an identifier. You can use the keyword <code>__typeof__</code> instead.
  366. This option is implied by the strict ISO C++ dialects: <samp>-ansi</samp>,
  367. <samp>-std=c++98</samp>, <samp>-std=c++11</samp>, etc.
  368. </p>
  369. </dd>
  370. <dt><code>-fno-implicit-templates</code></dt>
  371. <dd><a name="index-fno_002dimplicit_002dtemplates"></a>
  372. <a name="index-fimplicit_002dtemplates"></a>
  373. <p>Never emit code for non-inline templates that are instantiated
  374. implicitly (i.e. by use); only emit code for explicit instantiations.
  375. If you use this option, you must take care to structure your code to
  376. include all the necessary explicit instantiations to avoid getting
  377. undefined symbols at link time.
  378. See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>, for more information.
  379. </p>
  380. </dd>
  381. <dt><code>-fno-implicit-inline-templates</code></dt>
  382. <dd><a name="index-fno_002dimplicit_002dinline_002dtemplates"></a>
  383. <a name="index-fimplicit_002dinline_002dtemplates"></a>
  384. <p>Don&rsquo;t emit code for implicit instantiations of inline templates, either.
  385. The default is to handle inlines differently so that compiles with and
  386. without optimization need the same set of explicit instantiations.
  387. </p>
  388. </dd>
  389. <dt><code>-fno-implement-inlines</code></dt>
  390. <dd><a name="index-fno_002dimplement_002dinlines"></a>
  391. <a name="index-fimplement_002dinlines"></a>
  392. <p>To save space, do not emit out-of-line copies of inline functions
  393. controlled by <code>#pragma implementation</code>. This causes linker
  394. errors if these functions are not inlined everywhere they are called.
  395. </p>
  396. </dd>
  397. <dt><code>-fms-extensions</code></dt>
  398. <dd><a name="index-fms_002dextensions-1"></a>
  399. <p>Disable Wpedantic warnings about constructs used in MFC, such as implicit
  400. int and getting a pointer to member function via non-standard syntax.
  401. </p>
  402. </dd>
  403. <dt><code>-fnew-inheriting-ctors</code></dt>
  404. <dd><a name="index-fnew_002dinheriting_002dctors"></a>
  405. <p>Enable the P0136 adjustment to the semantics of C++11 constructor
  406. inheritance. This is part of C++17 but also considered to be a Defect
  407. Report against C++11 and C++14. This flag is enabled by default
  408. unless <samp>-fabi-version=10</samp> or lower is specified.
  409. </p>
  410. </dd>
  411. <dt><code>-fnew-ttp-matching</code></dt>
  412. <dd><a name="index-fnew_002dttp_002dmatching"></a>
  413. <p>Enable the P0522 resolution to Core issue 150, template template
  414. parameters and default arguments: this allows a template with default
  415. template arguments as an argument for a template template parameter
  416. with fewer template parameters. This flag is enabled by default for
  417. <samp>-std=c++17</samp>.
  418. </p>
  419. </dd>
  420. <dt><code>-fno-nonansi-builtins</code></dt>
  421. <dd><a name="index-fno_002dnonansi_002dbuiltins"></a>
  422. <a name="index-fnonansi_002dbuiltins"></a>
  423. <p>Disable built-in declarations of functions that are not mandated by
  424. ANSI/ISO C. These include <code>ffs</code>, <code>alloca</code>, <code>_exit</code>,
  425. <code>index</code>, <code>bzero</code>, <code>conjf</code>, and other related functions.
  426. </p>
  427. </dd>
  428. <dt><code>-fnothrow-opt</code></dt>
  429. <dd><a name="index-fnothrow_002dopt"></a>
  430. <p>Treat a <code>throw()</code> exception specification as if it were a
  431. <code>noexcept</code> specification to reduce or eliminate the text size
  432. overhead relative to a function with no exception specification. If
  433. the function has local variables of types with non-trivial
  434. destructors, the exception specification actually makes the
  435. function smaller because the EH cleanups for those variables can be
  436. optimized away. The semantic effect is that an exception thrown out of
  437. a function with such an exception specification results in a call
  438. to <code>terminate</code> rather than <code>unexpected</code>.
  439. </p>
  440. </dd>
  441. <dt><code>-fno-operator-names</code></dt>
  442. <dd><a name="index-fno_002doperator_002dnames"></a>
  443. <a name="index-foperator_002dnames"></a>
  444. <p>Do not treat the operator name keywords <code>and</code>, <code>bitand</code>,
  445. <code>bitor</code>, <code>compl</code>, <code>not</code>, <code>or</code> and <code>xor</code> as
  446. synonyms as keywords.
  447. </p>
  448. </dd>
  449. <dt><code>-fno-optional-diags</code></dt>
  450. <dd><a name="index-fno_002doptional_002ddiags"></a>
  451. <a name="index-foptional_002ddiags"></a>
  452. <p>Disable diagnostics that the standard says a compiler does not need to
  453. issue. Currently, the only such diagnostic issued by G++ is the one for
  454. a name having multiple meanings within a class.
  455. </p>
  456. </dd>
  457. <dt><code>-fpermissive</code></dt>
  458. <dd><a name="index-fpermissive"></a>
  459. <p>Downgrade some diagnostics about nonconformant code from errors to
  460. warnings. Thus, using <samp>-fpermissive</samp> allows some
  461. nonconforming code to compile.
  462. </p>
  463. </dd>
  464. <dt><code>-fno-pretty-templates</code></dt>
  465. <dd><a name="index-fno_002dpretty_002dtemplates"></a>
  466. <a name="index-fpretty_002dtemplates"></a>
  467. <p>When an error message refers to a specialization of a function
  468. template, the compiler normally prints the signature of the
  469. template followed by the template arguments and any typedefs or
  470. typenames in the signature (e.g. <code>void f(T) [with T = int]</code>
  471. rather than <code>void f(int)</code>) so that it&rsquo;s clear which template is
  472. involved. When an error message refers to a specialization of a class
  473. template, the compiler omits any template arguments that match
  474. the default template arguments for that template. If either of these
  475. behaviors make it harder to understand the error message rather than
  476. easier, you can use <samp>-fno-pretty-templates</samp> to disable them.
  477. </p>
  478. </dd>
  479. <dt><code>-fno-rtti</code></dt>
  480. <dd><a name="index-fno_002drtti"></a>
  481. <a name="index-frtti"></a>
  482. <p>Disable generation of information about every class with virtual
  483. functions for use by the C++ run-time type identification features
  484. (<code>dynamic_cast</code> and <code>typeid</code>). If you don&rsquo;t use those parts
  485. of the language, you can save some space by using this flag. Note that
  486. exception handling uses the same information, but G++ generates it as
  487. needed. The <code>dynamic_cast</code> operator can still be used for casts that
  488. do not require run-time type information, i.e. casts to <code>void *</code> or to
  489. unambiguous base classes.
  490. </p>
  491. <p>Mixing code compiled with <samp>-frtti</samp> with that compiled with
  492. <samp>-fno-rtti</samp> may not work. For example, programs may
  493. fail to link if a class compiled with <samp>-fno-rtti</samp> is used as a base
  494. for a class compiled with <samp>-frtti</samp>.
  495. </p>
  496. </dd>
  497. <dt><code>-fsized-deallocation</code></dt>
  498. <dd><a name="index-fsized_002ddeallocation"></a>
  499. <p>Enable the built-in global declarations
  500. </p><div class="smallexample">
  501. <pre class="smallexample">void operator delete (void *, std::size_t) noexcept;
  502. void operator delete[] (void *, std::size_t) noexcept;
  503. </pre></div>
  504. <p>as introduced in C++14. This is useful for user-defined replacement
  505. deallocation functions that, for example, use the size of the object
  506. to make deallocation faster. Enabled by default under
  507. <samp>-std=c++14</samp> and above. The flag <samp>-Wsized-deallocation</samp>
  508. warns about places that might want to add a definition.
  509. </p>
  510. </dd>
  511. <dt><code>-fstrict-enums</code></dt>
  512. <dd><a name="index-fstrict_002denums"></a>
  513. <p>Allow the compiler to optimize using the assumption that a value of
  514. enumerated type can only be one of the values of the enumeration (as
  515. defined in the C++ standard; basically, a value that can be
  516. represented in the minimum number of bits needed to represent all the
  517. enumerators). This assumption may not be valid if the program uses a
  518. cast to convert an arbitrary integer value to the enumerated type.
  519. </p>
  520. </dd>
  521. <dt><code>-fstrong-eval-order</code></dt>
  522. <dd><a name="index-fstrong_002deval_002dorder"></a>
  523. <p>Evaluate member access, array subscripting, and shift expressions in
  524. left-to-right order, and evaluate assignment in right-to-left order,
  525. as adopted for C++17. Enabled by default with <samp>-std=c++17</samp>.
  526. <samp>-fstrong-eval-order=some</samp> enables just the ordering of member
  527. access and shift expressions, and is the default without
  528. <samp>-std=c++17</samp>.
  529. </p>
  530. </dd>
  531. <dt><code>-ftemplate-backtrace-limit=<var>n</var></code></dt>
  532. <dd><a name="index-ftemplate_002dbacktrace_002dlimit"></a>
  533. <p>Set the maximum number of template instantiation notes for a single
  534. warning or error to <var>n</var>. The default value is 10.
  535. </p>
  536. </dd>
  537. <dt><code>-ftemplate-depth=<var>n</var></code></dt>
  538. <dd><a name="index-ftemplate_002ddepth"></a>
  539. <p>Set the maximum instantiation depth for template classes to <var>n</var>.
  540. A limit on the template instantiation depth is needed to detect
  541. endless recursions during template class instantiation. ANSI/ISO C++
  542. conforming programs must not rely on a maximum depth greater than 17
  543. (changed to 1024 in C++11). The default value is 900, as the compiler
  544. can run out of stack space before hitting 1024 in some situations.
  545. </p>
  546. </dd>
  547. <dt><code>-fno-threadsafe-statics</code></dt>
  548. <dd><a name="index-fno_002dthreadsafe_002dstatics"></a>
  549. <a name="index-fthreadsafe_002dstatics"></a>
  550. <p>Do not emit the extra code to use the routines specified in the C++
  551. ABI for thread-safe initialization of local statics. You can use this
  552. option to reduce code size slightly in code that doesn&rsquo;t need to be
  553. thread-safe.
  554. </p>
  555. </dd>
  556. <dt><code>-fuse-cxa-atexit</code></dt>
  557. <dd><a name="index-fuse_002dcxa_002datexit"></a>
  558. <p>Register destructors for objects with static storage duration with the
  559. <code>__cxa_atexit</code> function rather than the <code>atexit</code> function.
  560. This option is required for fully standards-compliant handling of static
  561. destructors, but only works if your C library supports
  562. <code>__cxa_atexit</code>.
  563. </p>
  564. </dd>
  565. <dt><code>-fno-use-cxa-get-exception-ptr</code></dt>
  566. <dd><a name="index-fno_002duse_002dcxa_002dget_002dexception_002dptr"></a>
  567. <a name="index-fuse_002dcxa_002dget_002dexception_002dptr"></a>
  568. <p>Don&rsquo;t use the <code>__cxa_get_exception_ptr</code> runtime routine. This
  569. causes <code>std::uncaught_exception</code> to be incorrect, but is necessary
  570. if the runtime routine is not available.
  571. </p>
  572. </dd>
  573. <dt><code>-fvisibility-inlines-hidden</code></dt>
  574. <dd><a name="index-fvisibility_002dinlines_002dhidden"></a>
  575. <p>This switch declares that the user does not attempt to compare
  576. pointers to inline functions or methods where the addresses of the two functions
  577. are taken in different shared objects.
  578. </p>
  579. <p>The effect of this is that GCC may, effectively, mark inline methods with
  580. <code>__attribute__ ((visibility (&quot;hidden&quot;)))</code> so that they do not
  581. appear in the export table of a DSO and do not require a PLT indirection
  582. when used within the DSO. Enabling this option can have a dramatic effect
  583. on load and link times of a DSO as it massively reduces the size of the
  584. dynamic export table when the library makes heavy use of templates.
  585. </p>
  586. <p>The behavior of this switch is not quite the same as marking the
  587. methods as hidden directly, because it does not affect static variables
  588. local to the function or cause the compiler to deduce that
  589. the function is defined in only one shared object.
  590. </p>
  591. <p>You may mark a method as having a visibility explicitly to negate the
  592. effect of the switch for that method. For example, if you do want to
  593. compare pointers to a particular inline method, you might mark it as
  594. having default visibility. Marking the enclosing class with explicit
  595. visibility has no effect.
  596. </p>
  597. <p>Explicitly instantiated inline methods are unaffected by this option
  598. as their linkage might otherwise cross a shared library boundary.
  599. See <a href="Template-Instantiation.html#Template-Instantiation">Template Instantiation</a>.
  600. </p>
  601. </dd>
  602. <dt><code>-fvisibility-ms-compat</code></dt>
  603. <dd><a name="index-fvisibility_002dms_002dcompat"></a>
  604. <p>This flag attempts to use visibility settings to make GCC&rsquo;s C++
  605. linkage model compatible with that of Microsoft Visual Studio.
  606. </p>
  607. <p>The flag makes these changes to GCC&rsquo;s linkage model:
  608. </p>
  609. <ol>
  610. <li> It sets the default visibility to <code>hidden</code>, like
  611. <samp>-fvisibility=hidden</samp>.
  612. </li><li> Types, but not their members, are not hidden by default.
  613. </li><li> The One Definition Rule is relaxed for types without explicit
  614. visibility specifications that are defined in more than one
  615. shared object: those declarations are permitted if they are
  616. permitted when this option is not used.
  617. </li></ol>
  618. <p>In new code it is better to use <samp>-fvisibility=hidden</samp> and
  619. export those classes that are intended to be externally visible.
  620. Unfortunately it is possible for code to rely, perhaps accidentally,
  621. on the Visual Studio behavior.
  622. </p>
  623. <p>Among the consequences of these changes are that static data members
  624. of the same type with the same name but defined in different shared
  625. objects are different, so changing one does not change the other;
  626. and that pointers to function members defined in different shared
  627. objects may not compare equal. When this flag is given, it is a
  628. violation of the ODR to define types with the same name differently.
  629. </p>
  630. </dd>
  631. <dt><code>-fno-weak</code></dt>
  632. <dd><a name="index-fno_002dweak"></a>
  633. <a name="index-fweak"></a>
  634. <p>Do not use weak symbol support, even if it is provided by the linker.
  635. By default, G++ uses weak symbols if they are available. This
  636. option exists only for testing, and should not be used by end-users;
  637. it results in inferior code and has no benefits. This option may
  638. be removed in a future release of G++.
  639. </p>
  640. </dd>
  641. <dt><code>-fext-numeric-literals <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  642. <dd><a name="index-fext_002dnumeric_002dliterals"></a>
  643. <a name="index-fno_002dext_002dnumeric_002dliterals"></a>
  644. <p>Accept imaginary, fixed-point, or machine-defined
  645. literal number suffixes as GNU extensions.
  646. When this option is turned off these suffixes are treated
  647. as C++11 user-defined literal numeric suffixes.
  648. This is on by default for all pre-C++11 dialects and all GNU dialects:
  649. <samp>-std=c++98</samp>, <samp>-std=gnu++98</samp>, <samp>-std=gnu++11</samp>,
  650. <samp>-std=gnu++14</samp>.
  651. This option is off by default
  652. for ISO C++11 onwards (<samp>-std=c++11</samp>, ...).
  653. </p>
  654. </dd>
  655. <dt><code>-nostdinc++</code></dt>
  656. <dd><a name="index-nostdinc_002b_002b"></a>
  657. <p>Do not search for header files in the standard directories specific to
  658. C++, but do still search the other standard directories. (This option
  659. is used when building the C++ library.)
  660. </p></dd>
  661. </dl>
  662. <p>In addition, these warning options have meanings only for C++ programs:
  663. </p>
  664. <dl compact="compact">
  665. <dt><code>-Wabi-tag <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  666. <dd><a name="index-Wabi_002dtag"></a>
  667. <a name="index-Wabi_002dtag-1"></a>
  668. <p>Warn when a type with an ABI tag is used in a context that does not
  669. have that ABI tag. See <a href="C_002b_002b-Attributes.html#C_002b_002b-Attributes">C++ Attributes</a> for more information
  670. about ABI tags.
  671. </p>
  672. </dd>
  673. <dt><code>-Wcomma-subscript <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  674. <dd><a name="index-Wcomma_002dsubscript"></a>
  675. <a name="index-Wno_002dcomma_002dsubscript"></a>
  676. <p>Warn about uses of a comma expression within a subscripting expression.
  677. This usage was deprecated in C++2a. However, a comma expression wrapped
  678. in <code>( )</code> is not deprecated. Example:
  679. </p>
  680. <div class="smallexample">
  681. <pre class="smallexample">void f(int *a, int b, int c) {
  682. a[b,c]; // deprecated
  683. a[(b,c)]; // OK
  684. }
  685. </pre></div>
  686. <p>Enabled by default with <samp>-std=c++2a</samp>.
  687. </p>
  688. </dd>
  689. <dt><code>-Wctor-dtor-privacy <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  690. <dd><a name="index-Wctor_002ddtor_002dprivacy"></a>
  691. <a name="index-Wno_002dctor_002ddtor_002dprivacy"></a>
  692. <p>Warn when a class seems unusable because all the constructors or
  693. destructors in that class are private, and it has neither friends nor
  694. public static member functions. Also warn if there are no non-private
  695. methods, and there&rsquo;s at least one private member function that isn&rsquo;t
  696. a constructor or destructor.
  697. </p>
  698. </dd>
  699. <dt><code>-Wdelete-non-virtual-dtor <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  700. <dd><a name="index-Wdelete_002dnon_002dvirtual_002ddtor"></a>
  701. <a name="index-Wno_002ddelete_002dnon_002dvirtual_002ddtor"></a>
  702. <p>Warn when <code>delete</code> is used to destroy an instance of a class that
  703. has virtual functions and non-virtual destructor. It is unsafe to delete
  704. an instance of a derived class through a pointer to a base class if the
  705. base class does not have a virtual destructor. This warning is enabled
  706. by <samp>-Wall</samp>.
  707. </p>
  708. </dd>
  709. <dt><code>-Wdeprecated-copy <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  710. <dd><a name="index-Wdeprecated_002dcopy"></a>
  711. <a name="index-Wno_002ddeprecated_002dcopy"></a>
  712. <p>Warn that the implicit declaration of a copy constructor or copy
  713. assignment operator is deprecated if the class has a user-provided
  714. copy constructor or copy assignment operator, in C++11 and up. This
  715. warning is enabled by <samp>-Wextra</samp>. With
  716. <samp>-Wdeprecated-copy-dtor</samp>, also deprecate if the class has a
  717. user-provided destructor.
  718. </p>
  719. </dd>
  720. <dt><code>-Wno-init-list-lifetime <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  721. <dd><a name="index-Winit_002dlist_002dlifetime"></a>
  722. <a name="index-Wno_002dinit_002dlist_002dlifetime"></a>
  723. <p>Do not warn about uses of <code>std::initializer_list</code> that are likely
  724. to result in dangling pointers. Since the underlying array for an
  725. <code>initializer_list</code> is handled like a normal C++ temporary object,
  726. it is easy to inadvertently keep a pointer to the array past the end
  727. of the array&rsquo;s lifetime. For example:
  728. </p>
  729. <ul>
  730. <li> If a function returns a temporary <code>initializer_list</code>, or a local
  731. <code>initializer_list</code> variable, the array&rsquo;s lifetime ends at the end
  732. of the return statement, so the value returned has a dangling pointer.
  733. </li><li> If a new-expression creates an <code>initializer_list</code>, the array only
  734. lives until the end of the enclosing full-expression, so the
  735. <code>initializer_list</code> in the heap has a dangling pointer.
  736. </li><li> When an <code>initializer_list</code> variable is assigned from a
  737. brace-enclosed initializer list, the temporary array created for the
  738. right side of the assignment only lives until the end of the
  739. full-expression, so at the next statement the <code>initializer_list</code>
  740. variable has a dangling pointer.
  741. <div class="smallexample">
  742. <pre class="smallexample">// li's initial underlying array lives as long as li
  743. std::initializer_list&lt;int&gt; li = { 1,2,3 };
  744. // assignment changes li to point to a temporary array
  745. li = { 4, 5 };
  746. // now the temporary is gone and li has a dangling pointer
  747. int i = li.begin()[0] // undefined behavior
  748. </pre></div>
  749. </li><li> When a list constructor stores the <code>begin</code> pointer from the
  750. <code>initializer_list</code> argument, this doesn&rsquo;t extend the lifetime of
  751. the array, so if a class variable is constructed from a temporary
  752. <code>initializer_list</code>, the pointer is left dangling by the end of
  753. the variable declaration statement.
  754. </li></ul>
  755. </dd>
  756. <dt><code>-Wno-literal-suffix <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  757. <dd><a name="index-Wliteral_002dsuffix"></a>
  758. <a name="index-Wno_002dliteral_002dsuffix"></a>
  759. <p>Do not warn when a string or character literal is followed by a
  760. ud-suffix which does not begin with an underscore. As a conforming
  761. extension, GCC treats such suffixes as separate preprocessing tokens
  762. in order to maintain backwards compatibility with code that uses
  763. formatting macros from <code>&lt;inttypes.h&gt;</code>. For example:
  764. </p>
  765. <div class="smallexample">
  766. <pre class="smallexample">#define __STDC_FORMAT_MACROS
  767. #include &lt;inttypes.h&gt;
  768. #include &lt;stdio.h&gt;
  769. int main() {
  770. int64_t i64 = 123;
  771. printf(&quot;My int64: %&quot; PRId64&quot;\n&quot;, i64);
  772. }
  773. </pre></div>
  774. <p>In this case, <code>PRId64</code> is treated as a separate preprocessing token.
  775. </p>
  776. <p>This option also controls warnings when a user-defined literal
  777. operator is declared with a literal suffix identifier that doesn&rsquo;t
  778. begin with an underscore. Literal suffix identifiers that don&rsquo;t begin
  779. with an underscore are reserved for future standardization.
  780. </p>
  781. <p>These warnings are enabled by default.
  782. </p>
  783. </dd>
  784. <dt><code>-Wno-narrowing <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  785. <dd><a name="index-Wnarrowing"></a>
  786. <a name="index-Wno_002dnarrowing"></a>
  787. <p>For C++11 and later standards, narrowing conversions are diagnosed by default,
  788. as required by the standard. A narrowing conversion from a constant produces
  789. an error, and a narrowing conversion from a non-constant produces a warning,
  790. but <samp>-Wno-narrowing</samp> suppresses the diagnostic.
  791. Note that this does not affect the meaning of well-formed code;
  792. narrowing conversions are still considered ill-formed in SFINAE contexts.
  793. </p>
  794. <p>With <samp>-Wnarrowing</samp> in C++98, warn when a narrowing
  795. conversion prohibited by C++11 occurs within
  796. &lsquo;<samp>{ }</samp>&rsquo;, e.g.
  797. </p>
  798. <div class="smallexample">
  799. <pre class="smallexample">int i = { 2.2 }; // error: narrowing from double to int
  800. </pre></div>
  801. <p>This flag is included in <samp>-Wall</samp> and <samp>-Wc++11-compat</samp>.
  802. </p>
  803. </dd>
  804. <dt><code>-Wnoexcept <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  805. <dd><a name="index-Wnoexcept"></a>
  806. <a name="index-Wno_002dnoexcept"></a>
  807. <p>Warn when a noexcept-expression evaluates to false because of a call
  808. to a function that does not have a non-throwing exception
  809. specification (i.e. <code>throw()</code> or <code>noexcept</code>) but is known by
  810. the compiler to never throw an exception.
  811. </p>
  812. </dd>
  813. <dt><code>-Wnoexcept-type <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  814. <dd><a name="index-Wnoexcept_002dtype"></a>
  815. <a name="index-Wno_002dnoexcept_002dtype"></a>
  816. <p>Warn if the C++17 feature making <code>noexcept</code> part of a function
  817. type changes the mangled name of a symbol relative to C++14. Enabled
  818. by <samp>-Wabi</samp> and <samp>-Wc++17-compat</samp>.
  819. </p>
  820. <p>As an example:
  821. </p>
  822. <div class="smallexample">
  823. <pre class="smallexample">template &lt;class T&gt; void f(T t) { t(); };
  824. void g() noexcept;
  825. void h() { f(g); }
  826. </pre></div>
  827. <p>In C++14, <code>f</code> calls <code>f&lt;void(*)()&gt;</code>, but in
  828. C++17 it calls <code>f&lt;void(*)()noexcept&gt;</code>.
  829. </p>
  830. </dd>
  831. <dt><code>-Wclass-memaccess <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  832. <dd><a name="index-Wclass_002dmemaccess"></a>
  833. <a name="index-Wno_002dclass_002dmemaccess"></a>
  834. <p>Warn when the destination of a call to a raw memory function such as
  835. <code>memset</code> or <code>memcpy</code> is an object of class type, and when writing
  836. into such an object might bypass the class non-trivial or deleted constructor
  837. or copy assignment, violate const-correctness or encapsulation, or corrupt
  838. virtual table pointers. Modifying the representation of such objects may
  839. violate invariants maintained by member functions of the class. For example,
  840. the call to <code>memset</code> below is undefined because it modifies a non-trivial
  841. class object and is, therefore, diagnosed. The safe way to either initialize
  842. or clear the storage of objects of such types is by using the appropriate
  843. constructor or assignment operator, if one is available.
  844. </p><div class="smallexample">
  845. <pre class="smallexample">std::string str = &quot;abc&quot;;
  846. memset (&amp;str, 0, sizeof str);
  847. </pre></div>
  848. <p>The <samp>-Wclass-memaccess</samp> option is enabled by <samp>-Wall</samp>.
  849. Explicitly casting the pointer to the class object to <code>void *</code> or
  850. to a type that can be safely accessed by the raw memory function suppresses
  851. the warning.
  852. </p>
  853. </dd>
  854. <dt><code>-Wnon-virtual-dtor <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  855. <dd><a name="index-Wnon_002dvirtual_002ddtor"></a>
  856. <a name="index-Wno_002dnon_002dvirtual_002ddtor"></a>
  857. <p>Warn when a class has virtual functions and an accessible non-virtual
  858. destructor itself or in an accessible polymorphic base class, in which
  859. case it is possible but unsafe to delete an instance of a derived
  860. class through a pointer to the class itself or base class. This
  861. warning is automatically enabled if <samp>-Weffc++</samp> is specified.
  862. </p>
  863. </dd>
  864. <dt><code>-Wregister <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  865. <dd><a name="index-Wregister"></a>
  866. <a name="index-Wno_002dregister"></a>
  867. <p>Warn on uses of the <code>register</code> storage class specifier, except
  868. when it is part of the GNU <a href="Explicit-Register-Variables.html#Explicit-Register-Variables">Explicit Register Variables</a> extension.
  869. The use of the <code>register</code> keyword as storage class specifier has
  870. been deprecated in C++11 and removed in C++17.
  871. Enabled by default with <samp>-std=c++17</samp>.
  872. </p>
  873. </dd>
  874. <dt><code>-Wreorder <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  875. <dd><a name="index-Wreorder"></a>
  876. <a name="index-Wno_002dreorder"></a>
  877. <a name="index-reordering_002c-warning"></a>
  878. <a name="index-warning-for-reordering-of-member-initializers"></a>
  879. <p>Warn when the order of member initializers given in the code does not
  880. match the order in which they must be executed. For instance:
  881. </p>
  882. <div class="smallexample">
  883. <pre class="smallexample">struct A {
  884. int i;
  885. int j;
  886. A(): j (0), i (1) { }
  887. };
  888. </pre></div>
  889. <p>The compiler rearranges the member initializers for <code>i</code>
  890. and <code>j</code> to match the declaration order of the members, emitting
  891. a warning to that effect. This warning is enabled by <samp>-Wall</samp>.
  892. </p>
  893. </dd>
  894. <dt><code>-Wno-pessimizing-move <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  895. <dd><a name="index-Wpessimizing_002dmove"></a>
  896. <a name="index-Wno_002dpessimizing_002dmove"></a>
  897. <p>This warning warns when a call to <code>std::move</code> prevents copy
  898. elision. A typical scenario when copy elision can occur is when returning in
  899. a function with a class return type, when the expression being returned is the
  900. name of a non-volatile automatic object, and is not a function parameter, and
  901. has the same type as the function return type.
  902. </p>
  903. <div class="smallexample">
  904. <pre class="smallexample">struct T {
  905. &hellip;
  906. };
  907. T fn()
  908. {
  909. T t;
  910. &hellip;
  911. return std::move (t);
  912. }
  913. </pre></div>
  914. <p>But in this example, the <code>std::move</code> call prevents copy elision.
  915. </p>
  916. <p>This warning is enabled by <samp>-Wall</samp>.
  917. </p>
  918. </dd>
  919. <dt><code>-Wno-redundant-move <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  920. <dd><a name="index-Wredundant_002dmove"></a>
  921. <a name="index-Wno_002dredundant_002dmove"></a>
  922. <p>This warning warns about redundant calls to <code>std::move</code>; that is, when
  923. a move operation would have been performed even without the <code>std::move</code>
  924. call. This happens because the compiler is forced to treat the object as if
  925. it were an rvalue in certain situations such as returning a local variable,
  926. where copy elision isn&rsquo;t applicable. Consider:
  927. </p>
  928. <div class="smallexample">
  929. <pre class="smallexample">struct T {
  930. &hellip;
  931. };
  932. T fn(T t)
  933. {
  934. &hellip;
  935. return std::move (t);
  936. }
  937. </pre></div>
  938. <p>Here, the <code>std::move</code> call is redundant. Because G++ implements Core
  939. Issue 1579, another example is:
  940. </p>
  941. <div class="smallexample">
  942. <pre class="smallexample">struct T { // convertible to U
  943. &hellip;
  944. };
  945. struct U {
  946. &hellip;
  947. };
  948. U fn()
  949. {
  950. T t;
  951. &hellip;
  952. return std::move (t);
  953. }
  954. </pre></div>
  955. <p>In this example, copy elision isn&rsquo;t applicable because the type of the
  956. expression being returned and the function return type differ, yet G++
  957. treats the return value as if it were designated by an rvalue.
  958. </p>
  959. <p>This warning is enabled by <samp>-Wextra</samp>.
  960. </p>
  961. </dd>
  962. <dt><code>-Wredundant-tags <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  963. <dd><a name="index-Wredundant_002dtags"></a>
  964. <a name="index-Wno_002dredundant_002dtags"></a>
  965. <p>Warn about redundant class-key and enum-key in references to class types
  966. and enumerated types in contexts where the key can be eliminated without
  967. causing an ambiguity. For example:
  968. </p>
  969. <div class="smallexample">
  970. <pre class="smallexample">struct foo;
  971. struct foo *p; // warn that keyword struct can be eliminated
  972. </pre></div>
  973. <p>On the other hand, in this example there is no warning:
  974. </p>
  975. <div class="smallexample">
  976. <pre class="smallexample">struct foo;
  977. void foo (); // &quot;hides&quot; struct foo
  978. void bar (struct foo&amp;); // no warning, keyword struct is necessary
  979. </pre></div>
  980. </dd>
  981. <dt><code>-Wno-subobject-linkage <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  982. <dd><a name="index-Wsubobject_002dlinkage"></a>
  983. <a name="index-Wno_002dsubobject_002dlinkage"></a>
  984. <p>Do not warn
  985. if a class type has a base or a field whose type uses the anonymous
  986. namespace or depends on a type with no linkage. If a type A depends on
  987. a type B with no or internal linkage, defining it in multiple
  988. translation units would be an ODR violation because the meaning of B
  989. is different in each translation unit. If A only appears in a single
  990. translation unit, the best way to silence the warning is to give it
  991. internal linkage by putting it in an anonymous namespace as well. The
  992. compiler doesn&rsquo;t give this warning for types defined in the main .C
  993. file, as those are unlikely to have multiple definitions.
  994. <samp>-Wsubobject-linkage</samp> is enabled by default.
  995. </p>
  996. </dd>
  997. <dt><code>-Weffc++ <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  998. <dd><a name="index-Weffc_002b_002b"></a>
  999. <a name="index-Wno_002deffc_002b_002b"></a>
  1000. <p>Warn about violations of the following style guidelines from Scott Meyers&rsquo;
  1001. <cite>Effective C++</cite> series of books:
  1002. </p>
  1003. <ul>
  1004. <li> Define a copy constructor and an assignment operator for classes
  1005. with dynamically-allocated memory.
  1006. </li><li> Prefer initialization to assignment in constructors.
  1007. </li><li> Have <code>operator=</code> return a reference to <code>*this</code>.
  1008. </li><li> Don&rsquo;t try to return a reference when you must return an object.
  1009. </li><li> Distinguish between prefix and postfix forms of increment and
  1010. decrement operators.
  1011. </li><li> Never overload <code>&amp;&amp;</code>, <code>||</code>, or <code>,</code>.
  1012. </li></ul>
  1013. <p>This option also enables <samp>-Wnon-virtual-dtor</samp>, which is also
  1014. one of the effective C++ recommendations. However, the check is
  1015. extended to warn about the lack of virtual destructor in accessible
  1016. non-polymorphic bases classes too.
  1017. </p>
  1018. <p>When selecting this option, be aware that the standard library
  1019. headers do not obey all of these guidelines; use &lsquo;<samp>grep -v</samp>&rsquo;
  1020. to filter out those warnings.
  1021. </p>
  1022. </dd>
  1023. <dt><code>-Wstrict-null-sentinel <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1024. <dd><a name="index-Wstrict_002dnull_002dsentinel"></a>
  1025. <a name="index-Wno_002dstrict_002dnull_002dsentinel"></a>
  1026. <p>Warn about the use of an uncasted <code>NULL</code> as sentinel. When
  1027. compiling only with GCC this is a valid sentinel, as <code>NULL</code> is defined
  1028. to <code>__null</code>. Although it is a null pointer constant rather than a
  1029. null pointer, it is guaranteed to be of the same size as a pointer.
  1030. But this use is not portable across different compilers.
  1031. </p>
  1032. </dd>
  1033. <dt><code>-Wno-non-template-friend <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1034. <dd><a name="index-Wno_002dnon_002dtemplate_002dfriend"></a>
  1035. <a name="index-Wnon_002dtemplate_002dfriend"></a>
  1036. <p>Disable warnings when non-template friend functions are declared
  1037. within a template. In very old versions of GCC that predate implementation
  1038. of the ISO standard, declarations such as
  1039. &lsquo;<samp>friend int foo(int)</samp>&rsquo;, where the name of the friend is an unqualified-id,
  1040. could be interpreted as a particular specialization of a template
  1041. function; the warning exists to diagnose compatibility problems,
  1042. and is enabled by default.
  1043. </p>
  1044. </dd>
  1045. <dt><code>-Wold-style-cast <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1046. <dd><a name="index-Wold_002dstyle_002dcast"></a>
  1047. <a name="index-Wno_002dold_002dstyle_002dcast"></a>
  1048. <p>Warn if an old-style (C-style) cast to a non-void type is used within
  1049. a C++ program. The new-style casts (<code>dynamic_cast</code>,
  1050. <code>static_cast</code>, <code>reinterpret_cast</code>, and <code>const_cast</code>) are
  1051. less vulnerable to unintended effects and much easier to search for.
  1052. </p>
  1053. </dd>
  1054. <dt><code>-Woverloaded-virtual <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1055. <dd><a name="index-Woverloaded_002dvirtual"></a>
  1056. <a name="index-Wno_002doverloaded_002dvirtual"></a>
  1057. <a name="index-overloaded-virtual-function_002c-warning"></a>
  1058. <a name="index-warning-for-overloaded-virtual-function"></a>
  1059. <p>Warn when a function declaration hides virtual functions from a
  1060. base class. For example, in:
  1061. </p>
  1062. <div class="smallexample">
  1063. <pre class="smallexample">struct A {
  1064. virtual void f();
  1065. };
  1066. struct B: public A {
  1067. void f(int);
  1068. };
  1069. </pre></div>
  1070. <p>the <code>A</code> class version of <code>f</code> is hidden in <code>B</code>, and code
  1071. like:
  1072. </p>
  1073. <div class="smallexample">
  1074. <pre class="smallexample">B* b;
  1075. b-&gt;f();
  1076. </pre></div>
  1077. <p>fails to compile.
  1078. </p>
  1079. </dd>
  1080. <dt><code>-Wno-pmf-conversions <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1081. <dd><a name="index-Wno_002dpmf_002dconversions"></a>
  1082. <a name="index-Wpmf_002dconversions"></a>
  1083. <p>Disable the diagnostic for converting a bound pointer to member function
  1084. to a plain pointer.
  1085. </p>
  1086. </dd>
  1087. <dt><code>-Wsign-promo <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1088. <dd><a name="index-Wsign_002dpromo"></a>
  1089. <a name="index-Wno_002dsign_002dpromo"></a>
  1090. <p>Warn when overload resolution chooses a promotion from unsigned or
  1091. enumerated type to a signed type, over a conversion to an unsigned type of
  1092. the same size. Previous versions of G++ tried to preserve
  1093. unsignedness, but the standard mandates the current behavior.
  1094. </p>
  1095. </dd>
  1096. <dt><code>-Wtemplates <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1097. <dd><a name="index-Wtemplates"></a>
  1098. <a name="index-Wno_002dtemplates"></a>
  1099. <p>Warn when a primary template declaration is encountered. Some coding
  1100. rules disallow templates, and this may be used to enforce that rule.
  1101. The warning is inactive inside a system header file, such as the STL, so
  1102. one can still use the STL. One may also instantiate or specialize
  1103. templates.
  1104. </p>
  1105. </dd>
  1106. <dt><code>-Wmismatched-tags <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1107. <dd><a name="index-Wmismatched_002dtags"></a>
  1108. <a name="index-Wno_002dmismatched_002dtags"></a>
  1109. <p>Warn for declarations of structs, classes, and class templates and their
  1110. specializations with a class-key that does not match either the definition
  1111. or the first declaration if no definition is provided.
  1112. </p>
  1113. <p>For example, the declaration of <code>struct Object</code> in the argument list
  1114. of <code>draw</code> triggers the warning. To avoid it, either remove the redundant
  1115. class-key <code>struct</code> or replace it with <code>class</code> to match its definition.
  1116. </p><div class="smallexample">
  1117. <pre class="smallexample">class Object {
  1118. public:
  1119. virtual ~Object () = 0;
  1120. };
  1121. void draw (struct Object*);
  1122. </pre></div>
  1123. <p>It is not wrong to declare a class with the class-key <code>struct</code> as
  1124. the example above shows. The <samp>-Wmismatched-tags</samp> option is intended
  1125. to help achieve a consistent style of class declarations. In code that is
  1126. intended to be portable to Windows-based compilers the warning helps prevent
  1127. unresolved references due to the difference in the mangling of symbols
  1128. declared with different class-keys. The option can be used either on its
  1129. own or in conjunction with <samp>-Wredundant-tags</samp>.
  1130. </p>
  1131. </dd>
  1132. <dt><code>-Wmultiple-inheritance <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1133. <dd><a name="index-Wmultiple_002dinheritance"></a>
  1134. <a name="index-Wno_002dmultiple_002dinheritance"></a>
  1135. <p>Warn when a class is defined with multiple direct base classes. Some
  1136. coding rules disallow multiple inheritance, and this may be used to
  1137. enforce that rule. The warning is inactive inside a system header file,
  1138. such as the STL, so one can still use the STL. One may also define
  1139. classes that indirectly use multiple inheritance.
  1140. </p>
  1141. </dd>
  1142. <dt><code>-Wvirtual-inheritance</code></dt>
  1143. <dd><a name="index-Wvirtual_002dinheritance"></a>
  1144. <a name="index-Wno_002dvirtual_002dinheritance"></a>
  1145. <p>Warn when a class is defined with a virtual direct base class. Some
  1146. coding rules disallow multiple inheritance, and this may be used to
  1147. enforce that rule. The warning is inactive inside a system header file,
  1148. such as the STL, so one can still use the STL. One may also define
  1149. classes that indirectly use virtual inheritance.
  1150. </p>
  1151. </dd>
  1152. <dt><code>-Wno-virtual-move-assign</code></dt>
  1153. <dd><a name="index-Wvirtual_002dmove_002dassign"></a>
  1154. <a name="index-Wno_002dvirtual_002dmove_002dassign"></a>
  1155. <p>Suppress warnings about inheriting from a virtual base with a
  1156. non-trivial C++11 move assignment operator. This is dangerous because
  1157. if the virtual base is reachable along more than one path, it is
  1158. moved multiple times, which can mean both objects end up in the
  1159. moved-from state. If the move assignment operator is written to avoid
  1160. moving from a moved-from object, this warning can be disabled.
  1161. </p>
  1162. </dd>
  1163. <dt><code>-Wnamespaces</code></dt>
  1164. <dd><a name="index-Wnamespaces"></a>
  1165. <a name="index-Wno_002dnamespaces"></a>
  1166. <p>Warn when a namespace definition is opened. Some coding rules disallow
  1167. namespaces, and this may be used to enforce that rule. The warning is
  1168. inactive inside a system header file, such as the STL, so one can still
  1169. use the STL. One may also use using directives and qualified names.
  1170. </p>
  1171. </dd>
  1172. <dt><code>-Wno-terminate <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1173. <dd><a name="index-Wterminate"></a>
  1174. <a name="index-Wno_002dterminate"></a>
  1175. <p>Disable the warning about a throw-expression that will immediately
  1176. result in a call to <code>terminate</code>.
  1177. </p>
  1178. </dd>
  1179. <dt><code>-Wno-class-conversion <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1180. <dd><a name="index-Wno_002dclass_002dconversion"></a>
  1181. <a name="index-Wclass_002dconversion"></a>
  1182. <p>Do not warn when a conversion function converts an
  1183. object to the same type, to a base class of that type, or to void; such
  1184. a conversion function will never be called.
  1185. </p>
  1186. </dd>
  1187. <dt><code>-Wvolatile <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1188. <dd><a name="index-Wvolatile"></a>
  1189. <a name="index-Wno_002dvolatile"></a>
  1190. <p>Warn about deprecated uses of the <code>volatile</code> qualifier. This includes
  1191. postfix and prefix <code>++</code> and <code>--</code> expressions of
  1192. <code>volatile</code>-qualified types, using simple assignments where the left
  1193. operand is a <code>volatile</code>-qualified non-class type for their value,
  1194. compound assignments where the left operand is a <code>volatile</code>-qualified
  1195. non-class type, <code>volatile</code>-qualified function return type,
  1196. <code>volatile</code>-qualified parameter type, and structured bindings of a
  1197. <code>volatile</code>-qualified type. This usage was deprecated in C++20.
  1198. </p>
  1199. <p>Enabled by default with <samp>-std=c++2a</samp>.
  1200. </p>
  1201. </dd>
  1202. <dt><code>-Wzero-as-null-pointer-constant <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1203. <dd><a name="index-Wzero_002das_002dnull_002dpointer_002dconstant"></a>
  1204. <a name="index-Wno_002dzero_002das_002dnull_002dpointer_002dconstant"></a>
  1205. <p>Warn when a literal &lsquo;<samp>0</samp>&rsquo; is used as null pointer constant. This can
  1206. be useful to facilitate the conversion to <code>nullptr</code> in C++11.
  1207. </p>
  1208. </dd>
  1209. <dt><code>-Waligned-new</code></dt>
  1210. <dd><a name="index-Waligned_002dnew"></a>
  1211. <a name="index-Wno_002daligned_002dnew"></a>
  1212. <p>Warn about a new-expression of a type that requires greater alignment
  1213. than the <code>alignof(std::max_align_t)</code> but uses an allocation
  1214. function without an explicit alignment parameter. This option is
  1215. enabled by <samp>-Wall</samp>.
  1216. </p>
  1217. <p>Normally this only warns about global allocation functions, but
  1218. <samp>-Waligned-new=all</samp> also warns about class member allocation
  1219. functions.
  1220. </p>
  1221. </dd>
  1222. <dt><code>-Wno-placement-new</code></dt>
  1223. <dt><code>-Wplacement-new=<var>n</var></code></dt>
  1224. <dd><a name="index-Wplacement_002dnew"></a>
  1225. <a name="index-Wno_002dplacement_002dnew"></a>
  1226. <p>Warn about placement new expressions with undefined behavior, such as
  1227. constructing an object in a buffer that is smaller than the type of
  1228. the object. For example, the placement new expression below is diagnosed
  1229. because it attempts to construct an array of 64 integers in a buffer only
  1230. 64 bytes large.
  1231. </p><div class="smallexample">
  1232. <pre class="smallexample">char buf [64];
  1233. new (buf) int[64];
  1234. </pre></div>
  1235. <p>This warning is enabled by default.
  1236. </p>
  1237. <dl compact="compact">
  1238. <dt><code>-Wplacement-new=1</code></dt>
  1239. <dd><p>This is the default warning level of <samp>-Wplacement-new</samp>. At this
  1240. level the warning is not issued for some strictly undefined constructs that
  1241. GCC allows as extensions for compatibility with legacy code. For example,
  1242. the following <code>new</code> expression is not diagnosed at this level even
  1243. though it has undefined behavior according to the C++ standard because
  1244. it writes past the end of the one-element array.
  1245. </p><div class="smallexample">
  1246. <pre class="smallexample">struct S { int n, a[1]; };
  1247. S *s = (S *)malloc (sizeof *s + 31 * sizeof s-&gt;a[0]);
  1248. new (s-&gt;a)int [32]();
  1249. </pre></div>
  1250. </dd>
  1251. <dt><code>-Wplacement-new=2</code></dt>
  1252. <dd><p>At this level, in addition to diagnosing all the same constructs as at level
  1253. 1, a diagnostic is also issued for placement new expressions that construct
  1254. an object in the last member of structure whose type is an array of a single
  1255. element and whose size is less than the size of the object being constructed.
  1256. While the previous example would be diagnosed, the following construct makes
  1257. use of the flexible member array extension to avoid the warning at level 2.
  1258. </p><div class="smallexample">
  1259. <pre class="smallexample">struct S { int n, a[]; };
  1260. S *s = (S *)malloc (sizeof *s + 32 * sizeof s-&gt;a[0]);
  1261. new (s-&gt;a)int [32]();
  1262. </pre></div>
  1263. </dd>
  1264. </dl>
  1265. </dd>
  1266. <dt><code>-Wcatch-value</code></dt>
  1267. <dt><code>-Wcatch-value=<var>n</var> <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1268. <dd><a name="index-Wcatch_002dvalue"></a>
  1269. <a name="index-Wno_002dcatch_002dvalue"></a>
  1270. <p>Warn about catch handlers that do not catch via reference.
  1271. With <samp>-Wcatch-value=1</samp> (or <samp>-Wcatch-value</samp> for short)
  1272. warn about polymorphic class types that are caught by value.
  1273. With <samp>-Wcatch-value=2</samp> warn about all class types that are caught
  1274. by value. With <samp>-Wcatch-value=3</samp> warn about all types that are
  1275. not caught by reference. <samp>-Wcatch-value</samp> is enabled by <samp>-Wall</samp>.
  1276. </p>
  1277. </dd>
  1278. <dt><code>-Wconditionally-supported <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1279. <dd><a name="index-Wconditionally_002dsupported"></a>
  1280. <a name="index-Wno_002dconditionally_002dsupported"></a>
  1281. <p>Warn for conditionally-supported (C++11 [intro.defs]) constructs.
  1282. </p>
  1283. </dd>
  1284. <dt><code>-Wno-delete-incomplete <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1285. <dd><a name="index-Wdelete_002dincomplete"></a>
  1286. <a name="index-Wno_002ddelete_002dincomplete"></a>
  1287. <p>Do not warn when deleting a pointer to incomplete type, which may cause
  1288. undefined behavior at runtime. This warning is enabled by default.
  1289. </p>
  1290. </dd>
  1291. <dt><code>-Wextra-semi <span class="roman">(C++, Objective-C++ only)</span></code></dt>
  1292. <dd><a name="index-Wextra_002dsemi"></a>
  1293. <a name="index-Wno_002dextra_002dsemi"></a>
  1294. <p>Warn about redundant semicolons after in-class function definitions.
  1295. </p>
  1296. </dd>
  1297. <dt><code>-Wno-inaccessible-base <span class="roman">(C++, Objective-C++ only)</span></code></dt>
  1298. <dd><a name="index-Winaccessible_002dbase"></a>
  1299. <a name="index-Wno_002dinaccessible_002dbase"></a>
  1300. <p>This option controls warnings
  1301. when a base class is inaccessible in a class derived from it due to
  1302. ambiguity. The warning is enabled by default.
  1303. Note that the warning for ambiguous virtual
  1304. bases is enabled by the <samp>-Wextra</samp> option.
  1305. </p><div class="smallexample">
  1306. <pre class="smallexample">struct A { int a; };
  1307. struct B : A { };
  1308. struct C : B, A { };
  1309. </pre></div>
  1310. </dd>
  1311. <dt><code>-Wno-inherited-variadic-ctor</code></dt>
  1312. <dd><a name="index-Winherited_002dvariadic_002dctor"></a>
  1313. <a name="index-Wno_002dinherited_002dvariadic_002dctor"></a>
  1314. <p>Suppress warnings about use of C++11 inheriting constructors when the
  1315. base class inherited from has a C variadic constructor; the warning is
  1316. on by default because the ellipsis is not inherited.
  1317. </p>
  1318. </dd>
  1319. <dt><code>-Wno-invalid-offsetof <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1320. <dd><a name="index-Wno_002dinvalid_002doffsetof"></a>
  1321. <a name="index-Winvalid_002doffsetof"></a>
  1322. <p>Suppress warnings from applying the <code>offsetof</code> macro to a non-POD
  1323. type. According to the 2014 ISO C++ standard, applying <code>offsetof</code>
  1324. to a non-standard-layout type is undefined. In existing C++ implementations,
  1325. however, <code>offsetof</code> typically gives meaningful results.
  1326. This flag is for users who are aware that they are
  1327. writing nonportable code and who have deliberately chosen to ignore the
  1328. warning about it.
  1329. </p>
  1330. <p>The restrictions on <code>offsetof</code> may be relaxed in a future version
  1331. of the C++ standard.
  1332. </p>
  1333. </dd>
  1334. <dt><code>-Wsized-deallocation <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1335. <dd><a name="index-Wsized_002ddeallocation"></a>
  1336. <a name="index-Wno_002dsized_002ddeallocation"></a>
  1337. <p>Warn about a definition of an unsized deallocation function
  1338. </p><div class="smallexample">
  1339. <pre class="smallexample">void operator delete (void *) noexcept;
  1340. void operator delete[] (void *) noexcept;
  1341. </pre></div>
  1342. <p>without a definition of the corresponding sized deallocation function
  1343. </p><div class="smallexample">
  1344. <pre class="smallexample">void operator delete (void *, std::size_t) noexcept;
  1345. void operator delete[] (void *, std::size_t) noexcept;
  1346. </pre></div>
  1347. <p>or vice versa. Enabled by <samp>-Wextra</samp> along with
  1348. <samp>-fsized-deallocation</samp>.
  1349. </p>
  1350. </dd>
  1351. <dt><code>-Wsuggest-final-types</code></dt>
  1352. <dd><a name="index-Wno_002dsuggest_002dfinal_002dtypes"></a>
  1353. <a name="index-Wsuggest_002dfinal_002dtypes"></a>
  1354. <p>Warn about types with virtual methods where code quality would be improved
  1355. if the type were declared with the C++11 <code>final</code> specifier,
  1356. or, if possible,
  1357. declared in an anonymous namespace. This allows GCC to more aggressively
  1358. devirtualize the polymorphic calls. This warning is more effective with
  1359. link-time optimization,
  1360. where the information about the class hierarchy graph is
  1361. more complete.
  1362. </p>
  1363. </dd>
  1364. <dt><code>-Wsuggest-final-methods</code></dt>
  1365. <dd><a name="index-Wno_002dsuggest_002dfinal_002dmethods"></a>
  1366. <a name="index-Wsuggest_002dfinal_002dmethods"></a>
  1367. <p>Warn about virtual methods where code quality would be improved if the method
  1368. were declared with the C++11 <code>final</code> specifier,
  1369. or, if possible, its type were
  1370. declared in an anonymous namespace or with the <code>final</code> specifier.
  1371. This warning is
  1372. more effective with link-time optimization, where the information about the
  1373. class hierarchy graph is more complete. It is recommended to first consider
  1374. suggestions of <samp>-Wsuggest-final-types</samp> and then rebuild with new
  1375. annotations.
  1376. </p>
  1377. </dd>
  1378. <dt><code>-Wsuggest-override</code></dt>
  1379. <dd><a name="index-Wsuggest_002doverride"></a>
  1380. <a name="index-Wno_002dsuggest_002doverride"></a>
  1381. <p>Warn about overriding virtual functions that are not marked with the
  1382. <code>override</code> keyword.
  1383. </p>
  1384. </dd>
  1385. <dt><code>-Wuseless-cast <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1386. <dd><a name="index-Wuseless_002dcast"></a>
  1387. <a name="index-Wno_002duseless_002dcast"></a>
  1388. <p>Warn when an expression is casted to its own type.
  1389. </p>
  1390. </dd>
  1391. <dt><code>-Wno-conversion-null <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  1392. <dd><a name="index-Wconversion_002dnull"></a>
  1393. <a name="index-Wno_002dconversion_002dnull"></a>
  1394. <p>Do not warn for conversions between <code>NULL</code> and non-pointer
  1395. types. <samp>-Wconversion-null</samp> is enabled by default.
  1396. </p>
  1397. </dd>
  1398. </dl>
  1399. <hr>
  1400. <div class="header">
  1401. <p>
  1402. 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>
  1403. </div>
  1404. </body>
  1405. </html>