Bug 1232224 - Streamline setting of compile warnings in configure.in. r=glandium,cpeterson.

The main changes are to the warnings, which are as follows.

- Kept -Wall.

- Part of -Wall or on by default; remove all mentions:
  * -Waddress
  * -Wchar-subscripts
  * -Wcomment
  * -Wconversion-null
  * -Wendif-labels
  * -Wenum-compare
  * -Wimplicit-function-declaration
  * -Wint-to-pointer-cast
  * -Wmissing-braces
  * -Wmultichar
  * -Wnonnull
  * -Wparentheses
  * -Wpointer-sign
  * -Wpointer-to-int-cast (C only)
  * -Wreorder
  * -Wreturn-type
  * -Wsequence-point
  * -Wsign-compare (C++ only)
  * -Wswitch
  * -Wtrigraphs
  * -Wuninitialized
  * -Wunknown-pragmas
  * -Wunused-label
  * -Wunused-value
  * -Wwrite-strings (C++ only)

- Part of -Wextra; kept where present, added where missing:
  * -Wempty-body
  * -Wignored-qualifiers (not added for C++ code; many fixes needed to enable)
  * -Wtype-limits

- Part of -pedantic; kept where present, added where missing:
  * -pointer-arith

- C++ only, kept:
  * -Wno-invalid-offsetof
  * -Woverloaded-virtual

- Clang-only, kept:
  * -Wnon-literal-null-conversion (affected by a clang bug; see the big comment
    in the code)
  * -Wrange-loop-analysis (C++ only)
  * -Wno-unused-local-typedef

- This no longer exists?  I kept it to be safe:
  * -Winline-new-delete

A consequence of this is that, when --enable-warnings-as-errors is on, in
directories which have ALLOW_COMPILER_WARNINGS specified we no longer have any
fatal warnings. (We previously did have all the explicitly-mentioned
-Werror=foo ones.) This is a sensible change; if we are going to allow warnings
in a directory we should allow all of them, not just some of them.

Other changes:

- Some C warnings incorrectly used the CXX macros. Fixes that.

- Moves comments about warnings closer to the lines where they are defined, to
  make it easier to keep the comments consistent with the code.

- Reorders things a little, e.g. so that all enabled warnings are before all
  disabled warnings.

The C and C++ warnings are now very similar, in both configure.in and
js/src/configure.in.

--HG--
extra : rebase_source : 6f8db0fecda1315504a29fbcafb6fdee3053d8a5
This commit is contained in:
Nicholas Nethercote 2015-12-16 18:39:50 -08:00
parent c40483da3d
commit 6d93e1b2e4
2 changed files with 123 additions and 225 deletions

View File

@ -1444,65 +1444,35 @@ if test "$GNU_CC"; then
fi fi
# Turn on gcc/clang warnings: # Turn on gcc/clang warnings:
# https://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Warning-Options.html # https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Warning-Options.html
#
# -Wall - turn on a lot of warnings # -Wall - lots of useful warnings
# -Wchar-subscripts - catches array index using signed char
# -Wcomment - catches nested comments
# -Wempty-body - catches bugs, e.g. "if (c); foo();", few false positives # -Wempty-body - catches bugs, e.g. "if (c); foo();", few false positives
# -Wendif-labels - catches `#else FOO` and `#endif FOO` not in comment
# -Wenum-compare - catches comparison of different enum types
# -Wignored-qualifiers - catches returns types with qualifiers like const # -Wignored-qualifiers - catches returns types with qualifiers like const
# -Wint-to-pointer-cast - catches cast to pointer from integer of different size
# -Wmultichar - catches multicharacter integer constants like 'THIS'
# -Wnon-literal-null-conversion - catches expressions used as a null pointer constant
# -Wnonnull - catches NULL used with functions arguments marked as non-null
# -Wpointer-arith - catches pointer arithmetic using NULL or sizeof(void) # -Wpointer-arith - catches pointer arithmetic using NULL or sizeof(void)
# -Wpointer-sign - catches mixing pointers to signed and unsigned types
# -Wpointer-to-int-cast - catches casts from pointer to different sized int
# -Wreturn-type - catches missing returns, zero false positives
# -Wsequence-point - catches undefined order behavior like `a = a++`
# -Wsign-compare - catches comparison of signed and unsigned types
# -Wtrigraphs - catches unlikely use of trigraphs
# -Wtype-limits - catches overflow bugs, few false positives # -Wtype-limits - catches overflow bugs, few false positives
# -Wunknown-pragmas - catches unexpected #pragma directives
#
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wall" _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wall"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wempty-body" _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wempty-body"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wpointer-to-int-cast" _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wignored-qualifiers"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wsign-compare" _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wpointer-arith"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wtype-limits" _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wtype-limits"
# Treat some warnings as errors if --enable-warnings-as-errors: # -Wnon-literal-null-conversion - catches expressions used as a null pointer constant
if test "$MOZ_ENABLE_WARNINGS_AS_ERRORS"; then # -Wsometimes-initialized - catches some uninitialized values
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=char-subscripts"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=comment"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=endif-labels"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=enum-compare"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=ignored-qualifiers"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=int-to-pointer-cast"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=multichar"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=nonnull"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=pointer-arith"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=pointer-sign"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=return-type"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=sequence-point"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=trigraphs"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=uninitialized"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=unknown-pragmas"
MOZ_C_SUPPORTS_WARNING(-Werror=, non-literal-null-conversion, ac_c_has_werror_non_literal_null_conversion)
MOZ_C_SUPPORTS_WARNING(-Werror=, sometimes-uninitialized, ac_c_has_sometimes_uninitialized)
fi
# Turn off the following warnings that -Wall turns on:
# -Wno-unused - lots of violations in third-party code
# -Wno-unused-local-typedef - catches unused typedefs, which are commonly used in assertion macros
# #
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wno-unused" # XXX: at the time of writing, the version of clang used on the OS X test
# machines has a bug that causes it to reject some valid files if both
MOZ_CXX_SUPPORTS_WARNING(-Wno-, unused-local-typedef, ac_cxx_has_wno_unused_local_typedef) # -Wnon-literal-null-conversion and -Wsometimes-uninitialized are
# specified. We work around this by instead using
# -Werror=non-literal-null-conversion, but we only do that when
# --enable-warnings-as-errors is specified so that no unexpected fatal
# warnings are produced.
if test "$MOZ_ENABLE_WARNINGS_AS_ERRORS"; then
MOZ_C_SUPPORTS_WARNING(-Werror=, non-literal-null-conversion, ac_c_has_non_literal_null_conversion)
fi
MOZ_C_SUPPORTS_WARNING(-W, sometimes-uninitialized, ac_c_has_sometimes_uninitialized)
# -Wcast-align - catches problems with cast alignment
if test -z "$INTEL_CC" -a -z "$CLANG_CC"; then if test -z "$INTEL_CC" -a -z "$CLANG_CC"; then
# Don't use -Wcast-align with ICC or clang # Don't use -Wcast-align with ICC or clang
case "$CPU_ARCH" in case "$CPU_ARCH" in
@ -1515,8 +1485,17 @@ if test "$GNU_CC"; then
esac esac
fi fi
# Turn off some non-useful warnings that -Wall turns on.
# -Wno-unused - lots of violations in third-party code
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wno-unused"
# -Wno-unused-local-typedef - catches unused typedefs, which are commonly used in assertion macros
MOZ_C_SUPPORTS_WARNING(-Wno-, unused-local-typedef, ac_c_has_wno_unused_local_typedef)
_DEFINES_CFLAGS='-include $(topobjdir)/mozilla-config.h -DMOZILLA_CLIENT' _DEFINES_CFLAGS='-include $(topobjdir)/mozilla-config.h -DMOZILLA_CLIENT'
_USE_CPP_INCLUDE_FLAG=1 _USE_CPP_INCLUDE_FLAG=1
ASFLAGS="$ASFLAGS $_DEFINES_CFLAGS" ASFLAGS="$ASFLAGS $_DEFINES_CFLAGS"
elif test "$SOLARIS_SUNPRO_CC"; then elif test "$SOLARIS_SUNPRO_CC"; then
@ -1548,65 +1527,37 @@ if test "$GNU_CXX"; then
CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-strict-aliasing" CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-strict-aliasing"
# Turn on gcc/clang warnings: # Turn on gcc/clang warnings:
# https://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Warning-Options.html # https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Warning-Options.html
#
# -Wall - turn on a lot of warnings # -Wall - lots of useful warnings
# -Wempty-body - catches bugs, e.g. "if (c); foo();", few false positives # -Wempty-body - catches bugs, e.g. "if (c); foo();", few false positives
# -Wendif-labels - catches `#else FOO` and `#endif FOO` not in comment
# -Wint-to-pointer-cast - catches cast to pointer from integer of different size
# -Wmissing-braces - catches aggregate initializers missing nested braces
# -Wnon-literal-null-conversion - catches expressions used as a null pointer constant
# -Woverloaded-virtual - function declaration hides virtual function from base class # -Woverloaded-virtual - function declaration hides virtual function from base class
# -Wparentheses - catches `if (a=b)` and operator precedence bugs
# -Wpointer-arith - catches pointer arithmetic using NULL or sizeof(void) # -Wpointer-arith - catches pointer arithmetic using NULL or sizeof(void)
# -Wrange-loop-analysis - catches copies during range-based for loops.
# -Wreturn-type - catches missing returns, zero false positives
# -Wsequence-point - catches undefined order behavior like `a = a++`
# -Wsign-compare - catches comparison of signed and unsigned types
# -Wswitch - catches switches without all enum cases or default case
# -Wtrigraphs - catches unlikely use of trigraphs
# -Wtype-limits - catches overflow bugs, few false positives # -Wtype-limits - catches overflow bugs, few false positives
# -Wunused-label - catches unused goto labels
# -Wwrite-strings - catches non-const char* pointers to string literals
#
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wall" _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wall"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wempty-body" _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wempty-body"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Woverloaded-virtual" _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Woverloaded-virtual"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wsign-compare" _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wpointer-arith"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wwrite-strings" _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wtype-limits"
# Treat some warnings as errors if --enable-warnings-as-errors: # -Wnon-literal-null-conversion - catches expressions used as a null pointer constant
if test "$MOZ_ENABLE_WARNINGS_AS_ERRORS"; then # -Wrange-loop-analysis - catches copies during range-based for loops.
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=endif-labels" # -Wsometimes-initialized - catches some uninitialized values
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=int-to-pointer-cast"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=missing-braces"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=parentheses"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=pointer-arith"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=return-type"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=sequence-point"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=switch"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=trigraphs"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=type-limits"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=uninitialized"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=unused-label"
MOZ_CXX_SUPPORTS_WARNING(-Werror=, non-literal-null-conversion, ac_cxx_has_werror_non_literal_null_conversion)
MOZ_CXX_SUPPORTS_WARNING(-Werror=, range-loop-analysis, ac_cxx_has_range_loop_analysis)
MOZ_CXX_SUPPORTS_WARNING(-Werror=, sometimes-uninitialized, ac_cxx_has_sometimes_uninitialized)
fi
# Turn off the following warnings that -Wall turns on:
# -Wno-invalid-offsetof - we use offsetof on non-POD types frequently
# -Wno-inline-new-delete - we inline 'new' and 'delete' in mozalloc
# -Wno-unused-local-typedef - catches unused typedefs, which are commonly used in assertion macros
# for performance reasons, and because GCC and clang accept it (though
# clang warns about it).
# #
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-invalid-offsetof" # XXX: at the time of writing, the version of clang used on the OS X test
# machines has a bug that causes it to reject some valid files if both
MOZ_CXX_SUPPORTS_WARNING(-Wno-, inline-new-delete, ac_cxx_has_wno_inline_new_delete) # -Wnon-literal-null-conversion and -Wsometimes-uninitialized are
MOZ_CXX_SUPPORTS_WARNING(-Wno-, unused-local-typedef, ac_cxx_has_wno_unused_local_typedef) # specified. We work around this by instead using
# -Werror=non-literal-null-conversion, but we only do that when
# --enable-warnings-as-errors is specified so that no unexpected fatal
# warnings are produced.
if test "$MOZ_ENABLE_WARNINGS_AS_ERRORS"; then
MOZ_CXX_SUPPORTS_WARNING(-Werror=, non-literal-null-conversion, ac_cxx_has_non_literal_null_conversion)
fi
MOZ_CXX_SUPPORTS_WARNING(-W, range-loop-analysis, ac_cxx_has_range_loop_analysis)
MOZ_CXX_SUPPORTS_WARNING(-W, sometimes-uninitialized, ac_cxx_has_sometimes_uninitialized)
# -Wcast-align - catches problems with cast alignment
if test -z "$INTEL_CXX" -a -z "$CLANG_CXX"; then if test -z "$INTEL_CXX" -a -z "$CLANG_CXX"; then
# Don't use -Wcast-align with ICC or clang # Don't use -Wcast-align with ICC or clang
case "$CPU_ARCH" in case "$CPU_ARCH" in
@ -1619,8 +1570,15 @@ if test "$GNU_CXX"; then
esac esac
fi fi
_DEFINES_CXXFLAGS='-DMOZILLA_CLIENT -include $(topobjdir)/mozilla-config.h' # Turn off some non-useful warnings that -Wall turns on.
_USE_CPP_INCLUDE_FLAG=1
# -Wno-invalid-offsetof - we use offsetof on non-POD types frequently
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-invalid-offsetof"
# -Wno-inline-new-delete - we inline 'new' and 'delete' in mozalloc
# -Wno-unused-local-typedef - catches unused typedefs, which are commonly used in assertion macros
MOZ_CXX_SUPPORTS_WARNING(-Wno-, inline-new-delete, ac_cxx_has_wno_inline_new_delete)
MOZ_CXX_SUPPORTS_WARNING(-Wno-, unused-local-typedef, ac_cxx_has_wno_unused_local_typedef)
# Recent clang and gcc support C++11 deleted functions without warnings if # Recent clang and gcc support C++11 deleted functions without warnings if
# compiling with -std=c++0x or -std=gnu++0x (or c++11 or gnu++11 in very new # compiling with -std=c++0x or -std=gnu++0x (or c++11 or gnu++11 in very new
@ -1633,6 +1591,9 @@ if test "$GNU_CXX"; then
MOZ_CXX_SUPPORTS_WARNING(-Wno-, extended-offsetof, ac_cxx_has_wno_extended_offsetof) MOZ_CXX_SUPPORTS_WARNING(-Wno-, extended-offsetof, ac_cxx_has_wno_extended_offsetof)
fi fi
_DEFINES_CXXFLAGS='-DMOZILLA_CLIENT -include $(topobjdir)/mozilla-config.h'
_USE_CPP_INCLUDE_FLAG=1
else else
_DEFINES_CXXFLAGS='-DMOZILLA_CLIENT -D_MOZILLA_CONFIG_H_ $(ACDEFINES)' _DEFINES_CXXFLAGS='-DMOZILLA_CLIENT -D_MOZILLA_CONFIG_H_ $(ACDEFINES)'
fi fi

View File

@ -1187,79 +1187,35 @@ if test "$GNU_CC"; then
LDFLAGS=$_SAVE_LDFLAGS) LDFLAGS=$_SAVE_LDFLAGS)
# Turn on gcc/clang warnings: # Turn on gcc/clang warnings:
# https://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Warning-Options.html # https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Warning-Options.html
#
# -Wall - turn on a lot of warnings # -Wall - lots of useful warnings
# -Waddress - catches suspicious uses of memory addresses
# -Wchar-subscripts - catches array index using signed char
# -Wcomment - catches nested comments
# -Wempty-body - catches bugs, e.g. "if (c); foo();", few false positives # -Wempty-body - catches bugs, e.g. "if (c); foo();", few false positives
# -Wendif-labels - catches `#else FOO` and `#endif FOO` not in comment
# -Wenum-compare - catches comparison of different enum types
# -Wignored-qualifiers - catches returns types with qualifiers like const # -Wignored-qualifiers - catches returns types with qualifiers like const
# -Wimplicit-function-declaration - catches missing C function prototypes
# -Wint-to-pointer-cast - catches cast to pointer from integer of different size
# -Wmissing-braces - catches aggregate initializers missing nested braces
# -Wmultichar - catches multicharacter integer constants like 'THIS'
# -Wnon-literal-null-conversion - catches expressions used as a null pointer constant
# -Wnonnull - catches NULL used with functions arguments marked as non-null
# -Wparentheses - catches `if (a=b)` and operator precedence bugs
# -Wpointer-arith - catches pointer arithmetic using NULL or sizeof(void) # -Wpointer-arith - catches pointer arithmetic using NULL or sizeof(void)
# -Wpointer-sign - catches mixing pointers to signed and unsigned types
# -Wpointer-to-int-cast - catches casts from pointer to different sized int
# -Wreturn-type - catches missing returns, zero false positives
# -Wsequence-point - catches undefined order behavior like `a = a++`
# -Wsign-compare - catches comparison of signed and unsigned types
# -Wswitch - catches switches without all enum cases or default case
# -Wtrigraphs - catches unlikely use of trigraphs
# -Wtype-limits - catches overflow bugs, few false positives # -Wtype-limits - catches overflow bugs, few false positives
# -Wunknown-pragmas - catches unexpected #pragma directives
# -Wwrite-strings - catches non-const char* pointers to string literals
#
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wall" _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wall"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wsign-compare" _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wempty-body"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wignored-qualifiers"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wpointer-arith"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wtype-limits" _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wtype-limits"
# Treat some warnings as errors if --enable-warnings-as-errors: # -Wnon-literal-null-conversion - catches expressions used as a null pointer constant
if test "$MOZ_ENABLE_WARNINGS_AS_ERRORS"; then # -Wsometimes-initialized - catches some uninitialized values
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=address"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=char-subscripts"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=comment"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=empty-body"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=endif-labels"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=enum-compare"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=ignored-qualifiers"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=implicit-function-declaration"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=int-to-pointer-cast"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=missing-braces"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=multichar"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=nonnull"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=parentheses"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=pointer-arith"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=pointer-sign"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=pointer-to-int-cast"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=return-type"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=sequence-point"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=switch"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=trigraphs"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=uninitialized"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=unknown-pragmas"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=write-strings"
MOZ_C_SUPPORTS_WARNING(-Werror=, non-literal-null-conversion, ac_c_has_werror_non_literal_null_conversion)
MOZ_C_SUPPORTS_WARNING(-Werror=, sometimes-uninitialized, ac_c_has_sometimes_uninitialized)
fi
# Turn off the following warnings that -Wall turns on:
# -Wno-unused - lots of violations in third-party code
# -Wno-inline-new-delete - we inline 'new' and 'delete' in mozalloc
# -Wno-unused-local-typedef - catches unused typedefs, which are commonly used in assertion macros
# #
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wno-unused" # XXX: at the time of writing, the version of clang used on the OS X test
# machines has a bug that causes it to reject some valid files if both
MOZ_CXX_SUPPORTS_WARNING(-Wno-, inline-new-delete, ac_cxx_has_wno_inline_new_delete) # -Wnon-literal-null-conversion and -Wsometimes-uninitialized are
MOZ_CXX_SUPPORTS_WARNING(-Wno-, unused-local-typedef, ac_cxx_has_wno_unused_local_typedef) # specified. We work around this by instead using
# -Werror=non-literal-null-conversion, but we only do that when
# --enable-warnings-as-errors is specified so that no unexpected fatal
# warnings are produced.
if test "$MOZ_ENABLE_WARNINGS_AS_ERRORS"; then
MOZ_C_SUPPORTS_WARNING(-Werror=, non-literal-null-conversion, ac_c_has_non_literal_null_conversion)
fi
MOZ_C_SUPPORTS_WARNING(-W, sometimes-uninitialized, ac_c_has_sometimes_uninitialized)
# -Wcast-align - catches problems with cast alignment
if test -z "$INTEL_CC" -a -z "$CLANG_CC"; then if test -z "$INTEL_CC" -a -z "$CLANG_CC"; then
# Don't use -Wcast-align with ICC or clang # Don't use -Wcast-align with ICC or clang
case "$CPU_ARCH" in case "$CPU_ARCH" in
@ -1272,6 +1228,14 @@ if test "$GNU_CC"; then
esac esac
fi fi
# Turn off some non-useful warnings that -Wall turns on.
# -Wno-unused - lots of violations in third-party code
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wno-unused"
# -Wno-unused-local-typedef - catches unused typedefs, which are commonly used in assertion macros
MOZ_C_SUPPORTS_WARNING(-Wno-, unused-local-typedef, ac_c_has_wno_unused_local_typedef)
_DEFINES_CFLAGS='-include $(topobjdir)/js/src/js-confdefs.h -DMOZILLA_CLIENT' _DEFINES_CFLAGS='-include $(topobjdir)/js/src/js-confdefs.h -DMOZILLA_CLIENT'
_USE_CPP_INCLUDE_FLAG=1 _USE_CPP_INCLUDE_FLAG=1
@ -1301,77 +1265,40 @@ fi
if test "$GNU_CXX"; then if test "$GNU_CXX"; then
# Turn on gcc/clang warnings: # Turn on gcc/clang warnings:
# https://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Warning-Options.html # https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Warning-Options.html
#
# -Wall - turn on a lot of warnings # -Wall - lots of useful warnings
# -Wchar-subscripts - catches array index using signed char
# -Wcomment - catches nested comments
# -Wconversion-null - catches conversions between NULL and non-pointer types
# -Wempty-body - catches bugs, e.g. "if (c); foo();", few false positives # -Wempty-body - catches bugs, e.g. "if (c); foo();", few false positives
# -Wendif-labels - catches `#else FOO` and `#endif FOO` not in comment
# -Wignored-qualifiers - catches returns types with qualifiers like const
# -Wint-to-pointer-cast - catches cast to pointer from integer of different size
# -Wmissing-braces - catches aggregate initializers missing nested braces
# -Wnon-literal-null-conversion - catches expressions used as a null pointer constant
# -Woverloaded-virtual - function declaration hides virtual function from base class # -Woverloaded-virtual - function declaration hides virtual function from base class
# -Wparentheses - catches `if (a=b)` and operator precedence bugs
# -Wpointer-arith - catches pointer arithmetic using NULL or sizeof(void) # -Wpointer-arith - catches pointer arithmetic using NULL or sizeof(void)
# -Wpointer-to-int-cast - catches casts from pointer to different sized int
# -Wrange-loop-analysis - catches copies during range-based for loops.
# -Wreorder - catches ctor initializer list not matching class definition order
# -Wreturn-type - catches missing returns, zero false positives
# -Wsequence-point - catches undefined order behavior like `a = a++`
# -Wsign-compare - catches comparison of signed and unsigned types
# -Wswitch - catches switches without all enum cases or default case
# -Wtrigraphs - catches unlikely use of trigraphs
# -Wtype-limits - catches overflow bugs, few false positives # -Wtype-limits - catches overflow bugs, few false positives
# -Wunknown-pragmas - catches unexpected #pragma directives
# -Wunused-label - catches unused goto labels
# -Wunused-value - catches unused expression results
# -Wwrite-strings - catches non-const char* pointers to string literals
#
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wall" _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wall"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wsign-compare" _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wempty-body"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Woverloaded-virtual"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wpointer-arith"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wtype-limits" _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wtype-limits"
# -Wclass-varargs - ???
# -Wnon-literal-null-conversion - catches expressions used as a null pointer constant
# -Wrange-loop-analysis - catches copies during range-based for loops.
# -Wsometimes-initialized - catches some uninitialized values
#
# XXX: at the time of writing, the version of clang used on the OS X test
# machines has a bug that causes it to reject some valid files if both
# -Wnon-literal-null-conversion and -Wsometimes-uninitialized are
# specified. We work around this by instead using
# -Werror=non-literal-null-conversion, but we only do that when
# --enable-warnings-as-errors is specified so that no unexpected fatal
# warnings are produced.
MOZ_CXX_SUPPORTS_WARNING(-W, class-varargs, ac_cxx_has_wclass_varargs) MOZ_CXX_SUPPORTS_WARNING(-W, class-varargs, ac_cxx_has_wclass_varargs)
# Treat some warnings as errors if --enable-warnings-as-errors:
if test "$MOZ_ENABLE_WARNINGS_AS_ERRORS"; then if test "$MOZ_ENABLE_WARNINGS_AS_ERRORS"; then
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=char-subscripts" MOZ_CXX_SUPPORTS_WARNING(-Werror=, non-literal-null-conversion, ac_cxx_has_non_literal_null_conversion)
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=comment"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=endif-labels"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=ignored-qualifiers"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=int-to-pointer-cast"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=missing-braces"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=overloaded-virtual"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=parentheses"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=pointer-arith"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=reorder"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=return-type"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=sequence-point"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=switch"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=trigraphs"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=uninitialized"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=unknown-pragmas"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=unused-label"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=unused-value"
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Werror=write-strings"
MOZ_CXX_SUPPORTS_WARNING(-Werror=, conversion-null, ac_cxx_has_werror_conversion_null)
MOZ_CXX_SUPPORTS_WARNING(-Werror=, non-literal-null-conversion, ac_cxx_has_werror_non_literal_null_conversion)
MOZ_CXX_SUPPORTS_WARNING(-Werror=, range-loop-analysis, ac_cxx_has_range_loop_analysis)
MOZ_CXX_SUPPORTS_WARNING(-Werror=, sometimes-uninitialized, ac_cxx_has_sometimes_uninitialized)
fi fi
MOZ_CXX_SUPPORTS_WARNING(-W, range-loop-analysis, ac_cxx_has_range_loop_analysis)
MOZ_CXX_SUPPORTS_WARNING(-W, sometimes-uninitialized, ac_cxx_has_sometimes_uninitialized)
# Turn off the following warnings that -Wall turns on: # -Wcast-align - catches problems with cast alignment
# -Wno-invalid-offsetof - we use offsetof on non-POD types frequently
# -Wno-unused-local-typedef - catches unused typedefs, which are commonly used in assertion macros
#
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-invalid-offsetof"
MOZ_CXX_SUPPORTS_WARNING(-Wno-, unused-local-typedef, ac_cxx_has_wno_unused_local_typedef)
if test -z "$INTEL_CXX" -a -z "$CLANG_CXX"; then if test -z "$INTEL_CXX" -a -z "$CLANG_CXX"; then
# Don't use -Wcast-align with ICC or clang # Don't use -Wcast-align with ICC or clang
case "$CPU_ARCH" in case "$CPU_ARCH" in
@ -1384,8 +1311,15 @@ if test "$GNU_CXX"; then
esac esac
fi fi
_DEFINES_CXXFLAGS='-DMOZILLA_CLIENT -include $(topobjdir)/js/src/js-confdefs.h' # Turn off some non-useful warnings that -Wall turns on.
_USE_CPP_INCLUDE_FLAG=1
# -Wno-invalid-offsetof - we use offsetof on non-POD types frequently
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-invalid-offsetof"
# -Wno-inline-new-delete - we inline 'new' and 'delete' in mozalloc
# -Wno-unused-local-typedef - catches unused typedefs, which are commonly used in assertion macros
MOZ_CXX_SUPPORTS_WARNING(-Wno-, inline-new-delete, ac_cxx_has_wno_inline_new_delete)
MOZ_CXX_SUPPORTS_WARNING(-Wno-, unused-local-typedef, ac_cxx_has_wno_unused_local_typedef)
# Recent clang and gcc support C++11 deleted functions without warnings if # Recent clang and gcc support C++11 deleted functions without warnings if
# compiling with -std=c++0x or -std=gnu++0x (or c++11 or gnu++11 in very new # compiling with -std=c++0x or -std=gnu++0x (or c++11 or gnu++11 in very new
@ -1398,6 +1332,9 @@ if test "$GNU_CXX"; then
MOZ_CXX_SUPPORTS_WARNING(-Wno-, extended-offsetof, ac_cxx_has_wno_extended_offsetof) MOZ_CXX_SUPPORTS_WARNING(-Wno-, extended-offsetof, ac_cxx_has_wno_extended_offsetof)
fi fi
_DEFINES_CXXFLAGS='-DMOZILLA_CLIENT -include $(topobjdir)/js/src/js-confdefs.h'
_USE_CPP_INCLUDE_FLAG=1
else else
_DEFINES_CXXFLAGS='-DMOZILLA_CLIENT -D_JS_CONFDEFS_H_ $(ACDEFINES)' _DEFINES_CXXFLAGS='-DMOZILLA_CLIENT -D_JS_CONFDEFS_H_ $(ACDEFINES)'
fi fi