Bug 1483761 - Enable clang's -Wshadow-field-in-constructor warnings. r=glandium
authorChris Peterson <cpeterson@mozilla.com>
Mon, 20 Aug 2018 10:10:57 -0700
changeset 481296 f41a14a1b4de976d7a36094644195847007f9b35
parent 481295 36f6bab3d669cef41b9b2089e9081af388ce1c2b
child 481297 6d30bac7078b1c9eb2e16ed7702204b8d41fc43e
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersglandium
bugs1483761
milestone63.0a1
Bug 1483761 - Enable clang's -Wshadow-field-in-constructor warnings. r=glandium This opt-in warning catches bugs where a constructor modifies a constructor parameter that shadows member variable name. The code probably intended to change the member variable value, not the paramter. There are currently no -Wshadow-field-in-constructor warnings in mozilla-central. https://clang.llvm.org/docs/DiagnosticsReference.html#wshadow-field-in-constructor-modified Differential Revision: https://phabricator.services.mozilla.com/D3822
build/moz.configure/warnings.configure
--- a/build/moz.configure/warnings.configure
+++ b/build/moz.configure/warnings.configure
@@ -26,16 +26,19 @@ add_gcc_warning('-Wempty-body')
 add_gcc_warning('-Wignored-qualifiers')
 
 # function declaration hides virtual function from base class
 add_gcc_warning('-Woverloaded-virtual', cxx_compiler)
 
 # catches pointer arithmetic using NULL or sizeof(void)
 add_gcc_warning('-Wpointer-arith')
 
+# catch modifying constructor parameter that shadows member variable
+check_and_add_gcc_warning('-Wshadow-field-in-constructor-modified')
+
 # catches comparing signed/unsigned ints
 add_gcc_warning('-Wsign-compare')
 
 # catches overflow bugs, few false positives
 add_gcc_warning('-Wtype-limits')
 
 # catches some dead code
 add_gcc_warning('-Wunreachable-code')