Skip to content
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

[cwg1699] clang interprets friendship rules lexically; other compilers do not #44053

Open
llvmbot opened this issue Jan 29, 2020 · 4 comments
Open
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 29, 2020

Bugzilla Link 44708
Version 9.0
OS Linux
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@DougGregor,@zygoloid

Extended Description

The following code:

class A {
  friend class B;
  int m;
};

class B {
  friend void f(A* p) { p->m = 32; }
};

compiles in clang version 9.0.0-2. If the function body is defined outside of the class, the compiler correctly issues an error about not being able to access the private member.

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jan 31, 2020

Well, per [class.access.base]p5, "A member m is accessible at the point R when named in class N if [...] m as a member of N is private, and R occurs in a [...] friend of class N"

The reference to p->m occurs in class B, which is a friend of class A, so arguably this is valid.

This question is the subject of CWG issue 1699 (http://wg21.link/cwg1699), and the consensus opinion when that was last discussed seemed to be that Clang's current behavior is correct.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@shafik
Copy link
Collaborator

shafik commented Jun 21, 2023

It looks like this behavior has changed but dr 1699 looks like is still active and appears to be on EWGs plate

CC @erichkeane

@shafik
Copy link
Collaborator

shafik commented Jun 21, 2023

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jun 21, 2023
@llvmbot
Copy link
Collaborator Author

llvmbot commented Jun 21, 2023

@llvm/issue-subscribers-clang-frontend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants