Sometimes, due to the nicety of a compiler, language or luck of a programmer, a programmer may get away with some pretty sloppy code. In order to produce the cleanest build possible, i'd like to configure my Xcode settings to complain about the slightest suspected impropriety.
From your experience, what would you suggest?
The following comes to mind, but is there more?
i use something like this in my codebase (make an xcconfig). it's slightly dated (partly for toolset compatibility), but generally compatible with c, c++, objc, objc++ using Xcode's gcc4.2 and clang:
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES
GCC_TREAT_NONCONFORMANT_CODE_ERRORS_AS_WARNINGS = YES
GCC_TREAT_WARNINGS_AS_ERRORS = NO
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES
GCC_WARN_ABOUT_GLOBAL_CONSTRUCTORS = YES
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
GCC_WARN_ABOUT_MISSING_NEWLINE = YES
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES
GCC_WARN_ABOUT_RETURN_TYPE = YES
GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
GCC_WARN_INHIBIT_ALL_WARNINGS = NO
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
GCC_WARN_MISSING_PARENTHESES = YES
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES
GCC_WARN_PEDANTIC = YES
GCC_WARN_SHADOW = YES
GCC_WARN_SIGN_COMPARE = YES
GCC_WARN_STRICT_SELECTOR_MATCH = YES
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
GCC_WARN_UNDECLARED_SELECTOR = YES
GCC_WARN_UNKNOWN_PRAGMAS = YES
GCC_WARN_UNUSED_FUNCTION = YES
GCC_WARN_UNUSED_LABEL = YES
GCC_WARN_UNUSED_PARAMETER = YES
GCC_WARN_UNUSED_VALUE = YES
GCC_WARN_UNUSED_VARIABLE = YES
// this gets sloppy
WARNING_CFLAGS = -Waddress -Woverflow -Winline -pedantic -Wundef -Wstrict-overflow -Wstrict-overflow=4 -Wsequence-point -Wdeprecated-declarations -Wendif-labels -Winit-self -Wstrict-aliasing=2 -Wstrict-aliasing -Wextra -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion -Wfloat-equal -Wformat -Wformat=2 -Wformat-extra-args -Wformat-security -Wimplicit -Winit-self -Winvalid-pch -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmultichar -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wstack-protector -Wsign-compare -Wswitch -Wswitch-default -Wswitch-enum -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wvariadic-macros -Winline -Wformat-nonliteral $(inherited)
WARNING_CPLUSPLUSFLAGS = -Wno-long-long -Waddress -Woverflow -Winline -Wno-non-virtual-dtor -pedantic -Wundef -Wstrict-overflow -Wstrict-overflow=4 -Wsequence-point -Wdeprecated-declarations -Wendif-labels -Winit-self -Wstrict-aliasing=2 -Wstrict-aliasing -Wextra -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion -Wfloat-equal -Wformat -Wformat=2 -Wformat-extra-args -Wformat-security -Wimplicit -Winit-self -Winvalid-offsetof -Winvalid-pch -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmultichar -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wstack-protector -Wsign-compare -Wswitch -Wswitch-default -Wswitch-enum -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wvariadic-macros -Wreorder -Weffc++ -Wdeprecated -Woverloaded-virtual -Wsign-promo -Wold-style-cast -Winline -Wformat-nonliteral $(inherited)
// not categorized as a warning, but will enable warnings
GCC_STRICT_ALIASING = YES
// Apple headers are too much for this
GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = NO
// useful for some output (conversions), but useless for the other half (implicit conversions which do not apply to c++). clang covers many of the cases with its warnings.
GCC_WARN_PROTOTYPE_CONVERSION = NO
// disabled by default - *do* enable in optimized configurations
GCC_WARN_UNINITIALIZED_AUTOS = NO
// clang-ana:
CLANG_ANALYZER_DEADCODE_DEADSTORES = YES
CLANG_ANALYZER_DEADCODE_IDEMPOTENT_OPERATIONS = YES
CLANG_ANALYZER_OBJC_SELF_INIT = YES
if you've already dropped gcc, then you can remove many which clang does not support. clang has a few options of its own (varies greatly by the distributions you're using).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With