Use of std::auto_ptr, removed from the standard in C++17

ID

c.correctness.auto_ptr

Severity

low

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

low

Resource

Resource Management

Language

C / C++

Description

This code uses std::auto_ptr, which was deprecated in C11 and removed from the standard in C17. Its copy semantics transfer ownership and silently null out the source, so a plain copy or a pass-by-value into a container corrupts the original pointer. Replace it with std::unique_ptr, or std::shared_ptr when ownership must be shared.

Rationale

This code uses std::auto_ptr, which was deprecated in C11 and removed from the standard in C17. Its copy semantics transfer ownership and silently null out the source, so a plain copy or a pass-by-value into a container corrupts the original pointer. Replace it with std::unique_ptr, or std::shared_ptr when ownership must be shared.

The following code illustrates the pattern detected by this rule:

std::auto_ptr<int> make_int()
{
    // FLAGGED: Use of std::auto_ptr, removed from the standard in C++17
    std::auto_ptr<int> p(new int(5));
    return p;
}

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