Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A20-8-5-A20-8-6: Cannot create a smart pointer with nullptr value #721

Open
nbusser-sr opened this issue Sep 30, 2024 · 0 comments
Open
Labels
false positive/false negative An issue related to observed false positives or false negatives.

Comments

@nbusser-sr
Copy link

nbusser-sr commented Sep 30, 2024

Affected rules

  • 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.

Description

A20-8-5 triggers when initializing an unique_ptr to nullptr.
A20-8-6 triggers when initializing an shared_ptr to nullptr.

Initializing a smart pointer with a nullptr value can be however necessary in some specific cases.

Example

std::unique_ptr<bool> uniquePtr{nullptr}; // Triggers A20-8-5
std::shared_ptr<bool> sharedPtr{nullptr}; // Triggers A20-8-6
@nbusser-sr nbusser-sr added the false positive/false negative An issue related to observed false positives or false negatives. label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false positive/false negative An issue related to observed false positives or false negatives.
Projects
None yet
Development

No branches or pull requests

1 participant