isocpp / isocpp/CppCoreGuidelines

Clarification on the scope of rule C.83

Open
#1,683 2 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

The company I work for employs a third party static code quality checker. This tool has recently adopted a number of additional checks. One of them is rule C.83. The tool very literally implements the mentioned enforcement "A class without virtual functions should have a swap member function declared."

The consequence of this is that any Plain Old Datatype and non-polymorphic class is flagged if it misses the swap method.
The solution advised is to add

class C
{
   ...
   void swap(C &other) noexcept { std::swap(*this, other); } 
   ...
};

in such cases.

I wonder if this was the intention of the rule and if perhaps some context is missing as to when to apply this rule.

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.83 section in CppCoreGuidelines.md and compare its stated enforcement with the examples and wording referenced in the issue. Clarify whether the rule applies to all non-polymorphic classes or needs additional context; done means the guideline's scope is explicit enough to resolve the static-checker interpretation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.