-
Notifications
You must be signed in to change notification settings - Fork 9
fix(c++): Add a section title comment for grouping defaulted/deleted copy/move constructors & assignment operators. #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
davidlion
wants to merge
8
commits into
y-scope:main
Choose a base branch
from
davidlion:category-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+44
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
598fdfa
Add exception section to grouping.
davidlion e95e976
Addressed some review comments.
davidlion 8c48c3f
Fixed wording.
davidlion 60a71de
Apply suggestions from code review.
davidlion e829618
Added review comment; removed windows new lines.
davidlion aa904d0
Small tweak.
davidlion de5627b
Fix section link.
davidlion 37d3e2d
Actually fix links.
davidlion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -146,7 +146,11 @@ that begin with a title comment, where the comment is simply the name of the sec | |||||
| 4. Static methods | ||||||
| 5. Static data members | ||||||
| 6. Constructors | ||||||
| * [See the exception below](#defaulteddeleted-copymove-constructors-and-assignment-operators) | ||||||
| when defaulting/deleting both a copy/move constructor *and* assignment operator. | ||||||
| 7. Operators | ||||||
| * [See the exception below](#defaulteddeleted-copymove-constructors-and-assignment-operators) | ||||||
| when defaulting/deleting both a copy/move constructor *and* assignment operator. | ||||||
| 8. Destructor | ||||||
| 9. Methods implementing `<InheritedClass>` | ||||||
| * I.e., methods implementing abstract methods from the class `<InheritedClass>`. | ||||||
|
|
@@ -159,9 +163,49 @@ that begin with a title comment, where the comment is simply the name of the sec | |||||
| Note, `<InheritedClass>` is a placeholder that should be replaced with the name of the class that | ||||||
| first declares the virtual method. | ||||||
|
|
||||||
| ##### Defaulted/deleted copy/move constructors and assignment operators | ||||||
|
|
||||||
| To improve clarity, when defaulting/deleting both the copy/move constructor *and* assignment | ||||||
| operator of a class they should be grouped together. These groups should come between the | ||||||
| `Constructors` and `Operators` groups, with any other constructors or operators still in their | ||||||
| normal groups. | ||||||
|
|
||||||
| This commonly occurs when adhering to ["the rule of 5"][cpp-core-guideline-rule-of-5], as once any | ||||||
| copy, move, or destructor function is defined or deleted, they all must be defined or deleted. | ||||||
|
|
||||||
| :::{note} | ||||||
| Defaulting and deleting these constructors and operators should only be done when necessary and | ||||||
| should be omitted when possible, following ["the rule of zero"][cpp-core-guideline-rule-of-0]. | ||||||
|
|
||||||
| [clang-tidy's special-member-functions][clang-tidy-special-member-functions] check will enforce the | ||||||
| rule of 5, so generally you can wait for it to tell you when to define/delete these functions if | ||||||
| you're unsure. | ||||||
| ::: | ||||||
|
|
||||||
| For example: | ||||||
|
|
||||||
| ```cpp | ||||||
| // Constructors | ||||||
| Foo() { ... }; | ||||||
|
|
||||||
| // Default copy constructor and assignment operator. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Foo(const Foo&) = default; | ||||||
| Foo& operator=(const Foo&) = default; | ||||||
|
|
||||||
| // Default move constructor and assignment operator. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Foo(Foo&&) = default; | ||||||
| Foo& operator=(Foo&&) = default; | ||||||
|
|
||||||
| // Destructor | ||||||
| ~Foo() { ... }; | ||||||
| ``` | ||||||
|
|
||||||
| [adding-cpp-linting]: https://github.com/y-scope/yscope-dev-utils/blob/main/docs/lint-tools-cpp.md | ||||||
| [clang-format-config]: https://github.com/y-scope/yscope-dev-utils/blob/main/lint-configs/.clang-format | ||||||
| [clang-tidy-config]: https://github.com/y-scope/yscope-dev-utils/blob/main/lint-configs/.clang-tidy | ||||||
| [clang-tidy-special-member-functions]: https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/special-member-functions.html | ||||||
| [cpp-core-guideline-rule-of-0]: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rc-zero | ||||||
| [cpp-core-guideline-rule-of-5]: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rc-five | ||||||
| [google-cpp-style]: https://google.github.io/styleguide/cppguide.html | ||||||
| [google-cpp-style-classes]: https://google.github.io/styleguide/cppguide.html#Classes | ||||||
| [google-cpp-style-declaration-order]: https://google.github.io/styleguide/cppguide.html#Declaration_Order | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Necessary in order to get Sphinx to link to the heading correctly.