Warning-Options.html 147 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358
  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): Warning Options</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Warning Options">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Warning 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="Debugging-Options.html#Debugging-Options" rel="next" title="Debugging Options">
  31. <link href="Diagnostic-Message-Formatting-Options.html#Diagnostic-Message-Formatting-Options" rel="prev" title="Diagnostic Message Formatting 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="Warning-Options"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Debugging-Options.html#Debugging-Options" accesskey="n" rel="next">Debugging Options</a>, Previous: <a href="Diagnostic-Message-Formatting-Options.html#Diagnostic-Message-Formatting-Options" accesskey="p" rel="prev">Diagnostic Message Formatting 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-to-Request-or-Suppress-Warnings"></a>
  69. <h3 class="section">3.8 Options to Request or Suppress Warnings</h3>
  70. <a name="index-options-to-control-warnings"></a>
  71. <a name="index-warning-messages"></a>
  72. <a name="index-messages_002c-warning"></a>
  73. <a name="index-suppressing-warnings"></a>
  74. <p>Warnings are diagnostic messages that report constructions that
  75. are not inherently erroneous but that are risky or suggest there
  76. may have been an error.
  77. </p>
  78. <p>The following language-independent options do not enable specific
  79. warnings but control the kinds of diagnostics produced by GCC.
  80. </p>
  81. <dl compact="compact">
  82. <dd><a name="index-syntax-checking"></a>
  83. </dd>
  84. <dt><code>-fsyntax-only</code></dt>
  85. <dd><a name="index-fsyntax_002donly"></a>
  86. <p>Check the code for syntax errors, but don&rsquo;t do anything beyond that.
  87. </p>
  88. </dd>
  89. <dt><code>-fmax-errors=<var>n</var></code></dt>
  90. <dd><a name="index-fmax_002derrors"></a>
  91. <p>Limits the maximum number of error messages to <var>n</var>, at which point
  92. GCC bails out rather than attempting to continue processing the source
  93. code. If <var>n</var> is 0 (the default), there is no limit on the number
  94. of error messages produced. If <samp>-Wfatal-errors</samp> is also
  95. specified, then <samp>-Wfatal-errors</samp> takes precedence over this
  96. option.
  97. </p>
  98. </dd>
  99. <dt><code>-w</code></dt>
  100. <dd><a name="index-w"></a>
  101. <p>Inhibit all warning messages.
  102. </p>
  103. </dd>
  104. <dt><code>-Werror</code></dt>
  105. <dd><a name="index-Werror"></a>
  106. <a name="index-Wno_002derror"></a>
  107. <p>Make all warnings into errors.
  108. </p>
  109. </dd>
  110. <dt><code>-Werror=</code></dt>
  111. <dd><a name="index-Werror_003d"></a>
  112. <a name="index-Wno_002derror_003d"></a>
  113. <p>Make the specified warning into an error. The specifier for a warning
  114. is appended; for example <samp>-Werror=switch</samp> turns the warnings
  115. controlled by <samp>-Wswitch</samp> into errors. This switch takes a
  116. negative form, to be used to negate <samp>-Werror</samp> for specific
  117. warnings; for example <samp>-Wno-error=switch</samp> makes
  118. <samp>-Wswitch</samp> warnings not be errors, even when <samp>-Werror</samp>
  119. is in effect.
  120. </p>
  121. <p>The warning message for each controllable warning includes the
  122. option that controls the warning. That option can then be used with
  123. <samp>-Werror=</samp> and <samp>-Wno-error=</samp> as described above.
  124. (Printing of the option in the warning message can be disabled using the
  125. <samp>-fno-diagnostics-show-option</samp> flag.)
  126. </p>
  127. <p>Note that specifying <samp>-Werror=</samp><var>foo</var> automatically implies
  128. <samp>-W</samp><var>foo</var>. However, <samp>-Wno-error=</samp><var>foo</var> does not
  129. imply anything.
  130. </p>
  131. </dd>
  132. <dt><code>-Wfatal-errors</code></dt>
  133. <dd><a name="index-Wfatal_002derrors"></a>
  134. <a name="index-Wno_002dfatal_002derrors"></a>
  135. <p>This option causes the compiler to abort compilation on the first error
  136. occurred rather than trying to keep going and printing further error
  137. messages.
  138. </p>
  139. </dd>
  140. </dl>
  141. <p>You can request many specific warnings with options beginning with
  142. &lsquo;<samp>-W</samp>&rsquo;, for example <samp>-Wimplicit</samp> to request warnings on
  143. implicit declarations. Each of these specific warning options also
  144. has a negative form beginning &lsquo;<samp>-Wno-</samp>&rsquo; to turn off warnings; for
  145. example, <samp>-Wno-implicit</samp>. This manual lists only one of the
  146. two forms, whichever is not the default. For further
  147. language-specific options also refer to <a href="C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options">C++ Dialect Options</a> and
  148. <a href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options">Objective-C and Objective-C++ Dialect Options</a>.
  149. </p>
  150. <p>Some options, such as <samp>-Wall</samp> and <samp>-Wextra</samp>, turn on other
  151. options, such as <samp>-Wunused</samp>, which may turn on further options,
  152. such as <samp>-Wunused-value</samp>. The combined effect of positive and
  153. negative forms is that more specific options have priority over less
  154. specific ones, independently of their position in the command-line. For
  155. options of the same specificity, the last one takes effect. Options
  156. enabled or disabled via pragmas (see <a href="Diagnostic-Pragmas.html#Diagnostic-Pragmas">Diagnostic Pragmas</a>) take effect
  157. as if they appeared at the end of the command-line.
  158. </p>
  159. <p>When an unrecognized warning option is requested (e.g.,
  160. <samp>-Wunknown-warning</samp>), GCC emits a diagnostic stating
  161. that the option is not recognized. However, if the <samp>-Wno-</samp> form
  162. is used, the behavior is slightly different: no diagnostic is
  163. produced for <samp>-Wno-unknown-warning</samp> unless other diagnostics
  164. are being produced. This allows the use of new <samp>-Wno-</samp> options
  165. with old compilers, but if something goes wrong, the compiler
  166. warns that an unrecognized option is present.
  167. </p>
  168. <dl compact="compact">
  169. <dt><code>-Wpedantic</code></dt>
  170. <dt><code>-pedantic</code></dt>
  171. <dd><a name="index-pedantic-1"></a>
  172. <a name="index-Wpedantic"></a>
  173. <p>Issue all the warnings demanded by strict ISO C and ISO C++;
  174. reject all programs that use forbidden extensions, and some other
  175. programs that do not follow ISO C and ISO C++. For ISO C, follows the
  176. version of the ISO C standard specified by any <samp>-std</samp> option used.
  177. </p>
  178. <p>Valid ISO C and ISO C++ programs should compile properly with or without
  179. this option (though a rare few require <samp>-ansi</samp> or a
  180. <samp>-std</samp> option specifying the required version of ISO C). However,
  181. without this option, certain GNU extensions and traditional C and C++
  182. features are supported as well. With this option, they are rejected.
  183. </p>
  184. <p><samp>-Wpedantic</samp> does not cause warning messages for use of the
  185. alternate keywords whose names begin and end with &lsquo;<samp>__</samp>&rsquo;. Pedantic
  186. warnings are also disabled in the expression that follows
  187. <code>__extension__</code>. However, only system header files should use
  188. these escape routes; application programs should avoid them.
  189. See <a href="Alternate-Keywords.html#Alternate-Keywords">Alternate Keywords</a>.
  190. </p>
  191. <p>Some users try to use <samp>-Wpedantic</samp> to check programs for strict ISO
  192. C conformance. They soon find that it does not do quite what they want:
  193. it finds some non-ISO practices, but not all&mdash;only those for which
  194. ISO C <em>requires</em> a diagnostic, and some others for which
  195. diagnostics have been added.
  196. </p>
  197. <p>A feature to report any failure to conform to ISO C might be useful in
  198. some instances, but would require considerable additional work and would
  199. be quite different from <samp>-Wpedantic</samp>. We don&rsquo;t have plans to
  200. support such a feature in the near future.
  201. </p>
  202. <p>Where the standard specified with <samp>-std</samp> represents a GNU
  203. extended dialect of C, such as &lsquo;<samp>gnu90</samp>&rsquo; or &lsquo;<samp>gnu99</samp>&rsquo;, there is a
  204. corresponding <em>base standard</em>, the version of ISO C on which the GNU
  205. extended dialect is based. Warnings from <samp>-Wpedantic</samp> are given
  206. where they are required by the base standard. (It does not make sense
  207. for such warnings to be given only for features not in the specified GNU
  208. C dialect, since by definition the GNU dialects of C include all
  209. features the compiler supports with the given option, and there would be
  210. nothing to warn about.)
  211. </p>
  212. </dd>
  213. <dt><code>-pedantic-errors</code></dt>
  214. <dd><a name="index-pedantic_002derrors-1"></a>
  215. <p>Give an error whenever the <em>base standard</em> (see <samp>-Wpedantic</samp>)
  216. requires a diagnostic, in some cases where there is undefined behavior
  217. at compile-time and in some other cases that do not prevent compilation
  218. of programs that are valid according to the standard. This is not
  219. equivalent to <samp>-Werror=pedantic</samp>, since there are errors enabled
  220. by this option and not enabled by the latter and vice versa.
  221. </p>
  222. </dd>
  223. <dt><code>-Wall</code></dt>
  224. <dd><a name="index-Wall"></a>
  225. <a name="index-Wno_002dall"></a>
  226. <p>This enables all the warnings about constructions that some users
  227. consider questionable, and that are easy to avoid (or modify to
  228. prevent the warning), even in conjunction with macros. This also
  229. enables some language-specific warnings described in <a href="C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options">C++ Dialect Options</a> and <a href="Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html#Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options">Objective-C and Objective-C++ Dialect Options</a>.
  230. </p>
  231. <p><samp>-Wall</samp> turns on the following warning flags:
  232. </p>
  233. <div class="smallexample">
  234. <pre class="smallexample">-Waddress
  235. -Warray-bounds=1 <span class="roman">(only with</span> <samp>-O2</samp><span class="roman">)</span>
  236. -Wbool-compare
  237. -Wbool-operation
  238. -Wc++11-compat -Wc++14-compat
  239. -Wchar-subscripts
  240. -Wcomment
  241. -Wduplicate-decl-specifier <span class="roman">(C and Objective-C only)</span>
  242. -Wenum-compare <span class="roman">(in C/ObjC; this is on by default in C++)</span>
  243. -Wformat
  244. -Wint-in-bool-context
  245. -Wimplicit <span class="roman">(C and Objective-C only)</span>
  246. -Wimplicit-int <span class="roman">(C and Objective-C only)</span>
  247. -Wimplicit-function-declaration <span class="roman">(C and Objective-C only)</span>
  248. -Winit-self <span class="roman">(only for C++)</span>
  249. -Wlogical-not-parentheses
  250. -Wmain <span class="roman">(only for C/ObjC and unless</span> <samp>-ffreestanding</samp><span class="roman">)</span>
  251. -Wmaybe-uninitialized
  252. -Wmemset-elt-size
  253. -Wmemset-transposed-args
  254. -Wmisleading-indentation <span class="roman">(only for C/C++)</span>
  255. -Wmissing-braces <span class="roman">(only for C/ObjC)</span>
  256. -Wnarrowing <span class="roman">(only for C++)</span>
  257. -Wnonnull
  258. -Wnonnull-compare
  259. -Wopenmp-simd
  260. -Wparentheses
  261. -Wpointer-sign
  262. -Wreorder
  263. -Wreturn-type
  264. -Wsequence-point
  265. -Wsign-compare <span class="roman">(only in C++)</span>
  266. -Wsizeof-pointer-memaccess
  267. -Wstrict-aliasing
  268. -Wstrict-overflow=1
  269. -Wswitch
  270. -Wtautological-compare
  271. -Wtrigraphs
  272. -Wuninitialized
  273. -Wunknown-pragmas
  274. -Wunused-function
  275. -Wunused-label
  276. -Wunused-value
  277. -Wunused-variable
  278. -Wvolatile-register-var
  279. </pre></div>
  280. <p>Note that some warning flags are not implied by <samp>-Wall</samp>. Some of
  281. them warn about constructions that users generally do not consider
  282. questionable, but which occasionally you might wish to check for;
  283. others warn about constructions that are necessary or hard to avoid in
  284. some cases, and there is no simple way to modify the code to suppress
  285. the warning. Some of them are enabled by <samp>-Wextra</samp> but many of
  286. them must be enabled individually.
  287. </p>
  288. </dd>
  289. <dt><code>-Wextra</code></dt>
  290. <dd><a name="index-W"></a>
  291. <a name="index-Wextra"></a>
  292. <a name="index-Wno_002dextra"></a>
  293. <p>This enables some extra warning flags that are not enabled by
  294. <samp>-Wall</samp>. (This option used to be called <samp>-W</samp>. The older
  295. name is still supported, but the newer name is more descriptive.)
  296. </p>
  297. <div class="smallexample">
  298. <pre class="smallexample">-Wclobbered
  299. -Wempty-body
  300. -Wignored-qualifiers
  301. -Wimplicit-fallthrough=3
  302. -Wmissing-field-initializers
  303. -Wmissing-parameter-type <span class="roman">(C only)</span>
  304. -Wold-style-declaration <span class="roman">(C only)</span>
  305. -Woverride-init
  306. -Wsign-compare <span class="roman">(C only)</span>
  307. -Wtype-limits
  308. -Wuninitialized
  309. -Wshift-negative-value <span class="roman">(in C++03 and in C99 and newer)</span>
  310. -Wunused-parameter <span class="roman">(only with</span> <samp>-Wunused</samp> <span class="roman">or</span> <samp>-Wall</samp><span class="roman">)</span>
  311. -Wunused-but-set-parameter <span class="roman">(only with</span> <samp>-Wunused</samp> <span class="roman">or</span> <samp>-Wall</samp><span class="roman">)</span>
  312. </pre></div>
  313. <p>The option <samp>-Wextra</samp> also prints warning messages for the
  314. following cases:
  315. </p>
  316. <ul>
  317. <li> A pointer is compared against integer zero with <code>&lt;</code>, <code>&lt;=</code>,
  318. <code>&gt;</code>, or <code>&gt;=</code>.
  319. </li><li> (C++ only) An enumerator and a non-enumerator both appear in a
  320. conditional expression.
  321. </li><li> (C++ only) Ambiguous virtual bases.
  322. </li><li> (C++ only) Subscripting an array that has been declared <code>register</code>.
  323. </li><li> (C++ only) Taking the address of a variable that has been declared
  324. <code>register</code>.
  325. </li><li> (C++ only) A base class is not initialized in the copy constructor
  326. of a derived class.
  327. </li></ul>
  328. </dd>
  329. <dt><code>-Wchar-subscripts</code></dt>
  330. <dd><a name="index-Wchar_002dsubscripts"></a>
  331. <a name="index-Wno_002dchar_002dsubscripts"></a>
  332. <p>Warn if an array subscript has type <code>char</code>. This is a common cause
  333. of error, as programmers often forget that this type is signed on some
  334. machines.
  335. This warning is enabled by <samp>-Wall</samp>.
  336. </p>
  337. </dd>
  338. <dt><code>-Wchkp</code></dt>
  339. <dd><a name="index-Wchkp"></a>
  340. <p>Warn about an invalid memory access that is found by Pointer Bounds Checker
  341. (<samp>-fcheck-pointer-bounds</samp>).
  342. </p>
  343. </dd>
  344. <dt><code>-Wno-coverage-mismatch</code></dt>
  345. <dd><a name="index-Wno_002dcoverage_002dmismatch"></a>
  346. <p>Warn if feedback profiles do not match when using the
  347. <samp>-fprofile-use</samp> option.
  348. If a source file is changed between compiling with <samp>-fprofile-gen</samp> and
  349. with <samp>-fprofile-use</samp>, the files with the profile feedback can fail
  350. to match the source file and GCC cannot use the profile feedback
  351. information. By default, this warning is enabled and is treated as an
  352. error. <samp>-Wno-coverage-mismatch</samp> can be used to disable the
  353. warning or <samp>-Wno-error=coverage-mismatch</samp> can be used to
  354. disable the error. Disabling the error for this warning can result in
  355. poorly optimized code and is useful only in the
  356. case of very minor changes such as bug fixes to an existing code-base.
  357. Completely disabling the warning is not recommended.
  358. </p>
  359. </dd>
  360. <dt><code>-Wno-cpp</code></dt>
  361. <dd><p><span class="roman">(C, Objective-C, C++, Objective-C++ and Fortran only)</span>
  362. </p>
  363. <p>Suppress warning messages emitted by <code>#warning</code> directives.
  364. </p>
  365. </dd>
  366. <dt><code>-Wdouble-promotion <span class="roman">(C, C++, Objective-C and Objective-C++ only)</span></code></dt>
  367. <dd><a name="index-Wdouble_002dpromotion"></a>
  368. <a name="index-Wno_002ddouble_002dpromotion"></a>
  369. <p>Give a warning when a value of type <code>float</code> is implicitly
  370. promoted to <code>double</code>. CPUs with a 32-bit &ldquo;single-precision&rdquo;
  371. floating-point unit implement <code>float</code> in hardware, but emulate
  372. <code>double</code> in software. On such a machine, doing computations
  373. using <code>double</code> values is much more expensive because of the
  374. overhead required for software emulation.
  375. </p>
  376. <p>It is easy to accidentally do computations with <code>double</code> because
  377. floating-point literals are implicitly of type <code>double</code>. For
  378. example, in:
  379. </p><div class="smallexample">
  380. <pre class="smallexample">float area(float radius)
  381. {
  382. return 3.14159 * radius * radius;
  383. }
  384. </pre></div>
  385. <p>the compiler performs the entire computation with <code>double</code>
  386. because the floating-point literal is a <code>double</code>.
  387. </p>
  388. </dd>
  389. <dt><code>-Wduplicate-decl-specifier <span class="roman">(C and Objective-C only)</span></code></dt>
  390. <dd><a name="index-Wduplicate_002ddecl_002dspecifier"></a>
  391. <a name="index-Wno_002dduplicate_002ddecl_002dspecifier"></a>
  392. <p>Warn if a declaration has duplicate <code>const</code>, <code>volatile</code>,
  393. <code>restrict</code> or <code>_Atomic</code> specifier. This warning is enabled by
  394. <samp>-Wall</samp>.
  395. </p>
  396. </dd>
  397. <dt><code>-Wformat</code></dt>
  398. <dt><code>-Wformat=<var>n</var></code></dt>
  399. <dd><a name="index-Wformat"></a>
  400. <a name="index-Wno_002dformat"></a>
  401. <a name="index-ffreestanding-2"></a>
  402. <a name="index-fno_002dbuiltin-1"></a>
  403. <a name="index-Wformat_003d"></a>
  404. <p>Check calls to <code>printf</code> and <code>scanf</code>, etc., to make sure that
  405. the arguments supplied have types appropriate to the format string
  406. specified, and that the conversions specified in the format string make
  407. sense. This includes standard functions, and others specified by format
  408. attributes (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>), in the <code>printf</code>,
  409. <code>scanf</code>, <code>strftime</code> and <code>strfmon</code> (an X/Open extension,
  410. not in the C standard) families (or other target-specific families).
  411. Which functions are checked without format attributes having been
  412. specified depends on the standard version selected, and such checks of
  413. functions without the attribute specified are disabled by
  414. <samp>-ffreestanding</samp> or <samp>-fno-builtin</samp>.
  415. </p>
  416. <p>The formats are checked against the format features supported by GNU
  417. libc version 2.2. These include all ISO C90 and C99 features, as well
  418. as features from the Single Unix Specification and some BSD and GNU
  419. extensions. Other library implementations may not support all these
  420. features; GCC does not support warning about features that go beyond a
  421. particular library&rsquo;s limitations. However, if <samp>-Wpedantic</samp> is used
  422. with <samp>-Wformat</samp>, warnings are given about format features not
  423. in the selected standard version (but not for <code>strfmon</code> formats,
  424. since those are not in any version of the C standard). See <a href="C-Dialect-Options.html#C-Dialect-Options">Options Controlling C Dialect</a>.
  425. </p>
  426. <dl compact="compact">
  427. <dt><code>-Wformat=1</code></dt>
  428. <dt><code>-Wformat</code></dt>
  429. <dd><a name="index-Wformat-1"></a>
  430. <a name="index-Wformat_003d1"></a>
  431. <p>Option <samp>-Wformat</samp> is equivalent to <samp>-Wformat=1</samp>, and
  432. <samp>-Wno-format</samp> is equivalent to <samp>-Wformat=0</samp>. Since
  433. <samp>-Wformat</samp> also checks for null format arguments for several
  434. functions, <samp>-Wformat</samp> also implies <samp>-Wnonnull</samp>. Some
  435. aspects of this level of format checking can be disabled by the
  436. options: <samp>-Wno-format-contains-nul</samp>,
  437. <samp>-Wno-format-extra-args</samp>, and <samp>-Wno-format-zero-length</samp>.
  438. <samp>-Wformat</samp> is enabled by <samp>-Wall</samp>.
  439. </p>
  440. </dd>
  441. <dt><code>-Wno-format-contains-nul</code></dt>
  442. <dd><a name="index-Wno_002dformat_002dcontains_002dnul"></a>
  443. <a name="index-Wformat_002dcontains_002dnul"></a>
  444. <p>If <samp>-Wformat</samp> is specified, do not warn about format strings that
  445. contain NUL bytes.
  446. </p>
  447. </dd>
  448. <dt><code>-Wno-format-extra-args</code></dt>
  449. <dd><a name="index-Wno_002dformat_002dextra_002dargs"></a>
  450. <a name="index-Wformat_002dextra_002dargs"></a>
  451. <p>If <samp>-Wformat</samp> is specified, do not warn about excess arguments to a
  452. <code>printf</code> or <code>scanf</code> format function. The C standard specifies
  453. that such arguments are ignored.
  454. </p>
  455. <p>Where the unused arguments lie between used arguments that are
  456. specified with &lsquo;<samp>$</samp>&rsquo; operand number specifications, normally
  457. warnings are still given, since the implementation could not know what
  458. type to pass to <code>va_arg</code> to skip the unused arguments. However,
  459. in the case of <code>scanf</code> formats, this option suppresses the
  460. warning if the unused arguments are all pointers, since the Single
  461. Unix Specification says that such unused arguments are allowed.
  462. </p>
  463. </dd>
  464. <dt><code>-Wformat-overflow</code></dt>
  465. <dt><code>-Wformat-overflow=<var>level</var></code></dt>
  466. <dd><a name="index-Wformat_002doverflow"></a>
  467. <a name="index-Wno_002dformat_002doverflow"></a>
  468. <p>Warn about calls to formatted input/output functions such as <code>sprintf</code>
  469. and <code>vsprintf</code> that might overflow the destination buffer. When the
  470. exact number of bytes written by a format directive cannot be determined
  471. at compile-time it is estimated based on heuristics that depend on the
  472. <var>level</var> argument and on optimization. While enabling optimization
  473. will in most cases improve the accuracy of the warning, it may also
  474. result in false positives.
  475. </p>
  476. <dl compact="compact">
  477. <dt><code>-Wformat-overflow</code></dt>
  478. <dt><code>-Wformat-overflow=1</code></dt>
  479. <dd><a name="index-Wformat_002doverflow-1"></a>
  480. <a name="index-Wno_002dformat_002doverflow-1"></a>
  481. <p>Level <var>1</var> of <samp>-Wformat-overflow</samp> enabled by <samp>-Wformat</samp>
  482. employs a conservative approach that warns only about calls that most
  483. likely overflow the buffer. At this level, numeric arguments to format
  484. directives with unknown values are assumed to have the value of one, and
  485. strings of unknown length to be empty. Numeric arguments that are known
  486. to be bounded to a subrange of their type, or string arguments whose output
  487. is bounded either by their directive&rsquo;s precision or by a finite set of
  488. string literals, are assumed to take on the value within the range that
  489. results in the most bytes on output. For example, the call to <code>sprintf</code>
  490. below is diagnosed because even with both <var>a</var> and <var>b</var> equal to zero,
  491. the terminating NUL character (<code>'\0'</code>) appended by the function
  492. to the destination buffer will be written past its end. Increasing
  493. the size of the buffer by a single byte is sufficient to avoid the
  494. warning, though it may not be sufficient to avoid the overflow.
  495. </p>
  496. <div class="smallexample">
  497. <pre class="smallexample">void f (int a, int b)
  498. {
  499. char buf [12];
  500. sprintf (buf, &quot;a = %i, b = %i\n&quot;, a, b);
  501. }
  502. </pre></div>
  503. </dd>
  504. <dt><code>-Wformat-overflow=2</code></dt>
  505. <dd><p>Level <var>2</var> warns also about calls that might overflow the destination
  506. buffer given an argument of sufficient length or magnitude. At level
  507. <var>2</var>, unknown numeric arguments are assumed to have the minimum
  508. representable value for signed types with a precision greater than 1, and
  509. the maximum representable value otherwise. Unknown string arguments whose
  510. length cannot be assumed to be bounded either by the directive&rsquo;s precision,
  511. or by a finite set of string literals they may evaluate to, or the character
  512. array they may point to, are assumed to be 1 character long.
  513. </p>
  514. <p>At level <var>2</var>, the call in the example above is again diagnosed, but
  515. this time because with <var>a</var> equal to a 32-bit <code>INT_MIN</code> the first
  516. <code>%i</code> directive will write some of its digits beyond the end of
  517. the destination buffer. To make the call safe regardless of the values
  518. of the two variables, the size of the destination buffer must be increased
  519. to at least 34 bytes. GCC includes the minimum size of the buffer in
  520. an informational note following the warning.
  521. </p>
  522. <p>An alternative to increasing the size of the destination buffer is to
  523. constrain the range of formatted values. The maximum length of string
  524. arguments can be bounded by specifying the precision in the format
  525. directive. When numeric arguments of format directives can be assumed
  526. to be bounded by less than the precision of their type, choosing
  527. an appropriate length modifier to the format specifier will reduce
  528. the required buffer size. For example, if <var>a</var> and <var>b</var> in the
  529. example above can be assumed to be within the precision of
  530. the <code>short int</code> type then using either the <code>%hi</code> format
  531. directive or casting the argument to <code>short</code> reduces the maximum
  532. required size of the buffer to 24 bytes.
  533. </p>
  534. <div class="smallexample">
  535. <pre class="smallexample">void f (int a, int b)
  536. {
  537. char buf [23];
  538. sprintf (buf, &quot;a = %hi, b = %i\n&quot;, a, (short)b);
  539. }
  540. </pre></div>
  541. </dd>
  542. </dl>
  543. </dd>
  544. <dt><code>-Wno-format-zero-length</code></dt>
  545. <dd><a name="index-Wno_002dformat_002dzero_002dlength"></a>
  546. <a name="index-Wformat_002dzero_002dlength"></a>
  547. <p>If <samp>-Wformat</samp> is specified, do not warn about zero-length formats.
  548. The C standard specifies that zero-length formats are allowed.
  549. </p>
  550. </dd>
  551. <dt><code>-Wformat=2</code></dt>
  552. <dd><a name="index-Wformat_003d2"></a>
  553. <p>Enable <samp>-Wformat</samp> plus additional format checks. Currently
  554. equivalent to <samp>-Wformat -Wformat-nonliteral -Wformat-security
  555. -Wformat-y2k</samp>.
  556. </p>
  557. </dd>
  558. <dt><code>-Wformat-nonliteral</code></dt>
  559. <dd><a name="index-Wformat_002dnonliteral"></a>
  560. <a name="index-Wno_002dformat_002dnonliteral"></a>
  561. <p>If <samp>-Wformat</samp> is specified, also warn if the format string is not a
  562. string literal and so cannot be checked, unless the format function
  563. takes its format arguments as a <code>va_list</code>.
  564. </p>
  565. </dd>
  566. <dt><code>-Wformat-security</code></dt>
  567. <dd><a name="index-Wformat_002dsecurity"></a>
  568. <a name="index-Wno_002dformat_002dsecurity"></a>
  569. <p>If <samp>-Wformat</samp> is specified, also warn about uses of format
  570. functions that represent possible security problems. At present, this
  571. warns about calls to <code>printf</code> and <code>scanf</code> functions where the
  572. format string is not a string literal and there are no format arguments,
  573. as in <code>printf (foo);</code>. This may be a security hole if the format
  574. string came from untrusted input and contains &lsquo;<samp>%n</samp>&rsquo;. (This is
  575. currently a subset of what <samp>-Wformat-nonliteral</samp> warns about, but
  576. in future warnings may be added to <samp>-Wformat-security</samp> that are not
  577. included in <samp>-Wformat-nonliteral</samp>.)
  578. </p>
  579. </dd>
  580. <dt><code>-Wformat-signedness</code></dt>
  581. <dd><a name="index-Wformat_002dsignedness"></a>
  582. <a name="index-Wno_002dformat_002dsignedness"></a>
  583. <p>If <samp>-Wformat</samp> is specified, also warn if the format string
  584. requires an unsigned argument and the argument is signed and vice versa.
  585. </p>
  586. </dd>
  587. <dt><code>-Wformat-truncation</code></dt>
  588. <dt><code>-Wformat-truncation=<var>level</var></code></dt>
  589. <dd><a name="index-Wformat_002dtruncation"></a>
  590. <a name="index-Wno_002dformat_002dtruncation"></a>
  591. <p>Warn about calls to formatted input/output functions such as <code>snprintf</code>
  592. and <code>vsnprintf</code> that might result in output truncation. When the exact
  593. number of bytes written by a format directive cannot be determined at
  594. compile-time it is estimated based on heuristics that depend on
  595. the <var>level</var> argument and on optimization. While enabling optimization
  596. will in most cases improve the accuracy of the warning, it may also result
  597. in false positives. Except as noted otherwise, the option uses the same
  598. logic <samp>-Wformat-overflow</samp>.
  599. </p>
  600. <dl compact="compact">
  601. <dt><code>-Wformat-truncation</code></dt>
  602. <dt><code>-Wformat-truncation=1</code></dt>
  603. <dd><a name="index-Wformat_002dtruncation-1"></a>
  604. <a name="index-Wno_002dformat_002doverflow-2"></a>
  605. <p>Level <var>1</var> of <samp>-Wformat-truncation</samp> enabled by <samp>-Wformat</samp>
  606. employs a conservative approach that warns only about calls to bounded
  607. functions whose return value is unused and that will most likely result
  608. in output truncation.
  609. </p>
  610. </dd>
  611. <dt><code>-Wformat-truncation=2</code></dt>
  612. <dd><p>Level <var>2</var> warns also about calls to bounded functions whose return
  613. value is used and that might result in truncation given an argument of
  614. sufficient length or magnitude.
  615. </p></dd>
  616. </dl>
  617. </dd>
  618. <dt><code>-Wformat-y2k</code></dt>
  619. <dd><a name="index-Wformat_002dy2k"></a>
  620. <a name="index-Wno_002dformat_002dy2k"></a>
  621. <p>If <samp>-Wformat</samp> is specified, also warn about <code>strftime</code>
  622. formats that may yield only a two-digit year.
  623. </p></dd>
  624. </dl>
  625. </dd>
  626. <dt><code>-Wnonnull</code></dt>
  627. <dd><a name="index-Wnonnull"></a>
  628. <a name="index-Wno_002dnonnull"></a>
  629. <p>Warn about passing a null pointer for arguments marked as
  630. requiring a non-null value by the <code>nonnull</code> function attribute.
  631. </p>
  632. <p><samp>-Wnonnull</samp> is included in <samp>-Wall</samp> and <samp>-Wformat</samp>. It
  633. can be disabled with the <samp>-Wno-nonnull</samp> option.
  634. </p>
  635. </dd>
  636. <dt><code>-Wnonnull-compare</code></dt>
  637. <dd><a name="index-Wnonnull_002dcompare"></a>
  638. <a name="index-Wno_002dnonnull_002dcompare"></a>
  639. <p>Warn when comparing an argument marked with the <code>nonnull</code>
  640. function attribute against null inside the function.
  641. </p>
  642. <p><samp>-Wnonnull-compare</samp> is included in <samp>-Wall</samp>. It
  643. can be disabled with the <samp>-Wno-nonnull-compare</samp> option.
  644. </p>
  645. </dd>
  646. <dt><code>-Wnull-dereference</code></dt>
  647. <dd><a name="index-Wnull_002ddereference"></a>
  648. <a name="index-Wno_002dnull_002ddereference"></a>
  649. <p>Warn if the compiler detects paths that trigger erroneous or
  650. undefined behavior due to dereferencing a null pointer. This option
  651. is only active when <samp>-fdelete-null-pointer-checks</samp> is active,
  652. which is enabled by optimizations in most targets. The precision of
  653. the warnings depends on the optimization options used.
  654. </p>
  655. </dd>
  656. <dt><code>-Winit-self <span class="roman">(C, C++, Objective-C and Objective-C++ only)</span></code></dt>
  657. <dd><a name="index-Winit_002dself"></a>
  658. <a name="index-Wno_002dinit_002dself"></a>
  659. <p>Warn about uninitialized variables that are initialized with themselves.
  660. Note this option can only be used with the <samp>-Wuninitialized</samp> option.
  661. </p>
  662. <p>For example, GCC warns about <code>i</code> being uninitialized in the
  663. following snippet only when <samp>-Winit-self</samp> has been specified:
  664. </p><div class="smallexample">
  665. <pre class="smallexample">int f()
  666. {
  667. int i = i;
  668. return i;
  669. }
  670. </pre></div>
  671. <p>This warning is enabled by <samp>-Wall</samp> in C++.
  672. </p>
  673. </dd>
  674. <dt><code>-Wimplicit-int <span class="roman">(C and Objective-C only)</span></code></dt>
  675. <dd><a name="index-Wimplicit_002dint"></a>
  676. <a name="index-Wno_002dimplicit_002dint"></a>
  677. <p>Warn when a declaration does not specify a type.
  678. This warning is enabled by <samp>-Wall</samp>.
  679. </p>
  680. </dd>
  681. <dt><code>-Wimplicit-function-declaration <span class="roman">(C and Objective-C only)</span></code></dt>
  682. <dd><a name="index-Wimplicit_002dfunction_002ddeclaration"></a>
  683. <a name="index-Wno_002dimplicit_002dfunction_002ddeclaration"></a>
  684. <p>Give a warning whenever a function is used before being declared. In
  685. C99 mode (<samp>-std=c99</samp> or <samp>-std=gnu99</samp>), this warning is
  686. enabled by default and it is made into an error by
  687. <samp>-pedantic-errors</samp>. This warning is also enabled by
  688. <samp>-Wall</samp>.
  689. </p>
  690. </dd>
  691. <dt><code>-Wimplicit <span class="roman">(C and Objective-C only)</span></code></dt>
  692. <dd><a name="index-Wimplicit"></a>
  693. <a name="index-Wno_002dimplicit"></a>
  694. <p>Same as <samp>-Wimplicit-int</samp> and <samp>-Wimplicit-function-declaration</samp>.
  695. This warning is enabled by <samp>-Wall</samp>.
  696. </p>
  697. </dd>
  698. <dt><code>-Wimplicit-fallthrough</code></dt>
  699. <dd><a name="index-Wimplicit_002dfallthrough"></a>
  700. <a name="index-Wno_002dimplicit_002dfallthrough"></a>
  701. <p><samp>-Wimplicit-fallthrough</samp> is the same as <samp>-Wimplicit-fallthrough=3</samp>
  702. and <samp>-Wno-implicit-fallthrough</samp> is the same as
  703. <samp>-Wimplicit-fallthrough=0</samp>.
  704. </p>
  705. </dd>
  706. <dt><code>-Wimplicit-fallthrough=<var>n</var></code></dt>
  707. <dd><a name="index-Wimplicit_002dfallthrough_003d"></a>
  708. <p>Warn when a switch case falls through. For example:
  709. </p>
  710. <div class="smallexample">
  711. <pre class="smallexample">switch (cond)
  712. {
  713. case 1:
  714. a = 1;
  715. break;
  716. case 2:
  717. a = 2;
  718. case 3:
  719. a = 3;
  720. break;
  721. }
  722. </pre></div>
  723. <p>This warning does not warn when the last statement of a case cannot
  724. fall through, e.g. when there is a return statement or a call to function
  725. declared with the noreturn attribute. <samp>-Wimplicit-fallthrough=</samp>
  726. also takes into account control flow statements, such as ifs, and only
  727. warns when appropriate. E.g.
  728. </p>
  729. <div class="smallexample">
  730. <pre class="smallexample">switch (cond)
  731. {
  732. case 1:
  733. if (i &gt; 3) {
  734. bar (5);
  735. break;
  736. } else if (i &lt; 1) {
  737. bar (0);
  738. } else
  739. return;
  740. default:
  741. &hellip;
  742. }
  743. </pre></div>
  744. <p>Since there are occasions where a switch case fall through is desirable,
  745. GCC provides an attribute, <code>__attribute__ ((fallthrough))</code>, that is
  746. to be used along with a null statement to suppress this warning that
  747. would normally occur:
  748. </p>
  749. <div class="smallexample">
  750. <pre class="smallexample">switch (cond)
  751. {
  752. case 1:
  753. bar (0);
  754. __attribute__ ((fallthrough));
  755. default:
  756. &hellip;
  757. }
  758. </pre></div>
  759. <p>C++17 provides a standard way to suppress the <samp>-Wimplicit-fallthrough</samp>
  760. warning using <code>[[fallthrough]];</code> instead of the GNU attribute. In C++11
  761. or C++14 users can use <code>[[gnu::fallthrough]];</code>, which is a GNU extension.
  762. Instead of the these attributes, it is also possible to add a fallthrough
  763. comment to silence the warning. The whole body of the C or C++ style comment
  764. should match the given regular expressions listed below. The option argument
  765. <var>n</var> specifies what kind of comments are accepted:
  766. </p>
  767. <ul>
  768. <li> <samp>-Wimplicit-fallthrough=0</samp> disables the warning altogether.
  769. </li><li> <samp>-Wimplicit-fallthrough=1</samp> matches <code>.*</code> regular
  770. expression, any comment is used as fallthrough comment.
  771. </li><li> <samp>-Wimplicit-fallthrough=2</samp> case insensitively matches
  772. <code>.*falls?[ \t-]*thr(ough|u).*</code> regular expression.
  773. </li><li> <samp>-Wimplicit-fallthrough=3</samp> case sensitively matches one of the
  774. following regular expressions:
  775. <ul>
  776. <li> <code>-fallthrough</code>
  777. </li><li> <code>@fallthrough@</code>
  778. </li><li> <code>lint -fallthrough[ \t]*</code>
  779. </li><li> <code>[ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?<br>FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?</code>
  780. </li><li> <code>[ \t.!]*(Else,? |Intentional(ly)? )?<br>Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?</code>
  781. </li><li> <code>[ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?<br>fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?</code>
  782. </li></ul>
  783. </li><li> <samp>-Wimplicit-fallthrough=4</samp> case sensitively matches one of the
  784. following regular expressions:
  785. <ul>
  786. <li> <code>-fallthrough</code>
  787. </li><li> <code>@fallthrough@</code>
  788. </li><li> <code>lint -fallthrough[ \t]*</code>
  789. </li><li> <code>[ \t]*FALLTHR(OUGH|U)[ \t]*</code>
  790. </li></ul>
  791. </li><li> <samp>-Wimplicit-fallthrough=5</samp> doesn&rsquo;t recognize any comments as
  792. fallthrough comments, only attributes disable the warning.
  793. </li></ul>
  794. <p>The comment needs to be followed after optional whitespace and other comments
  795. by <code>case</code> or <code>default</code> keywords or by a user label that precedes some
  796. <code>case</code> or <code>default</code> label.
  797. </p>
  798. <div class="smallexample">
  799. <pre class="smallexample">switch (cond)
  800. {
  801. case 1:
  802. bar (0);
  803. /* FALLTHRU */
  804. default:
  805. &hellip;
  806. }
  807. </pre></div>
  808. <p>The <samp>-Wimplicit-fallthrough=3</samp> warning is enabled by <samp>-Wextra</samp>.
  809. </p>
  810. </dd>
  811. <dt><code>-Wignored-qualifiers <span class="roman">(C and C++ only)</span></code></dt>
  812. <dd><a name="index-Wignored_002dqualifiers"></a>
  813. <a name="index-Wno_002dignored_002dqualifiers"></a>
  814. <p>Warn if the return type of a function has a type qualifier
  815. such as <code>const</code>. For ISO C such a type qualifier has no effect,
  816. since the value returned by a function is not an lvalue.
  817. For C++, the warning is only emitted for scalar types or <code>void</code>.
  818. ISO C prohibits qualified <code>void</code> return types on function
  819. definitions, so such return types always receive a warning
  820. even without this option.
  821. </p>
  822. <p>This warning is also enabled by <samp>-Wextra</samp>.
  823. </p>
  824. </dd>
  825. <dt><code>-Wignored-attributes <span class="roman">(C and C++ only)</span></code></dt>
  826. <dd><a name="index-Wignored_002dattributes"></a>
  827. <a name="index-Wno_002dignored_002dattributes"></a>
  828. <p>Warn when an attribute is ignored. This is different from the
  829. <samp>-Wattributes</samp> option in that it warns whenever the compiler decides
  830. to drop an attribute, not that the attribute is either unknown, used in a
  831. wrong place, etc. This warning is enabled by default.
  832. </p>
  833. </dd>
  834. <dt><code>-Wmain</code></dt>
  835. <dd><a name="index-Wmain"></a>
  836. <a name="index-Wno_002dmain"></a>
  837. <p>Warn if the type of <code>main</code> is suspicious. <code>main</code> should be
  838. a function with external linkage, returning int, taking either zero
  839. arguments, two, or three arguments of appropriate types. This warning
  840. is enabled by default in C++ and is enabled by either <samp>-Wall</samp>
  841. or <samp>-Wpedantic</samp>.
  842. </p>
  843. </dd>
  844. <dt><code>-Wmisleading-indentation <span class="roman">(C and C++ only)</span></code></dt>
  845. <dd><a name="index-Wmisleading_002dindentation"></a>
  846. <a name="index-Wno_002dmisleading_002dindentation"></a>
  847. <p>Warn when the indentation of the code does not reflect the block structure.
  848. Specifically, a warning is issued for <code>if</code>, <code>else</code>, <code>while</code>, and
  849. <code>for</code> clauses with a guarded statement that does not use braces,
  850. followed by an unguarded statement with the same indentation.
  851. </p>
  852. <p>In the following example, the call to &ldquo;bar&rdquo; is misleadingly indented as
  853. if it were guarded by the &ldquo;if&rdquo; conditional.
  854. </p>
  855. <div class="smallexample">
  856. <pre class="smallexample"> if (some_condition ())
  857. foo ();
  858. bar (); /* Gotcha: this is not guarded by the &quot;if&quot;. */
  859. </pre></div>
  860. <p>In the case of mixed tabs and spaces, the warning uses the
  861. <samp>-ftabstop=</samp> option to determine if the statements line up
  862. (defaulting to 8).
  863. </p>
  864. <p>The warning is not issued for code involving multiline preprocessor logic
  865. such as the following example.
  866. </p>
  867. <div class="smallexample">
  868. <pre class="smallexample"> if (flagA)
  869. foo (0);
  870. #if SOME_CONDITION_THAT_DOES_NOT_HOLD
  871. if (flagB)
  872. #endif
  873. foo (1);
  874. </pre></div>
  875. <p>The warning is not issued after a <code>#line</code> directive, since this
  876. typically indicates autogenerated code, and no assumptions can be made
  877. about the layout of the file that the directive references.
  878. </p>
  879. <p>This warning is enabled by <samp>-Wall</samp> in C and C++.
  880. </p>
  881. </dd>
  882. <dt><code>-Wmissing-braces</code></dt>
  883. <dd><a name="index-Wmissing_002dbraces"></a>
  884. <a name="index-Wno_002dmissing_002dbraces"></a>
  885. <p>Warn if an aggregate or union initializer is not fully bracketed. In
  886. the following example, the initializer for <code>a</code> is not fully
  887. bracketed, but that for <code>b</code> is fully bracketed. This warning is
  888. enabled by <samp>-Wall</samp> in C.
  889. </p>
  890. <div class="smallexample">
  891. <pre class="smallexample">int a[2][2] = { 0, 1, 2, 3 };
  892. int b[2][2] = { { 0, 1 }, { 2, 3 } };
  893. </pre></div>
  894. <p>This warning is enabled by <samp>-Wall</samp>.
  895. </p>
  896. </dd>
  897. <dt><code>-Wmissing-include-dirs <span class="roman">(C, C++, Objective-C and Objective-C++ only)</span></code></dt>
  898. <dd><a name="index-Wmissing_002dinclude_002ddirs"></a>
  899. <a name="index-Wno_002dmissing_002dinclude_002ddirs"></a>
  900. <p>Warn if a user-supplied include directory does not exist.
  901. </p>
  902. </dd>
  903. <dt><code>-Wparentheses</code></dt>
  904. <dd><a name="index-Wparentheses"></a>
  905. <a name="index-Wno_002dparentheses"></a>
  906. <p>Warn if parentheses are omitted in certain contexts, such
  907. as when there is an assignment in a context where a truth value
  908. is expected, or when operators are nested whose precedence people
  909. often get confused about.
  910. </p>
  911. <p>Also warn if a comparison like <code>x&lt;=y&lt;=z</code> appears; this is
  912. equivalent to <code>(x&lt;=y ? 1 : 0) &lt;= z</code>, which is a different
  913. interpretation from that of ordinary mathematical notation.
  914. </p>
  915. <p>Also warn for dangerous uses of the GNU extension to
  916. <code>?:</code> with omitted middle operand. When the condition
  917. in the <code>?</code>: operator is a boolean expression, the omitted value is
  918. always 1. Often programmers expect it to be a value computed
  919. inside the conditional expression instead.
  920. </p>
  921. <p>This warning is enabled by <samp>-Wall</samp>.
  922. </p>
  923. </dd>
  924. <dt><code>-Wsequence-point</code></dt>
  925. <dd><a name="index-Wsequence_002dpoint"></a>
  926. <a name="index-Wno_002dsequence_002dpoint"></a>
  927. <p>Warn about code that may have undefined semantics because of violations
  928. of sequence point rules in the C and C++ standards.
  929. </p>
  930. <p>The C and C++ standards define the order in which expressions in a C/C++
  931. program are evaluated in terms of <em>sequence points</em>, which represent
  932. a partial ordering between the execution of parts of the program: those
  933. executed before the sequence point, and those executed after it. These
  934. occur after the evaluation of a full expression (one which is not part
  935. of a larger expression), after the evaluation of the first operand of a
  936. <code>&amp;&amp;</code>, <code>||</code>, <code>? :</code> or <code>,</code> (comma) operator, before a
  937. function is called (but after the evaluation of its arguments and the
  938. expression denoting the called function), and in certain other places.
  939. Other than as expressed by the sequence point rules, the order of
  940. evaluation of subexpressions of an expression is not specified. All
  941. these rules describe only a partial order rather than a total order,
  942. since, for example, if two functions are called within one expression
  943. with no sequence point between them, the order in which the functions
  944. are called is not specified. However, the standards committee have
  945. ruled that function calls do not overlap.
  946. </p>
  947. <p>It is not specified when between sequence points modifications to the
  948. values of objects take effect. Programs whose behavior depends on this
  949. have undefined behavior; the C and C++ standards specify that &ldquo;Between
  950. the previous and next sequence point an object shall have its stored
  951. value modified at most once by the evaluation of an expression.
  952. Furthermore, the prior value shall be read only to determine the value
  953. to be stored.&rdquo;. If a program breaks these rules, the results on any
  954. particular implementation are entirely unpredictable.
  955. </p>
  956. <p>Examples of code with undefined behavior are <code>a = a++;</code>, <code>a[n]
  957. = b[n++]</code> and <code>a[i++] = i;</code>. Some more complicated cases are not
  958. diagnosed by this option, and it may give an occasional false positive
  959. result, but in general it has been found fairly effective at detecting
  960. this sort of problem in programs.
  961. </p>
  962. <p>The C++17 standard will define the order of evaluation of operands in
  963. more cases: in particular it requires that the right-hand side of an
  964. assignment be evaluated before the left-hand side, so the above
  965. examples are no longer undefined. But this warning will still warn
  966. about them, to help people avoid writing code that is undefined in C
  967. and earlier revisions of C++.
  968. </p>
  969. <p>The standard is worded confusingly, therefore there is some debate
  970. over the precise meaning of the sequence point rules in subtle cases.
  971. Links to discussions of the problem, including proposed formal
  972. definitions, may be found on the GCC readings page, at
  973. <a href="http://gcc.gnu.org/readings.html">http://gcc.gnu.org/readings.html</a>.
  974. </p>
  975. <p>This warning is enabled by <samp>-Wall</samp> for C and C++.
  976. </p>
  977. </dd>
  978. <dt><code>-Wno-return-local-addr</code></dt>
  979. <dd><a name="index-Wno_002dreturn_002dlocal_002daddr"></a>
  980. <a name="index-Wreturn_002dlocal_002daddr"></a>
  981. <p>Do not warn about returning a pointer (or in C++, a reference) to a
  982. variable that goes out of scope after the function returns.
  983. </p>
  984. </dd>
  985. <dt><code>-Wreturn-type</code></dt>
  986. <dd><a name="index-Wreturn_002dtype"></a>
  987. <a name="index-Wno_002dreturn_002dtype"></a>
  988. <p>Warn whenever a function is defined with a return type that defaults
  989. to <code>int</code>. Also warn about any <code>return</code> statement with no
  990. return value in a function whose return type is not <code>void</code>
  991. (falling off the end of the function body is considered returning
  992. without a value).
  993. </p>
  994. <p>For C only, warn about a <code>return</code> statement with an expression in a
  995. function whose return type is <code>void</code>, unless the expression type is
  996. also <code>void</code>. As a GNU extension, the latter case is accepted
  997. without a warning unless <samp>-Wpedantic</samp> is used.
  998. </p>
  999. <p>For C++, a function without return type always produces a diagnostic
  1000. message, even when <samp>-Wno-return-type</samp> is specified. The only
  1001. exceptions are <code>main</code> and functions defined in system headers.
  1002. </p>
  1003. <p>This warning is enabled by <samp>-Wall</samp>.
  1004. </p>
  1005. </dd>
  1006. <dt><code>-Wshift-count-negative</code></dt>
  1007. <dd><a name="index-Wshift_002dcount_002dnegative"></a>
  1008. <a name="index-Wno_002dshift_002dcount_002dnegative"></a>
  1009. <p>Warn if shift count is negative. This warning is enabled by default.
  1010. </p>
  1011. </dd>
  1012. <dt><code>-Wshift-count-overflow</code></dt>
  1013. <dd><a name="index-Wshift_002dcount_002doverflow"></a>
  1014. <a name="index-Wno_002dshift_002dcount_002doverflow"></a>
  1015. <p>Warn if shift count &gt;= width of type. This warning is enabled by default.
  1016. </p>
  1017. </dd>
  1018. <dt><code>-Wshift-negative-value</code></dt>
  1019. <dd><a name="index-Wshift_002dnegative_002dvalue"></a>
  1020. <a name="index-Wno_002dshift_002dnegative_002dvalue"></a>
  1021. <p>Warn if left shifting a negative value. This warning is enabled by
  1022. <samp>-Wextra</samp> in C99 and C++11 modes (and newer).
  1023. </p>
  1024. </dd>
  1025. <dt><code>-Wshift-overflow</code></dt>
  1026. <dt><code>-Wshift-overflow=<var>n</var></code></dt>
  1027. <dd><a name="index-Wshift_002doverflow"></a>
  1028. <a name="index-Wno_002dshift_002doverflow"></a>
  1029. <p>Warn about left shift overflows. This warning is enabled by
  1030. default in C99 and C++11 modes (and newer).
  1031. </p>
  1032. <dl compact="compact">
  1033. <dt><code>-Wshift-overflow=1</code></dt>
  1034. <dd><p>This is the warning level of <samp>-Wshift-overflow</samp> and is enabled
  1035. by default in C99 and C++11 modes (and newer). This warning level does
  1036. not warn about left-shifting 1 into the sign bit. (However, in C, such
  1037. an overflow is still rejected in contexts where an integer constant expression
  1038. is required.)
  1039. </p>
  1040. </dd>
  1041. <dt><code>-Wshift-overflow=2</code></dt>
  1042. <dd><p>This warning level also warns about left-shifting 1 into the sign bit,
  1043. unless C++14 mode is active.
  1044. </p></dd>
  1045. </dl>
  1046. </dd>
  1047. <dt><code>-Wswitch</code></dt>
  1048. <dd><a name="index-Wswitch"></a>
  1049. <a name="index-Wno_002dswitch"></a>
  1050. <p>Warn whenever a <code>switch</code> statement has an index of enumerated type
  1051. and lacks a <code>case</code> for one or more of the named codes of that
  1052. enumeration. (The presence of a <code>default</code> label prevents this
  1053. warning.) <code>case</code> labels outside the enumeration range also
  1054. provoke warnings when this option is used (even if there is a
  1055. <code>default</code> label).
  1056. This warning is enabled by <samp>-Wall</samp>.
  1057. </p>
  1058. </dd>
  1059. <dt><code>-Wswitch-default</code></dt>
  1060. <dd><a name="index-Wswitch_002ddefault"></a>
  1061. <a name="index-Wno_002dswitch_002ddefault"></a>
  1062. <p>Warn whenever a <code>switch</code> statement does not have a <code>default</code>
  1063. case.
  1064. </p>
  1065. </dd>
  1066. <dt><code>-Wswitch-enum</code></dt>
  1067. <dd><a name="index-Wswitch_002denum"></a>
  1068. <a name="index-Wno_002dswitch_002denum"></a>
  1069. <p>Warn whenever a <code>switch</code> statement has an index of enumerated type
  1070. and lacks a <code>case</code> for one or more of the named codes of that
  1071. enumeration. <code>case</code> labels outside the enumeration range also
  1072. provoke warnings when this option is used. The only difference
  1073. between <samp>-Wswitch</samp> and this option is that this option gives a
  1074. warning about an omitted enumeration code even if there is a
  1075. <code>default</code> label.
  1076. </p>
  1077. </dd>
  1078. <dt><code>-Wswitch-bool</code></dt>
  1079. <dd><a name="index-Wswitch_002dbool"></a>
  1080. <a name="index-Wno_002dswitch_002dbool"></a>
  1081. <p>Warn whenever a <code>switch</code> statement has an index of boolean type
  1082. and the case values are outside the range of a boolean type.
  1083. It is possible to suppress this warning by casting the controlling
  1084. expression to a type other than <code>bool</code>. For example:
  1085. </p><div class="smallexample">
  1086. <pre class="smallexample">switch ((int) (a == 4))
  1087. {
  1088. &hellip;
  1089. }
  1090. </pre></div>
  1091. <p>This warning is enabled by default for C and C++ programs.
  1092. </p>
  1093. </dd>
  1094. <dt><code>-Wswitch-unreachable</code></dt>
  1095. <dd><a name="index-Wswitch_002dunreachable"></a>
  1096. <a name="index-Wno_002dswitch_002dunreachable"></a>
  1097. <p>Warn whenever a <code>switch</code> statement contains statements between the
  1098. controlling expression and the first case label, which will never be
  1099. executed. For example:
  1100. </p><div class="smallexample">
  1101. <pre class="smallexample">switch (cond)
  1102. {
  1103. i = 15;
  1104. &hellip;
  1105. case 5:
  1106. &hellip;
  1107. }
  1108. </pre></div>
  1109. <p><samp>-Wswitch-unreachable</samp> does not warn if the statement between the
  1110. controlling expression and the first case label is just a declaration:
  1111. </p><div class="smallexample">
  1112. <pre class="smallexample">switch (cond)
  1113. {
  1114. int i;
  1115. &hellip;
  1116. case 5:
  1117. i = 5;
  1118. &hellip;
  1119. }
  1120. </pre></div>
  1121. <p>This warning is enabled by default for C and C++ programs.
  1122. </p>
  1123. </dd>
  1124. <dt><code>-Wsync-nand <span class="roman">(C and C++ only)</span></code></dt>
  1125. <dd><a name="index-Wsync_002dnand"></a>
  1126. <a name="index-Wno_002dsync_002dnand"></a>
  1127. <p>Warn when <code>__sync_fetch_and_nand</code> and <code>__sync_nand_and_fetch</code>
  1128. built-in functions are used. These functions changed semantics in GCC 4.4.
  1129. </p>
  1130. </dd>
  1131. <dt><code>-Wunused-but-set-parameter</code></dt>
  1132. <dd><a name="index-Wunused_002dbut_002dset_002dparameter"></a>
  1133. <a name="index-Wno_002dunused_002dbut_002dset_002dparameter"></a>
  1134. <p>Warn whenever a function parameter is assigned to, but otherwise unused
  1135. (aside from its declaration).
  1136. </p>
  1137. <p>To suppress this warning use the <code>unused</code> attribute
  1138. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1139. </p>
  1140. <p>This warning is also enabled by <samp>-Wunused</samp> together with
  1141. <samp>-Wextra</samp>.
  1142. </p>
  1143. </dd>
  1144. <dt><code>-Wunused-but-set-variable</code></dt>
  1145. <dd><a name="index-Wunused_002dbut_002dset_002dvariable"></a>
  1146. <a name="index-Wno_002dunused_002dbut_002dset_002dvariable"></a>
  1147. <p>Warn whenever a local variable is assigned to, but otherwise unused
  1148. (aside from its declaration).
  1149. This warning is enabled by <samp>-Wall</samp>.
  1150. </p>
  1151. <p>To suppress this warning use the <code>unused</code> attribute
  1152. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1153. </p>
  1154. <p>This warning is also enabled by <samp>-Wunused</samp>, which is enabled
  1155. by <samp>-Wall</samp>.
  1156. </p>
  1157. </dd>
  1158. <dt><code>-Wunused-function</code></dt>
  1159. <dd><a name="index-Wunused_002dfunction"></a>
  1160. <a name="index-Wno_002dunused_002dfunction"></a>
  1161. <p>Warn whenever a static function is declared but not defined or a
  1162. non-inline static function is unused.
  1163. This warning is enabled by <samp>-Wall</samp>.
  1164. </p>
  1165. </dd>
  1166. <dt><code>-Wunused-label</code></dt>
  1167. <dd><a name="index-Wunused_002dlabel"></a>
  1168. <a name="index-Wno_002dunused_002dlabel"></a>
  1169. <p>Warn whenever a label is declared but not used.
  1170. This warning is enabled by <samp>-Wall</samp>.
  1171. </p>
  1172. <p>To suppress this warning use the <code>unused</code> attribute
  1173. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1174. </p>
  1175. </dd>
  1176. <dt><code>-Wunused-local-typedefs <span class="roman">(C, Objective-C, C++ and Objective-C++ only)</span></code></dt>
  1177. <dd><a name="index-Wunused_002dlocal_002dtypedefs"></a>
  1178. <p>Warn when a typedef locally defined in a function is not used.
  1179. This warning is enabled by <samp>-Wall</samp>.
  1180. </p>
  1181. </dd>
  1182. <dt><code>-Wunused-parameter</code></dt>
  1183. <dd><a name="index-Wunused_002dparameter"></a>
  1184. <a name="index-Wno_002dunused_002dparameter"></a>
  1185. <p>Warn whenever a function parameter is unused aside from its declaration.
  1186. </p>
  1187. <p>To suppress this warning use the <code>unused</code> attribute
  1188. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1189. </p>
  1190. </dd>
  1191. <dt><code>-Wno-unused-result</code></dt>
  1192. <dd><a name="index-Wunused_002dresult"></a>
  1193. <a name="index-Wno_002dunused_002dresult"></a>
  1194. <p>Do not warn if a caller of a function marked with attribute
  1195. <code>warn_unused_result</code> (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>) does not use
  1196. its return value. The default is <samp>-Wunused-result</samp>.
  1197. </p>
  1198. </dd>
  1199. <dt><code>-Wunused-variable</code></dt>
  1200. <dd><a name="index-Wunused_002dvariable"></a>
  1201. <a name="index-Wno_002dunused_002dvariable"></a>
  1202. <p>Warn whenever a local or static variable is unused aside from its
  1203. declaration. This option implies <samp>-Wunused-const-variable=1</samp> for C,
  1204. but not for C++. This warning is enabled by <samp>-Wall</samp>.
  1205. </p>
  1206. <p>To suppress this warning use the <code>unused</code> attribute
  1207. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1208. </p>
  1209. </dd>
  1210. <dt><code>-Wunused-const-variable</code></dt>
  1211. <dt><code>-Wunused-const-variable=<var>n</var></code></dt>
  1212. <dd><a name="index-Wunused_002dconst_002dvariable"></a>
  1213. <a name="index-Wno_002dunused_002dconst_002dvariable"></a>
  1214. <p>Warn whenever a constant static variable is unused aside from its declaration.
  1215. <samp>-Wunused-const-variable=1</samp> is enabled by <samp>-Wunused-variable</samp>
  1216. for C, but not for C++. In C this declares variable storage, but in C++ this
  1217. is not an error since const variables take the place of <code>#define</code>s.
  1218. </p>
  1219. <p>To suppress this warning use the <code>unused</code> attribute
  1220. (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>).
  1221. </p>
  1222. <dl compact="compact">
  1223. <dt><code>-Wunused-const-variable=1</code></dt>
  1224. <dd><p>This is the warning level that is enabled by <samp>-Wunused-variable</samp> for
  1225. C. It warns only about unused static const variables defined in the main
  1226. compilation unit, but not about static const variables declared in any
  1227. header included.
  1228. </p>
  1229. </dd>
  1230. <dt><code>-Wunused-const-variable=2</code></dt>
  1231. <dd><p>This warning level also warns for unused constant static variables in
  1232. headers (excluding system headers). This is the warning level of
  1233. <samp>-Wunused-const-variable</samp> and must be explicitly requested since
  1234. in C++ this isn&rsquo;t an error and in C it might be harder to clean up all
  1235. headers included.
  1236. </p></dd>
  1237. </dl>
  1238. </dd>
  1239. <dt><code>-Wunused-value</code></dt>
  1240. <dd><a name="index-Wunused_002dvalue"></a>
  1241. <a name="index-Wno_002dunused_002dvalue"></a>
  1242. <p>Warn whenever a statement computes a result that is explicitly not
  1243. used. To suppress this warning cast the unused expression to
  1244. <code>void</code>. This includes an expression-statement or the left-hand
  1245. side of a comma expression that contains no side effects. For example,
  1246. an expression such as <code>x[i,j]</code> causes a warning, while
  1247. <code>x[(void)i,j]</code> does not.
  1248. </p>
  1249. <p>This warning is enabled by <samp>-Wall</samp>.
  1250. </p>
  1251. </dd>
  1252. <dt><code>-Wunused</code></dt>
  1253. <dd><a name="index-Wunused"></a>
  1254. <a name="index-Wno_002dunused"></a>
  1255. <p>All the above <samp>-Wunused</samp> options combined.
  1256. </p>
  1257. <p>In order to get a warning about an unused function parameter, you must
  1258. either specify <samp>-Wextra -Wunused</samp> (note that <samp>-Wall</samp> implies
  1259. <samp>-Wunused</samp>), or separately specify <samp>-Wunused-parameter</samp>.
  1260. </p>
  1261. </dd>
  1262. <dt><code>-Wuninitialized</code></dt>
  1263. <dd><a name="index-Wuninitialized"></a>
  1264. <a name="index-Wno_002duninitialized"></a>
  1265. <p>Warn if an automatic variable is used without first being initialized
  1266. or if a variable may be clobbered by a <code>setjmp</code> call. In C++,
  1267. warn if a non-static reference or non-static <code>const</code> member
  1268. appears in a class without constructors.
  1269. </p>
  1270. <p>If you want to warn about code that uses the uninitialized value of the
  1271. variable in its own initializer, use the <samp>-Winit-self</samp> option.
  1272. </p>
  1273. <p>These warnings occur for individual uninitialized or clobbered
  1274. elements of structure, union or array variables as well as for
  1275. variables that are uninitialized or clobbered as a whole. They do
  1276. not occur for variables or elements declared <code>volatile</code>. Because
  1277. these warnings depend on optimization, the exact variables or elements
  1278. for which there are warnings depends on the precise optimization
  1279. options and version of GCC used.
  1280. </p>
  1281. <p>Note that there may be no warning about a variable that is used only
  1282. to compute a value that itself is never used, because such
  1283. computations may be deleted by data flow analysis before the warnings
  1284. are printed.
  1285. </p>
  1286. </dd>
  1287. <dt><code>-Winvalid-memory-model</code></dt>
  1288. <dd><a name="index-Winvalid_002dmemory_002dmodel"></a>
  1289. <a name="index-Wno_002dinvalid_002dmemory_002dmodel"></a>
  1290. <p>Warn for invocations of <a href="_005f_005fatomic-Builtins.html#g_t_005f_005fatomic-Builtins">__atomic Builtins</a>, <a href="_005f_005fsync-Builtins.html#g_t_005f_005fsync-Builtins">__sync Builtins</a>,
  1291. and the C11 atomic generic functions with a memory consistency argument
  1292. that is either invalid for the operation or outside the range of values
  1293. of the <code>memory_order</code> enumeration. For example, since the
  1294. <code>__atomic_store</code> and <code>__atomic_store_n</code> built-ins are only
  1295. defined for the relaxed, release, and sequentially consistent memory
  1296. orders the following code is diagnosed:
  1297. </p>
  1298. <div class="smallexample">
  1299. <pre class="smallexample">void store (int *i)
  1300. {
  1301. __atomic_store_n (i, 0, memory_order_consume);
  1302. }
  1303. </pre></div>
  1304. <p><samp>-Winvalid-memory-model</samp> is enabled by default.
  1305. </p>
  1306. </dd>
  1307. <dt><code>-Wmaybe-uninitialized</code></dt>
  1308. <dd><a name="index-Wmaybe_002duninitialized"></a>
  1309. <a name="index-Wno_002dmaybe_002duninitialized"></a>
  1310. <p>For an automatic variable, if there exists a path from the function
  1311. entry to a use of the variable that is initialized, but there exist
  1312. some other paths for which the variable is not initialized, the compiler
  1313. emits a warning if it cannot prove the uninitialized paths are not
  1314. executed at run time. These warnings are made optional because GCC is
  1315. not smart enough to see all the reasons why the code might be correct
  1316. in spite of appearing to have an error. Here is one example of how
  1317. this can happen:
  1318. </p>
  1319. <div class="smallexample">
  1320. <pre class="smallexample">{
  1321. int x;
  1322. switch (y)
  1323. {
  1324. case 1: x = 1;
  1325. break;
  1326. case 2: x = 4;
  1327. break;
  1328. case 3: x = 5;
  1329. }
  1330. foo (x);
  1331. }
  1332. </pre></div>
  1333. <p>If the value of <code>y</code> is always 1, 2 or 3, then <code>x</code> is
  1334. always initialized, but GCC doesn&rsquo;t know this. To suppress the
  1335. warning, you need to provide a default case with assert(0) or
  1336. similar code.
  1337. </p>
  1338. <a name="index-longjmp-warnings"></a>
  1339. <p>This option also warns when a non-volatile automatic variable might be
  1340. changed by a call to <code>longjmp</code>. These warnings as well are possible
  1341. only in optimizing compilation.
  1342. </p>
  1343. <p>The compiler sees only the calls to <code>setjmp</code>. It cannot know
  1344. where <code>longjmp</code> will be called; in fact, a signal handler could
  1345. call it at any point in the code. As a result, you may get a warning
  1346. even when there is in fact no problem because <code>longjmp</code> cannot
  1347. in fact be called at the place that would cause a problem.
  1348. </p>
  1349. <p>Some spurious warnings can be avoided if you declare all the functions
  1350. you use that never return as <code>noreturn</code>. See <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>.
  1351. </p>
  1352. <p>This warning is enabled by <samp>-Wall</samp> or <samp>-Wextra</samp>.
  1353. </p>
  1354. </dd>
  1355. <dt><code>-Wunknown-pragmas</code></dt>
  1356. <dd><a name="index-Wunknown_002dpragmas"></a>
  1357. <a name="index-Wno_002dunknown_002dpragmas"></a>
  1358. <a name="index-warning-for-unknown-pragmas"></a>
  1359. <a name="index-unknown-pragmas_002c-warning"></a>
  1360. <a name="index-pragmas_002c-warning-of-unknown"></a>
  1361. <p>Warn when a <code>#pragma</code> directive is encountered that is not understood by
  1362. GCC. If this command-line option is used, warnings are even issued
  1363. for unknown pragmas in system header files. This is not the case if
  1364. the warnings are only enabled by the <samp>-Wall</samp> command-line option.
  1365. </p>
  1366. </dd>
  1367. <dt><code>-Wno-pragmas</code></dt>
  1368. <dd><a name="index-Wno_002dpragmas"></a>
  1369. <a name="index-Wpragmas"></a>
  1370. <p>Do not warn about misuses of pragmas, such as incorrect parameters,
  1371. invalid syntax, or conflicts between pragmas. See also
  1372. <samp>-Wunknown-pragmas</samp>.
  1373. </p>
  1374. </dd>
  1375. <dt><code>-Wstrict-aliasing</code></dt>
  1376. <dd><a name="index-Wstrict_002daliasing"></a>
  1377. <a name="index-Wno_002dstrict_002daliasing"></a>
  1378. <p>This option is only active when <samp>-fstrict-aliasing</samp> is active.
  1379. It warns about code that might break the strict aliasing rules that the
  1380. compiler is using for optimization. The warning does not catch all
  1381. cases, but does attempt to catch the more common pitfalls. It is
  1382. included in <samp>-Wall</samp>.
  1383. It is equivalent to <samp>-Wstrict-aliasing=3</samp>
  1384. </p>
  1385. </dd>
  1386. <dt><code>-Wstrict-aliasing=n</code></dt>
  1387. <dd><a name="index-Wstrict_002daliasing_003dn"></a>
  1388. <p>This option is only active when <samp>-fstrict-aliasing</samp> is active.
  1389. It warns about code that might break the strict aliasing rules that the
  1390. compiler is using for optimization.
  1391. Higher levels correspond to higher accuracy (fewer false positives).
  1392. Higher levels also correspond to more effort, similar to the way <samp>-O</samp>
  1393. works.
  1394. <samp>-Wstrict-aliasing</samp> is equivalent to <samp>-Wstrict-aliasing=3</samp>.
  1395. </p>
  1396. <p>Level 1: Most aggressive, quick, least accurate.
  1397. Possibly useful when higher levels
  1398. do not warn but <samp>-fstrict-aliasing</samp> still breaks the code, as it has very few
  1399. false negatives. However, it has many false positives.
  1400. Warns for all pointer conversions between possibly incompatible types,
  1401. even if never dereferenced. Runs in the front end only.
  1402. </p>
  1403. <p>Level 2: Aggressive, quick, not too precise.
  1404. May still have many false positives (not as many as level 1 though),
  1405. and few false negatives (but possibly more than level 1).
  1406. Unlike level 1, it only warns when an address is taken. Warns about
  1407. incomplete types. Runs in the front end only.
  1408. </p>
  1409. <p>Level 3 (default for <samp>-Wstrict-aliasing</samp>):
  1410. Should have very few false positives and few false
  1411. negatives. Slightly slower than levels 1 or 2 when optimization is enabled.
  1412. Takes care of the common pun+dereference pattern in the front end:
  1413. <code>*(int*)&amp;some_float</code>.
  1414. If optimization is enabled, it also runs in the back end, where it deals
  1415. with multiple statement cases using flow-sensitive points-to information.
  1416. Only warns when the converted pointer is dereferenced.
  1417. Does not warn about incomplete types.
  1418. </p>
  1419. </dd>
  1420. <dt><code>-Wstrict-overflow</code></dt>
  1421. <dt><code>-Wstrict-overflow=<var>n</var></code></dt>
  1422. <dd><a name="index-Wstrict_002doverflow"></a>
  1423. <a name="index-Wno_002dstrict_002doverflow"></a>
  1424. <p>This option is only active when <samp>-fstrict-overflow</samp> is active.
  1425. It warns about cases where the compiler optimizes based on the
  1426. assumption that signed overflow does not occur. Note that it does not
  1427. warn about all cases where the code might overflow: it only warns
  1428. about cases where the compiler implements some optimization. Thus
  1429. this warning depends on the optimization level.
  1430. </p>
  1431. <p>An optimization that assumes that signed overflow does not occur is
  1432. perfectly safe if the values of the variables involved are such that
  1433. overflow never does, in fact, occur. Therefore this warning can
  1434. easily give a false positive: a warning about code that is not
  1435. actually a problem. To help focus on important issues, several
  1436. warning levels are defined. No warnings are issued for the use of
  1437. undefined signed overflow when estimating how many iterations a loop
  1438. requires, in particular when determining whether a loop will be
  1439. executed at all.
  1440. </p>
  1441. <dl compact="compact">
  1442. <dt><code>-Wstrict-overflow=1</code></dt>
  1443. <dd><p>Warn about cases that are both questionable and easy to avoid. For
  1444. example, with <samp>-fstrict-overflow</samp>, the compiler simplifies
  1445. <code>x + 1 &gt; x</code> to <code>1</code>. This level of
  1446. <samp>-Wstrict-overflow</samp> is enabled by <samp>-Wall</samp>; higher levels
  1447. are not, and must be explicitly requested.
  1448. </p>
  1449. </dd>
  1450. <dt><code>-Wstrict-overflow=2</code></dt>
  1451. <dd><p>Also warn about other cases where a comparison is simplified to a
  1452. constant. For example: <code>abs (x) &gt;= 0</code>. This can only be
  1453. simplified when <samp>-fstrict-overflow</samp> is in effect, because
  1454. <code>abs (INT_MIN)</code> overflows to <code>INT_MIN</code>, which is less than
  1455. zero. <samp>-Wstrict-overflow</samp> (with no level) is the same as
  1456. <samp>-Wstrict-overflow=2</samp>.
  1457. </p>
  1458. </dd>
  1459. <dt><code>-Wstrict-overflow=3</code></dt>
  1460. <dd><p>Also warn about other cases where a comparison is simplified. For
  1461. example: <code>x + 1 &gt; 1</code> is simplified to <code>x &gt; 0</code>.
  1462. </p>
  1463. </dd>
  1464. <dt><code>-Wstrict-overflow=4</code></dt>
  1465. <dd><p>Also warn about other simplifications not covered by the above cases.
  1466. For example: <code>(x * 10) / 5</code> is simplified to <code>x * 2</code>.
  1467. </p>
  1468. </dd>
  1469. <dt><code>-Wstrict-overflow=5</code></dt>
  1470. <dd><p>Also warn about cases where the compiler reduces the magnitude of a
  1471. constant involved in a comparison. For example: <code>x + 2 &gt; y</code> is
  1472. simplified to <code>x + 1 &gt;= y</code>. This is reported only at the
  1473. highest warning level because this simplification applies to many
  1474. comparisons, so this warning level gives a very large number of
  1475. false positives.
  1476. </p></dd>
  1477. </dl>
  1478. </dd>
  1479. <dt><code>-Wstringop-overflow</code></dt>
  1480. <dt><code>-Wstringop-overflow=<var>type</var></code></dt>
  1481. <dd><a name="index-Wstringop_002doverflow"></a>
  1482. <a name="index-Wno_002dstringop_002doverflow"></a>
  1483. <p>Warn for calls to string manipulation functions such as <code>memcpy</code> and
  1484. <code>strcpy</code> that are determined to overflow the destination buffer. The
  1485. optional argument is one greater than the type of Object Size Checking to
  1486. perform to determine the size of the destination. See <a href="Object-Size-Checking.html#Object-Size-Checking">Object Size Checking</a>.
  1487. The argument is meaningful only for functions that operate on character arrays
  1488. but not for raw memory functions like <code>memcpy</code> which always make use
  1489. of Object Size type-0. The option also warns for calls that specify a size
  1490. in excess of the largest possible object or at most <code>SIZE_MAX / 2</code> bytes.
  1491. The option produces the best results with optimization enabled but can detect
  1492. a small subset of simple buffer overflows even without optimization in
  1493. calls to the GCC built-in functions like <code>__builtin_memcpy</code> that
  1494. correspond to the standard functions. In any case, the option warns about
  1495. just a subset of buffer overflows detected by the corresponding overflow
  1496. checking built-ins. For example, the option will issue a warning for
  1497. the <code>strcpy</code> call below because it copies at least 5 characters
  1498. (the string <code>&quot;blue&quot;</code> including the terminating NUL) into the buffer
  1499. of size 4.
  1500. </p>
  1501. <div class="smallexample">
  1502. <pre class="smallexample">enum Color { blue, purple, yellow };
  1503. const char* f (enum Color clr)
  1504. {
  1505. static char buf [4];
  1506. const char *str;
  1507. switch (clr)
  1508. {
  1509. case blue: str = &quot;blue&quot;; break;
  1510. case purple: str = &quot;purple&quot;; break;
  1511. case yellow: str = &quot;yellow&quot;; break;
  1512. }
  1513. return strcpy (buf, str); // warning here
  1514. }
  1515. </pre></div>
  1516. <p>Option <samp>-Wstringop-overflow=2</samp> is enabled by default.
  1517. </p>
  1518. <dl compact="compact">
  1519. <dt><code>-Wstringop-overflow</code></dt>
  1520. <dt><code>-Wstringop-overflow=1</code></dt>
  1521. <dd><a name="index-Wstringop_002doverflow-1"></a>
  1522. <a name="index-Wno_002dstringop_002doverflow-1"></a>
  1523. <p>The <samp>-Wstringop-overflow=1</samp> option uses type-zero Object Size Checking
  1524. to determine the sizes of destination objects. This is the default setting
  1525. of the option. At this setting the option will not warn for writes past
  1526. the end of subobjects of larger objects accessed by pointers unless the
  1527. size of the largest surrounding object is known. When the destination may
  1528. be one of several objects it is assumed to be the largest one of them. On
  1529. Linux systems, when optimization is enabled at this setting the option warns
  1530. for the same code as when the <code>_FORTIFY_SOURCE</code> macro is defined to
  1531. a non-zero value.
  1532. </p>
  1533. </dd>
  1534. <dt><code>-Wstringop-overflow=2</code></dt>
  1535. <dd><p>The <samp>-Wstringop-overflow=2</samp> option uses type-one Object Size Checking
  1536. to determine the sizes of destination objects. At this setting the option
  1537. will warn about overflows when writing to members of the largest complete
  1538. objects whose exact size is known. It will, however, not warn for excessive
  1539. writes to the same members of unknown objects referenced by pointers since
  1540. they may point to arrays containing unknown numbers of elements.
  1541. </p>
  1542. </dd>
  1543. <dt><code>-Wstringop-overflow=3</code></dt>
  1544. <dd><p>The <samp>-Wstringop-overflow=3</samp> option uses type-two Object Size Checking
  1545. to determine the sizes of destination objects. At this setting the option
  1546. warns about overflowing the smallest object or data member. This is the
  1547. most restrictive setting of the option that may result in warnings for safe
  1548. code.
  1549. </p>
  1550. </dd>
  1551. <dt><code>-Wstringop-overflow=4</code></dt>
  1552. <dd><p>The <samp>-Wstringop-overflow=4</samp> option uses type-three Object Size Checking
  1553. to determine the sizes of destination objects. At this setting the option
  1554. will warn about overflowing any data members, and when the destination is
  1555. one of several objects it uses the size of the largest of them to decide
  1556. whether to issue a warning. Similarly to <samp>-Wstringop-overflow=3</samp> this
  1557. setting of the option may result in warnings for benign code.
  1558. </p></dd>
  1559. </dl>
  1560. </dd>
  1561. <dt><code>-Wsuggest-attribute=<span class="roman">[</span>pure<span class="roman">|</span>const<span class="roman">|</span>noreturn<span class="roman">|</span>format<span class="roman">]</span></code></dt>
  1562. <dd><a name="index-Wsuggest_002dattribute_003d"></a>
  1563. <a name="index-Wno_002dsuggest_002dattribute_003d"></a>
  1564. <p>Warn for cases where adding an attribute may be beneficial. The
  1565. attributes currently supported are listed below.
  1566. </p>
  1567. <dl compact="compact">
  1568. <dt><code>-Wsuggest-attribute=pure</code></dt>
  1569. <dt><code>-Wsuggest-attribute=const</code></dt>
  1570. <dt><code>-Wsuggest-attribute=noreturn</code></dt>
  1571. <dd><a name="index-Wsuggest_002dattribute_003dpure"></a>
  1572. <a name="index-Wno_002dsuggest_002dattribute_003dpure"></a>
  1573. <a name="index-Wsuggest_002dattribute_003dconst"></a>
  1574. <a name="index-Wno_002dsuggest_002dattribute_003dconst"></a>
  1575. <a name="index-Wsuggest_002dattribute_003dnoreturn"></a>
  1576. <a name="index-Wno_002dsuggest_002dattribute_003dnoreturn"></a>
  1577. <p>Warn about functions that might be candidates for attributes
  1578. <code>pure</code>, <code>const</code> or <code>noreturn</code>. The compiler only warns for
  1579. functions visible in other compilation units or (in the case of <code>pure</code> and
  1580. <code>const</code>) if it cannot prove that the function returns normally. A function
  1581. returns normally if it doesn&rsquo;t contain an infinite loop or return abnormally
  1582. by throwing, calling <code>abort</code> or trapping. This analysis requires option
  1583. <samp>-fipa-pure-const</samp>, which is enabled by default at <samp>-O</samp> and
  1584. higher. Higher optimization levels improve the accuracy of the analysis.
  1585. </p>
  1586. </dd>
  1587. <dt><code>-Wsuggest-attribute=format</code></dt>
  1588. <dt><code>-Wmissing-format-attribute</code></dt>
  1589. <dd><a name="index-Wsuggest_002dattribute_003dformat"></a>
  1590. <a name="index-Wmissing_002dformat_002dattribute"></a>
  1591. <a name="index-Wno_002dsuggest_002dattribute_003dformat"></a>
  1592. <a name="index-Wno_002dmissing_002dformat_002dattribute"></a>
  1593. <a name="index-Wformat-2"></a>
  1594. <a name="index-Wno_002dformat-1"></a>
  1595. <p>Warn about function pointers that might be candidates for <code>format</code>
  1596. attributes. Note these are only possible candidates, not absolute ones.
  1597. GCC guesses that function pointers with <code>format</code> attributes that
  1598. are used in assignment, initialization, parameter passing or return
  1599. statements should have a corresponding <code>format</code> attribute in the
  1600. resulting type. I.e. the left-hand side of the assignment or
  1601. initialization, the type of the parameter variable, or the return type
  1602. of the containing function respectively should also have a <code>format</code>
  1603. attribute to avoid the warning.
  1604. </p>
  1605. <p>GCC also warns about function definitions that might be
  1606. candidates for <code>format</code> attributes. Again, these are only
  1607. possible candidates. GCC guesses that <code>format</code> attributes
  1608. might be appropriate for any function that calls a function like
  1609. <code>vprintf</code> or <code>vscanf</code>, but this might not always be the
  1610. case, and some functions for which <code>format</code> attributes are
  1611. appropriate may not be detected.
  1612. </p></dd>
  1613. </dl>
  1614. </dd>
  1615. <dt><code>-Wsuggest-final-types</code></dt>
  1616. <dd><a name="index-Wno_002dsuggest_002dfinal_002dtypes"></a>
  1617. <a name="index-Wsuggest_002dfinal_002dtypes"></a>
  1618. <p>Warn about types with virtual methods where code quality would be improved
  1619. if the type were declared with the C++11 <code>final</code> specifier,
  1620. or, if possible,
  1621. declared in an anonymous namespace. This allows GCC to more aggressively
  1622. devirtualize the polymorphic calls. This warning is more effective with link
  1623. time optimization, where the information about the class hierarchy graph is
  1624. more complete.
  1625. </p>
  1626. </dd>
  1627. <dt><code>-Wsuggest-final-methods</code></dt>
  1628. <dd><a name="index-Wno_002dsuggest_002dfinal_002dmethods"></a>
  1629. <a name="index-Wsuggest_002dfinal_002dmethods"></a>
  1630. <p>Warn about virtual methods where code quality would be improved if the method
  1631. were declared with the C++11 <code>final</code> specifier,
  1632. or, if possible, its type were
  1633. declared in an anonymous namespace or with the <code>final</code> specifier.
  1634. This warning is
  1635. more effective with link-time optimization, where the information about the
  1636. class hierarchy graph is more complete. It is recommended to first consider
  1637. suggestions of <samp>-Wsuggest-final-types</samp> and then rebuild with new
  1638. annotations.
  1639. </p>
  1640. </dd>
  1641. <dt><code>-Wsuggest-override</code></dt>
  1642. <dd><p>Warn about overriding virtual functions that are not marked with the override
  1643. keyword.
  1644. </p>
  1645. </dd>
  1646. <dt><code>-Walloc-zero</code></dt>
  1647. <dd><a name="index-Wno_002dalloc_002dzero"></a>
  1648. <a name="index-Walloc_002dzero"></a>
  1649. <p>Warn about calls to allocation functions decorated with attribute
  1650. <code>alloc_size</code> that specify zero bytes, including those to the built-in
  1651. forms of the functions <code>aligned_alloc</code>, <code>alloca</code>, <code>calloc</code>,
  1652. <code>malloc</code>, and <code>realloc</code>. Because the behavior of these functions
  1653. when called with a zero size differs among implementations (and in the case
  1654. of <code>realloc</code> has been deprecated) relying on it may result in subtle
  1655. portability bugs and should be avoided.
  1656. </p>
  1657. </dd>
  1658. <dt><code>-Walloc-size-larger-than=<var>n</var></code></dt>
  1659. <dd><p>Warn about calls to functions decorated with attribute <code>alloc_size</code>
  1660. that attempt to allocate objects larger than the specified number of bytes,
  1661. or where the result of the size computation in an integer type with infinite
  1662. precision would exceed <code>SIZE_MAX / 2</code>. The option argument <var>n</var>
  1663. may end in one of the standard suffixes designating a multiple of bytes
  1664. such as <code>kB</code> and <code>KiB</code> for kilobyte and kibibyte, respectively,
  1665. <code>MB</code> and <code>MiB</code> for megabyte and mebibyte, and so on.
  1666. <samp>-Walloc-size-larger-than=</samp><var>PTRDIFF_MAX</var> is enabled by default.
  1667. Warnings controlled by the option can be disabled by specifying <var>n</var>
  1668. of <var>SIZE_MAX</var> or more.
  1669. See <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>.
  1670. </p>
  1671. </dd>
  1672. <dt><code>-Walloca</code></dt>
  1673. <dd><a name="index-Wno_002dalloca"></a>
  1674. <a name="index-Walloca"></a>
  1675. <p>This option warns on all uses of <code>alloca</code> in the source.
  1676. </p>
  1677. </dd>
  1678. <dt><code>-Walloca-larger-than=<var>n</var></code></dt>
  1679. <dd><p>This option warns on calls to <code>alloca</code> that are not bounded by a
  1680. controlling predicate limiting its argument of integer type to at most
  1681. <var>n</var> bytes, or calls to <code>alloca</code> where the bound is unknown.
  1682. Arguments of non-integer types are considered unbounded even if they
  1683. appear to be constrained to the expected range.
  1684. </p>
  1685. <p>For example, a bounded case of <code>alloca</code> could be:
  1686. </p>
  1687. <div class="smallexample">
  1688. <pre class="smallexample">void func (size_t n)
  1689. {
  1690. void *p;
  1691. if (n &lt;= 1000)
  1692. p = alloca (n);
  1693. else
  1694. p = malloc (n);
  1695. f (p);
  1696. }
  1697. </pre></div>
  1698. <p>In the above example, passing <code>-Walloca-larger-than=1000</code> would not
  1699. issue a warning because the call to <code>alloca</code> is known to be at most
  1700. 1000 bytes. However, if <code>-Walloca-larger-than=500</code> were passed,
  1701. the compiler would emit a warning.
  1702. </p>
  1703. <p>Unbounded uses, on the other hand, are uses of <code>alloca</code> with no
  1704. controlling predicate constraining its integer argument. For example:
  1705. </p>
  1706. <div class="smallexample">
  1707. <pre class="smallexample">void func ()
  1708. {
  1709. void *p = alloca (n);
  1710. f (p);
  1711. }
  1712. </pre></div>
  1713. <p>If <code>-Walloca-larger-than=500</code> were passed, the above would trigger
  1714. a warning, but this time because of the lack of bounds checking.
  1715. </p>
  1716. <p>Note, that even seemingly correct code involving signed integers could
  1717. cause a warning:
  1718. </p>
  1719. <div class="smallexample">
  1720. <pre class="smallexample">void func (signed int n)
  1721. {
  1722. if (n &lt; 500)
  1723. {
  1724. p = alloca (n);
  1725. f (p);
  1726. }
  1727. }
  1728. </pre></div>
  1729. <p>In the above example, <var>n</var> could be negative, causing a larger than
  1730. expected argument to be implicitly cast into the <code>alloca</code> call.
  1731. </p>
  1732. <p>This option also warns when <code>alloca</code> is used in a loop.
  1733. </p>
  1734. <p>This warning is not enabled by <samp>-Wall</samp>, and is only active when
  1735. <samp>-ftree-vrp</samp> is active (default for <samp>-O2</samp> and above).
  1736. </p>
  1737. <p>See also <samp>-Wvla-larger-than=<var>n</var></samp>.
  1738. </p>
  1739. </dd>
  1740. <dt><code>-Warray-bounds</code></dt>
  1741. <dt><code>-Warray-bounds=<var>n</var></code></dt>
  1742. <dd><a name="index-Wno_002darray_002dbounds"></a>
  1743. <a name="index-Warray_002dbounds"></a>
  1744. <p>This option is only active when <samp>-ftree-vrp</samp> is active
  1745. (default for <samp>-O2</samp> and above). It warns about subscripts to arrays
  1746. that are always out of bounds. This warning is enabled by <samp>-Wall</samp>.
  1747. </p>
  1748. <dl compact="compact">
  1749. <dt><code>-Warray-bounds=1</code></dt>
  1750. <dd><p>This is the warning level of <samp>-Warray-bounds</samp> and is enabled
  1751. by <samp>-Wall</samp>; higher levels are not, and must be explicitly requested.
  1752. </p>
  1753. </dd>
  1754. <dt><code>-Warray-bounds=2</code></dt>
  1755. <dd><p>This warning level also warns about out of bounds access for
  1756. arrays at the end of a struct and for arrays accessed through
  1757. pointers. This warning level may give a larger number of
  1758. false positives and is deactivated by default.
  1759. </p></dd>
  1760. </dl>
  1761. </dd>
  1762. <dt><code>-Wbool-compare</code></dt>
  1763. <dd><a name="index-Wno_002dbool_002dcompare"></a>
  1764. <a name="index-Wbool_002dcompare"></a>
  1765. <p>Warn about boolean expression compared with an integer value different from
  1766. <code>true</code>/<code>false</code>. For instance, the following comparison is
  1767. always false:
  1768. </p><div class="smallexample">
  1769. <pre class="smallexample">int n = 5;
  1770. &hellip;
  1771. if ((n &gt; 1) == 2) { &hellip; }
  1772. </pre></div>
  1773. <p>This warning is enabled by <samp>-Wall</samp>.
  1774. </p>
  1775. </dd>
  1776. <dt><code>-Wbool-operation</code></dt>
  1777. <dd><a name="index-Wno_002dbool_002doperation"></a>
  1778. <a name="index-Wbool_002doperation"></a>
  1779. <p>Warn about suspicious operations on expressions of a boolean type. For
  1780. instance, bitwise negation of a boolean is very likely a bug in the program.
  1781. For C, this warning also warns about incrementing or decrementing a boolean,
  1782. which rarely makes sense. (In C++, decrementing a boolean is always invalid.
  1783. Incrementing a boolean is invalid in C++1z, and deprecated otherwise.)
  1784. </p>
  1785. <p>This warning is enabled by <samp>-Wall</samp>.
  1786. </p>
  1787. </dd>
  1788. <dt><code>-Wduplicated-branches</code></dt>
  1789. <dd><a name="index-Wno_002dduplicated_002dbranches"></a>
  1790. <a name="index-Wduplicated_002dbranches"></a>
  1791. <p>Warn when an if-else has identical branches. This warning detects cases like
  1792. </p><div class="smallexample">
  1793. <pre class="smallexample">if (p != NULL)
  1794. return 0;
  1795. else
  1796. return 0;
  1797. </pre></div>
  1798. <p>It doesn&rsquo;t warn when both branches contain just a null statement. This warning
  1799. also warn for conditional operators:
  1800. </p><div class="smallexample">
  1801. <pre class="smallexample"> int i = x ? *p : *p;
  1802. </pre></div>
  1803. </dd>
  1804. <dt><code>-Wduplicated-cond</code></dt>
  1805. <dd><a name="index-Wno_002dduplicated_002dcond"></a>
  1806. <a name="index-Wduplicated_002dcond"></a>
  1807. <p>Warn about duplicated conditions in an if-else-if chain. For instance,
  1808. warn for the following code:
  1809. </p><div class="smallexample">
  1810. <pre class="smallexample">if (p-&gt;q != NULL) { &hellip; }
  1811. else if (p-&gt;q != NULL) { &hellip; }
  1812. </pre></div>
  1813. </dd>
  1814. <dt><code>-Wframe-address</code></dt>
  1815. <dd><a name="index-Wno_002dframe_002daddress"></a>
  1816. <a name="index-Wframe_002daddress"></a>
  1817. <p>Warn when the &lsquo;<samp>__builtin_frame_address</samp>&rsquo; or &lsquo;<samp>__builtin_return_address</samp>&rsquo;
  1818. is called with an argument greater than 0. Such calls may return indeterminate
  1819. values or crash the program. The warning is included in <samp>-Wall</samp>.
  1820. </p>
  1821. </dd>
  1822. <dt><code>-Wno-discarded-qualifiers <span class="roman">(C and Objective-C only)</span></code></dt>
  1823. <dd><a name="index-Wno_002ddiscarded_002dqualifiers"></a>
  1824. <a name="index-Wdiscarded_002dqualifiers"></a>
  1825. <p>Do not warn if type qualifiers on pointers are being discarded.
  1826. Typically, the compiler warns if a <code>const char *</code> variable is
  1827. passed to a function that takes a <code>char *</code> parameter. This option
  1828. can be used to suppress such a warning.
  1829. </p>
  1830. </dd>
  1831. <dt><code>-Wno-discarded-array-qualifiers <span class="roman">(C and Objective-C only)</span></code></dt>
  1832. <dd><a name="index-Wno_002ddiscarded_002darray_002dqualifiers"></a>
  1833. <a name="index-Wdiscarded_002darray_002dqualifiers"></a>
  1834. <p>Do not warn if type qualifiers on arrays which are pointer targets
  1835. are being discarded. Typically, the compiler warns if a
  1836. <code>const int (*)[]</code> variable is passed to a function that
  1837. takes a <code>int (*)[]</code> parameter. This option can be used to
  1838. suppress such a warning.
  1839. </p>
  1840. </dd>
  1841. <dt><code>-Wno-incompatible-pointer-types <span class="roman">(C and Objective-C only)</span></code></dt>
  1842. <dd><a name="index-Wno_002dincompatible_002dpointer_002dtypes"></a>
  1843. <a name="index-Wincompatible_002dpointer_002dtypes"></a>
  1844. <p>Do not warn when there is a conversion between pointers that have incompatible
  1845. types. This warning is for cases not covered by <samp>-Wno-pointer-sign</samp>,
  1846. which warns for pointer argument passing or assignment with different
  1847. signedness.
  1848. </p>
  1849. </dd>
  1850. <dt><code>-Wno-int-conversion <span class="roman">(C and Objective-C only)</span></code></dt>
  1851. <dd><a name="index-Wno_002dint_002dconversion"></a>
  1852. <a name="index-Wint_002dconversion"></a>
  1853. <p>Do not warn about incompatible integer to pointer and pointer to integer
  1854. conversions. This warning is about implicit conversions; for explicit
  1855. conversions the warnings <samp>-Wno-int-to-pointer-cast</samp> and
  1856. <samp>-Wno-pointer-to-int-cast</samp> may be used.
  1857. </p>
  1858. </dd>
  1859. <dt><code>-Wno-div-by-zero</code></dt>
  1860. <dd><a name="index-Wno_002ddiv_002dby_002dzero"></a>
  1861. <a name="index-Wdiv_002dby_002dzero"></a>
  1862. <p>Do not warn about compile-time integer division by zero. Floating-point
  1863. division by zero is not warned about, as it can be a legitimate way of
  1864. obtaining infinities and NaNs.
  1865. </p>
  1866. </dd>
  1867. <dt><code>-Wsystem-headers</code></dt>
  1868. <dd><a name="index-Wsystem_002dheaders"></a>
  1869. <a name="index-Wno_002dsystem_002dheaders"></a>
  1870. <a name="index-warnings-from-system-headers"></a>
  1871. <a name="index-system-headers_002c-warnings-from"></a>
  1872. <p>Print warning messages for constructs found in system header files.
  1873. Warnings from system headers are normally suppressed, on the assumption
  1874. that they usually do not indicate real problems and would only make the
  1875. compiler output harder to read. Using this command-line option tells
  1876. GCC to emit warnings from system headers as if they occurred in user
  1877. code. However, note that using <samp>-Wall</samp> in conjunction with this
  1878. option does <em>not</em> warn about unknown pragmas in system
  1879. headers&mdash;for that, <samp>-Wunknown-pragmas</samp> must also be used.
  1880. </p>
  1881. </dd>
  1882. <dt><code>-Wtautological-compare</code></dt>
  1883. <dd><a name="index-Wtautological_002dcompare"></a>
  1884. <a name="index-Wno_002dtautological_002dcompare"></a>
  1885. <p>Warn if a self-comparison always evaluates to true or false. This
  1886. warning detects various mistakes such as:
  1887. </p><div class="smallexample">
  1888. <pre class="smallexample">int i = 1;
  1889. &hellip;
  1890. if (i &gt; i) { &hellip; }
  1891. </pre></div>
  1892. <p>This warning is enabled by <samp>-Wall</samp>.
  1893. </p>
  1894. </dd>
  1895. <dt><code>-Wtrampolines</code></dt>
  1896. <dd><a name="index-Wtrampolines"></a>
  1897. <a name="index-Wno_002dtrampolines"></a>
  1898. <p>Warn about trampolines generated for pointers to nested functions.
  1899. A trampoline is a small piece of data or code that is created at run
  1900. time on the stack when the address of a nested function is taken, and is
  1901. used to call the nested function indirectly. For some targets, it is
  1902. made up of data only and thus requires no special treatment. But, for
  1903. most targets, it is made up of code and thus requires the stack to be
  1904. made executable in order for the program to work properly.
  1905. </p>
  1906. </dd>
  1907. <dt><code>-Wfloat-equal</code></dt>
  1908. <dd><a name="index-Wfloat_002dequal"></a>
  1909. <a name="index-Wno_002dfloat_002dequal"></a>
  1910. <p>Warn if floating-point values are used in equality comparisons.
  1911. </p>
  1912. <p>The idea behind this is that sometimes it is convenient (for the
  1913. programmer) to consider floating-point values as approximations to
  1914. infinitely precise real numbers. If you are doing this, then you need
  1915. to compute (by analyzing the code, or in some other way) the maximum or
  1916. likely maximum error that the computation introduces, and allow for it
  1917. when performing comparisons (and when producing output, but that&rsquo;s a
  1918. different problem). In particular, instead of testing for equality, you
  1919. should check to see whether the two values have ranges that overlap; and
  1920. this is done with the relational operators, so equality comparisons are
  1921. probably mistaken.
  1922. </p>
  1923. </dd>
  1924. <dt><code>-Wtraditional <span class="roman">(C and Objective-C only)</span></code></dt>
  1925. <dd><a name="index-Wtraditional"></a>
  1926. <a name="index-Wno_002dtraditional"></a>
  1927. <p>Warn about certain constructs that behave differently in traditional and
  1928. ISO C. Also warn about ISO C constructs that have no traditional C
  1929. equivalent, and/or problematic constructs that should be avoided.
  1930. </p>
  1931. <ul>
  1932. <li> Macro parameters that appear within string literals in the macro body.
  1933. In traditional C macro replacement takes place within string literals,
  1934. but in ISO C it does not.
  1935. </li><li> In traditional C, some preprocessor directives did not exist.
  1936. Traditional preprocessors only considered a line to be a directive
  1937. if the &lsquo;<samp>#</samp>&rsquo; appeared in column 1 on the line. Therefore
  1938. <samp>-Wtraditional</samp> warns about directives that traditional C
  1939. understands but ignores because the &lsquo;<samp>#</samp>&rsquo; does not appear as the
  1940. first character on the line. It also suggests you hide directives like
  1941. <code>#pragma</code> not understood by traditional C by indenting them. Some
  1942. traditional implementations do not recognize <code>#elif</code>, so this option
  1943. suggests avoiding it altogether.
  1944. </li><li> A function-like macro that appears without arguments.
  1945. </li><li> The unary plus operator.
  1946. </li><li> The &lsquo;<samp>U</samp>&rsquo; integer constant suffix, or the &lsquo;<samp>F</samp>&rsquo; or &lsquo;<samp>L</samp>&rsquo; floating-point
  1947. constant suffixes. (Traditional C does support the &lsquo;<samp>L</samp>&rsquo; suffix on integer
  1948. constants.) Note, these suffixes appear in macros defined in the system
  1949. headers of most modern systems, e.g. the &lsquo;<samp>_MIN</samp>&rsquo;/&lsquo;<samp>_MAX</samp>&rsquo; macros in <code>&lt;limits.h&gt;</code>.
  1950. Use of these macros in user code might normally lead to spurious
  1951. warnings, however GCC&rsquo;s integrated preprocessor has enough context to
  1952. avoid warning in these cases.
  1953. </li><li> A function declared external in one block and then used after the end of
  1954. the block.
  1955. </li><li> A <code>switch</code> statement has an operand of type <code>long</code>.
  1956. </li><li> A non-<code>static</code> function declaration follows a <code>static</code> one.
  1957. This construct is not accepted by some traditional C compilers.
  1958. </li><li> The ISO type of an integer constant has a different width or
  1959. signedness from its traditional type. This warning is only issued if
  1960. the base of the constant is ten. I.e. hexadecimal or octal values, which
  1961. typically represent bit patterns, are not warned about.
  1962. </li><li> Usage of ISO string concatenation is detected.
  1963. </li><li> Initialization of automatic aggregates.
  1964. </li><li> Identifier conflicts with labels. Traditional C lacks a separate
  1965. namespace for labels.
  1966. </li><li> Initialization of unions. If the initializer is zero, the warning is
  1967. omitted. This is done under the assumption that the zero initializer in
  1968. user code appears conditioned on e.g. <code>__STDC__</code> to avoid missing
  1969. initializer warnings and relies on default initialization to zero in the
  1970. traditional C case.
  1971. </li><li> Conversions by prototypes between fixed/floating-point values and vice
  1972. versa. The absence of these prototypes when compiling with traditional
  1973. C causes serious problems. This is a subset of the possible
  1974. conversion warnings; for the full set use <samp>-Wtraditional-conversion</samp>.
  1975. </li><li> Use of ISO C style function definitions. This warning intentionally is
  1976. <em>not</em> issued for prototype declarations or variadic functions
  1977. because these ISO C features appear in your code when using
  1978. libiberty&rsquo;s traditional C compatibility macros, <code>PARAMS</code> and
  1979. <code>VPARAMS</code>. This warning is also bypassed for nested functions
  1980. because that feature is already a GCC extension and thus not relevant to
  1981. traditional C compatibility.
  1982. </li></ul>
  1983. </dd>
  1984. <dt><code>-Wtraditional-conversion <span class="roman">(C and Objective-C only)</span></code></dt>
  1985. <dd><a name="index-Wtraditional_002dconversion"></a>
  1986. <a name="index-Wno_002dtraditional_002dconversion"></a>
  1987. <p>Warn if a prototype causes a type conversion that is different from what
  1988. would happen to the same argument in the absence of a prototype. This
  1989. includes conversions of fixed point to floating and vice versa, and
  1990. conversions changing the width or signedness of a fixed-point argument
  1991. except when the same as the default promotion.
  1992. </p>
  1993. </dd>
  1994. <dt><code>-Wdeclaration-after-statement <span class="roman">(C and Objective-C only)</span></code></dt>
  1995. <dd><a name="index-Wdeclaration_002dafter_002dstatement"></a>
  1996. <a name="index-Wno_002ddeclaration_002dafter_002dstatement"></a>
  1997. <p>Warn when a declaration is found after a statement in a block. This
  1998. construct, known from C++, was introduced with ISO C99 and is by default
  1999. allowed in GCC. It is not supported by ISO C90. See <a href="Mixed-Declarations.html#Mixed-Declarations">Mixed Declarations</a>.
  2000. </p>
  2001. </dd>
  2002. <dt><code>-Wshadow</code></dt>
  2003. <dd><a name="index-Wshadow"></a>
  2004. <a name="index-Wno_002dshadow"></a>
  2005. <p>Warn whenever a local variable or type declaration shadows another
  2006. variable, parameter, type, class member (in C++), or instance variable
  2007. (in Objective-C) or whenever a built-in function is shadowed. Note
  2008. that in C++, the compiler warns if a local variable shadows an
  2009. explicit typedef, but not if it shadows a struct/class/enum.
  2010. Same as <samp>-Wshadow=global</samp>.
  2011. </p>
  2012. </dd>
  2013. <dt><code>-Wno-shadow-ivar <span class="roman">(Objective-C only)</span></code></dt>
  2014. <dd><a name="index-Wno_002dshadow_002divar"></a>
  2015. <a name="index-Wshadow_002divar"></a>
  2016. <p>Do not warn whenever a local variable shadows an instance variable in an
  2017. Objective-C method.
  2018. </p>
  2019. </dd>
  2020. <dt><code>-Wshadow=global</code></dt>
  2021. <dd><a name="index-Wshadow_003dlocal"></a>
  2022. <p>The default for <samp>-Wshadow</samp>. Warns for any (global) shadowing.
  2023. </p>
  2024. </dd>
  2025. <dt><code>-Wshadow=local</code></dt>
  2026. <dd><a name="index-Wshadow_003dlocal-1"></a>
  2027. <p>Warn when a local variable shadows another local variable or parameter.
  2028. This warning is enabled by <samp>-Wshadow=global</samp>.
  2029. </p>
  2030. </dd>
  2031. <dt><code>-Wshadow=compatible-local</code></dt>
  2032. <dd><a name="index-Wshadow_003dcompatible_002dlocal"></a>
  2033. <p>Warn when a local variable shadows another local variable or parameter
  2034. whose type is compatible with that of the shadowing variable. In C++,
  2035. type compatibility here means the type of the shadowing variable can be
  2036. converted to that of the shadowed variable. The creation of this flag
  2037. (in addition to <samp>-Wshadow=local</samp>) is based on the idea that when
  2038. a local variable shadows another one of incompatible type, it is most
  2039. likely intentional, not a bug or typo, as shown in the following example:
  2040. </p>
  2041. <div class="smallexample">
  2042. <pre class="smallexample">for (SomeIterator i = SomeObj.begin(); i != SomeObj.end(); ++i)
  2043. {
  2044. for (int i = 0; i &lt; N; ++i)
  2045. {
  2046. ...
  2047. }
  2048. ...
  2049. }
  2050. </pre></div>
  2051. <p>Since the two variable <code>i</code> in the example above have incompatible types,
  2052. enabling only <samp>-Wshadow=compatible-local</samp> will not emit a warning.
  2053. Because their types are incompatible, if a programmer accidentally uses one
  2054. in place of the other, type checking will catch that and emit an error or
  2055. warning. So not warning (about shadowing) in this case will not lead to
  2056. undetected bugs. Use of this flag instead of <samp>-Wshadow=local</samp> can
  2057. possibly reduce the number of warnings triggered by intentional shadowing.
  2058. </p>
  2059. <p>This warning is enabled by <samp>-Wshadow=local</samp>.
  2060. </p>
  2061. </dd>
  2062. <dt><code>-Wlarger-than=<var>len</var></code></dt>
  2063. <dd><a name="index-Wlarger_002dthan_003dlen"></a>
  2064. <a name="index-Wlarger_002dthan_002dlen"></a>
  2065. <p>Warn whenever an object of larger than <var>len</var> bytes is defined.
  2066. </p>
  2067. </dd>
  2068. <dt><code>-Wframe-larger-than=<var>len</var></code></dt>
  2069. <dd><a name="index-Wframe_002dlarger_002dthan"></a>
  2070. <p>Warn if the size of a function frame is larger than <var>len</var> bytes.
  2071. The computation done to determine the stack frame size is approximate
  2072. and not conservative.
  2073. The actual requirements may be somewhat greater than <var>len</var>
  2074. even if you do not get a warning. In addition, any space allocated
  2075. via <code>alloca</code>, variable-length arrays, or related constructs
  2076. is not included by the compiler when determining
  2077. whether or not to issue a warning.
  2078. </p>
  2079. </dd>
  2080. <dt><code>-Wno-free-nonheap-object</code></dt>
  2081. <dd><a name="index-Wno_002dfree_002dnonheap_002dobject"></a>
  2082. <a name="index-Wfree_002dnonheap_002dobject"></a>
  2083. <p>Do not warn when attempting to free an object that was not allocated
  2084. on the heap.
  2085. </p>
  2086. </dd>
  2087. <dt><code>-Wstack-usage=<var>len</var></code></dt>
  2088. <dd><a name="index-Wstack_002dusage"></a>
  2089. <p>Warn if the stack usage of a function might be larger than <var>len</var> bytes.
  2090. The computation done to determine the stack usage is conservative.
  2091. Any space allocated via <code>alloca</code>, variable-length arrays, or related
  2092. constructs is included by the compiler when determining whether or not to
  2093. issue a warning.
  2094. </p>
  2095. <p>The message is in keeping with the output of <samp>-fstack-usage</samp>.
  2096. </p>
  2097. <ul>
  2098. <li> If the stack usage is fully static but exceeds the specified amount, it&rsquo;s:
  2099. <div class="smallexample">
  2100. <pre class="smallexample"> warning: stack usage is 1120 bytes
  2101. </pre></div>
  2102. </li><li> If the stack usage is (partly) dynamic but bounded, it&rsquo;s:
  2103. <div class="smallexample">
  2104. <pre class="smallexample"> warning: stack usage might be 1648 bytes
  2105. </pre></div>
  2106. </li><li> If the stack usage is (partly) dynamic and not bounded, it&rsquo;s:
  2107. <div class="smallexample">
  2108. <pre class="smallexample"> warning: stack usage might be unbounded
  2109. </pre></div>
  2110. </li></ul>
  2111. </dd>
  2112. <dt><code>-Wunsafe-loop-optimizations</code></dt>
  2113. <dd><a name="index-Wunsafe_002dloop_002doptimizations"></a>
  2114. <a name="index-Wno_002dunsafe_002dloop_002doptimizations"></a>
  2115. <p>Warn if the loop cannot be optimized because the compiler cannot
  2116. assume anything on the bounds of the loop indices. With
  2117. <samp>-funsafe-loop-optimizations</samp> warn if the compiler makes
  2118. such assumptions.
  2119. </p>
  2120. </dd>
  2121. <dt><code>-Wno-pedantic-ms-format <span class="roman">(MinGW targets only)</span></code></dt>
  2122. <dd><a name="index-Wno_002dpedantic_002dms_002dformat"></a>
  2123. <a name="index-Wpedantic_002dms_002dformat"></a>
  2124. <p>When used in combination with <samp>-Wformat</samp>
  2125. and <samp>-pedantic</samp> without GNU extensions, this option
  2126. disables the warnings about non-ISO <code>printf</code> / <code>scanf</code> format
  2127. width specifiers <code>I32</code>, <code>I64</code>, and <code>I</code> used on Windows targets,
  2128. which depend on the MS runtime.
  2129. </p>
  2130. </dd>
  2131. <dt><code>-Waligned-new</code></dt>
  2132. <dd><a name="index-Waligned_002dnew"></a>
  2133. <a name="index-Wno_002daligned_002dnew"></a>
  2134. <p>Warn about a new-expression of a type that requires greater alignment
  2135. than the <code>alignof(std::max_align_t)</code> but uses an allocation
  2136. function without an explicit alignment parameter. This option is
  2137. enabled by <samp>-Wall</samp>.
  2138. </p>
  2139. <p>Normally this only warns about global allocation functions, but
  2140. <samp>-Waligned-new=all</samp> also warns about class member allocation
  2141. functions.
  2142. </p>
  2143. </dd>
  2144. <dt><code>-Wplacement-new</code></dt>
  2145. <dt><code>-Wplacement-new=<var>n</var></code></dt>
  2146. <dd><a name="index-Wplacement_002dnew"></a>
  2147. <a name="index-Wno_002dplacement_002dnew"></a>
  2148. <p>Warn about placement new expressions with undefined behavior, such as
  2149. constructing an object in a buffer that is smaller than the type of
  2150. the object. For example, the placement new expression below is diagnosed
  2151. because it attempts to construct an array of 64 integers in a buffer only
  2152. 64 bytes large.
  2153. </p><div class="smallexample">
  2154. <pre class="smallexample">char buf [64];
  2155. new (buf) int[64];
  2156. </pre></div>
  2157. <p>This warning is enabled by default.
  2158. </p>
  2159. <dl compact="compact">
  2160. <dt><code>-Wplacement-new=1</code></dt>
  2161. <dd><p>This is the default warning level of <samp>-Wplacement-new</samp>. At this
  2162. level the warning is not issued for some strictly undefined constructs that
  2163. GCC allows as extensions for compatibility with legacy code. For example,
  2164. the following <code>new</code> expression is not diagnosed at this level even
  2165. though it has undefined behavior according to the C++ standard because
  2166. it writes past the end of the one-element array.
  2167. </p><div class="smallexample">
  2168. <pre class="smallexample">struct S { int n, a[1]; };
  2169. S *s = (S *)malloc (sizeof *s + 31 * sizeof s-&gt;a[0]);
  2170. new (s-&gt;a)int [32]();
  2171. </pre></div>
  2172. </dd>
  2173. <dt><code>-Wplacement-new=2</code></dt>
  2174. <dd><p>At this level, in addition to diagnosing all the same constructs as at level
  2175. 1, a diagnostic is also issued for placement new expressions that construct
  2176. an object in the last member of structure whose type is an array of a single
  2177. element and whose size is less than the size of the object being constructed.
  2178. While the previous example would be diagnosed, the following construct makes
  2179. use of the flexible member array extension to avoid the warning at level 2.
  2180. </p><div class="smallexample">
  2181. <pre class="smallexample">struct S { int n, a[]; };
  2182. S *s = (S *)malloc (sizeof *s + 32 * sizeof s-&gt;a[0]);
  2183. new (s-&gt;a)int [32]();
  2184. </pre></div>
  2185. </dd>
  2186. </dl>
  2187. </dd>
  2188. <dt><code>-Wpointer-arith</code></dt>
  2189. <dd><a name="index-Wpointer_002darith"></a>
  2190. <a name="index-Wno_002dpointer_002darith"></a>
  2191. <p>Warn about anything that depends on the &ldquo;size of&rdquo; a function type or
  2192. of <code>void</code>. GNU C assigns these types a size of 1, for
  2193. convenience in calculations with <code>void *</code> pointers and pointers
  2194. to functions. In C++, warn also when an arithmetic operation involves
  2195. <code>NULL</code>. This warning is also enabled by <samp>-Wpedantic</samp>.
  2196. </p>
  2197. </dd>
  2198. <dt><code>-Wpointer-compare</code></dt>
  2199. <dd><a name="index-Wpointer_002dcompare"></a>
  2200. <a name="index-Wno_002dpointer_002dcompare"></a>
  2201. <p>Warn if a pointer is compared with a zero character constant. This usually
  2202. means that the pointer was meant to be dereferenced. For example:
  2203. </p>
  2204. <div class="smallexample">
  2205. <pre class="smallexample">const char *p = foo ();
  2206. if (p == '\0')
  2207. return 42;
  2208. </pre></div>
  2209. <p>Note that the code above is invalid in C++11.
  2210. </p>
  2211. <p>This warning is enabled by default.
  2212. </p>
  2213. </dd>
  2214. <dt><code>-Wtype-limits</code></dt>
  2215. <dd><a name="index-Wtype_002dlimits"></a>
  2216. <a name="index-Wno_002dtype_002dlimits"></a>
  2217. <p>Warn if a comparison is always true or always false due to the limited
  2218. range of the data type, but do not warn for constant expressions. For
  2219. example, warn if an unsigned variable is compared against zero with
  2220. <code>&lt;</code> or <code>&gt;=</code>. This warning is also enabled by
  2221. <samp>-Wextra</samp>.
  2222. </p>
  2223. </dd>
  2224. <dt><code>-Wcomment</code></dt>
  2225. <dt><code>-Wcomments</code></dt>
  2226. <dd><a name="index-Wcomment"></a>
  2227. <a name="index-Wcomments"></a>
  2228. <p>Warn whenever a comment-start sequence &lsquo;<samp>/*</samp>&rsquo; appears in a &lsquo;<samp>/*</samp>&rsquo;
  2229. comment, or whenever a backslash-newline appears in a &lsquo;<samp>//</samp>&rsquo; comment.
  2230. This warning is enabled by <samp>-Wall</samp>.
  2231. </p>
  2232. </dd>
  2233. <dt><code>-Wtrigraphs</code></dt>
  2234. <dd><a name="index-Wtrigraphs"></a>
  2235. <a name="Wtrigraphs"></a><p>Warn if any trigraphs are encountered that might change the meaning of
  2236. the program. Trigraphs within comments are not warned about,
  2237. except those that would form escaped newlines.
  2238. </p>
  2239. <p>This option is implied by <samp>-Wall</samp>. If <samp>-Wall</samp> is not
  2240. given, this option is still enabled unless trigraphs are enabled. To
  2241. get trigraph conversion without warnings, but get the other
  2242. <samp>-Wall</samp> warnings, use &lsquo;<samp>-trigraphs -Wall -Wno-trigraphs</samp>&rsquo;.
  2243. </p>
  2244. </dd>
  2245. <dt><code>-Wundef</code></dt>
  2246. <dd><a name="index-Wundef"></a>
  2247. <a name="index-Wno_002dundef"></a>
  2248. <p>Warn if an undefined identifier is evaluated in an <code>#if</code> directive.
  2249. Such identifiers are replaced with zero.
  2250. </p>
  2251. </dd>
  2252. <dt><code>-Wexpansion-to-defined</code></dt>
  2253. <dd><a name="index-Wexpansion_002dto_002ddefined"></a>
  2254. <p>Warn whenever &lsquo;<samp>defined</samp>&rsquo; is encountered in the expansion of a macro
  2255. (including the case where the macro is expanded by an &lsquo;<samp>#if</samp>&rsquo; directive).
  2256. Such usage is not portable.
  2257. This warning is also enabled by <samp>-Wpedantic</samp> and <samp>-Wextra</samp>.
  2258. </p>
  2259. </dd>
  2260. <dt><code>-Wunused-macros</code></dt>
  2261. <dd><a name="index-Wunused_002dmacros"></a>
  2262. <p>Warn about macros defined in the main file that are unused. A macro
  2263. is <em>used</em> if it is expanded or tested for existence at least once.
  2264. The preprocessor also warns if the macro has not been used at the
  2265. time it is redefined or undefined.
  2266. </p>
  2267. <p>Built-in macros, macros defined on the command line, and macros
  2268. defined in include files are not warned about.
  2269. </p>
  2270. <p><em>Note:</em> If a macro is actually used, but only used in skipped
  2271. conditional blocks, then the preprocessor reports it as unused. To avoid the
  2272. warning in such a case, you might improve the scope of the macro&rsquo;s
  2273. definition by, for example, moving it into the first skipped block.
  2274. Alternatively, you could provide a dummy use with something like:
  2275. </p>
  2276. <div class="smallexample">
  2277. <pre class="smallexample">#if defined the_macro_causing_the_warning
  2278. #endif
  2279. </pre></div>
  2280. </dd>
  2281. <dt><code>-Wno-endif-labels</code></dt>
  2282. <dd><a name="index-Wno_002dendif_002dlabels"></a>
  2283. <a name="index-Wendif_002dlabels"></a>
  2284. <p>Do not warn whenever an <code>#else</code> or an <code>#endif</code> are followed by text.
  2285. This sometimes happens in older programs with code of the form
  2286. </p>
  2287. <div class="smallexample">
  2288. <pre class="smallexample">#if FOO
  2289. &hellip;
  2290. #else FOO
  2291. &hellip;
  2292. #endif FOO
  2293. </pre></div>
  2294. <p>The second and third <code>FOO</code> should be in comments.
  2295. This warning is on by default.
  2296. </p>
  2297. </dd>
  2298. <dt><code>-Wbad-function-cast <span class="roman">(C and Objective-C only)</span></code></dt>
  2299. <dd><a name="index-Wbad_002dfunction_002dcast"></a>
  2300. <a name="index-Wno_002dbad_002dfunction_002dcast"></a>
  2301. <p>Warn when a function call is cast to a non-matching type.
  2302. For example, warn if a call to a function returning an integer type
  2303. is cast to a pointer type.
  2304. </p>
  2305. </dd>
  2306. <dt><code>-Wc90-c99-compat <span class="roman">(C and Objective-C only)</span></code></dt>
  2307. <dd><a name="index-Wc90_002dc99_002dcompat"></a>
  2308. <a name="index-Wno_002dc90_002dc99_002dcompat"></a>
  2309. <p>Warn about features not present in ISO C90, but present in ISO C99.
  2310. For instance, warn about use of variable length arrays, <code>long long</code>
  2311. type, <code>bool</code> type, compound literals, designated initializers, and so
  2312. on. This option is independent of the standards mode. Warnings are disabled
  2313. in the expression that follows <code>__extension__</code>.
  2314. </p>
  2315. </dd>
  2316. <dt><code>-Wc99-c11-compat <span class="roman">(C and Objective-C only)</span></code></dt>
  2317. <dd><a name="index-Wc99_002dc11_002dcompat"></a>
  2318. <a name="index-Wno_002dc99_002dc11_002dcompat"></a>
  2319. <p>Warn about features not present in ISO C99, but present in ISO C11.
  2320. For instance, warn about use of anonymous structures and unions,
  2321. <code>_Atomic</code> type qualifier, <code>_Thread_local</code> storage-class specifier,
  2322. <code>_Alignas</code> specifier, <code>Alignof</code> operator, <code>_Generic</code> keyword,
  2323. and so on. This option is independent of the standards mode. Warnings are
  2324. disabled in the expression that follows <code>__extension__</code>.
  2325. </p>
  2326. </dd>
  2327. <dt><code>-Wc++-compat <span class="roman">(C and Objective-C only)</span></code></dt>
  2328. <dd><a name="index-Wc_002b_002b_002dcompat"></a>
  2329. <p>Warn about ISO C constructs that are outside of the common subset of
  2330. ISO C and ISO C++, e.g. request for implicit conversion from
  2331. <code>void *</code> to a pointer to non-<code>void</code> type.
  2332. </p>
  2333. </dd>
  2334. <dt><code>-Wc++11-compat <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2335. <dd><a name="index-Wc_002b_002b11_002dcompat"></a>
  2336. <p>Warn about C++ constructs whose meaning differs between ISO C++ 1998
  2337. and ISO C++ 2011, e.g., identifiers in ISO C++ 1998 that are keywords
  2338. in ISO C++ 2011. This warning turns on <samp>-Wnarrowing</samp> and is
  2339. enabled by <samp>-Wall</samp>.
  2340. </p>
  2341. </dd>
  2342. <dt><code>-Wc++14-compat <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2343. <dd><a name="index-Wc_002b_002b14_002dcompat"></a>
  2344. <p>Warn about C++ constructs whose meaning differs between ISO C++ 2011
  2345. and ISO C++ 2014. This warning is enabled by <samp>-Wall</samp>.
  2346. </p>
  2347. </dd>
  2348. <dt><code>-Wc++1z-compat <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2349. <dd><a name="index-Wc_002b_002b1z_002dcompat"></a>
  2350. <p>Warn about C++ constructs whose meaning differs between ISO C++ 2014
  2351. and the forthoming ISO C++ 2017(?). This warning is enabled by <samp>-Wall</samp>.
  2352. </p>
  2353. </dd>
  2354. <dt><code>-Wcast-qual</code></dt>
  2355. <dd><a name="index-Wcast_002dqual"></a>
  2356. <a name="index-Wno_002dcast_002dqual"></a>
  2357. <p>Warn whenever a pointer is cast so as to remove a type qualifier from
  2358. the target type. For example, warn if a <code>const char *</code> is cast
  2359. to an ordinary <code>char *</code>.
  2360. </p>
  2361. <p>Also warn when making a cast that introduces a type qualifier in an
  2362. unsafe way. For example, casting <code>char **</code> to <code>const char **</code>
  2363. is unsafe, as in this example:
  2364. </p>
  2365. <div class="smallexample">
  2366. <pre class="smallexample"> /* p is char ** value. */
  2367. const char **q = (const char **) p;
  2368. /* Assignment of readonly string to const char * is OK. */
  2369. *q = &quot;string&quot;;
  2370. /* Now char** pointer points to read-only memory. */
  2371. **p = 'b';
  2372. </pre></div>
  2373. </dd>
  2374. <dt><code>-Wcast-align</code></dt>
  2375. <dd><a name="index-Wcast_002dalign"></a>
  2376. <a name="index-Wno_002dcast_002dalign"></a>
  2377. <p>Warn whenever a pointer is cast such that the required alignment of the
  2378. target is increased. For example, warn if a <code>char *</code> is cast to
  2379. an <code>int *</code> on machines where integers can only be accessed at
  2380. two- or four-byte boundaries.
  2381. </p>
  2382. </dd>
  2383. <dt><code>-Wwrite-strings</code></dt>
  2384. <dd><a name="index-Wwrite_002dstrings"></a>
  2385. <a name="index-Wno_002dwrite_002dstrings"></a>
  2386. <p>When compiling C, give string constants the type <code>const
  2387. char[<var>length</var>]</code> so that copying the address of one into a
  2388. non-<code>const</code> <code>char *</code> pointer produces a warning. These
  2389. warnings help you find at compile time code that can try to write
  2390. into a string constant, but only if you have been very careful about
  2391. using <code>const</code> in declarations and prototypes. Otherwise, it is
  2392. just a nuisance. This is why we did not make <samp>-Wall</samp> request
  2393. these warnings.
  2394. </p>
  2395. <p>When compiling C++, warn about the deprecated conversion from string
  2396. literals to <code>char *</code>. This warning is enabled by default for C++
  2397. programs.
  2398. </p>
  2399. </dd>
  2400. <dt><code>-Wclobbered</code></dt>
  2401. <dd><a name="index-Wclobbered"></a>
  2402. <a name="index-Wno_002dclobbered"></a>
  2403. <p>Warn for variables that might be changed by <code>longjmp</code> or
  2404. <code>vfork</code>. This warning is also enabled by <samp>-Wextra</samp>.
  2405. </p>
  2406. </dd>
  2407. <dt><code>-Wconditionally-supported <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2408. <dd><a name="index-Wconditionally_002dsupported"></a>
  2409. <a name="index-Wno_002dconditionally_002dsupported"></a>
  2410. <p>Warn for conditionally-supported (C++11 [intro.defs]) constructs.
  2411. </p>
  2412. </dd>
  2413. <dt><code>-Wconversion</code></dt>
  2414. <dd><a name="index-Wconversion"></a>
  2415. <a name="index-Wno_002dconversion"></a>
  2416. <p>Warn for implicit conversions that may alter a value. This includes
  2417. conversions between real and integer, like <code>abs (x)</code> when
  2418. <code>x</code> is <code>double</code>; conversions between signed and unsigned,
  2419. like <code>unsigned ui = -1</code>; and conversions to smaller types, like
  2420. <code>sqrtf (M_PI)</code>. Do not warn for explicit casts like <code>abs
  2421. ((int) x)</code> and <code>ui = (unsigned) -1</code>, or if the value is not
  2422. changed by the conversion like in <code>abs (2.0)</code>. Warnings about
  2423. conversions between signed and unsigned integers can be disabled by
  2424. using <samp>-Wno-sign-conversion</samp>.
  2425. </p>
  2426. <p>For C++, also warn for confusing overload resolution for user-defined
  2427. conversions; and conversions that never use a type conversion
  2428. operator: conversions to <code>void</code>, the same type, a base class or a
  2429. reference to them. Warnings about conversions between signed and
  2430. unsigned integers are disabled by default in C++ unless
  2431. <samp>-Wsign-conversion</samp> is explicitly enabled.
  2432. </p>
  2433. </dd>
  2434. <dt><code>-Wno-conversion-null <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2435. <dd><a name="index-Wconversion_002dnull"></a>
  2436. <a name="index-Wno_002dconversion_002dnull"></a>
  2437. <p>Do not warn for conversions between <code>NULL</code> and non-pointer
  2438. types. <samp>-Wconversion-null</samp> is enabled by default.
  2439. </p>
  2440. </dd>
  2441. <dt><code>-Wzero-as-null-pointer-constant <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2442. <dd><a name="index-Wzero_002das_002dnull_002dpointer_002dconstant"></a>
  2443. <a name="index-Wno_002dzero_002das_002dnull_002dpointer_002dconstant"></a>
  2444. <p>Warn when a literal &lsquo;<samp>0</samp>&rsquo; is used as null pointer constant. This can
  2445. be useful to facilitate the conversion to <code>nullptr</code> in C++11.
  2446. </p>
  2447. </dd>
  2448. <dt><code>-Wsubobject-linkage <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2449. <dd><a name="index-Wsubobject_002dlinkage"></a>
  2450. <a name="index-Wno_002dsubobject_002dlinkage"></a>
  2451. <p>Warn if a class type has a base or a field whose type uses the anonymous
  2452. namespace or depends on a type with no linkage. If a type A depends on
  2453. a type B with no or internal linkage, defining it in multiple
  2454. translation units would be an ODR violation because the meaning of B
  2455. is different in each translation unit. If A only appears in a single
  2456. translation unit, the best way to silence the warning is to give it
  2457. internal linkage by putting it in an anonymous namespace as well. The
  2458. compiler doesn&rsquo;t give this warning for types defined in the main .C
  2459. file, as those are unlikely to have multiple definitions.
  2460. <samp>-Wsubobject-linkage</samp> is enabled by default.
  2461. </p>
  2462. </dd>
  2463. <dt><code>-Wdangling-else</code></dt>
  2464. <dd><a name="index-Wdangling_002delse"></a>
  2465. <a name="index-Wno_002ddangling_002delse"></a>
  2466. <p>Warn about constructions where there may be confusion to which
  2467. <code>if</code> statement an <code>else</code> branch belongs. Here is an example of
  2468. such a case:
  2469. </p>
  2470. <div class="smallexample">
  2471. <pre class="smallexample">{
  2472. if (a)
  2473. if (b)
  2474. foo ();
  2475. else
  2476. bar ();
  2477. }
  2478. </pre></div>
  2479. <p>In C/C++, every <code>else</code> branch belongs to the innermost possible
  2480. <code>if</code> statement, which in this example is <code>if (b)</code>. This is
  2481. often not what the programmer expected, as illustrated in the above
  2482. example by indentation the programmer chose. When there is the
  2483. potential for this confusion, GCC issues a warning when this flag
  2484. is specified. To eliminate the warning, add explicit braces around
  2485. the innermost <code>if</code> statement so there is no way the <code>else</code>
  2486. can belong to the enclosing <code>if</code>. The resulting code
  2487. looks like this:
  2488. </p>
  2489. <div class="smallexample">
  2490. <pre class="smallexample">{
  2491. if (a)
  2492. {
  2493. if (b)
  2494. foo ();
  2495. else
  2496. bar ();
  2497. }
  2498. }
  2499. </pre></div>
  2500. <p>This warning is enabled by <samp>-Wparentheses</samp>.
  2501. </p>
  2502. </dd>
  2503. <dt><code>-Wdate-time</code></dt>
  2504. <dd><a name="index-Wdate_002dtime"></a>
  2505. <a name="index-Wno_002ddate_002dtime"></a>
  2506. <p>Warn when macros <code>__TIME__</code>, <code>__DATE__</code> or <code>__TIMESTAMP__</code>
  2507. are encountered as they might prevent bit-wise-identical reproducible
  2508. compilations.
  2509. </p>
  2510. </dd>
  2511. <dt><code>-Wdelete-incomplete <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2512. <dd><a name="index-Wdelete_002dincomplete"></a>
  2513. <a name="index-Wno_002ddelete_002dincomplete"></a>
  2514. <p>Warn when deleting a pointer to incomplete type, which may cause
  2515. undefined behavior at runtime. This warning is enabled by default.
  2516. </p>
  2517. </dd>
  2518. <dt><code>-Wuseless-cast <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2519. <dd><a name="index-Wuseless_002dcast"></a>
  2520. <a name="index-Wno_002duseless_002dcast"></a>
  2521. <p>Warn when an expression is casted to its own type.
  2522. </p>
  2523. </dd>
  2524. <dt><code>-Wempty-body</code></dt>
  2525. <dd><a name="index-Wempty_002dbody"></a>
  2526. <a name="index-Wno_002dempty_002dbody"></a>
  2527. <p>Warn if an empty body occurs in an <code>if</code>, <code>else</code> or <code>do
  2528. while</code> statement. This warning is also enabled by <samp>-Wextra</samp>.
  2529. </p>
  2530. </dd>
  2531. <dt><code>-Wenum-compare</code></dt>
  2532. <dd><a name="index-Wenum_002dcompare"></a>
  2533. <a name="index-Wno_002denum_002dcompare"></a>
  2534. <p>Warn about a comparison between values of different enumerated types.
  2535. In C++ enumerated type mismatches in conditional expressions are also
  2536. diagnosed and the warning is enabled by default. In C this warning is
  2537. enabled by <samp>-Wall</samp>.
  2538. </p>
  2539. </dd>
  2540. <dt><code>-Wjump-misses-init <span class="roman">(C, Objective-C only)</span></code></dt>
  2541. <dd><a name="index-Wjump_002dmisses_002dinit"></a>
  2542. <a name="index-Wno_002djump_002dmisses_002dinit"></a>
  2543. <p>Warn if a <code>goto</code> statement or a <code>switch</code> statement jumps
  2544. forward across the initialization of a variable, or jumps backward to a
  2545. label after the variable has been initialized. This only warns about
  2546. variables that are initialized when they are declared. This warning is
  2547. only supported for C and Objective-C; in C++ this sort of branch is an
  2548. error in any case.
  2549. </p>
  2550. <p><samp>-Wjump-misses-init</samp> is included in <samp>-Wc++-compat</samp>. It
  2551. can be disabled with the <samp>-Wno-jump-misses-init</samp> option.
  2552. </p>
  2553. </dd>
  2554. <dt><code>-Wsign-compare</code></dt>
  2555. <dd><a name="index-Wsign_002dcompare"></a>
  2556. <a name="index-Wno_002dsign_002dcompare"></a>
  2557. <a name="index-warning-for-comparison-of-signed-and-unsigned-values"></a>
  2558. <a name="index-comparison-of-signed-and-unsigned-values_002c-warning"></a>
  2559. <a name="index-signed-and-unsigned-values_002c-comparison-warning"></a>
  2560. <p>Warn when a comparison between signed and unsigned values could produce
  2561. an incorrect result when the signed value is converted to unsigned.
  2562. In C++, this warning is also enabled by <samp>-Wall</samp>. In C, it is
  2563. also enabled by <samp>-Wextra</samp>.
  2564. </p>
  2565. </dd>
  2566. <dt><code>-Wsign-conversion</code></dt>
  2567. <dd><a name="index-Wsign_002dconversion"></a>
  2568. <a name="index-Wno_002dsign_002dconversion"></a>
  2569. <p>Warn for implicit conversions that may change the sign of an integer
  2570. value, like assigning a signed integer expression to an unsigned
  2571. integer variable. An explicit cast silences the warning. In C, this
  2572. option is enabled also by <samp>-Wconversion</samp>.
  2573. </p>
  2574. </dd>
  2575. <dt><code>-Wfloat-conversion</code></dt>
  2576. <dd><a name="index-Wfloat_002dconversion"></a>
  2577. <a name="index-Wno_002dfloat_002dconversion"></a>
  2578. <p>Warn for implicit conversions that reduce the precision of a real value.
  2579. This includes conversions from real to integer, and from higher precision
  2580. real to lower precision real values. This option is also enabled by
  2581. <samp>-Wconversion</samp>.
  2582. </p>
  2583. </dd>
  2584. <dt><code>-Wno-scalar-storage-order</code></dt>
  2585. <dd><a name="index-_002dWno_002dscalar_002dstorage_002dorder"></a>
  2586. <a name="index-_002dWscalar_002dstorage_002dorder"></a>
  2587. <p>Do not warn on suspicious constructs involving reverse scalar storage order.
  2588. </p>
  2589. </dd>
  2590. <dt><code>-Wsized-deallocation <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  2591. <dd><a name="index-Wsized_002ddeallocation"></a>
  2592. <a name="index-Wno_002dsized_002ddeallocation"></a>
  2593. <p>Warn about a definition of an unsized deallocation function
  2594. </p><div class="smallexample">
  2595. <pre class="smallexample">void operator delete (void *) noexcept;
  2596. void operator delete[] (void *) noexcept;
  2597. </pre></div>
  2598. <p>without a definition of the corresponding sized deallocation function
  2599. </p><div class="smallexample">
  2600. <pre class="smallexample">void operator delete (void *, std::size_t) noexcept;
  2601. void operator delete[] (void *, std::size_t) noexcept;
  2602. </pre></div>
  2603. <p>or vice versa. Enabled by <samp>-Wextra</samp> along with
  2604. <samp>-fsized-deallocation</samp>.
  2605. </p>
  2606. </dd>
  2607. <dt><code>-Wsizeof-pointer-memaccess</code></dt>
  2608. <dd><a name="index-Wsizeof_002dpointer_002dmemaccess"></a>
  2609. <a name="index-Wno_002dsizeof_002dpointer_002dmemaccess"></a>
  2610. <p>Warn for suspicious length parameters to certain string and memory built-in
  2611. functions if the argument uses <code>sizeof</code>. This warning warns e.g.
  2612. about <code>memset (ptr, 0, sizeof (ptr));</code> if <code>ptr</code> is not an array,
  2613. but a pointer, and suggests a possible fix, or about
  2614. <code>memcpy (&amp;foo, ptr, sizeof (&amp;foo));</code>. This warning is enabled by
  2615. <samp>-Wall</samp>.
  2616. </p>
  2617. </dd>
  2618. <dt><code>-Wsizeof-array-argument</code></dt>
  2619. <dd><a name="index-Wsizeof_002darray_002dargument"></a>
  2620. <a name="index-Wno_002dsizeof_002darray_002dargument"></a>
  2621. <p>Warn when the <code>sizeof</code> operator is applied to a parameter that is
  2622. declared as an array in a function definition. This warning is enabled by
  2623. default for C and C++ programs.
  2624. </p>
  2625. </dd>
  2626. <dt><code>-Wmemset-elt-size</code></dt>
  2627. <dd><a name="index-Wmemset_002delt_002dsize"></a>
  2628. <a name="index-Wno_002dmemset_002delt_002dsize"></a>
  2629. <p>Warn for suspicious calls to the <code>memset</code> built-in function, if the
  2630. first argument references an array, and the third argument is a number
  2631. equal to the number of elements, but not equal to the size of the array
  2632. in memory. This indicates that the user has omitted a multiplication by
  2633. the element size. This warning is enabled by <samp>-Wall</samp>.
  2634. </p>
  2635. </dd>
  2636. <dt><code>-Wmemset-transposed-args</code></dt>
  2637. <dd><a name="index-Wmemset_002dtransposed_002dargs"></a>
  2638. <a name="index-Wno_002dmemset_002dtransposed_002dargs"></a>
  2639. <p>Warn for suspicious calls to the <code>memset</code> built-in function, if the
  2640. second argument is not zero and the third argument is zero. This warns e.g.&nbsp;about <code>memset (buf, sizeof buf, 0)</code> where most probably
  2641. <code>memset (buf, 0, sizeof buf)</code> was meant instead. The diagnostics
  2642. is only emitted if the third argument is literal zero. If it is some
  2643. expression that is folded to zero, a cast of zero to some type, etc.,
  2644. it is far less likely that the user has mistakenly exchanged the arguments
  2645. and no warning is emitted. This warning is enabled by <samp>-Wall</samp>.
  2646. </p>
  2647. </dd>
  2648. <dt><code>-Waddress</code></dt>
  2649. <dd><a name="index-Waddress"></a>
  2650. <a name="index-Wno_002daddress"></a>
  2651. <p>Warn about suspicious uses of memory addresses. These include using
  2652. the address of a function in a conditional expression, such as
  2653. <code>void func(void); if (func)</code>, and comparisons against the memory
  2654. address of a string literal, such as <code>if (x == &quot;abc&quot;)</code>. Such
  2655. uses typically indicate a programmer error: the address of a function
  2656. always evaluates to true, so their use in a conditional usually
  2657. indicate that the programmer forgot the parentheses in a function
  2658. call; and comparisons against string literals result in unspecified
  2659. behavior and are not portable in C, so they usually indicate that the
  2660. programmer intended to use <code>strcmp</code>. This warning is enabled by
  2661. <samp>-Wall</samp>.
  2662. </p>
  2663. </dd>
  2664. <dt><code>-Wlogical-op</code></dt>
  2665. <dd><a name="index-Wlogical_002dop"></a>
  2666. <a name="index-Wno_002dlogical_002dop"></a>
  2667. <p>Warn about suspicious uses of logical operators in expressions.
  2668. This includes using logical operators in contexts where a
  2669. bit-wise operator is likely to be expected. Also warns when
  2670. the operands of a logical operator are the same:
  2671. </p><div class="smallexample">
  2672. <pre class="smallexample">extern int a;
  2673. if (a &lt; 0 &amp;&amp; a &lt; 0) { &hellip; }
  2674. </pre></div>
  2675. </dd>
  2676. <dt><code>-Wlogical-not-parentheses</code></dt>
  2677. <dd><a name="index-Wlogical_002dnot_002dparentheses"></a>
  2678. <a name="index-Wno_002dlogical_002dnot_002dparentheses"></a>
  2679. <p>Warn about logical not used on the left hand side operand of a comparison.
  2680. This option does not warn if the right operand is considered to be a boolean
  2681. expression. Its purpose is to detect suspicious code like the following:
  2682. </p><div class="smallexample">
  2683. <pre class="smallexample">int a;
  2684. &hellip;
  2685. if (!a &gt; 1) { &hellip; }
  2686. </pre></div>
  2687. <p>It is possible to suppress the warning by wrapping the LHS into
  2688. parentheses:
  2689. </p><div class="smallexample">
  2690. <pre class="smallexample">if ((!a) &gt; 1) { &hellip; }
  2691. </pre></div>
  2692. <p>This warning is enabled by <samp>-Wall</samp>.
  2693. </p>
  2694. </dd>
  2695. <dt><code>-Waggregate-return</code></dt>
  2696. <dd><a name="index-Waggregate_002dreturn"></a>
  2697. <a name="index-Wno_002daggregate_002dreturn"></a>
  2698. <p>Warn if any functions that return structures or unions are defined or
  2699. called. (In languages where you can return an array, this also elicits
  2700. a warning.)
  2701. </p>
  2702. </dd>
  2703. <dt><code>-Wno-aggressive-loop-optimizations</code></dt>
  2704. <dd><a name="index-Wno_002daggressive_002dloop_002doptimizations"></a>
  2705. <a name="index-Waggressive_002dloop_002doptimizations"></a>
  2706. <p>Warn if in a loop with constant number of iterations the compiler detects
  2707. undefined behavior in some statement during one or more of the iterations.
  2708. </p>
  2709. </dd>
  2710. <dt><code>-Wno-attributes</code></dt>
  2711. <dd><a name="index-Wno_002dattributes"></a>
  2712. <a name="index-Wattributes"></a>
  2713. <p>Do not warn if an unexpected <code>__attribute__</code> is used, such as
  2714. unrecognized attributes, function attributes applied to variables,
  2715. etc. This does not stop errors for incorrect use of supported
  2716. attributes.
  2717. </p>
  2718. </dd>
  2719. <dt><code>-Wno-builtin-declaration-mismatch</code></dt>
  2720. <dd><a name="index-Wno_002dbuiltin_002ddeclaration_002dmismatch"></a>
  2721. <a name="index-Wbuiltin_002ddeclaration_002dmismatch"></a>
  2722. <p>Warn if a built-in function is declared with the wrong signature.
  2723. This warning is enabled by default.
  2724. </p>
  2725. </dd>
  2726. <dt><code>-Wno-builtin-macro-redefined</code></dt>
  2727. <dd><a name="index-Wno_002dbuiltin_002dmacro_002dredefined"></a>
  2728. <a name="index-Wbuiltin_002dmacro_002dredefined"></a>
  2729. <p>Do not warn if certain built-in macros are redefined. This suppresses
  2730. warnings for redefinition of <code>__TIMESTAMP__</code>, <code>__TIME__</code>,
  2731. <code>__DATE__</code>, <code>__FILE__</code>, and <code>__BASE_FILE__</code>.
  2732. </p>
  2733. </dd>
  2734. <dt><code>-Wstrict-prototypes <span class="roman">(C and Objective-C only)</span></code></dt>
  2735. <dd><a name="index-Wstrict_002dprototypes"></a>
  2736. <a name="index-Wno_002dstrict_002dprototypes"></a>
  2737. <p>Warn if a function is declared or defined without specifying the
  2738. argument types. (An old-style function definition is permitted without
  2739. a warning if preceded by a declaration that specifies the argument
  2740. types.)
  2741. </p>
  2742. </dd>
  2743. <dt><code>-Wold-style-declaration <span class="roman">(C and Objective-C only)</span></code></dt>
  2744. <dd><a name="index-Wold_002dstyle_002ddeclaration"></a>
  2745. <a name="index-Wno_002dold_002dstyle_002ddeclaration"></a>
  2746. <p>Warn for obsolescent usages, according to the C Standard, in a
  2747. declaration. For example, warn if storage-class specifiers like
  2748. <code>static</code> are not the first things in a declaration. This warning
  2749. is also enabled by <samp>-Wextra</samp>.
  2750. </p>
  2751. </dd>
  2752. <dt><code>-Wold-style-definition <span class="roman">(C and Objective-C only)</span></code></dt>
  2753. <dd><a name="index-Wold_002dstyle_002ddefinition"></a>
  2754. <a name="index-Wno_002dold_002dstyle_002ddefinition"></a>
  2755. <p>Warn if an old-style function definition is used. A warning is given
  2756. even if there is a previous prototype.
  2757. </p>
  2758. </dd>
  2759. <dt><code>-Wmissing-parameter-type <span class="roman">(C and Objective-C only)</span></code></dt>
  2760. <dd><a name="index-Wmissing_002dparameter_002dtype"></a>
  2761. <a name="index-Wno_002dmissing_002dparameter_002dtype"></a>
  2762. <p>A function parameter is declared without a type specifier in K&amp;R-style
  2763. functions:
  2764. </p>
  2765. <div class="smallexample">
  2766. <pre class="smallexample">void foo(bar) { }
  2767. </pre></div>
  2768. <p>This warning is also enabled by <samp>-Wextra</samp>.
  2769. </p>
  2770. </dd>
  2771. <dt><code>-Wmissing-prototypes <span class="roman">(C and Objective-C only)</span></code></dt>
  2772. <dd><a name="index-Wmissing_002dprototypes"></a>
  2773. <a name="index-Wno_002dmissing_002dprototypes"></a>
  2774. <p>Warn if a global function is defined without a previous prototype
  2775. declaration. This warning is issued even if the definition itself
  2776. provides a prototype. Use this option to detect global functions
  2777. that do not have a matching prototype declaration in a header file.
  2778. This option is not valid for C++ because all function declarations
  2779. provide prototypes and a non-matching declaration declares an
  2780. overload rather than conflict with an earlier declaration.
  2781. Use <samp>-Wmissing-declarations</samp> to detect missing declarations in C++.
  2782. </p>
  2783. </dd>
  2784. <dt><code>-Wmissing-declarations</code></dt>
  2785. <dd><a name="index-Wmissing_002ddeclarations"></a>
  2786. <a name="index-Wno_002dmissing_002ddeclarations"></a>
  2787. <p>Warn if a global function is defined without a previous declaration.
  2788. Do so even if the definition itself provides a prototype.
  2789. Use this option to detect global functions that are not declared in
  2790. header files. In C, no warnings are issued for functions with previous
  2791. non-prototype declarations; use <samp>-Wmissing-prototypes</samp> to detect
  2792. missing prototypes. In C++, no warnings are issued for function templates,
  2793. or for inline functions, or for functions in anonymous namespaces.
  2794. </p>
  2795. </dd>
  2796. <dt><code>-Wmissing-field-initializers</code></dt>
  2797. <dd><a name="index-Wmissing_002dfield_002dinitializers"></a>
  2798. <a name="index-Wno_002dmissing_002dfield_002dinitializers"></a>
  2799. <a name="index-W-1"></a>
  2800. <a name="index-Wextra-1"></a>
  2801. <a name="index-Wno_002dextra-1"></a>
  2802. <p>Warn if a structure&rsquo;s initializer has some fields missing. For
  2803. example, the following code causes such a warning, because
  2804. <code>x.h</code> is implicitly zero:
  2805. </p>
  2806. <div class="smallexample">
  2807. <pre class="smallexample">struct s { int f, g, h; };
  2808. struct s x = { 3, 4 };
  2809. </pre></div>
  2810. <p>This option does not warn about designated initializers, so the following
  2811. modification does not trigger a warning:
  2812. </p>
  2813. <div class="smallexample">
  2814. <pre class="smallexample">struct s { int f, g, h; };
  2815. struct s x = { .f = 3, .g = 4 };
  2816. </pre></div>
  2817. <p>In C++ this option does not warn either about the empty { }
  2818. initializer, for example:
  2819. </p>
  2820. <div class="smallexample">
  2821. <pre class="smallexample">struct s { int f, g, h; };
  2822. s x = { };
  2823. </pre></div>
  2824. <p>This warning is included in <samp>-Wextra</samp>. To get other <samp>-Wextra</samp>
  2825. warnings without this one, use <samp>-Wextra -Wno-missing-field-initializers</samp>.
  2826. </p>
  2827. </dd>
  2828. <dt><code>-Wno-multichar</code></dt>
  2829. <dd><a name="index-Wno_002dmultichar"></a>
  2830. <a name="index-Wmultichar"></a>
  2831. <p>Do not warn if a multicharacter constant (&lsquo;<samp>'FOOF'</samp>&rsquo;) is used.
  2832. Usually they indicate a typo in the user&rsquo;s code, as they have
  2833. implementation-defined values, and should not be used in portable code.
  2834. </p>
  2835. </dd>
  2836. <dt><code>-Wnormalized=<span class="roman">[</span>none<span class="roman">|</span>id<span class="roman">|</span>nfc<span class="roman">|</span>nfkc<span class="roman">]</span></code></dt>
  2837. <dd><a name="index-Wnormalized_003d"></a>
  2838. <a name="index-Wnormalized"></a>
  2839. <a name="index-Wno_002dnormalized"></a>
  2840. <a name="index-NFC"></a>
  2841. <a name="index-NFKC"></a>
  2842. <a name="index-character-set_002c-input-normalization"></a>
  2843. <p>In ISO C and ISO C++, two identifiers are different if they are
  2844. different sequences of characters. However, sometimes when characters
  2845. outside the basic ASCII character set are used, you can have two
  2846. different character sequences that look the same. To avoid confusion,
  2847. the ISO 10646 standard sets out some <em>normalization rules</em> which
  2848. when applied ensure that two sequences that look the same are turned into
  2849. the same sequence. GCC can warn you if you are using identifiers that
  2850. have not been normalized; this option controls that warning.
  2851. </p>
  2852. <p>There are four levels of warning supported by GCC. The default is
  2853. <samp>-Wnormalized=nfc</samp>, which warns about any identifier that is
  2854. not in the ISO 10646 &ldquo;C&rdquo; normalized form, <em>NFC</em>. NFC is the
  2855. recommended form for most uses. It is equivalent to
  2856. <samp>-Wnormalized</samp>.
  2857. </p>
  2858. <p>Unfortunately, there are some characters allowed in identifiers by
  2859. ISO C and ISO C++ that, when turned into NFC, are not allowed in
  2860. identifiers. That is, there&rsquo;s no way to use these symbols in portable
  2861. ISO C or C++ and have all your identifiers in NFC.
  2862. <samp>-Wnormalized=id</samp> suppresses the warning for these characters.
  2863. It is hoped that future versions of the standards involved will correct
  2864. this, which is why this option is not the default.
  2865. </p>
  2866. <p>You can switch the warning off for all characters by writing
  2867. <samp>-Wnormalized=none</samp> or <samp>-Wno-normalized</samp>. You should
  2868. only do this if you are using some other normalization scheme (like
  2869. &ldquo;D&rdquo;), because otherwise you can easily create bugs that are
  2870. literally impossible to see.
  2871. </p>
  2872. <p>Some characters in ISO 10646 have distinct meanings but look identical
  2873. in some fonts or display methodologies, especially once formatting has
  2874. been applied. For instance <code>\u207F</code>, &ldquo;SUPERSCRIPT LATIN SMALL
  2875. LETTER N&rdquo;, displays just like a regular <code>n</code> that has been
  2876. placed in a superscript. ISO 10646 defines the <em>NFKC</em>
  2877. normalization scheme to convert all these into a standard form as
  2878. well, and GCC warns if your code is not in NFKC if you use
  2879. <samp>-Wnormalized=nfkc</samp>. This warning is comparable to warning
  2880. about every identifier that contains the letter O because it might be
  2881. confused with the digit 0, and so is not the default, but may be
  2882. useful as a local coding convention if the programming environment
  2883. cannot be fixed to display these characters distinctly.
  2884. </p>
  2885. </dd>
  2886. <dt><code>-Wno-deprecated</code></dt>
  2887. <dd><a name="index-Wno_002ddeprecated"></a>
  2888. <a name="index-Wdeprecated"></a>
  2889. <p>Do not warn about usage of deprecated features. See <a href="Deprecated-Features.html#Deprecated-Features">Deprecated Features</a>.
  2890. </p>
  2891. </dd>
  2892. <dt><code>-Wno-deprecated-declarations</code></dt>
  2893. <dd><a name="index-Wno_002ddeprecated_002ddeclarations"></a>
  2894. <a name="index-Wdeprecated_002ddeclarations"></a>
  2895. <p>Do not warn about uses of functions (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>),
  2896. variables (see <a href="Variable-Attributes.html#Variable-Attributes">Variable Attributes</a>), and types (see <a href="Type-Attributes.html#Type-Attributes">Type Attributes</a>) marked as deprecated by using the <code>deprecated</code>
  2897. attribute.
  2898. </p>
  2899. </dd>
  2900. <dt><code>-Wno-overflow</code></dt>
  2901. <dd><a name="index-Wno_002doverflow"></a>
  2902. <a name="index-Woverflow"></a>
  2903. <p>Do not warn about compile-time overflow in constant expressions.
  2904. </p>
  2905. </dd>
  2906. <dt><code>-Wno-odr</code></dt>
  2907. <dd><a name="index-Wno_002dodr"></a>
  2908. <a name="index-Wodr"></a>
  2909. <p>Warn about One Definition Rule violations during link-time optimization.
  2910. Requires <samp>-flto-odr-type-merging</samp> to be enabled. Enabled by default.
  2911. </p>
  2912. </dd>
  2913. <dt><code>-Wopenmp-simd</code></dt>
  2914. <dd><a name="index-Wopenm_002dsimd"></a>
  2915. <p>Warn if the vectorizer cost model overrides the OpenMP or the Cilk Plus
  2916. simd directive set by user. The <samp>-fsimd-cost-model=unlimited</samp>
  2917. option can be used to relax the cost model.
  2918. </p>
  2919. </dd>
  2920. <dt><code>-Woverride-init <span class="roman">(C and Objective-C only)</span></code></dt>
  2921. <dd><a name="index-Woverride_002dinit"></a>
  2922. <a name="index-Wno_002doverride_002dinit"></a>
  2923. <a name="index-W-2"></a>
  2924. <a name="index-Wextra-2"></a>
  2925. <a name="index-Wno_002dextra-2"></a>
  2926. <p>Warn if an initialized field without side effects is overridden when
  2927. using designated initializers (see <a href="Designated-Inits.html#Designated-Inits">Designated
  2928. Initializers</a>).
  2929. </p>
  2930. <p>This warning is included in <samp>-Wextra</samp>. To get other
  2931. <samp>-Wextra</samp> warnings without this one, use <samp>-Wextra
  2932. -Wno-override-init</samp>.
  2933. </p>
  2934. </dd>
  2935. <dt><code>-Woverride-init-side-effects <span class="roman">(C and Objective-C only)</span></code></dt>
  2936. <dd><a name="index-Woverride_002dinit_002dside_002deffects"></a>
  2937. <a name="index-Wno_002doverride_002dinit_002dside_002deffects"></a>
  2938. <p>Warn if an initialized field with side effects is overridden when
  2939. using designated initializers (see <a href="Designated-Inits.html#Designated-Inits">Designated
  2940. Initializers</a>). This warning is enabled by default.
  2941. </p>
  2942. </dd>
  2943. <dt><code>-Wpacked</code></dt>
  2944. <dd><a name="index-Wpacked"></a>
  2945. <a name="index-Wno_002dpacked"></a>
  2946. <p>Warn if a structure is given the packed attribute, but the packed
  2947. attribute has no effect on the layout or size of the structure.
  2948. Such structures may be mis-aligned for little benefit. For
  2949. instance, in this code, the variable <code>f.x</code> in <code>struct bar</code>
  2950. is misaligned even though <code>struct bar</code> does not itself
  2951. have the packed attribute:
  2952. </p>
  2953. <div class="smallexample">
  2954. <pre class="smallexample">struct foo {
  2955. int x;
  2956. char a, b, c, d;
  2957. } __attribute__((packed));
  2958. struct bar {
  2959. char z;
  2960. struct foo f;
  2961. };
  2962. </pre></div>
  2963. </dd>
  2964. <dt><code>-Wpacked-bitfield-compat</code></dt>
  2965. <dd><a name="index-Wpacked_002dbitfield_002dcompat"></a>
  2966. <a name="index-Wno_002dpacked_002dbitfield_002dcompat"></a>
  2967. <p>The 4.1, 4.2 and 4.3 series of GCC ignore the <code>packed</code> attribute
  2968. on bit-fields of type <code>char</code>. This has been fixed in GCC 4.4 but
  2969. the change can lead to differences in the structure layout. GCC
  2970. informs you when the offset of such a field has changed in GCC 4.4.
  2971. For example there is no longer a 4-bit padding between field <code>a</code>
  2972. and <code>b</code> in this structure:
  2973. </p>
  2974. <div class="smallexample">
  2975. <pre class="smallexample">struct foo
  2976. {
  2977. char a:4;
  2978. char b:8;
  2979. } __attribute__ ((packed));
  2980. </pre></div>
  2981. <p>This warning is enabled by default. Use
  2982. <samp>-Wno-packed-bitfield-compat</samp> to disable this warning.
  2983. </p>
  2984. </dd>
  2985. <dt><code>-Wpadded</code></dt>
  2986. <dd><a name="index-Wpadded"></a>
  2987. <a name="index-Wno_002dpadded"></a>
  2988. <p>Warn if padding is included in a structure, either to align an element
  2989. of the structure or to align the whole structure. Sometimes when this
  2990. happens it is possible to rearrange the fields of the structure to
  2991. reduce the padding and so make the structure smaller.
  2992. </p>
  2993. </dd>
  2994. <dt><code>-Wredundant-decls</code></dt>
  2995. <dd><a name="index-Wredundant_002ddecls"></a>
  2996. <a name="index-Wno_002dredundant_002ddecls"></a>
  2997. <p>Warn if anything is declared more than once in the same scope, even in
  2998. cases where multiple declaration is valid and changes nothing.
  2999. </p>
  3000. </dd>
  3001. <dt><code>-Wrestrict</code></dt>
  3002. <dd><a name="index-Wrestrict"></a>
  3003. <a name="index-Wno_002drestrict"></a>
  3004. <p>Warn when an argument passed to a restrict-qualified parameter
  3005. aliases with another argument.
  3006. </p>
  3007. </dd>
  3008. <dt><code>-Wnested-externs <span class="roman">(C and Objective-C only)</span></code></dt>
  3009. <dd><a name="index-Wnested_002dexterns"></a>
  3010. <a name="index-Wno_002dnested_002dexterns"></a>
  3011. <p>Warn if an <code>extern</code> declaration is encountered within a function.
  3012. </p>
  3013. </dd>
  3014. <dt><code>-Wno-inherited-variadic-ctor</code></dt>
  3015. <dd><a name="index-Winherited_002dvariadic_002dctor"></a>
  3016. <a name="index-Wno_002dinherited_002dvariadic_002dctor"></a>
  3017. <p>Suppress warnings about use of C++11 inheriting constructors when the
  3018. base class inherited from has a C variadic constructor; the warning is
  3019. on by default because the ellipsis is not inherited.
  3020. </p>
  3021. </dd>
  3022. <dt><code>-Winline</code></dt>
  3023. <dd><a name="index-Winline"></a>
  3024. <a name="index-Wno_002dinline"></a>
  3025. <p>Warn if a function that is declared as inline cannot be inlined.
  3026. Even with this option, the compiler does not warn about failures to
  3027. inline functions declared in system headers.
  3028. </p>
  3029. <p>The compiler uses a variety of heuristics to determine whether or not
  3030. to inline a function. For example, the compiler takes into account
  3031. the size of the function being inlined and the amount of inlining
  3032. that has already been done in the current function. Therefore,
  3033. seemingly insignificant changes in the source program can cause the
  3034. warnings produced by <samp>-Winline</samp> to appear or disappear.
  3035. </p>
  3036. </dd>
  3037. <dt><code>-Wno-invalid-offsetof <span class="roman">(C++ and Objective-C++ only)</span></code></dt>
  3038. <dd><a name="index-Wno_002dinvalid_002doffsetof"></a>
  3039. <a name="index-Winvalid_002doffsetof"></a>
  3040. <p>Suppress warnings from applying the <code>offsetof</code> macro to a non-POD
  3041. type. According to the 2014 ISO C++ standard, applying <code>offsetof</code>
  3042. to a non-standard-layout type is undefined. In existing C++ implementations,
  3043. however, <code>offsetof</code> typically gives meaningful results.
  3044. This flag is for users who are aware that they are
  3045. writing nonportable code and who have deliberately chosen to ignore the
  3046. warning about it.
  3047. </p>
  3048. <p>The restrictions on <code>offsetof</code> may be relaxed in a future version
  3049. of the C++ standard.
  3050. </p>
  3051. </dd>
  3052. <dt><code>-Wint-in-bool-context</code></dt>
  3053. <dd><a name="index-Wint_002din_002dbool_002dcontext"></a>
  3054. <a name="index-Wno_002dint_002din_002dbool_002dcontext"></a>
  3055. <p>Warn for suspicious use of integer values where boolean values are expected,
  3056. such as conditional expressions (?:) using non-boolean integer constants in
  3057. boolean context, like <code>if (a &lt;= b ? 2 : 3)</code>. Or left shifting of signed
  3058. integers in boolean context, like <code>for (a = 0; 1 &lt;&lt; a; a++);</code>. Likewise
  3059. for all kinds of multiplications regardless of the data type.
  3060. This warning is enabled by <samp>-Wall</samp>.
  3061. </p>
  3062. </dd>
  3063. <dt><code>-Wno-int-to-pointer-cast</code></dt>
  3064. <dd><a name="index-Wno_002dint_002dto_002dpointer_002dcast"></a>
  3065. <a name="index-Wint_002dto_002dpointer_002dcast"></a>
  3066. <p>Suppress warnings from casts to pointer type of an integer of a
  3067. different size. In C++, casting to a pointer type of smaller size is
  3068. an error. <samp>Wint-to-pointer-cast</samp> is enabled by default.
  3069. </p>
  3070. </dd>
  3071. <dt><code>-Wno-pointer-to-int-cast <span class="roman">(C and Objective-C only)</span></code></dt>
  3072. <dd><a name="index-Wno_002dpointer_002dto_002dint_002dcast"></a>
  3073. <a name="index-Wpointer_002dto_002dint_002dcast"></a>
  3074. <p>Suppress warnings from casts from a pointer to an integer type of a
  3075. different size.
  3076. </p>
  3077. </dd>
  3078. <dt><code>-Winvalid-pch</code></dt>
  3079. <dd><a name="index-Winvalid_002dpch"></a>
  3080. <a name="index-Wno_002dinvalid_002dpch"></a>
  3081. <p>Warn if a precompiled header (see <a href="Precompiled-Headers.html#Precompiled-Headers">Precompiled Headers</a>) is found in
  3082. the search path but cannot be used.
  3083. </p>
  3084. </dd>
  3085. <dt><code>-Wlong-long</code></dt>
  3086. <dd><a name="index-Wlong_002dlong"></a>
  3087. <a name="index-Wno_002dlong_002dlong"></a>
  3088. <p>Warn if <code>long long</code> type is used. This is enabled by either
  3089. <samp>-Wpedantic</samp> or <samp>-Wtraditional</samp> in ISO C90 and C++98
  3090. modes. To inhibit the warning messages, use <samp>-Wno-long-long</samp>.
  3091. </p>
  3092. </dd>
  3093. <dt><code>-Wvariadic-macros</code></dt>
  3094. <dd><a name="index-Wvariadic_002dmacros"></a>
  3095. <a name="index-Wno_002dvariadic_002dmacros"></a>
  3096. <p>Warn if variadic macros are used in ISO C90 mode, or if the GNU
  3097. alternate syntax is used in ISO C99 mode. This is enabled by either
  3098. <samp>-Wpedantic</samp> or <samp>-Wtraditional</samp>. To inhibit the warning
  3099. messages, use <samp>-Wno-variadic-macros</samp>.
  3100. </p>
  3101. </dd>
  3102. <dt><code>-Wvarargs</code></dt>
  3103. <dd><a name="index-Wvarargs"></a>
  3104. <a name="index-Wno_002dvarargs"></a>
  3105. <p>Warn upon questionable usage of the macros used to handle variable
  3106. arguments like <code>va_start</code>. This is default. To inhibit the
  3107. warning messages, use <samp>-Wno-varargs</samp>.
  3108. </p>
  3109. </dd>
  3110. <dt><code>-Wvector-operation-performance</code></dt>
  3111. <dd><a name="index-Wvector_002doperation_002dperformance"></a>
  3112. <a name="index-Wno_002dvector_002doperation_002dperformance"></a>
  3113. <p>Warn if vector operation is not implemented via SIMD capabilities of the
  3114. architecture. Mainly useful for the performance tuning.
  3115. Vector operation can be implemented <code>piecewise</code>, which means that the
  3116. scalar operation is performed on every vector element;
  3117. <code>in parallel</code>, which means that the vector operation is implemented
  3118. using scalars of wider type, which normally is more performance efficient;
  3119. and <code>as a single scalar</code>, which means that vector fits into a
  3120. scalar type.
  3121. </p>
  3122. </dd>
  3123. <dt><code>-Wno-virtual-move-assign</code></dt>
  3124. <dd><a name="index-Wvirtual_002dmove_002dassign"></a>
  3125. <a name="index-Wno_002dvirtual_002dmove_002dassign"></a>
  3126. <p>Suppress warnings about inheriting from a virtual base with a
  3127. non-trivial C++11 move assignment operator. This is dangerous because
  3128. if the virtual base is reachable along more than one path, it is
  3129. moved multiple times, which can mean both objects end up in the
  3130. moved-from state. If the move assignment operator is written to avoid
  3131. moving from a moved-from object, this warning can be disabled.
  3132. </p>
  3133. </dd>
  3134. <dt><code>-Wvla</code></dt>
  3135. <dd><a name="index-Wvla"></a>
  3136. <a name="index-Wno_002dvla"></a>
  3137. <p>Warn if a variable-length array is used in the code.
  3138. <samp>-Wno-vla</samp> prevents the <samp>-Wpedantic</samp> warning of
  3139. the variable-length array.
  3140. </p>
  3141. </dd>
  3142. <dt><code>-Wvla-larger-than=<var>n</var></code></dt>
  3143. <dd><p>If this option is used, the compiler will warn on uses of
  3144. variable-length arrays where the size is either unbounded, or bounded
  3145. by an argument that can be larger than <var>n</var> bytes. This is similar
  3146. to how <samp>-Walloca-larger-than=<var>n</var></samp> works, but with
  3147. variable-length arrays.
  3148. </p>
  3149. <p>Note that GCC may optimize small variable-length arrays of a known
  3150. value into plain arrays, so this warning may not get triggered for
  3151. such arrays.
  3152. </p>
  3153. <p>This warning is not enabled by <samp>-Wall</samp>, and is only active when
  3154. <samp>-ftree-vrp</samp> is active (default for <samp>-O2</samp> and above).
  3155. </p>
  3156. <p>See also <samp>-Walloca-larger-than=<var>n</var></samp>.
  3157. </p>
  3158. </dd>
  3159. <dt><code>-Wvolatile-register-var</code></dt>
  3160. <dd><a name="index-Wvolatile_002dregister_002dvar"></a>
  3161. <a name="index-Wno_002dvolatile_002dregister_002dvar"></a>
  3162. <p>Warn if a register variable is declared volatile. The volatile
  3163. modifier does not inhibit all optimizations that may eliminate reads
  3164. and/or writes to register variables. This warning is enabled by
  3165. <samp>-Wall</samp>.
  3166. </p>
  3167. </dd>
  3168. <dt><code>-Wdisabled-optimization</code></dt>
  3169. <dd><a name="index-Wdisabled_002doptimization"></a>
  3170. <a name="index-Wno_002ddisabled_002doptimization"></a>
  3171. <p>Warn if a requested optimization pass is disabled. This warning does
  3172. not generally indicate that there is anything wrong with your code; it
  3173. merely indicates that GCC&rsquo;s optimizers are unable to handle the code
  3174. effectively. Often, the problem is that your code is too big or too
  3175. complex; GCC refuses to optimize programs when the optimization
  3176. itself is likely to take inordinate amounts of time.
  3177. </p>
  3178. </dd>
  3179. <dt><code>-Wpointer-sign <span class="roman">(C and Objective-C only)</span></code></dt>
  3180. <dd><a name="index-Wpointer_002dsign"></a>
  3181. <a name="index-Wno_002dpointer_002dsign"></a>
  3182. <p>Warn for pointer argument passing or assignment with different signedness.
  3183. This option is only supported for C and Objective-C. It is implied by
  3184. <samp>-Wall</samp> and by <samp>-Wpedantic</samp>, which can be disabled with
  3185. <samp>-Wno-pointer-sign</samp>.
  3186. </p>
  3187. </dd>
  3188. <dt><code>-Wstack-protector</code></dt>
  3189. <dd><a name="index-Wstack_002dprotector"></a>
  3190. <a name="index-Wno_002dstack_002dprotector"></a>
  3191. <p>This option is only active when <samp>-fstack-protector</samp> is active. It
  3192. warns about functions that are not protected against stack smashing.
  3193. </p>
  3194. </dd>
  3195. <dt><code>-Woverlength-strings</code></dt>
  3196. <dd><a name="index-Woverlength_002dstrings"></a>
  3197. <a name="index-Wno_002doverlength_002dstrings"></a>
  3198. <p>Warn about string constants that are longer than the &ldquo;minimum
  3199. maximum&rdquo; length specified in the C standard. Modern compilers
  3200. generally allow string constants that are much longer than the
  3201. standard&rsquo;s minimum limit, but very portable programs should avoid
  3202. using longer strings.
  3203. </p>
  3204. <p>The limit applies <em>after</em> string constant concatenation, and does
  3205. not count the trailing NUL. In C90, the limit was 509 characters; in
  3206. C99, it was raised to 4095. C++98 does not specify a normative
  3207. minimum maximum, so we do not diagnose overlength strings in C++.
  3208. </p>
  3209. <p>This option is implied by <samp>-Wpedantic</samp>, and can be disabled with
  3210. <samp>-Wno-overlength-strings</samp>.
  3211. </p>
  3212. </dd>
  3213. <dt><code>-Wunsuffixed-float-constants <span class="roman">(C and Objective-C only)</span></code></dt>
  3214. <dd><a name="index-Wunsuffixed_002dfloat_002dconstants"></a>
  3215. <p>Issue a warning for any floating constant that does not have
  3216. a suffix. When used together with <samp>-Wsystem-headers</samp> it
  3217. warns about such constants in system header files. This can be useful
  3218. when preparing code to use with the <code>FLOAT_CONST_DECIMAL64</code> pragma
  3219. from the decimal floating-point extension to C99.
  3220. </p>
  3221. </dd>
  3222. <dt><code>-Wno-designated-init <span class="roman">(C and Objective-C only)</span></code></dt>
  3223. <dd><p>Suppress warnings when a positional initializer is used to initialize
  3224. a structure that has been marked with the <code>designated_init</code>
  3225. attribute.
  3226. </p>
  3227. </dd>
  3228. <dt><code>-Whsa</code></dt>
  3229. <dd><p>Issue a warning when HSAIL cannot be emitted for the compiled function or
  3230. OpenMP construct.
  3231. </p>
  3232. </dd>
  3233. </dl>
  3234. <hr>
  3235. <div class="header">
  3236. <p>
  3237. Next: <a href="Debugging-Options.html#Debugging-Options" accesskey="n" rel="next">Debugging Options</a>, Previous: <a href="Diagnostic-Message-Formatting-Options.html#Diagnostic-Message-Formatting-Options" accesskey="p" rel="prev">Diagnostic Message Formatting 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>
  3238. </div>
  3239. </body>
  3240. </html>