Open nbusser-sr opened 1 month ago
A20-8-5
cpp/autosar/make-unique-not-used-to-construct-object-owned-by-unique-ptr
Rule A20-8-5 (required, implementation, automated) std::make_unique shall be used to construct objects owned by std::unique_ptr.
A20-8-6
cpp/autosar/make-shared-not-used-to-construct-object-owned-by-shared-ptr
Rule A20-8-6 (required, implementation, automated) std::make_shared shall be used to construct objects owned by std::shared_ptr.
A20-8-5 triggers when initializing an unique_ptr to nullptr. A20-8-6 triggers when initializing an shared_ptr to nullptr.
unique_ptr
nullptr
shared_ptr
Initializing a smart pointer with a nullptr value can be however necessary in some specific cases.
std::unique_ptr<bool> uniquePtr{nullptr}; // Triggers A20-8-5 std::shared_ptr<bool> sharedPtr{nullptr}; // Triggers A20-8-6
It should be straight forward to exclude nullptr from these queries. Thanks for the report!
Affected rules
A20-8-5
:cpp/autosar/make-unique-not-used-to-construct-object-owned-by-unique-ptr
A20-8-6
:cpp/autosar/make-shared-not-used-to-construct-object-owned-by-shared-ptr
Description
A20-8-5
triggers when initializing anunique_ptr
tonullptr
.A20-8-6
triggers when initializing anshared_ptr
tonullptr
.Initializing a smart pointer with a
nullptr
value can be however necessary in some specific cases.Example