Error handling – Xcode: How to configure a project to make the most stringent compiler settings?

Sometimes, due to the accuracy of the programmer’s compiler, language or luck, the programmer may use some rather sloppy code. In order to produce the cleanest build, I want to configure my Xcode settings to complain about the slightest suspicion of improperity.

Based on your experience, what would you suggest?

The following are my thoughts, but are there more?

I use something like this in my code base (make an xcconfig). It’s a bit outdated (Partly for tool set compatibility), but usually compatible with gcc4.2 using Xcode and c, c, objc, and objc using 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 < br />GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
GCC_WARN_INHIBIT_A LL_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_UNUSED_FUNCTION = YES_UNUSED_FUNCTION = YES
GRNUSED_WARN_USED_WARN_WARN_YES YES 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 -Wmult ichar -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.< br />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 can’t delete many gcclangs, Supported content. clang has some options of its own (different depending on the distribution you are using).

Sometimes, due to the accuracy of the programmer’s compiler, language or luck The programmer may use some rather sloppy code. In order to produce the cleanest build, I want to configure my Xcode settings to complain about the slightest suspicion of impropriety.

Based on your experience , What would you suggest?

The following are my thoughts, but are there more?

I use something like this in my code base (making an xcconfig). It is a bit outdated (partially for toolset compatibility), but usually Compatible with gcc4.2 using Xcode and c,c,objc,objc using 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_PARENT_WARN_SHADOW = YES
GCC_PARENT_WARN_SELECT_WARN_YES SELECT_WARN_YES = YES
GCC_WARN_UNDECLARED_SELECTOR = YES
GCC_WARN_UNKNOWN_PRAGMAS = YES
GCC_WARN_UNUSED_FUNCTION = YES
GCC_WARN_UNUSED_LABEL = YES
GCC_WARN_USERN_YES_UNUSED />GCC_WARN_USED YES YES
GCC_WARN_UNUSED ary 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 -Wm issing-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_CPLUSFLAGS =- 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_DEADSTO RES = YES
CLANG_ANALYZER_DEADCODE_IDEMPOTENT_OPERATIONS = YES
CLANG_ANALYZER_OBJC_SELF_INIT = YES

If you have abandoned gcc, then you can delete many content that clang does not support. clang has some options of its own (due to The distribution you are using varies).

Leave a Comment

Your email address will not be published.