Reopening namespace std to add a declaration

ID

c.maintainability.modify_std_namespace

Severity

low

Remediation Complexity

medium

Remediation Risk

high

Remediation Effort

medium

Resource

Undefined Behavior

Language

C / C++

Description

This code reopens namespace std to add its own declaration. Outside the specific exceptions the standard carves out (template specializations for user-defined types), adding anything to std is undefined behavior: the name can collide with a future standard library addition, or with what a different translation unit or vendor library already put there. Move the declaration into your own namespace.

Rationale

This code reopens namespace std to add its own declaration. Outside the specific exceptions the standard carves out (template specializations for user-defined types), adding anything to std is undefined behavior: the name can collide with a future standard library addition, or with what a different translation unit or vendor library already put there. Move the declaration into your own namespace.

The following code illustrates the pattern detected by this rule:

// FLAGGED: Reopening namespace std to add a declaration
namespace std {
    void log_message(const char *msg) {}
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved