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
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.