Skip to content

Appendix C: Changes to "Define Copy, move, and destroy consistently"#2274

Open
eyalroz wants to merge 2 commits into
isocpp:masterfrom
eyalroz:revamp_sd_consistent
Open

Appendix C: Changes to "Define Copy, move, and destroy consistently"#2274
eyalroz wants to merge 2 commits into
isocpp:masterfrom
eyalroz:revamp_sd_consistent

Conversation

@eyalroz

@eyalroz eyalroz commented Apr 28, 2025

Copy link
Copy Markdown

These changes regard "Appendix C: Discussion", section "Define Copy, move, and destroy consistently".

This section is somewhat of a jumble, mixing some fragments from other sources, and some which seem like parts of drafts of alternative versions of existing guidelines. To be honest - I would not have added it to the guidelines to begin with, and kept it on a wiki with not-yet-ready / staging material. Anyway - I would like to shape it up to better fit the general description of content in the Discussion appendix, being more tight and less meandering and fragmented.

Changes:

  • Removed several notes which do not seem to add to what's already been said in existing rules, or in other text in this discussion section.
  • Moved up a piece of rationale for the "rule of zero", from the discussion to guideline C.21.
  • Rephrased some text to relate it to what's already been said in C.21 rather than being completely stand-alone;
  • Corrected a reference to Sutter & Alexandrescu's C++ Coding Guidelines - which just said "item 53" without saying where. Plus, it's item 52.
  • Added some minor emphasis to names of functions within the five, in the bulleted list of interrelations
  • Removed what I believe is a false guarantee regarding classes with reference methods: "the default destructor already does the right thing"; that's not a sound promise if copying and moving has complex custom logic. Toned down the rhetoric.
  • Removed the parenthesized note saying that "using a reference member is almost always wrong"; this is a strong claim that should not be made as an off-hand remark, in parentheses, in the appendix, and with no guideline even alluding as much. This fixes "Note that using a reference member is almost always wrong" ? #1707. But - see issue reference member #1809 regarding possibly guiding users to avoid reference members.

Corrected what I am certain is a mistype regarding reference methods: It is the default constructor that will certainly do the right thing.

…eference in the "Define Copy, move, and destroy consistently" section of "Appendix C: Discussion"
@eyalroz eyalroz changed the title Changes to "Define Copy, move, and destroy consistently" Appendix C: Changes to "Define Copy, move, and destroy consistently" Apr 28, 2025
@hsutter hsutter self-assigned this May 8, 2025
@eyalroz

eyalroz commented Jul 7, 2026

Copy link
Copy Markdown
Author

@hsutter : It's been over a year since you self-assigned this PR. Care to review it?

Comment thread CppCoreGuidelines.md

**Exceptions**: When any of the special functions are declared only to make them non-public or virtual, but without special semantics, it doesn't imply that the others are needed.
In rare cases, classes that have members of strange types (such as reference members) are an exception because they have peculiar copy semantics.
In a class holding a reference, you likely need to write the copy constructor and the assignment operator, but the default destructor already does the right thing. (Note that using a reference member is almost always wrong.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the assertion that this is almost always wrong addresses #1707. My opinion is that it is therefore an improvement. However my opinion differs, it seems, from that of the editors and holds no particular sway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Note that using a reference member is almost always wrong" ?

3 participants