Skip to content

C-12: a class may befriend its own CRTP base - #99

Merged
theAndreas merged 2 commits into
mainfrom
crtp-friend-base
Nov 16, 2026
Merged

theAndreas merged 2 commits into
mainfrom
crtp-friend-base

Conversation

@theAndreas

Copy link
Copy Markdown
Owner

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.py passes, with new cases for each form that passes and each that is still reported. AtmegaTimer's make tidy passes with the changed check and house-no-friend turned on.

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;`.
@theAndreas
theAndreas merged commit e10c164 into main Nov 16, 2026
1 check passed
@theAndreas
theAndreas deleted the crtp-friend-base branch November 16, 2026 08:00
@theAndreas theAndreas mentioned this pull request Nov 16, 2026
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.

2 participants