From Jason Turner

[class.friend]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpgf1yyh62/{from.md → to.md} +19 -18
tmp/tmpgf1yyh62/{from.md → to.md} RENAMED
@@ -70,31 +70,26 @@ class Z {
70
  };
71
  ```
72
 
73
  — *end example*]
74
 
75
- A friend declaration that does not declare a function shall have one of
76
- the following forms:
77
-
78
- ``` bnf
79
- friend elaborated-type-specifier ';'
80
- friend simple-type-specifier ';'
81
- friend typename-specifier ';'
82
- ```
83
 
84
  [*Note 1*: A friend declaration can be the *declaration* in a
85
  *template-declaration* [[temp.pre]], [[temp.friend]]. — *end note*]
86
 
87
- If the type specifier in a `friend` declaration designates a (possibly
88
- cv-qualified) class type, that class is declared as a friend; otherwise,
89
- the friend declaration is ignored.
90
 
91
  [*Example 4*:
92
 
93
  ``` cpp
94
  class C;
95
  typedef C Ct;
 
96
 
97
  class X1 {
98
  friend C; // OK, class C is a friend
99
  };
100
 
@@ -102,24 +97,30 @@ class X2 {
102
  friend Ct; // OK, class C is a friend
103
  friend D; // error: D not found
104
  friend class D; // OK, elaborated-type-specifier declares new class
105
  };
106
 
107
- template <typename T> class R {
108
- friend T;
 
 
 
 
 
109
  };
110
 
111
  R<C> rc; // class C is a friend of R<C>
112
- R<int> Ri; // OK, "friend int;" is ignored
 
 
 
 
 
113
  ```
114
 
115
  — *end example*]
116
 
117
- A function first declared in a friend declaration has the linkage of the
118
- namespace of which it is a member [[basic.link]]. Otherwise, the
119
- function retains its previous linkage [[dcl.stc]].
120
-
121
  [*Note 2*:
122
 
123
  A friend declaration refers to an entity, not (all overloads of) a name.
124
  A member function of a class `X` can be a friend of a class `Y`.
125
 
 
70
  };
71
  ```
72
 
73
  — *end example*]
74
 
75
+ A friend declaration that does not declare a function shall be a
76
+ *friend-type-declaration*.
 
 
 
 
 
 
77
 
78
  [*Note 1*: A friend declaration can be the *declaration* in a
79
  *template-declaration* [[temp.pre]], [[temp.friend]]. — *end note*]
80
 
81
+ If a *friend-type-specifier* in a friend declaration designates a
82
+ (possibly cv-qualified) class type, that class is declared as a friend;
83
+ otherwise, the *friend-type-specifier* is ignored.
84
 
85
  [*Example 4*:
86
 
87
  ``` cpp
88
  class C;
89
  typedef C Ct;
90
+ class E;
91
 
92
  class X1 {
93
  friend C; // OK, class C is a friend
94
  };
95
 
 
97
  friend Ct; // OK, class C is a friend
98
  friend D; // error: D not found
99
  friend class D; // OK, elaborated-type-specifier declares new class
100
  };
101
 
102
+ template <typename ... Ts> class R {
103
+ friend Ts...;
104
+ };
105
+
106
+ template <class... Ts, class... Us>
107
+ class R<R<Ts...>, R<Us...>> {
108
+ friend Ts::Nested..., Us...;
109
  };
110
 
111
  R<C> rc; // class C is a friend of R<C>
112
+ R<C, E> rce; // classes C and E are friends of R<C, E>
113
+ R<int> Ri; // OK, ``friend int;'' is ignored
114
+
115
+ struct E { struct Nested; };
116
+
117
+ R<R<E>, R<C, int>> rr; // E::Nested and C are friends of R<R<E>, R<C, int>>
118
  ```
119
 
120
  — *end example*]
121
 
 
 
 
 
122
  [*Note 2*:
123
 
124
  A friend declaration refers to an entity, not (all overloads of) a name.
125
  A member function of a class `X` can be a friend of a class `Y`.
126