...
This warning prevents build without --disable-warning-as-errors. Source code taken from master on Aug. 1 2016, with hash 2c1272d1e50b177fda189216fadabf1c6797890a g++ -o build/opt/mongo/client/dbclient.o -c -Woverloaded-virtual -Wno-maybe-uninitialized -std=c++11 -fno-omit-frame-pointer -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-const-variable -Wno-unused-but-set-variable -Wno-missing-braces -fstack-protector-strong -fno-builtin-memcmp -fPIE -DPCRE_STATIC -DNDEBUG -D_FORTIFY_SOURCE=2 -DBOOST_THREAD_VERSION=4 -DBOOST_THREAD_DONT_PROVIDE_VARIADIC_THREAD -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS -DBOOST_THREAD_HAS_NO_EINTR_BUG -Isrc/third_party/asio-asio-1-11-0/asio/include -Isrc/third_party/s2 -Isrc/third_party/pcre-8.39 -Isrc/third_party/boost-1.60.0 -Ibuild/opt -Isrc src/mongo/client/dbclient.cpp In file included from src/mongo/platform/compiler.h:151:0, from src/mongo/util/invariant.h:30, from src/mongo/base/string_data.h:41, from build/opt/mongo/base/error_codes.h:32, from src/mongo/base/status.h:34, from src/mongo/client/dbclient.cpp:37: src/mongo/client/dbclientcursor.h: In member function 'void mongo::DBClientCursor::_assertIfNull() const': src/mongo/util/assert_util.h:312:28: error: nonnull argument 'this' compared to NULL [-Werror=nonnull-compare] if (MONGO_unlikely(!(expr))) { \ ^~~~~~~ src/mongo/platform/compiler_gcc.h:77:80: note: in definition of macro 'MONGO_unlikely' #define MONGO_unlikely(x) static_cast(__builtin_expect(static_cast(x), 0)) ^ src/mongo/util/assert_util.h:309:17: note: in expansion of macro 'MONGO_uassert' #define uassert MONGO_uassert ^~~~~~~~~~~~~ src/mongo/client/dbclientcursor.h:290:9: note: in expansion of macro 'uassert' uassert(13348, "connection died", this); ^~~~~~~ cc1plus: all warnings being treated as errors scons: *** [build/opt/mongo/client/dbclient.o] Error 1 scons: building terminated because of errors. build/opt/mongo/client/dbclient.o failed: Error 1 gcc version: gcc (GCC) 6.1.1 20160707 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
xgen-internal-githook commented on Tue, 18 Apr 2017 01:18:10 +0000: Author: {u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'} Message: SERVER-25385 Eliminate checks of this against nullptr The compiler is free to eliminate them anyway, as it would have required UB to reach the check. (cherry picked from commit b9f8113e7f346f1449193834b77dc22fa4b1d8c7) Branch: v3.2 https://github.com/mongodb/mongo/commit/644c8130839d046599d254fded7da491b69b8289 acm commented on Wed, 17 Aug 2016 20:00:34 +0000: I have fixed the issues reported here, however, I'm unable to locally verify whether the tree compiles under GCC 6. xgen-internal-githook commented on Wed, 17 Aug 2016 20:00:04 +0000: Author: {u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'} Message: SERVER-25385 Eliminate checks of this against nullptr The compiler is free to eliminate them anyway, as it would have required UB to reach the check. Branch: master https://github.com/mongodb/mongo/commit/b9f8113e7f346f1449193834b77dc22fa4b1d8c7 acm commented on Mon, 8 Aug 2016 23:17:24 +0000: In both cases, the asserts are called from non-static member functions. As it would be undefined behavior to call such a function on nullptr, I think the compiler is entitled to assume that it doesn't happen in the member function. It would be interesting to see if the compiler is in fact emitting code to check, but in either case I think both instances of this error should be removed. mwhudson commented on Mon, 8 Aug 2016 02:27:01 +0000: There are two assert calls that hit this warning: (master)mwhudson@aeglos:/opt/opensource/mongo$ git grep -E '[mu]assert.*this)' src/mongo/client/dbclientcursor.h: uassert(13348, "connection died", this); src/mongo/db/storage/mmap_v1/catalog/namespace_details.cpp: massert(10350, "allocExtra: base ns missing?", this); The warning seems legitimate to me but maybe it's a useful check in some circumstances...