Friend's templated environment is incorrectly friended
| Bugzilla Link | 13915 |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @dwblaikie,@DougGregor |
Extended Description
$ cat t.cpp
template <class T >
struct A {
struct B { };
static void f () {
T::g ();
}
};
class C {
template <class T> friend struct A<T>::B;
static void g () { }
};
void h () {
A<C>::f ();
}
$ clang++ -c t.cpp
This is mentioned/due to the limited support in SemaDeclCXX.cpp:10103-10119:
// Handle the case of a templated-scope friend class. e.g.
// template
I don't know the details any further than that, but at least it'll give me/someone else a better starting point/context when they go to look at this.
At least we're issuing an on-by-default diagnostic about this since Clang 3.4: https://godbolt.org/z/jPeG6z41v
@llvm/issue-subscribers-clang-frontend
Bisected: the reported behavior no longer reproduces starting with #216555 (https://github.com/llvm/llvm-project/commit/2e78e25f3e5db4b634dd1daf95fea14b1db52c3a).
Godbolt: https://godbolt.org/z/Kzed7nKn9
- Clang 23.1.0 (assertions): Accepts
A<C>::f()and emits a call toC::g() - Clang (assertions trunk): Rejects
T::g()as private
This is only an observed change in behavior. I have not checked whether #216555 addresses the cause of this report or only stops it from reproducing; whether that resolves the issue is up to the maintainers.
Prepared with assistance from Codex.