AutosarC++17_03-A18.1.3ΒΆ
The std::auto_ptr type shall not be used
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
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 271687 2017-03-23 08:57:35Z piotr.tanski $
#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
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.