Repository navigation
C-12: a class may befriend its own CRTP base - #99
Merged
Merged
Conversation
A CRTP base calls hooks of its derived class, which the class keeps private with `friend Base;` so that no one else calls them. Without it the hooks had to be public, which C-12 means to prevent. The friend of a direct base whose class template takes the class itself as an argument passes house-no-friend now: written as the base, through an alias or with the injected name. A base of another class, or a class that is no base, is still reported. The derived side of v0.11.0's `friend Self;`.
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A class that derives from a CRTP base may now befriend that base. The base calls hooks of the class, and the friend keeps them private to everyone else, a sketch or a test included. Until now the no-friend check reported it, and the hooks had to be public to pass, which is what C-12 means to prevent. It is the other side of the exception v0.11.0 made for a CRTP base that befriends its derived class.
Only the class's own CRTP base passes: a direct base whose template takes the class itself as an argument. It may be written out, through an alias, or with the class's injected name. A base of another class, a class that is no base, and a base that is no CRTP base are still reported. C-12 names the third exception, and the changelog says what a project can drop on the update.
Why now: AtmegaTimer's timer modes befriend their core so, and keep the check off for it (AtmegaTimer A-13).
How it was checked:
tests/tidy_module.pypasses, with new cases for each form that passes and each that is still reported. AtmegaTimer'smake tidypasses with the changed check andhouse-no-friendturned on.