[SERVER-289] don't pollute global namespaces ( WAS: Mongo #assert squashes other asserts) Created: 10/Sep/09  Updated: 12/Jul/16  Resolved: 23/Apr/10

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: None
Fix Version/s: 1.5.1

Type: Bug Priority: Major - P3
Reporter: Jack Saalweachter Assignee: Mathias Stearn
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

When you try to assert something in a file which includes dbclient.h, the mongo assert replaces other asserts which may have been declared.

EXAMPLE:

foo.cc:
#include <cassert>
#include <mongo/client/dbclient.h>

int main() {
assert(false);
}

YIELDS:

> g++ foo.cc -o foo
foo.cc: In function 'int main()':
foo.cc:5: error: 'asserted' was not declared in this scope



 Comments   
Comment by Mathias Stearn [ 23/Apr/10 ]

fixed with http://github.com/mongodb/mongo/commit/60002a474169de84eac6bce20836ee553abf731c

If you include mongo/client/cleanup.h it will remove our global macros.

Comment by Eliot Horowitz (Inactive) [ 17/Oct/09 ]

merged that patch

Comment by metagoto [ 17/Oct/09 ]

I did a quick fix: moving 'using namespace' directives inside the mongo ns declaration in stdafx.h.
Also needed: add the 2 directives in shell/dbshell.cpp (which is not in the mongo ns)
I also had to qualify a few shared_ptr with boost:: in util/log.h

The client part is 'fixed': i can build my project which depends on libmongoclient without names conflicts (even with -std=c++0x)

My commit is
http://github.com/metagoto/mongo/commit/dbfcac22a173e22b39921017dc4c7ce85016796a

My master branch is up to date at that time. mongo server, tools, shell and lib compile with both sm and v8 on osx

Comment by Eliot Horowitz (Inactive) [ 08/Oct/09 ]

made it compile at least - still squases, just uses mongo::asserted

Generated at Thu Feb 08 02:53:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.