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


1545. friend function templates defined in class templates

Section: 13.7.5  [temp.friend]     Status: NAD     Submitter: Daniel Krügler     Date: 2012-08-25

The status of an example like the following is not clear:

   template<class> struct x {
     template<class T>
     friend bool operator==(x<T>, x<T>) { return false; }

  int main() {
    x<int> x1;
    x<double> x2;
    x1 == x1;
    x2 == x2;

Such a friend definition is permitted by 13.7.5 [temp.friend] paragraph 2:

A friend function template may be defined within a class or class template...

Paragraph 4 appears to be related, but deals only with friend functions, not friend function templates:

When a function is defined in a friend function declaration in a class template, the function is instantiated when the function is odr-used. The same restrictions on multiple declarations and definitions that apply to non-template function declarations and definitions also apply to these implicit definitions.

Rationale (February, 2021):

The resolution of issue 2174 deleted the paragraph in question and makes clear the treatment of friend function templates.