Warning flags for Clang

Below is the complete list of the warning flags I use with Clang, the C frontend for LLVM.
I personally use those flags for all my production code, for C, C++ and Objective-C development.

Basically, all warning flags are activated. I had to look at the Clang source code to find all of them.

I also created a header file which automatically sets those flags, when compiling source code.
This way, whether you use an IDE or command-line to compile your code, you won't need anymore to set those flags, as long as you include the header.
It's available here on GitHub. Enjoy!

Warning flags list:

  • -Wabi
  • -Waddress-of-temporary
  • -Waddress
  • -Waggregate-return
  • -Wall
  • -Wambiguous-member-template
  • -Warc-abi
  • -Warc-non-pod-memaccess
  • -Warc-retain-cycles
  • -Warc-unsafe-retained-assign
  • -Warc
  • -Watomic-properties
  • -Wattributes
  • -Wavailability
  • -Wbad-function-cast
  • -Wbind-to-temporary-copy
  • -Wbitwise-op-parentheses
  • -Wbool-conversions
  • -Wbuiltin-macro-redefined
  • -Wc++-compat
  • -Wc++0x-compat
  • -Wc++0x-extensions
  • -Wcast-align
  • -Wcast-qual
  • -Wchar-align
  • -Wchar-subscripts
  • -Wcomment
  • -Wcomments
  • -Wconditional-uninitialized
  • -Wconversion
  • -Wctor-dtor-privacy
  • -Wcustom-atomic-properties
  • -Wdeclaration-after-statement
  • -Wdefault-arg-special-member
  • -Wdelegating-ctor-cycles
  • -Wdelete-non-virtual-dtor
  • -Wdeprecated-declarations
  • -Wdeprecated-implementations
  • -Wdeprecated-writable-strings
  • -Wdeprecated
  • -Wdisabled-optimization
  • -Wdiscard-qual
  • -Wdiv-by-zero
  • -Wduplicate-method-arg
  • -Weffc++
  • -Wempty-body
  • -Wendif-labels
  • -Wexit-time-destructors
  • -Wextra-tokens
  • -Wextra
  • -Wformat-extra-args
  • -Wformat-nonliteral
  • -Wformat-zero-length
  • -Wformat
  • -Wformat=2
  • -Wfour-char-constants
  • -Wglobal-constructors
  • -Wgnu-designator
  • -Wgnu
  • -Wheader-hygiene
  • -Widiomatic-parentheses
  • -Wignored-qualifiers
  • -Wimplicit-atomic-properties
  • -Wimplicit-function-declaration
  • -Wimplicit-int
  • -Wimplicit
  • -Wimport
  • -Wincompatible-pointer-types
  • -Winit-self
  • -Winitializer-overrides
  • -Winline
  • -Wint-to-pointer-cast
  • -Winvalid-offsetof
  • -Winvalid-pch
  • -Wlarge-by-value-copy
  • -Wliteral-range
  • -Wlocal-type-template-args
  • -Wlogical-op-parentheses
  • -Wlong-long
  • -Wmain
  • -Wmicrosoft
  • -Wmismatched-tags
  • -Wmissing-braces
  • -Wmissing-declarations
  • -Wmissing-field-initializers
  • -Wmissing-format-attribute
  • -Wmissing-include-dirs
  • -Wmissing-noreturn
  • -Wmost
  • -Wmultichar
  • -Wnested-externs
  • -Wnewline-eof
  • -Wnon-gcc
  • -Wnon-virtual-dtor
  • -Wnonfragile-abi2
  • -Wnonnull
  • -Wnonportable-cfstrings
  • -Wnull-dereference
  • -Wobjc-nonunified-exceptions
  • -Wold-style-cast
  • -Wold-style-definition
  • -Wout-of-line-declaration
  • -Woverflow
  • -Woverlength-strings
  • -Woverloaded-virtual
  • -Wpacked
  • -Wpadded
  • -Wparentheses
  • -Wpointer-arith
  • -Wpointer-to-int-cast
  • -Wprotocol
  • -Wreadonly-setter-attrs
  • -Wredundant-decls
  • -Wreorder
  • -Wreturn-type
  • -Wself-assign
  • -Wsemicolon-before-method-body
  • -Wsequence-point
  • -Wshadow
  • -Wshorten-64-to-32
  • -Wsign-compare
  • -Wsign-promo
  • -Wsizeof-array-argument
  • -Wstack-protector
  • -Wstrict-aliasing
  • -Wstrict-overflow
  • -Wstrict-prototypes
  • -Wstrict-selector-match
  • -Wsuper-class-method-mismatch
  • -Wswitch-default
  • -Wswitch-enum
  • -Wswitch
  • -Wsynth
  • -Wtautological-compare
  • -Wtrigraphs
  • -Wtype-limits
  • -Wundeclared-selector
  • -Wuninitialized
  • -Wunknown-pragmas
  • -Wunnamed-type-template-args
  • -Wunneeded-internal-declaration
  • -Wunneeded-member-function
  • -Wunused-argument
  • -Wunused-exception-parameter
  • -Wunused-function
  • -Wunused-label
  • -Wunused-member-function
  • -Wunused-parameter
  • -Wunused-value
  • -Wunused-variable
  • -Wunused
  • -Wused-but-marked-unused
  • -Wvariadic-macros
  • -Wvector-conversions
  • -Wvla
  • -Wvolatile-register-var
  • -Wwrite-strings

Comments

Author
pyhax
Date
05/24/2012 12:40
Did you know about the -Weverything flag?
Author
Jean-David Gadina
Date
05/25/2012 18:27
Sure, but unfortunately, it's not recognized by some implementations, especially implementations from Apple. : )
Author
Peter
Date
07/29/2012 18:44
Apple's clang 4.0 recognizes -Weverything.
Author
clang warning flag list | Chen Dai
Date
07/10/2013 22:37
[...] http://www.noxeos.com/2012/01/10/warning-flags-clang/ [...]