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 · 1 comment
Open
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low Standard-AUTOSAR user-report Issue reported by an end user of CodeQL Coding Standards

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
@lcartey lcartey added the user-report Issue reported by an end user of CodeQL Coding Standards label Oct 15, 2024
@lcartey lcartey added Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address Impact-Low labels Oct 23, 2024
@lcartey
Copy link
Collaborator

lcartey commented Oct 23, 2024

It should be straight forward to exclude nullptr from these queries. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low Standard-AUTOSAR user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

No branches or pull requests

3 participants