GeneralPurpose-UsingNamespaceInHeader

Do not use ‘using namespace’ in a header file

Required inputs: IR

using namespace in headers can unexpectedly change the meaning of identifiers in other code files that import that header and should therefore be avoided.
Bad code:
// foo.hpp
#include <string>
using namespace std; // ERROR: Use of "using namespace" in header file.
void foo(const string&);

// foo.cpp
#include "foo.hpp"
void foo(const string& s) {
    // ...
}
Good code:
// foo.hpp
#include <string>
void foo(const std::string&);

// foo.cpp
#include "foo.hpp"
using namespace std; // OK: Use of "using namespace" in primary/implementation file
void foo(const string& s) {
    // ...
}

Possible Messages

Key

Text

Severity

Disabled

using_namespace_in_header

Use of “using namespace” in header file.

None

False

Options