Title
friend function templates defined in class templates
Status
nad
Section
13.7.5 [temp.friend]
Submitter
Daniel Krügler

Created on 2012-08-25.00:00:00 last changed 46 months ago

Messages

Date: 2021-02-15.00:00:00

Rationale (February, 2021):

The resolution of issue 2174 deleted the paragraph in question and makes clear the treatment of friend function templates.
Date: 2022-11-20.07:54:16

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.
History
Date User Action Args
2021-02-17 00:00:00adminsetmessages: + msg6511
2021-02-17 00:00:00adminsetstatus: drafting -> nad
2012-11-03 00:00:00adminsetstatus: open -> drafting
2012-08-25 00:00:00admincreate