Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`DIR-15-8-1`: move assignment self-assignment false positive

Open
#889 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
devtools

Research direction

Start with cpp/misra/src/rules/DIR-15-8-1/CopyAndMoveAssignmentsShallHandleSelfAssignment.ql and run it against the provided main.cpp example to reproduce the alert on the move assignment operator. Review the rule's handling of move-and-swap self-assignment, then verify that this valid pattern is no longer reported while the intended DIR-15-8-1 violations remain detected.

Written by the indexing model from the issue text.

Description

Difficulty-Medium false positive/false negative Impact-Medium
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.

Dominant language
CodeQL
Stars
227
Forks
82
Avg merge
6d 7h
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/codeql-coding-standards

All issues in github/codeql-coding-standards

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.