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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: legacy-0.8.0
    • Component/s: None
    • Labels:
    • Environment:
      All

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              3 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: