You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

C++ places all standard definitions inside the std namespace. Furthermore, C++ 2003, Section 17.4.3.1 "Reserved names", says:

It is undefined for a C++ program to add declarations or definitions to namespace std or namespaces within namespace std unless otherwise specified. A program may add template specializations for any standard library template to namespace std. Such a specialization (complete or partial) of a standard library template results in undefined behavior unless the declaration depends on a user-defined type of external linkage and unless the specialization meets the standard library requirements for the original template.

Noncompliant Code Example

This code is noncompliant because it alters the standard namespace.

namespace std {
  int x;
};

Compliant Solution

namespace nonstd {
  int x;
};

Risk Assessment

Altering the standard namespace can cause undefined behavior in the C++ standard library.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

MSC34-CPP

high

unlikely

medium

P12

L1

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

[ISO/IEC 10646-2003]


PRE12-CPP. Define numeric constants in a portable way      01. Preprocessor (PRE)      PRE31-CPP. Avoid side-effects in arguments to unsafe macros

  • No labels