This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


1918. friend templates with dependent scopes

Section: 13.7.5  [temp.friend]     Status: open     Submitter: Richard Smith     Date: 2014-04-27

It is not clear what should happen for an example like:

  template<typename T> struct A {
    class B {
      class C {};
  class X {
    static int x;
    template <typename T> friend class A<T>::B::C;
  template<> struct A<int> {
    typedef struct Q B;
  struct Q {
    class C {
      int f() { return X::x; }

It appears that the friend template matches Q::C, because that class is also A<int>::B::C, but neither GCC nor EDG allow this code (saying X::x is inaccessible). (Clang doesn't support friend template declarations with a dependent scope.)

A strict reading of 13.7.5 [temp.friend] paragraph 5 might suggest that the friend declaration itself is ill-formed, because it does not declare a member of a class template, but I can't find any compiler that implements template friends that way.