isocpp / isocpp/CppCoreGuidelines

C.21 Exception for copy-and-swap idiom

Open
#2,164 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

C.21 is missing an exception for the copy-and-swap idiom. It's perfectly safe (and considered idiomatic by many) for resource management to write:

T& operator=(T) noexcept { /* ... */ }

This would violate C.21 since technically, the user has only defined the copy assignment operator, and the move assignment operator is implicitly not declared.

The lack of an exception to this rule also manifests itself in clang-tidy false positives. See:

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.

Research direction

Start with the C.21 guideline text and compare its special-member-function requirements with the copy-and-swap example in the issue. Review the linked clang-tidy issue and Stack Overflow discussion for the false-positive context. Done means C.21 clearly addresses this idiom without weakening its intended rule.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.