[Bug c++/110037] New: GCC accepts private member access of enclosing through friend function of inner class
jlame646 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue May 30 10:37:10 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110037
Bug ID: 110037
Summary: GCC accepts private member access of enclosing through
friend function of inner class
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jlame646 at gmail dot com
Target Milestone: ---
The following program is accepted by gcc and clang:
https://godbolt.org/z/Gs479M4Tf
```
template <typename T>
class Outer
{
public:
struct Inner {
friend bool operator==(const Inner& a, const Inner& b) {
return a.outer_.private_member_ == b.outer_.private_member_;
}
Inner(Outer<T> & o):outer_{o}
{
}
private:
Outer<T>& outer_;
};
friend struct Iterator;
//friend bool operator==(const Inner& a, const Inner& b);
private:
int private_member_;
};
bool test(Outer<int>::Inner A, Outer<int>::Inner B)
{
return A == B;
}
int main()
{
Outer<int> o;
Outer<int>::Inner i(o);
Outer<int>::Inner j(o);
if(i==j){}
}
```
[class.nest#4] makes this ill-formed.
More information about the Gcc-bugs
mailing list