This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-10-26


1918. friend templates with dependent scopes

Section: 13.7.5  [temp.friend]     Status: CD5     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.

Additional note (January, 2024)

The example is ill-formed per the resolution of issue 1862 (adopted in November, 2017).