AutosarC++17_10-A18.1.3ΒΆ

The std::auto_ptr type shall not be used

Required inputs: IR

Rationale

The std::auto_ptr smart pointer is deprecated since C++11 Language Standard and it is planned to be withdrawn in C++17 Language Standard.

The std::auto_ptr provides unusual copy semantics and it can not be placed in STL containers. It is recommended to use std::unique_ptr instead.

Example
// $Id: A18-1-3.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <cstdint>
#include <memory>
#include <vector>
void Fn() noexcept {
  std::auto_ptr<std::int32_t> ptr1(new std::int32_t(10)); // Non-compliant
  std::unique_ptr<std::int32_t> ptr2 =
      std::make_unique<std::int32_t>(10);     // Compliant
  std::vector<std::auto_ptr<std::int32_t>> v; // Non-compliant
}
See Also
  • HIC++ v4.0 [8]: 1.3.4 Do not use deprecated STL library features.
  • cppreference.com [15]: std::auto_ptr.

Possible Messages

Key

Text

Severity

Disabled

type_used

The std::auto_ptr shall not be used.

None

False

Options