warnings.configure 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. js_option('--enable-warnings-as-errors', env='MOZ_ENABLE_WARNINGS_AS_ERRORS',
  6. default=depends('MOZ_AUTOMATION', '--help')(lambda x, _: bool(x)),
  7. help='Enable treating warnings as errors')
  8. add_old_configure_assignment(
  9. 'MOZ_ENABLE_WARNINGS_AS_ERRORS',
  10. depends('--enable-warnings-as-errors')(lambda x: bool(x)))
  11. # GCC/Clang warnings:
  12. # https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Warning-Options.html
  13. # lots of useful warnings
  14. add_gcc_warning('-Wall')
  15. # catches C++ version forward-compat issues
  16. add_gcc_warning('-Wc++11-compat', cxx_compiler)
  17. # catches bugs, e.g. "if (c); foo();", few false positives
  18. add_gcc_warning('-Wempty-body')
  19. # catches return types with qualifiers like const
  20. add_gcc_warning('-Wignored-qualifiers')
  21. # function declaration hides virtual function from base class
  22. add_gcc_warning('-Woverloaded-virtual', cxx_compiler)
  23. # catches pointer arithmetic using NULL or sizeof(void)
  24. add_gcc_warning('-Wpointer-arith')
  25. # catches comparing signed/unsigned ints
  26. add_gcc_warning('-Wsign-compare')
  27. # catches overflow bugs, few false positives
  28. add_gcc_warning('-Wtype-limits')
  29. # catches some dead code
  30. add_gcc_warning('-Wunreachable-code')
  31. # catches treating string literals as non-const
  32. add_gcc_warning('-Wwrite-strings', cxx_compiler)
  33. # turned on by -Wall, but we use offsetof on non-POD types frequently
  34. add_gcc_warning('-Wno-invalid-offsetof', cxx_compiler)
  35. # catches objects passed by value to variadic functions.
  36. check_and_add_gcc_warning('-Wclass-varargs')
  37. # catches issues around loops
  38. check_and_add_gcc_warning('-Wloop-analysis')
  39. # catches C++ version forward-compat issues
  40. check_and_add_gcc_warning('-Wc++11-compat-pedantic', cxx_compiler)
  41. check_and_add_gcc_warning('-Wc++14-compat', cxx_compiler)
  42. check_and_add_gcc_warning('-Wc++14-compat-pedantic', cxx_compiler)
  43. check_and_add_gcc_warning('-Wc++1z-compat', cxx_compiler)
  44. # catches unintentional switch case fallthroughs
  45. check_and_add_gcc_warning('-Wimplicit-fallthrough', cxx_compiler)
  46. # catches expressions used as a null pointer constant
  47. # XXX: at the time of writing, the version of clang used on the OS X test
  48. # machines has a bug that causes it to reject some valid files if both
  49. # -Wnon-literal-null-conversion and -Wsometimes-uninitialized are
  50. # specified. We work around this by instead using
  51. # -Werror=non-literal-null-conversion, but we only do that when
  52. # --enable-warnings-as-errors is specified so that no unexpected fatal
  53. # warnings are produced.
  54. check_and_add_gcc_warning('-Werror=non-literal-null-conversion',
  55. when='--enable-warnings-as-errors')
  56. # catches string literals used in boolean expressions
  57. check_and_add_gcc_warning('-Wstring-conversion')
  58. # catches inconsistent use of mutexes
  59. check_and_add_gcc_warning('-Wthread-safety')
  60. # we inline 'new' and 'delete' in mozalloc
  61. check_and_add_gcc_warning('-Wno-inline-new-delete', cxx_compiler)
  62. # Prevent the following GCC warnings from being treated as errors:
  63. # too many false positives
  64. check_and_add_gcc_warning('-Wno-error=maybe-uninitialized')
  65. # we don't want our builds held hostage when a platform-specific API
  66. # becomes deprecated.
  67. check_and_add_gcc_warning('-Wno-error=deprecated-declarations')
  68. # false positives depending on optimization
  69. check_and_add_gcc_warning('-Wno-error=array-bounds')
  70. # can't get rid of those PGO warnings
  71. check_and_add_gcc_warning('-Wno-error=coverage-mismatch', when='MOZ_PGO')
  72. # false positives during PGO
  73. check_and_add_gcc_warning('-Wno-error=free-nonheap-object', when='MOZ_PGO')
  74. # Would be a pain to fix all occurrences, for very little gain
  75. check_and_add_gcc_warning('-Wno-error=multistatement-macros')
  76. # We use mix of both POSIX and Win32 printf format across the tree, so format
  77. # warnings are useless on mingw.
  78. check_and_add_gcc_warning('-Wno-format',
  79. when=depends(target)(lambda t: t.kernel == 'WINNT'))
  80. # Disable a warning with GCC 7+.
  81. # We are far from using C++17 and the impact of the warning will be
  82. # limited to a potential public ABI.
  83. # Currently only affecting js/
  84. check_and_add_gcc_warning('-Wno-noexcept-type', cxx_compiler,
  85. when=depends(build_project)
  86. (lambda build_project: build_project == 'js'))
  87. # Please keep these last in this file
  88. add_old_configure_assignment('_WARNINGS_CFLAGS', warnings_cflags)
  89. add_old_configure_assignment('_WARNINGS_CXXFLAGS', warnings_cxxflags)