-
Notifications
You must be signed in to change notification settings - Fork 22
BaseMembersFinalizer considers the relationship between inherited members and shadowing #1026
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
base: develop
Are you sure you want to change the base?
Conversation
An automated preview of the documentation is available at https://1026.mrdocs.prtest2.cppalliance.org/index.html |
1 similar comment
An automated preview of the documentation is available at https://1026.mrdocs.prtest2.cppalliance.org/index.html |
Note: |
An automated preview of the documentation is available at https://1026.mrdocs.prtest2.cppalliance.org/index.html |
RecordInterface const& base, | ||
AccessKind const A) | ||
{ | ||
auto&& members = allMembers(derived); |
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.
Isn't members
a value type with const-reference semantics? Is this a reference to a temporary we're relying on the compiler to keep alive?
If so, wouldn't
auto members = allMembers(derived);
mean the same thing here since this is just a view?
// Private members of the base are never accessible unless friended. | ||
inheritBaseMembers(derivedId, derived.Public, base.Public); | ||
inheritBaseMembers(derivedId, derived.Protected, base.Protected); | ||
inheritBaseMembers(derivedId, derived.Public, base.Public, members); |
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.
Is this safe? members
is a const-view of the derived members, but the function is changing the set of members. It's OK to ask for all members there again, but this is supposed to be a lazy operation (unless there's some bug somewhere else).
} | ||
|
||
// Check if derived class has a member that shadows the base member | ||
auto shadowIt = std::ranges::find_if( |
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.
Oh... Here's the relevant point. Yes. We can just call "allMembers" here to get all members of derived. This should be a lazy operation so there's no extra non-constant cost in just calling it again.
The only unnecessary extra-cost we have here is the cost of iterating all kinds of members while we want the functions in different access modes. We can fix that by just creating a lazy range that only contains the functions, or by iterating the functions for each access mode.
This is great. I just checked how the example in #1025 behaves: https://godbolt.org/z/PbfEsTq5b
Something to think about is the use of the term' shadowing.' I don't know if there's a good solution to that, but there's another issue: the relationship between these inherited members and using decl shadows. We've been using the same term for two different things. When we work on this other issue, we would be doing it in the code and it could be confusing. You probably already did this, but please also check if there's any interaction between this solution and the option regarding how these members should be inherited ( |
Oh... That's very interesting. So we want the information about inheritance to be correct regardless of what the user chose for There's a solution to that. In this case, we can extract these private entities either way. We currently use |
fixes #1025