author Chris Peterson <>
Sat, 08 Apr 2017 12:36:48 -0700
changeset 563349 d99ad92ef75ae4bbf0b7bc945f2c15179c5b29b0
parent 496295 b5daeb2d408d1cdc087895b5fe7d244df51a5b94
permissions -rw-r--r--
Bug 1356843 - Enable -Wcomma clang warnings. r?glandium Warn about possible misuse of the comma operator such as between two statements or to call a function for side effects within an expression. Only enable these -Wcomma warnings for C++ code because there are almost two hundred -Wcomma warnings in third-party C libraries. I reviewed the C warnings and confirmed none of them were latent bugs. We won't fix these libraries' warnings so they are just noise. MozReview-Commit-ID: 1JXJumg6DsJ

# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

js_option('--enable-warnings-as-errors', env='MOZ_ENABLE_WARNINGS_AS_ERRORS',
          default=depends('MOZ_AUTOMATION', '--help')(lambda x, _: bool(x)),
          help='Enable treating warnings as errors')

    depends('--enable-warnings-as-errors')(lambda x: bool(x)))

# GCC/Clang warnings:

# lots of useful warnings

# catches C++ version forward-compat issues
add_gcc_warning('-Wc++11-compat', cxx_compiler)

# catches bugs, e.g. "if (c); foo();", few false positives

# catches return types with qualifiers like const

# function declaration hides virtual function from base class
add_gcc_warning('-Woverloaded-virtual', cxx_compiler)

# catches pointer arithmetic using NULL or sizeof(void)

# catches comparing signed/unsigned ints

# catches overflow bugs, few false positives

# catches some dead code

# catches treating string literals as non-const
add_gcc_warning('-Wwrite-strings', cxx_compiler)

# turned on by -Wall, but we use offsetof on non-POD types frequently
add_gcc_warning('-Wno-invalid-offsetof', cxx_compiler)

# catches objects passed by value to variadic functions.

# catches issues around loops

# catches C++ version forward-compat issues
check_and_add_gcc_warning('-Wc++11-compat-pedantic', cxx_compiler)
check_and_add_gcc_warning('-Wc++14-compat', cxx_compiler)
check_and_add_gcc_warning('-Wc++14-compat-pedantic', cxx_compiler)
check_and_add_gcc_warning('-Wc++1z-compat', cxx_compiler)

# catches suspicious uses of the comma operator
check_and_add_gcc_warning('-Wcomma', cxx_compiler)

# catches unintentional switch case fallthroughs
check_and_add_gcc_warning('-Wimplicit-fallthrough', cxx_compiler)

# catches expressions used as a null pointer constant
# 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.

# catches string literals used in boolean expressions

# we inline 'new' and 'delete' in mozalloc
check_and_add_gcc_warning('-Wno-inline-new-delete', cxx_compiler)

# Prevent the following GCC warnings from being treated as errors:
# too many false positives

# we don't want our builds held hostage when a platform-specific API
# becomes deprecated.

# false positives depending on optimization

# can't get rid of those PGO warnings
check_and_add_gcc_warning('-Wno-error=coverage-mismatch', when='MOZ_PGO')

# false positives during PGO
check_and_add_gcc_warning('-Wno-error=free-nonheap-object', when='MOZ_PGO')

# catches format/argument mismatches with printf

# We use mix of both POSIX and Win32 printf format across the tree, so format
# warnings are useless on mingw.
                          when=depends(target)(lambda t: t.kernel == 'WINNT'))

# We hit this all over the place with the gtest INSTANTIATE_TEST_CASE_P macro

# Please keep these last in this file
add_old_configure_assignment('_WARNINGS_CFLAGS', warnings_cflags)
add_old_configure_assignment('_WARNINGS_CXXFLAGS', warnings_cxxflags)