-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Clang incorrectly treats hidden friend
function definitions as a member of the class for purposes of member access
#57723
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
Comments
@llvm/issue-subscribers-clang-frontend |
It looks like the difference is in CheckAccess(*this, R.getNameLoc(), Entity); The call to |
I think last time we looked into this, it was very unclear which compiler was correct. Friendship normally means anything lexically within the befriended entity is granted access; excluding nested friends from that would be odd. |
I was basing this on [class.friend]p10 which says:
but I am not confident of this take. Is there a defect report? I could not find an obvious one that related to this. Otherwise if you think it is worth it I can ask core about this and see what they say. |
@zygoloid I believe that [class.friend]p2 should tell us the correct interpretation:
That paragraph does not include friend declarations (a friend declaration is neither a base-specifier nor a member declaration). |
I believe this ends up being DR 1699 which is now with EWG: cplusplus/papers#1573 Also see #44053 |
Hey all! Not sure if the title is correct/useful, but basically, given:
struct kitty
struct puppy
, with afriend kitty
declaration, and a private data memberx
int get_x(puppy p)
, which is a hidden friend ofkitty
get_x
is allowed to accesspuppy::x
, despite it not being a friend ofpuppy
. Note that ifget_x
is defined out-of-line fromkitty
, it is not able to accesspuppy::x
, and that MSVC and GCC correctly implement this.Examples
The bug
godbolt link
Out-of-line definition of the
friend
functiongodbolt link
The text was updated successfully, but these errors were encountered: