Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-44

Client facing headers should not say "using namespace std" in header scope

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • legacy-0.8.0
    • Affects Version/s: None
    • Component/s: None
    • Environment:
      All

      mongo/bson/bsontypes.h does 'using namespace std' in header context.

      Even though its contained in the mongo namespace, best practice is that names from other namespaces should be namespace qualified in headers, for the following reason:

      // From who knows where in my include chain...
      class string

      { /* ... */ }

      ; // NOT std::string, global scope

      // From mongo headers...
      #include <string>

      namespace mongo {
      using namespace std;
      class BSONObjBuilder {
      // ...
      // ERROR: 'string' ambiguous here!!!
      BSONObjBuilder& append(const string& fieldName , BSONObj subObj);
      // ...
      } // namespace mongo

      By 'using namespace std', and using names from the std namespace without qualification, you expose yourself to ambiguity with any global names introduced in other headers that shadow names in namespace std. When integrating the BSON headers (or other client facing headers) into complex existing applications that already integrate many libraries the potential for such conflicts materializing in practice grows considerably.

            Assignee:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Reporter:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: