Title
friend templates with dependent scopes
Status
cd5
Section
13.7.5 [temp.friend]
Submitter
Richard Smith

Created on 2014-04-27.00:00:00 last changed 10 months ago

Messages

Date: 2024-01-15.00:00:00

Additional note (January, 2024)

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

Date: 2014-04-27.00:00:00

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.

History
Date User Action Args
2024-01-13 12:51:15adminsetmessages: + msg7568
2024-01-13 12:51:15adminsetstatus: open -> cd5
2014-04-27 00:00:00admincreate