tag:blogger.com,1999:blog-2420869991974935734.post1839396666806923847..comments2023-07-02T17:04:56.386+02:00Comments on Krister Walfridsson’s old blog: Useful GCC warning options not enabled by -Wall -WextraKrister Walfridssonhttp://www.blogger.com/profile/02591279630933941271noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-2420869991974935734.post-89776040973042246852018-08-07T21:10:14.713+02:002018-08-07T21:10:14.713+02:00The blog post was written for GCC 7 (where -Wall d...The blog post was written for GCC 7 (where -Wall does not enable -Wrestrict). I had not noticed that it was added to GCC 8, but I have updated the blog post with a note about compiler versions. Thanks!Krister Walfridssonhttps://www.blogger.com/profile/02591279630933941271noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-27476383441151838312018-08-07T12:30:32.044+02:002018-08-07T12:30:32.044+02:00Thank you for this great post.
According to https:...Thank you for this great post.<br />According to https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html the option "-Wrestrict" is already enabled by "-Wall":<br />"The -Wrestrict option detects some instances of simple overlap even without optimization but works best at -O2 and above. It is included in -Wall."versathttps://www.blogger.com/profile/07959477954437396336noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-45018199958453961052018-04-02T11:02:58.999+02:002018-04-02T11:02:58.999+02:00It is problematic. GCC reports an error for unknow...It is problematic. GCC reports an error for unknown warning options.Krister Walfridssonhttps://www.blogger.com/profile/02591279630933941271noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-78503289645305019982018-03-16T01:15:27.689+01:002018-03-16T01:15:27.689+01:00may it be problematic to include warnings that are...may it be problematic to include warnings that are not supported by the host ? Or will they just be ignored ?Anonymoushttps://www.blogger.com/profile/04072807018320909671noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-60043120244124091842017-10-16T23:56:02.557+02:002017-10-16T23:56:02.557+02:00I don't see -Wlogical-op in GCC 4.7 ... was ...I don't see -Wlogical-op in GCC 4.7 ... was it actually introduced in GCC 6, not 4.3 ?dibanezhttps://www.blogger.com/profile/03600575977724151286noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-4563599563069092852017-10-10T01:21:50.250+02:002017-10-10T01:21:50.250+02:00Thanks! These are some nice examples. I've bee...Thanks! These are some nice examples. I've been using a slew extra GCC warnings for 5 years or so by now, so its nice surprise to find more.<br /><br />Do you ever/selectively promote warnings to warnings to errors?<br />I usually promote most of "definitely undefined behavior"-warnings to errors, and I'm considering promoting -Wduplicated-cond and<br />-Wduplicated-branches to errors.<br />For reference, these are my usual warning flags:<br /><br />-Wno-variadic-macros -W -Wpedantic -Wextra -Wall -Wcast-align -Wcast-qual -Wstrict-aliasing=2 -Wframe-larger-than=32768 -Wno-strict-overflow -Wsync-nand -Wtrampolines -Wsign-compare -Werror=float-equal -Werror=missing-braces -Werror=init-self -Werror=logical-op -Werror=write-strings -Werror=address -Werror=array-bounds -Werror=char-subscripts -Werror=enum-compare -Werror=implicit-int -Werror=empty-body -Werror=main -Werror=aggressive-loop-optimizations -Werror=nonnull -Werror=parentheses -Werror=pointer-sign -Werror=return-type -Werror=sequence-point -Werror=uninitialized -Werror=volatile-register-var -Werror=ignored-qualifiers -Werror=missing-parameter-type -Werror=old-style-declaration -Wno-error=maybe-uninitialized -Wno-unused-function -Wodr -Wformat-signedness -Wsuggest-final-types -Wsuggest-final-methods -Wno-ignored-attributes -Wno-missing-field-initializers -Wshift-overflow=2 -Wduplicated-cond \<br />-Wduplicated-branches -Werror=restrict -Wdouble-promotion -Wformat=2<br />Lars Bonnichsenhttps://www.blogger.com/profile/14350844348136298737noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-82205624601618943052017-10-08T12:55:18.216+02:002017-10-08T12:55:18.216+02:00I have not had any such problems in the code I wor...I have not had any such problems in the code I work with, but I can see how this may be a problem for large code bases...<br /><br />GCC 7 introduced a modifier to the warning option, so \(\verb!-Wshadow=local!\) does only warn when a local variable shadows another local variable or parameter. This solves the problem Linus complained about, but it fails to warn about your example...Krister Walfridssonhttps://www.blogger.com/profile/02591279630933941271noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-43377361665113704092017-10-08T12:30:51.363+02:002017-10-08T12:30:51.363+02:00Yes, it is useful – but it is already included in ...Yes, it is useful – but it is already included in \(\verb!-Wall!\).Krister Walfridssonhttps://www.blogger.com/profile/02591279630933941271noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-8313875695260222672017-10-05T20:37:16.480+02:002017-10-05T20:37:16.480+02:00Very interesting! Some of these warnings are more...Very interesting! Some of these warnings are more what one would expect from static analysis, rather than from the compiler. <br /><br />One caution, though -- at least in my testing -Wshadow is pretty much unusable on gcc because of the many false positives. clang seems to do a much better job. I wrote about this at http://btorpey.github.io/blog/2015/03/17/shadow/<br />Anonymoushttps://www.blogger.com/profile/01254919523217180099noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-40237249969602338032017-10-05T03:04:47.483+02:002017-10-05T03:04:47.483+02:00There is the very useful -Wmisleading-indentationThere is the very useful -Wmisleading-indentationBramhttps://www.blogger.com/profile/07666511303597120943noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-36432794154616139052017-09-30T04:40:55.494+02:002017-09-30T04:40:55.494+02:00Thanks!Thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-60863341589146151202017-09-25T12:11:29.474+02:002017-09-25T12:11:29.474+02:00There are some cases where it can warn incorrectly...There are some cases where it can warn incorrectly. It does not happen too often, but those cases often need big changes in the code's structure for the warning to disappear (i.e. it is not enough to just initialize a variable as for the incorrect warnings you may get from \(\verb!-Wuninitialize!\)).Krister Walfridssonhttps://www.blogger.com/profile/02591279630933941271noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-63980911423199374982017-09-24T22:23:30.818+02:002017-09-24T22:23:30.818+02:00Great post! I wonder why -Wnull-dereference is not...Great post! I wonder why -Wnull-dereference is not enabled. It is such a common mistake!oliwerhttps://www.blogger.com/profile/16770047582901520379noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-37413739922575437022017-09-18T12:52:59.445+02:002017-09-18T12:52:59.445+02:00I was a bit lazy when I wrote the blog post... Sor...I was a bit lazy when I wrote the blog post... Sorry!<br /><br />But I have now added information about when the options were introduced, and which are restricted to C/C++.Krister Walfridssonhttps://www.blogger.com/profile/02591279630933941271noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-4646788527387408412017-09-18T09:14:29.179+02:002017-09-18T09:14:29.179+02:00Indded. Also some of them can only be applied to g...Indded. Also some of them can only be applied to gcc and others only to g++.Unknownhttps://www.blogger.com/profile/16218536340634800982noreply@blogger.comtag:blogger.com,1999:blog-2420869991974935734.post-15901217825868648162017-09-18T02:14:16.514+02:002017-09-18T02:14:16.514+02:00It would be useful to know which gcc version is re...It would be useful to know which gcc version is required for each of this flag.Cyanhttps://www.blogger.com/profile/02905407922640810117noreply@blogger.com