issue • Something you don’t care about, or a false positive ➡ Disable the warning (locally or globally) • Something you don’t understand ➡ Figure it out, son // .xcconfig: GCC_TREAT_WARNINGS_AS_ERRORS = YES // cmd-line: -Werror If the compiler warns you about something, it is either:
unless you explicitly disable them. Obviously believed to be useful to everyone, with extremely low false-positive rates • -Wall — There is high confidence in both the value and low false-positive rate of these warnings • -Wextra — These warnings are believed to be valuable and robust (not buggy), but they may have high false- positive rates or common philosophical objections • -Wpedantic — Enforces strict ISO C/C++. • -Weverything — An “insane group” that enables literally every warning in clang (even the buggy, unfinished ones). Meant strictly for clang developers.
— a local variable or type declaration shadows another variable, parameter, type, or class member (in C++), or whenever a built-in function is shadowed int main(int argc, char *argv[]) { if (1 == 1) { int argc = 9; NSLog(@"The int is %i.", argc); } }
Direct comparison of {a string literal / an array literal / a dictionary literal / a numeric literal / a boxed expression} has undefined behavior. Use -isEqual: instead. (on by default) • -Warc-repeated-use-of-weak — Weak {variable / property / implicit property / instance variable} is accessed multiple times in this {function / method / block / lambda} but may be unpredictably set to nil; assign to a strong variable to keep the object alive (not in any common warning group; must explicitly enable) • A bunch of warnings based on annotations you add to your code • A bunch of C++ warnings
“TODO” here. • You can look at GCC’s documentation • Unfortunately some of those warnings are not implemented in Clang, but it will still accept the warning flags without complaint, for “GCC compatibility” • You can look at clang’s source code • include/clang/Basic/DiagnosticGroups.td • include/clang/Basic/DiagnosticSemaKinds.td
// Suppress warnings by pretending this is a system header #pragma GCC system_header #pragma clang system_header #import "libfoo.h" // MyCode.m #import "libfoo_imports.h"
at least -Wall and -Wextra • You can try -Weverything to see what else there is, but you probably don’t want to leave it on • If third-party code triggers your warnings, don’t completely disable the warnings for all of your code — there are easy ways around this • The compiler loves you and wants to help you out — let it!