Skip to content

DIR-15-8-1: move assignment self-assignment false positive #889

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

Open
fjatWbyT opened this issue Apr 24, 2025 · 0 comments
Open

DIR-15-8-1: move assignment self-assignment false positive #889

fjatWbyT opened this issue Apr 24, 2025 · 0 comments
Labels
false positive/false negative An issue related to observed false positives or false negatives.

Comments

@fjatWbyT
Copy link
Contributor

Affected rules

  • DIR-15-8-1

Description

Using the "move-and-swap idiom" proposed in the directive's example as a solution to address potential issues with self-assignment leads to an alert.

Example

#include <utility>

class resource_manager {
  public:
    resource_manager() = default;
    ~resource_manager() = default;
    resource_manager(resource_manager const&) = delete;
    resource_manager(resource_manager&&) = default;
    resource_manager& operator=(resource_manager const&) = delete;
    resource_manager& operator=(resource_manager&& other) & noexcept {
        resource_manager temp{std::move(other)};
        std::swap(resource_, temp.resource_);
        return *this;
    }
  private:
    using resource = int;
    resource resource_;
};

int main() {}

I am getting a

"DIR-15-8-1: User-provided copy assignment operators and move assignment operators shall handle self-assignment","User-provided copy assignment operators and move assignment operators shall handle self-assignment.","error","User defined copy or user defined move does not handle self-assignment correctly.","/main.cpp","10","23","10","31"

when analyzing with cpp/misra/src/rules/DIR-15-8-1/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql.

@fjatWbyT fjatWbyT added the false positive/false negative An issue related to observed false positives or false negatives. label Apr 24, 2025
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