Compiling error when using mongo-cxx-driver 26compt 2.6.7 release with option -Wextra

115 views
Skip to first unread message

Jacky Zhu

unread,
Jan 20, 2015, 5:43:18 PM1/20/15
to mongod...@googlegroups.com
Hi,

I got error "error: ordered comparison of pointer with integer zero [-Werror=extra]" when compiling our project against mongo-cxx-driver 26compa branch 2.6.7 release, which I downloaded from Git: https://github.com/mongodb/mongo-cxx-driver/releases/tag/legacy-0.0-26compat-2.6.7.

The root cause of this problem is in the function ScopedDbConnection::ok() of file src/mongo/client/connpool.h. Now it is:
bool ok() const { return _conn > 0; }

This triggers compiling error if -Wextra flag is enabled. 

           The option -Wextra also prints warning messages for the following cases:
                   A pointer is compared against integer zero with <, <=, >, or >=.

It is more straightforward to validate the pointer by pointer != 0, and thus won't trigger the -Wextra as well.

I thinks it makes more sense to change the line to:
bool ok() const { return _conn != 0; }

Andrew Morrow

unread,
Jan 20, 2015, 5:53:11 PM1/20/15
to mongod...@googlegroups.com

Hi - 

Thanks for the report.

In general, it is not possible for us to ensure that our headers compile without warnings on all compilers on all platforms. We do build cleanly with -Wall -Werror on many compilers, but the level of checking enabled with -Wextra can flag many legitimate constructs.

While I agree that the code you indicated could be simplified in the way you suggest, we are not currently applying non-mandatory fixes to the 26compat branch, since it is intended to be a 1:1 representation of the driver code as it would have been made available had we not separated it from the server sources. However, please be aware that the upcoming legacy-1.0.0 release has had many more warnings scrubbed out of it, and, in particular, the connpool.h header is no longer present, since support for connection pools has been removed.

Your easiest workaround is to either not compile the 26compat headers with -Wextra, or to upgrade to legacy-1.0.0, currently expected to ship on January 27th.

Thanks,
Andrew



--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/2f8b7d2e-d4ec-4d8a-b6c9-9adec1bc7cb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jacky Zhu

unread,
Jan 20, 2015, 6:07:10 PM1/20/15
to mongod...@googlegroups.com
Hi Andrew,

Thanks for the explanation. Our project is going into code freeze stage, so the stable legacy branch is a little bit too late for us (though only 6 days).
It's not easy to remove the -Wextra flag due to how makefile is organized in our project.

We may choose to patch the 26compat branch locally by modifying the code in connpool.h.



acm於 2015年1月21日星期三 UTC+11上午9時53分11秒寫道:

Andrew Morrow

unread,
Jan 21, 2015, 10:17:13 AM1/21/15
to mongod...@googlegroups.com

Another possibility would be to write your own header that includes ours, but wrap the inclusion with pragmas to push/pop the warning state to suppress the warnings that are being raised.

We actually already do this in dbclient.h for some windows warning using #pragma warning(push), #pragma warning(disable), #pragma warning(pop) sequences. You could do the same on windows, or use the GCC diagnostic pragmas (https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html) for GCC. So, for example, make a header our_dbclient.h that would look like:

#ifndef OUR_DBCLIENT_H
#define OUR_DBCLIENT_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Whatever"

#include <mongo/client/dbclient.h>

#pragma GCC diagnostic pop

#endif // OUR_DBCLIENT_H

And then just include our_dbclient.h everywhere you would normally include mongo/client/dbclient.h.

Hope this helps,
Andrew


Reply all
Reply to author
Forward
0 new messages