Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
Labels
Difficulty-MediumA false positive or false negative report which is expected to take 1-5 days effort to address Impact-Medium false positive/false negativeAn issue related to observed false positives or false negatives.
@fjatWbyT

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty-MediumA false positive or false negative report which is expected to take 1-5 days effort to address Impact-Medium false positive/false negativeAn issue related to observed false positives or false negatives.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /