Bug 1406618 - Enable gcc -Wduplicated-cond warnings. r=glandium
authorChris Peterson <cpeterson@mozilla.com>
Thu, 05 Oct 2017 23:14:02 -0700
changeset 679054 c63d0efbbcfd4a33e325ae4a41be043d6a247405
parent 678456 cc0c99d812fd1cb33e13450a1d025d1f7d69e244
child 679055 c4492a71092ec7ea0962b1c3f323406891f4a870
push id84141
push userbmo:schien@mozilla.com
push dateThu, 12 Oct 2017 11:13:04 +0000
reviewersglandium
bugs1406618
milestone58.0a1
Bug 1406618 - Enable gcc -Wduplicated-cond warnings. r=glandium Warn about duplicated conditions in if-else-if chains, which are unreachable code and likely copy/paste bugs. The -Wduplicated-cond flag is available in gcc 6 and later. int example(int a) { if (a == 0) a = 42; else if (a == 0) // -Wduplicated-cond warning! a = 43; return a; } MozReview-Commit-ID: F9hqxMCct74
build/moz.configure/warnings.configure
--- a/build/moz.configure/warnings.configure
+++ b/build/moz.configure/warnings.configure
@@ -60,16 +60,19 @@ check_and_add_gcc_warning('-Wloop-analys
 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 possible misuse of the comma operator
 check_and_add_gcc_warning('-Wcomma', cxx_compiler)
 
+# catches duplicated conditions in if-else-if chains
+check_and_add_gcc_warning('-Wduplicated-cond')
+
 # 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