Main Content

AUTOSAR C++14 Rule A17-6-1

Non-standard entities shall not be added to standard namespaces

Since R2020a

Description

Rule Definition

Non-standard entities shall not be added to standard namespaces.

Rationale

Adding declarations or definitions to namespace std or its subspaces:or to posix or its subspaces, leads to undefined behavior. For instance, any addition within braces here leads to undefined behavior:

namespace std {
  ...
}

Likewise, explicitly specializing a member function or member class of a standard library leads to undefined behavior.

Polyspace Implementation

The checker flags additions to the namespaces std, posix, or their subspaces, or specializations of class or function templates from these namespaces.

The rule specification allows exceptions to the specialization aspect of the rule for standard library templates that require a user-defined type. If you have a process that all rule violations must be justified and an issue flagged by the checker belongs to this category of exceptions, justify the issue using comments in your result or code. See:

Troubleshooting

If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Check Information

Group: Library introduction
Category: Required, Automated

Version History

Introduced in R2020a