RFC: Enabling as many warnings as possible with Xcode and gcc 4
RFC: Enabling as many warnings as possible with Xcode and gcc 4
- Subject: RFC: Enabling as many warnings as possible with Xcode and gcc 4
- From: "Sean McBride" <email@hidden>
- Date: Fri, 21 Jul 2006 15:47:53 -0400
- Organization: Rogue Research
Hi all,
I'm starting a new project and want to enable as many compiler warnings
as possible.
My starting point is this document:
<http://developer.apple.com/tools/xcode/staticanalysis.html>
which suggests starting with -Wall and -Wextra and adding more warnings
from there. It provides a list of warnings not included by -Wall and -
Wextra, but there are some errors and omissions.
It has been a royal PITA, but I have assembled a pretty comprehensive
list, and I want to share it since I find it useful.
Some warnings only apply to some languages and gcc will give a warning
if a warning flag is passed when compiling a file of the wrong
language! So the C-only warnings need to be added to OTHER_CFLAGS (make
sure your OTHER_CPLUSPLUSFLAGS do not include OTHER_CFLAGS). The C++-
only warnings need to be added to OTHER_CPLUSPLUSFLAGS. The other
warnings should be added to WARNING_CFLAGS. Whenever possible, prefer a
predefined Xcode option to a gcc flag. For example, prefer
GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES to -Weffc++ because the
former is smart and is only applied to C++ files, the latter will
generate annoying warnings if added to WARNING_CFLAGS instead of
OTHER_CPLUSPLUSFLAGS.
Thanks to people on this list for (unknowingly) helping me with this!
Here's my list, with a few comments for certain warnings, I would
greatly appreciate any feedback:
------
C only
------
-Wdiv-by-zero
-Wtraditional
If you care about K&R C
-Wdeclaration-after-statement
If you care about pre-C99
-Wbad-function-cast
-Wstrict-prototypes
-Wold-style-definition
-Wmissing-prototypes
-Wmissing-declarations
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
-Wnested-externs
--------
C++ only
--------
-Wabi
-Wctor-dtor-privacy
-Weffc++
GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES
-Wstrict-null-sentinel
-Wold-style-cast
-Woverloaded-virtual
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
-Wsign-promo
-Winvalid-offsetof
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
----------------
Objective-C only
----------------
-Wprotocol
-Wselector
gives very many warnings
-Wstrict-selector-match
-Wundeclared-selector
-------------
All languages
-------------
-Wsystem-headers
Apple's header give too many warnings
-Wfloat-equal
-Wundef
-Wendif-labels
-Wshadow
GCC_WARN_SHADOW = YES
-Wlarger-than-len
you have to pick len, for example: -Wlarger-than-10000
-Wpointer-arith
-Wcast-qual
Useless for Cocoa, will warn for:
NSString* str = @"hello";
<rdar://4625600>
-Wcast-align
-Wwrite-strings
-Wconversion
Useless for Cocoa, will warn for:
[button setEnabled:YES];
warning: passing argument 1 of 'setEnabled:' with different width due to
prototype
<rdar://4625881>: Behaves Correctly
-Waggregate-return
-Wmissing-noreturn
-Wmissing-format-attribute
-Wno-multichar
-Wdeprecated-declarations
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES
-Wpacked
-Wpadded
-Wredundant-decls
-Wunreachable-code
Will warn on every line where you use assert() from assert.h.
<rdar://4625614>
-Winline
-Winvalid-pch
-Wdisabled-optimization
-Wshorten-64-to-32
-Wformat=2
-Wfour-char-constants
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
-Wnewline-eof
GCC_WARN_ABOUT_MISSING_NEWLINE = NO
And here are the exact settings I use for my projects. Its not every
warning above because some are just too obnoxious, but it's a starting point:
// Compiler warnings
// C-only warnings
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
OTHER_CFLAGS = -Wdiv-by-zero -Wbad-function-cast -Wstrict-prototypes -
Wold-style-definition -Wmissing-prototypes -Wnested-externs
// C++-only warnings
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
OTHER_CPLUSPLUSFLAGS = -Wabi -Wctor-dtor-privacy -Wstrict-null-sentinel -
Wsign-promo
// For all languages and Objective-C-only
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
GCC_WARN_ABOUT_MISSING_NEWLINE = NO
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES
GCC_WARN_SHADOW = YES
WARNING_CFLAGS = -Wall -Wextra -Wprotocol -Wstrict-selector-match -
Wundeclared-selector -Wundef -Wendif-labels -Wlarger-than-10000 -
Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-noreturn -Wmissing-
format-attribute -Wno-multichar -Wpacked -Wredundant-decls -Winline -
Winvalid-pch -Wdisabled-optimization -Wshorten-64-to-32 -Wformat=2
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden