错误处理 – Xcode:如何配置项目以使最严格的编译器设置成为可能?

前端之家收集整理的这篇文章主要介绍了错误处理 – Xcode:如何配置项目以使最严格的编译器设置成为可能?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有时,由于程序员的编译器,语言或运气的精确性,程序员可能会使用一些相当邋code的代码.为了产生最干净的构建,我想配置我的 Xcode设置来抱怨最轻微的怀疑不当.

根据您的经验,您会建议什么?

以下是我的想法,但还有更多吗?

解决方法

我在我的代码库中使用这样的东西(制作一个xcconfig).它有点过时(部分用于工具集兼容性),但通常与使用Xcode的gcc4.2和clang的c,c,objc,objc兼容:

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

如果你已经放弃了gcc,那么你可以删除许多clang不支持内容. clang有自己的一些选项(因你使用的发行版而异).

猜你在找的Xcode相关文章