llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Friend's templated environment is incorrectly friended

Open llvmbot opened this issue 14 years ago • 4 comments

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

llvmbot avatar Sep 25 '12 11:09 llvmbot

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 class A::B; // FIXME: we don't support these right now

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.

dwblaikie avatar Nov 06 '12 23:11 dwblaikie

At least we're issuing an on-by-default diagnostic about this since Clang 3.4: https://godbolt.org/z/jPeG6z41v

Endilll avatar May 21 '23 07:05 Endilll

@llvm/issue-subscribers-clang-frontend

llvmbot avatar May 21 '23 07:05 llvmbot

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 to C::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.

hongtaihu avatar Nov 15 '26 08:11 hongtaihu