From Jason Turner

[class.friend]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpkxdueucd/{from.md → to.md} +27 -27
tmp/tmpkxdueucd/{from.md → to.md} RENAMED
@@ -1,6 +1,6 @@
1
- ## Friends <a id="class.friend">[[class.friend]]</a>
2
 
3
  A friend of a class is a function or class that is given permission to
4
  use the private and protected member names from the class. A class
5
  specifies its friends, if any, by way of friend declarations. Such
6
  declarations give special access rights to the friends, but they do not
@@ -82,26 +82,25 @@ class A {
82
  };
83
  ```
84
 
85
  — *end example*]
86
 
87
- A `friend` declaration that does not declare a function shall have one
88
- of the following forms:
89
 
90
  ``` bnf
91
- 'friend' elaborated-type-specifier ';'
92
- 'friend' simple-type-specifier ';'
93
- 'friend' typename-specifier ';'
94
  ```
95
 
96
- [*Note 1*: A `friend` declaration may be the *declaration* in a
97
- *template-declaration* (Clause  [[temp]],
98
- [[temp.friend]]). — *end note*]
99
 
100
  If the type specifier in a `friend` declaration designates a (possibly
101
  cv-qualified) class type, that class is declared as a friend; otherwise,
102
- the `friend` declaration is ignored.
103
 
104
  [*Example 5*:
105
 
106
  ``` cpp
107
  class C;
@@ -126,16 +125,17 @@ R<int> Ri; // OK: "friend int;" is ignored
126
  ```
127
 
128
  — *end example*]
129
 
130
  A function first declared in a friend declaration has the linkage of the
131
- namespace of which it is a member ([[basic.link]]). Otherwise, the
132
- function retains its previous linkage ([[dcl.stc]]).
 
133
 
134
- When a `friend` declaration refers to an overloaded name or operator,
135
- only the function specified by the parameter types becomes a friend. A
136
- member function of a class `X` can be a friend of a class `Y`.
137
 
138
  [*Example 6*:
139
 
140
  ``` cpp
141
  class Y {
@@ -146,12 +146,12 @@ class Y {
146
  ```
147
 
148
  — *end example*]
149
 
150
  A function can be defined in a friend declaration of a class if and only
151
- if the class is a non-local class ([[class.local]]), the function name
152
- is unqualified, and the function has namespace scope.
153
 
154
  [*Example 7*:
155
 
156
  ``` cpp
157
  class M {
@@ -160,23 +160,23 @@ class M {
160
  };
161
  ```
162
 
163
  — *end example*]
164
 
165
- Such a function is implicitly an inline function ([[dcl.inline]]). A
166
- `friend` function defined in a class is in the (lexical) scope of the
167
- class in which it is defined. A friend function defined outside the
168
- class is not ([[basic.lookup.unqual]]).
169
 
170
  No *storage-class-specifier* shall appear in the *decl-specifier-seq* of
171
  a friend declaration.
172
 
173
  A name nominated by a friend declaration shall be accessible in the
174
  scope of the class containing the friend declaration. The meaning of the
175
  friend declaration is the same whether the friend declaration appears in
176
- the `private`, `protected` or `public` ([[class.mem]]) portion of the
177
- class *member-specification*.
178
 
179
  Friendship is neither inherited nor transitive.
180
 
181
  [*Example 8*:
182
 
@@ -203,13 +203,13 @@ class D : public B {
203
  };
204
  ```
205
 
206
  — *end example*]
207
 
208
- If a friend declaration appears in a local class ([[class.local]]) and
209
- the name specified is an unqualified name, a prior declaration is looked
210
- up without considering scopes that are outside the innermost enclosing
211
  non-class scope. For a friend function declaration, if there is no prior
212
  declaration, the program is ill-formed. For a friend class declaration,
213
  if there is no prior declaration, the class that is specified belongs to
214
  the innermost enclosing non-class scope, but if it is subsequently
215
  referenced, its name is not found by name lookup until a matching
@@ -230,11 +230,11 @@ void f() {
230
  friend void a(); // error, ::a is not considered
231
  friend void b(); // OK
232
  friend void c(); // error
233
  };
234
  X* px; // OK, but ::X is found
235
- Z* pz; // error, no Z is found
236
  }
237
  ```
238
 
239
  — *end example*]
240
 
 
1
+ ### Friends <a id="class.friend">[[class.friend]]</a>
2
 
3
  A friend of a class is a function or class that is given permission to
4
  use the private and protected member names from the class. A class
5
  specifies its friends, if any, by way of friend declarations. Such
6
  declarations give special access rights to the friends, but they do not
 
82
  };
83
  ```
84
 
85
  — *end example*]
86
 
87
+ A friend declaration that does not declare a function shall have one of
88
+ the following forms:
89
 
90
  ``` bnf
91
+ friend elaborated-type-specifier ';'
92
+ friend simple-type-specifier ';'
93
+ friend typename-specifier ';'
94
  ```
95
 
96
+ [*Note 1*: A friend declaration may be the *declaration* in a
97
+ *template-declaration* ([[temp.pre]], [[temp.friend]]). — *end note*]
 
98
 
99
  If the type specifier in a `friend` declaration designates a (possibly
100
  cv-qualified) class type, that class is declared as a friend; otherwise,
101
+ the friend declaration is ignored.
102
 
103
  [*Example 5*:
104
 
105
  ``` cpp
106
  class C;
 
125
  ```
126
 
127
  — *end example*]
128
 
129
  A function first declared in a friend declaration has the linkage of the
130
+ namespace of which it is a member ([[basic.link]],
131
+ [[namespace.memdef]]). Otherwise, the function retains its previous
132
+ linkage [[dcl.stc]].
133
 
134
+ When a friend declaration refers to an overloaded name or operator, only
135
+ the function specified by the parameter types becomes a friend. A member
136
+ function of a class `X` can be a friend of a class `Y`.
137
 
138
  [*Example 6*:
139
 
140
  ``` cpp
141
  class Y {
 
146
  ```
147
 
148
  — *end example*]
149
 
150
  A function can be defined in a friend declaration of a class if and only
151
+ if the class is a non-local class [[class.local]], the function name is
152
+ unqualified, and the function has namespace scope.
153
 
154
  [*Example 7*:
155
 
156
  ``` cpp
157
  class M {
 
160
  };
161
  ```
162
 
163
  — *end example*]
164
 
165
+ Such a function is implicitly an inline [[dcl.inline]] function if it is
166
+ attached to the global module. A friend function defined in a class is
167
+ in the (lexical) scope of the class in which it is defined. A friend
168
+ function defined outside the class is not [[basic.lookup.unqual]].
169
 
170
  No *storage-class-specifier* shall appear in the *decl-specifier-seq* of
171
  a friend declaration.
172
 
173
  A name nominated by a friend declaration shall be accessible in the
174
  scope of the class containing the friend declaration. The meaning of the
175
  friend declaration is the same whether the friend declaration appears in
176
+ the private, protected, or public [[class.mem]] portion of the class
177
+ *member-specification*.
178
 
179
  Friendship is neither inherited nor transitive.
180
 
181
  [*Example 8*:
182
 
 
203
  };
204
  ```
205
 
206
  — *end example*]
207
 
208
+ If a friend declaration appears in a local class [[class.local]] and the
209
+ name specified is an unqualified name, a prior declaration is looked up
210
+ without considering scopes that are outside the innermost enclosing
211
  non-class scope. For a friend function declaration, if there is no prior
212
  declaration, the program is ill-formed. For a friend class declaration,
213
  if there is no prior declaration, the class that is specified belongs to
214
  the innermost enclosing non-class scope, but if it is subsequently
215
  referenced, its name is not found by name lookup until a matching
 
230
  friend void a(); // error, ::a is not considered
231
  friend void b(); // OK
232
  friend void c(); // error
233
  };
234
  X* px; // OK, but ::X is found
235
+ Z* pz; // error: no Z is found
236
  }
237
  ```
238
 
239
  — *end example*]
240