[SERVER-23399] Remove usage of using-directives and using-declarations declared with namespace scope in header files Created: 29/Mar/16  Updated: 06/Dec/22  Resolved: 31/May/19

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

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: DO NOT USE - Backlog - Dev Tools
Resolution: Won't Fix Votes: 0
Labels: neweng, platforms-re-triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Developer Tools
Operating System: ALL
Participants:

 Description   

These pollute the namespace they are declared in, for all source files that include these headers (directly or indirectly).

Preliminary list here:

$ find src/mongo -name '*.h' | grep -v stdx/ | grep -v platform/ | xargs git grep -E '^using [^n][^=]*::'
src/mongo/client/fetcher.h:using executor::RemoteCommandRequest;
src/mongo/db/exec/text.h:using std::unique_ptr;
src/mongo/db/exec/text.h:using std::vector;
src/mongo/db/exec/text.h:using fts::FTSQueryImpl;
src/mongo/db/exec/text.h:using fts::FTSSpec;
src/mongo/db/exec/text_match.h:using std::unique_ptr;
src/mongo/db/exec/text_match.h:using fts::FTSMatcher;
src/mongo/db/exec/text_match.h:using fts::FTSQueryImpl;
src/mongo/db/exec/text_match.h:using fts::FTSSpec;
src/mongo/db/exec/text_or.h:using std::unique_ptr;
src/mongo/db/exec/text_or.h:using std::vector;
src/mongo/db/exec/text_or.h:using fts::FTSSpec;
src/mongo/db/field_parser-inl.h:using mongoutils::str::stream;
src/mongo/dbtests/dbtests.h:using std::shared_ptr;
src/mongo/util/concurrency/threadlocal.h:using boost::thread_specific_ptr;
src/mongo/util/log.h:using logger::LogstreamBuilder;
src/mongo/util/log.h:using logger::LabeledLevel;
src/mongo/util/log.h:using logger::Tee;
src/mongo/util/time_support.h:using stdx::chrono::duration_cast;
$ find src/mongo -name '*.h' | grep -v stdx/ | grep -v platform/ | xargs git grep -E '^using namespace'
src/mongo/db/storage/paths.h:using namespace mongoutils;
src/mongo/dbtests/dbtests.h:using namespace mongo;
src/mongo/dbtests/dbtests.h:using namespace mongo::unittest;
src/mongo/util/mongoutils/str.h:using namespace mongoutils;



 Comments   
Comment by Billy Donahue [ 31/May/19 ]

It's unclear whether a namespace is being "polluted" or merely deliberately composed by these using declarations. Also some namespaces are details and it's ok to bring stuff into them because the impact of doing so is controlled.

The uses of using namespace directives are more controversial, but can still be instances of deliberate composition.

Comment by Mark Benvenuto [ 19/Dec/16 ]

We will also need to add a new check to cpplint.py. There is no similar existing check for banning usings, but a check can be modeled after the regex in the descriptions.

Generated at Thu Feb 08 04:03:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.