AutosarC++18_03-A18.1.3ΒΆ

The std::auto_ptr type shall not be used

Required inputs: IR

Rationale

The std::auto_ptr type has been deprecated since the C++11 Language Standard and is removed from the C++17 Language Standard. Due to the lack of move semantics in pre C++11 standards, it provides unusual copy semantics and cannot be placed in STL containers.

The correct alternative is std::unique_ptr, which shall be used 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.
  • A1-1-1 in section 6.1.1

Possible Messages

Key

Text

Severity

Disabled

type_used

The std::auto_ptr shall not be used.

None

False

Options