From Jason Turner

[basic.def.odr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpc0uemptt/{from.md → to.md} +278 -135
tmp/tmpc0uemptt/{from.md → to.md} RENAMED
@@ -1,36 +1,41 @@
1
  ## One-definition rule <a id="basic.def.odr">[[basic.def.odr]]</a>
2
 
3
  No translation unit shall contain more than one definition of any
4
- variable, function, class type, enumeration type, or template.
 
 
5
 
6
- An expression is *potentially evaluated* unless it is an unevaluated
7
- operand (Clause  [[expr]]) or a subexpression thereof. The set of
8
- *potential results* of an expression `e` is defined as follows:
 
 
9
 
10
- - If `e` is an *id-expression* ([[expr.prim.id]]), the set contains
11
- only `e`.
12
- - If `e` is a subscripting operation ([[expr.sub]]) with an array
13
- operand, the set contains the potential results of that operand.
14
- - If `e` is a class member access expression ([[expr.ref]]), the set
15
- contains the potential results of the object expression.
16
- - If `e` is a pointer-to-member expression ([[expr.mptr.oper]]) whose
17
- second operand is a constant expression, the set contains the
18
- potential results of the object expression.
19
- - If `e` has the form `(e1)`, the set contains the potential results of
20
- `e1`.
21
- - If `e` is a glvalue conditional expression ([[expr.cond]]), the set
22
- is the union of the sets of potential results of the second and third
 
23
  operands.
24
- - If `e` is a comma expression ([[expr.comma]]), the set contains the
25
  potential results of the right operand.
26
  - Otherwise, the set is empty.
27
 
28
  [*Note 1*:
29
 
30
  This set is a (possibly-empty) set of *id-expression*s, each of which is
31
- either `e` or a subexpression of `e`.
32
 
33
  [*Example 1*:
34
 
35
  In the following example, the set of potential results of the
36
  initializer of `n` contains the first `S::x` subexpression, but not the
@@ -45,67 +50,145 @@ int n = b ? (1, S::x) // S::x is not odr-used here
45
 
46
  — *end example*]
47
 
48
  — *end note*]
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  A variable `x` whose name appears as a potentially-evaluated expression
51
- `ex` is *odr-used* by `ex` unless applying the lvalue-to-rvalue
52
- conversion ([[conv.lval]]) to `x` yields a constant expression (
53
- [[expr.const]]) that does not invoke any non-trivial functions and, if
54
- `x` is an object, `ex` is an element of the set of potential results of
55
- an expression `e`, where either the lvalue-to-rvalue conversion (
56
- [[conv.lval]]) is applied to `e`, or `e` is a discarded-value
57
- expression (Clause [[expr]]). `this` is odr-used if it appears as a
58
- potentially-evaluated expression (including as the result of the
59
- implicit transformation in the body of a non-static member function (
60
- [[class.mfct.non-static]])). A virtual member function is odr-used if it
61
- is not pure. A function whose name appears as a potentially-evaluated
62
- expression is odr-used if it is the unique lookup result or the selected
63
- member of a set of overloaded functions ([[basic.lookup]],
64
- [[over.match]], [[over.over]]), unless it is a pure virtual function and
65
- either its name is not explicitly qualified or the expression forms a
66
- pointer to member ([[expr.unary.op]]).
67
 
68
- [*Note 2*: This covers calls to named functions ([[expr.call]]),
69
- operator overloading (Clause  [[over]]), user-defined conversions (
70
- [[class.conv.fct]]), allocation functions for placement
71
- *new-expression*s ([[expr.new]]), as well as non-default
72
- initialization ([[dcl.init]]). A constructor selected to copy or move
73
- an object of class type is odr-used even if the call is actually elided
74
- by the implementation ([[class.copy]]). — *end note*]
 
 
 
75
 
76
- An allocation or deallocation function for a class is odr-used by a
77
- *new-expression* appearing in a potentially-evaluated expression as
78
- specified in  [[expr.new]] and  [[class.free]]. A deallocation function
79
- for a class is odr-used by a delete expression appearing in a
80
- potentially-evaluated expression as specified in  [[expr.delete]] and 
81
- [[class.free]]. A non-placement allocation or deallocation function for
82
- a class is odr-used by the definition of a constructor of that class. A
 
 
 
 
83
  non-placement deallocation function for a class is odr-used by the
84
  definition of the destructor of that class, or by being selected by the
85
- lookup at the point of definition of a virtual destructor (
86
- [[class.dtor]]).[^2] An assignment operator function in a class is
87
- odr-used by an implicitly-defined copy-assignment or move-assignment
88
- function for another class as specified in  [[class.copy]]. A
89
- constructor for a class is odr-used as specified in  [[dcl.init]]. A
90
- destructor for a class is odr-used if it is potentially invoked (
91
- [[class.dtor]]).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  Every program shall contain exactly one definition of every non-inline
94
  function or variable that is odr-used in that program outside of a
95
- discarded statement ([[stmt.if]]); no diagnostic required. The
96
- definition can appear explicitly in the program, it can be found in the
97
- standard or a user-defined library, or (when appropriate) it is
98
- implicitly defined (see  [[class.ctor]], [[class.dtor]] and
99
- [[class.copy]]). An inline function or variable shall be defined in
100
- every translation unit in which it is odr-used outside of a discarded
101
- statement.
102
-
103
- Exactly one definition of a class is required in a translation unit if
104
- the class is used in a way that requires the class type to be complete.
105
-
106
- [*Example 2*:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
  The following complete translation unit is well-formed, even though it
109
  never defines `X`:
110
 
111
  ``` cpp
@@ -119,92 +202,97 @@ X* x2; // use X in pointer formation
119
  [*Note 3*:
120
 
121
  The rules for declarations and expressions describe in which contexts
122
  complete class types are required. A class type `T` must be complete if:
123
 
124
- - an object of type `T` is defined ([[basic.def]]), or
125
- - a non-static class data member of type `T` is declared (
126
- [[class.mem]]), or
127
  - `T` is used as the allocated type or array element type in a
128
- *new-expression* ([[expr.new]]), or
129
  - an lvalue-to-rvalue conversion is applied to a glvalue referring to an
130
- object of type `T` ([[conv.lval]]), or
131
  - an expression is converted (either implicitly or explicitly) to type
132
- `T` (Clause  [[conv]], [[expr.type.conv]], [[expr.dynamic.cast]],
133
  [[expr.static.cast]], [[expr.cast]]), or
134
  - an expression that is not a null pointer constant, and has type other
135
  than cv `void*`, is converted to the type pointer to `T` or reference
136
- to `T` using a standard conversion (Clause  [[conv]]), a
137
- `dynamic_cast` ([[expr.dynamic.cast]]) or a `static_cast` (
138
- [[expr.static.cast]]), or
139
- - a class member access operator is applied to an expression of type
140
- `T` ([[expr.ref]]), or
141
- - the `typeid` operator ([[expr.typeid]]) or the `sizeof` operator (
142
- [[expr.sizeof]]) is applied to an operand of type `T`, or
143
- - a function with a return type or argument type of type `T` is
144
- defined ([[basic.def]]) or called ([[expr.call]]), or
145
- - a class with a base class of type `T` is defined (Clause 
146
- [[class.derived]]), or
147
- - an lvalue of type `T` is assigned to ([[expr.ass]]), or
148
- - the type `T` is the subject of an `alignof` expression (
149
- [[expr.alignof]]), or
150
  - an *exception-declaration* has type `T`, reference to `T`, or pointer
151
- to `T` ([[except.handle]]).
152
 
153
  — *end note*]
154
 
155
- There can be more than one definition of a class type (Clause 
156
- [[class]]), enumeration type ([[dcl.enum]]), inline function with
157
- external linkage ([[dcl.inline]]), inline variable with external
158
- linkage ([[dcl.inline]]), class template (Clause  [[temp]]), non-static
159
- function template ([[temp.fct]]), static data member of a class
160
- template ([[temp.static]]), member function of a class template (
161
- [[temp.mem.func]]), or template specialization for which some template
162
- parameters are not specified ([[temp.spec]], [[temp.class.spec]]) in a
163
- program provided that each definition appears in a different translation
164
- unit, and provided the definitions satisfy the following requirements.
165
- Given such an entity named `D` defined in more than one translation
166
- unit, then
167
 
168
- - each definition of `D` shall consist of the same sequence of tokens;
169
- and
170
- - in each definition of `D`, corresponding names, looked up according
171
- to  [[basic.lookup]], shall refer to an entity defined within the
172
- definition of `D`, or shall refer to the same entity, after overload
173
- resolution ([[over.match]]) and after matching of partial template
174
- specialization ([[temp.over]]), except that a name can refer to
175
- - a non-volatile `const` object with internal or no linkage if the
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  object
177
  - has the same literal type in all definitions of `D`,
178
- - is initialized with a constant expression ([[expr.const]]),
179
  - is not odr-used in any definition of `D`, and
180
  - has the same value in all definitions of `D`,
181
 
182
  or
183
  - a reference with internal or no linkage initialized with a constant
184
  expression such that the reference refers to the same entity in all
185
- definitions of `D`;
186
-
187
- and
188
- - in each definition of `D`, corresponding entities shall have the same
189
- language linkage; and
190
- - in each definition of `D`, the overloaded operators referred to, the
 
191
  implicit calls to conversion functions, constructors, operator new
192
  functions and operator delete functions, shall refer to the same
193
- function, or to a function defined within the definition of `D`; and
194
- - in each definition of `D`, a default argument used by an (implicit or
195
- explicit) function call is treated as if its token sequence were
196
- present in the definition of `D`; that is, the default argument is
197
- subject to the requirements described in this paragraph (and, if the
198
- default argument has subexpressions with default arguments, this
199
- requirement applies recursively).[^3]
200
- - if `D` is a class with an implicitly-declared constructor (
201
- [[class.ctor]]), it is as if the constructor was implicitly defined in
202
- every translation unit where it is odr-used, and the implicit
203
- definition in every translation unit shall call the same constructor
204
- for a subobject of `D`.
205
- \[*Example 3*:
206
  ``` cpp
207
  // translation unit 1:
208
  struct X {
209
  X(int, int);
210
  X(int, int, int);
@@ -227,15 +315,70 @@ unit, then
227
  D d2; // X(int, int, int) called by D();
228
  // D()'s implicit definition violates the ODR
229
  ```
230
 
231
  — *end example*]
 
 
 
 
 
232
 
233
  If `D` is a template and is defined in more than one translation unit,
234
  then the preceding requirements shall apply both to names from the
235
- template’s enclosing scope used in the template definition (
236
- [[temp.nondep]]), and also to dependent names at the point of
237
- instantiation ([[temp.dep]]). If the definitions of `D` satisfy all
238
- these requirements, then the behavior is as if there were a single
239
- definition of `D`. If the definitions of `D` do not satisfy these
240
- requirements, then the behavior is undefined.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
 
1
  ## One-definition rule <a id="basic.def.odr">[[basic.def.odr]]</a>
2
 
3
  No translation unit shall contain more than one definition of any
4
+ variable, function, class type, enumeration type, template, default
5
+ argument for a parameter (for a function in a given scope), or default
6
+ template argument.
7
 
8
+ An expression or conversion is *potentially evaluated* unless it is an
9
+ unevaluated operand [[expr.prop]], a subexpression thereof, or a
10
+ conversion in an initialization or conversion sequence in such a
11
+ context. The set of *potential results* of an expression E is defined as
12
+ follows:
13
 
14
+ - If E is an *id-expression* [[expr.prim.id]], the set contains only E.
15
+ - If E is a subscripting operation [[expr.sub]] with an array operand,
16
+ the set contains the potential results of that operand.
17
+ - If E is a class member access expression [[expr.ref]] of the form E₁
18
+ `.` `template`ₒₚₜ E₂ naming a non-static data member, the set
19
+ contains the potential results of E₁.
20
+ - If E is a class member access expression naming a static data member,
21
+ the set contains the *id-expression* designating the data member.
22
+ - If E is a pointer-to-member expression [[expr.mptr.oper]] of the form
23
+ E₁ `.*` E₂, the set contains the potential results of E₁.
24
+ - If E has the form `(E₁)`, the set contains the potential results of
25
+ E₁.
26
+ - If E is a glvalue conditional expression [[expr.cond]], the set is the
27
+ union of the sets of potential results of the second and third
28
  operands.
29
+ - If E is a comma expression [[expr.comma]], the set contains the
30
  potential results of the right operand.
31
  - Otherwise, the set is empty.
32
 
33
  [*Note 1*:
34
 
35
  This set is a (possibly-empty) set of *id-expression*s, each of which is
36
+ either E or a subexpression of E.
37
 
38
  [*Example 1*:
39
 
40
  In the following example, the set of potential results of the
41
  initializer of `n` contains the first `S::x` subexpression, but not the
 
50
 
51
  — *end example*]
52
 
53
  — *end note*]
54
 
55
+ A function is *named by* an expression or conversion as follows:
56
+
57
+ - A function is named by an expression or conversion if it is the
58
+ selected member of an overload set ([[basic.lookup]], [[over.match]],
59
+ [[over.over]]) in an overload resolution performed as part of forming
60
+ that expression or conversion, unless it is a pure virtual function
61
+ and either the expression is not an *id-expression* naming the
62
+ function with an explicitly qualified name or the expression forms a
63
+ pointer to member [[expr.unary.op]]. \[*Note 2*: This covers taking
64
+ the address of functions ([[conv.func]], [[expr.unary.op]]), calls to
65
+ named functions [[expr.call]], operator overloading [[over]],
66
+ user-defined conversions [[class.conv.fct]], allocation functions for
67
+ *new-expression*s [[expr.new]], as well as non-default initialization
68
+ [[dcl.init]]. A constructor selected to copy or move an object of
69
+ class type is considered to be named by an expression or conversion
70
+ even if the call is actually elided by the implementation
71
+ [[class.copy.elision]]. — *end note*]
72
+ - A deallocation function for a class is named by a *new-expression* if
73
+ it is the single matching deallocation function for the allocation
74
+ function selected by overload resolution, as specified in 
75
+ [[expr.new]].
76
+ - A deallocation function for a class is named by a *delete-expression*
77
+ if it is the selected usual deallocation function as specified in 
78
+ [[expr.delete]] and  [[class.free]].
79
+
80
  A variable `x` whose name appears as a potentially-evaluated expression
81
+ E is *odr-used* by E unless
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
+ - `x` is a reference that is usable in constant expressions
84
+ [[expr.const]], or
85
+ - `x` is a variable of non-reference type that is usable in constant
86
+ expressions and has no mutable subobjects, and E is an element of the
87
+ set of potential results of an expression of non-volatile-qualified
88
+ non-class type to which the lvalue-to-rvalue conversion [[conv.lval]]
89
+ is applied, or
90
+ - `x` is a variable of non-reference type, and E is an element of the
91
+ set of potential results of a discarded-value expression [[expr.prop]]
92
+ to which the lvalue-to-rvalue conversion is not applied.
93
 
94
+ A structured binding is odr-used if it appears as a
95
+ potentially-evaluated expression.
96
+
97
+ `*this` is odr-used if `this` appears as a potentially-evaluated
98
+ expression (including as the result of the implicit transformation in
99
+ the body of a non-static member function ([[class.mfct.non-static]])).
100
+
101
+ A virtual member function is odr-used if it is not pure. A function is
102
+ odr-used if it is named by a potentially-evaluated expression or
103
+ conversion. A non-placement allocation or deallocation function for a
104
+ class is odr-used by the definition of a constructor of that class. A
105
  non-placement deallocation function for a class is odr-used by the
106
  definition of the destructor of that class, or by being selected by the
107
+ lookup at the point of definition of a virtual destructor
108
+ [[class.dtor]].[^2]
109
+
110
+ An assignment operator function in a class is odr-used by an
111
+ implicitly-defined copy-assignment or move-assignment function for
112
+ another class as specified in  [[class.copy.assign]]. A constructor for
113
+ a class is odr-used as specified in  [[dcl.init]]. A destructor for a
114
+ class is odr-used if it is potentially invoked [[class.dtor]].
115
+
116
+ A local entity [[basic.pre]] is *odr-usable* in a declarative region
117
+ [[basic.scope.declarative]] if:
118
+
119
+ - either the local entity is not `*this`, or an enclosing class or
120
+ non-lambda function parameter scope exists and, if the innermost such
121
+ scope is a function parameter scope, it corresponds to a non-static
122
+ member function, and
123
+ - for each intervening declarative region [[basic.scope.declarative]]
124
+ between the point at which the entity is introduced and the region
125
+ (where `*this` is considered to be introduced within the innermost
126
+ enclosing class or non-lambda function definition scope), either:
127
+ - the intervening declarative region is a block scope, or
128
+ - the intervening declarative region is the function parameter scope
129
+ of a *lambda-expression* that has a *simple-capture* naming the
130
+ entity or has a *capture-default*, and the block scope of the
131
+ *lambda-expression* is also an intervening declarative region.
132
+
133
+ If a local entity is odr-used in a declarative region in which it is not
134
+ odr-usable, the program is ill-formed.
135
+
136
+ [*Example 2*:
137
+
138
+ ``` cpp
139
+ void f(int n) {
140
+ [] { n = 1; }; // error: n is not odr-usable due to intervening lambda-expression
141
+ struct A {
142
+ void f() { n = 2; } // error: n is not odr-usable due to intervening function definition scope
143
+ };
144
+ void g(int = n); // error: n is not odr-usable due to intervening function parameter scope
145
+ [=](int k = n) {}; // error: n is not odr-usable due to being
146
+ // outside the block scope of the lambda-expression
147
+ [&] { [n]{ return n; }; }; // OK
148
+ }
149
+ ```
150
+
151
+ — *end example*]
152
 
153
  Every program shall contain exactly one definition of every non-inline
154
  function or variable that is odr-used in that program outside of a
155
+ discarded statement [[stmt.if]]; no diagnostic required. The definition
156
+ can appear explicitly in the program, it can be found in the standard or
157
+ a user-defined library, or (when appropriate) it is implicitly defined
158
+ (see  [[class.default.ctor]], [[class.copy.ctor]], [[class.dtor]], and
159
+ [[class.copy.assign]]).
160
+
161
+ [*Example 3*:
162
+
163
+ ``` cpp
164
+ auto f() {
165
+ struct A {};
166
+ return A{};
167
+ }
168
+ decltype(f()) g();
169
+ auto x = g();
170
+ ```
171
+
172
+ A program containing this translation unit is ill-formed because `g` is
173
+ odr-used but not defined, and cannot be defined in any other translation
174
+ unit because the local class `A` cannot be named outside this
175
+ translation unit.
176
+
177
+ — *end example*]
178
+
179
+ A *definition domain* is a *private-module-fragment* or the portion of a
180
+ translation unit excluding its *private-module-fragment* (if any). A
181
+ definition of an inline function or variable shall be reachable from the
182
+ end of every definition domain in which it is odr-used outside of a
183
+ discarded statement.
184
+
185
+ A definition of a class is required to be reachable in every context in
186
+ which the class is used in a way that requires the class type to be
187
+ complete.
188
+
189
+ [*Example 4*:
190
 
191
  The following complete translation unit is well-formed, even though it
192
  never defines `X`:
193
 
194
  ``` cpp
 
202
  [*Note 3*:
203
 
204
  The rules for declarations and expressions describe in which contexts
205
  complete class types are required. A class type `T` must be complete if:
206
 
207
+ - an object of type `T` is defined [[basic.def]], or
208
+ - a non-static class data member of type `T` is declared [[class.mem]],
209
+ or
210
  - `T` is used as the allocated type or array element type in a
211
+ *new-expression* [[expr.new]], or
212
  - an lvalue-to-rvalue conversion is applied to a glvalue referring to an
213
+ object of type `T` [[conv.lval]], or
214
  - an expression is converted (either implicitly or explicitly) to type
215
+ `T` ([[conv]], [[expr.type.conv]], [[expr.dynamic.cast]],
216
  [[expr.static.cast]], [[expr.cast]]), or
217
  - an expression that is not a null pointer constant, and has type other
218
  than cv `void*`, is converted to the type pointer to `T` or reference
219
+ to `T` using a standard conversion [[conv]], a `dynamic_cast`
220
+ [[expr.dynamic.cast]] or a `static_cast` [[expr.static.cast]], or
221
+ - a class member access operator is applied to an expression of type `T`
222
+ [[expr.ref]], or
223
+ - the `typeid` operator [[expr.typeid]] or the `sizeof` operator
224
+ [[expr.sizeof]] is applied to an operand of type `T`, or
225
+ - a function with a return type or argument type of type `T` is defined
226
+ [[basic.def]] or called [[expr.call]], or
227
+ - a class with a base class of type `T` is defined [[class.derived]], or
228
+ - an lvalue of type `T` is assigned to [[expr.ass]], or
229
+ - the type `T` is the subject of an `alignof` expression
230
+ [[expr.alignof]], or
 
 
231
  - an *exception-declaration* has type `T`, reference to `T`, or pointer
232
+ to `T` [[except.handle]].
233
 
234
  — *end note*]
235
 
236
+ There can be more than one definition of a
 
 
 
 
 
 
 
 
 
 
 
237
 
238
+ - class type [[class]],
239
+ - enumeration type [[dcl.enum]],
240
+ - inline function or variable [[dcl.inline]],
241
+ - templated entity [[temp.pre]],
242
+ - default argument for a parameter (for a function in a given scope)
243
+ [[dcl.fct.default]], or
244
+ - default template argument [[temp.param]]
245
+
246
+ in a program provided that each definition appears in a different
247
+ translation unit and the definitions satisfy the following requirements.
248
+ Given such an entity `D` defined in more than one translation unit, for
249
+ all definitions of `D`, or, if `D` is an unnamed enumeration, for all
250
+ definitions of `D` that are reachable at any given program point, the
251
+ following requirements shall be satisfied.
252
+
253
+ - Each such definition shall not be attached to a named module
254
+ [[module.unit]].
255
+ - Each such definition shall consist of the same sequence of tokens,
256
+ where the definition of a closure type is considered to consist of the
257
+ sequence of tokens of the corresponding *lambda-expression*.
258
+ - In each such definition, corresponding names, looked up according to 
259
+ [[basic.lookup]], shall refer to the same entity, after overload
260
+ resolution [[over.match]] and after matching of partial template
261
+ specialization [[temp.over]], except that a name can refer to
262
+ - a non-volatile const object with internal or no linkage if the
263
  object
264
  - has the same literal type in all definitions of `D`,
265
+ - is initialized with a constant expression [[expr.const]],
266
  - is not odr-used in any definition of `D`, and
267
  - has the same value in all definitions of `D`,
268
 
269
  or
270
  - a reference with internal or no linkage initialized with a constant
271
  expression such that the reference refers to the same entity in all
272
+ definitions of `D`.
273
+ - In each such definition, except within the default arguments and
274
+ default template arguments of `D`, corresponding *lambda-expression*s
275
+ shall have the same closure type (see below).
276
+ - In each such definition, corresponding entities shall have the same
277
+ language linkage.
278
+ - In each such definition, the overloaded operators referred to, the
279
  implicit calls to conversion functions, constructors, operator new
280
  functions and operator delete functions, shall refer to the same
281
+ function.
282
+ - In each such definition, a default argument used by an (implicit or
283
+ explicit) function call or a default template argument used by an
284
+ (implicit or explicit) *template-id* or *simple-template-id* is
285
+ treated as if its token sequence were present in the definition of
286
+ `D`; that is, the default argument or default template argument is
287
+ subject to the requirements described in this paragraph (recursively).
288
+ - If `D` is a class with an implicitly-declared constructor (
289
+ [[class.default.ctor]], [[class.copy.ctor]]), it is as if the
290
+ constructor was implicitly defined in every translation unit where it
291
+ is odr-used, and the implicit definition in every translation unit
292
+ shall call the same constructor for a subobject of `D`.
293
+ \[*Example 5*:
294
  ``` cpp
295
  // translation unit 1:
296
  struct X {
297
  X(int, int);
298
  X(int, int, int);
 
315
  D d2; // X(int, int, int) called by D();
316
  // D()'s implicit definition violates the ODR
317
  ```
318
 
319
  — *end example*]
320
+ - If `D` is a class with a defaulted three-way comparison operator
321
+ function [[class.spaceship]], it is as if the operator was implicitly
322
+ defined in every translation unit where it is odr-used, and the
323
+ implicit definition in every translation unit shall call the same
324
+ comparison operators for each subobject of `D`.
325
 
326
  If `D` is a template and is defined in more than one translation unit,
327
  then the preceding requirements shall apply both to names from the
328
+ template’s enclosing scope used in the template definition
329
+ [[temp.nondep]], and also to dependent names at the point of
330
+ instantiation [[temp.dep]]. These requirements also apply to
331
+ corresponding entities defined within each definition of `D` (including
332
+ the closure types of *lambda-expression*s, but excluding entities
333
+ defined within default arguments or default template arguments of either
334
+ `D` or an entity not defined within `D`). For each such entity and for
335
+ `D` itself, the behavior is as if there is a single entity with a single
336
+ definition, including in the application of these requirements to other
337
+ entities.
338
+
339
+ [*Note 4*: The entity is still declared in multiple translation units,
340
+ and [[basic.link]] still applies to these declarations. In particular,
341
+ *lambda-expression*s [[expr.prim.lambda]] appearing in the type of `D`
342
+ may result in the different declarations having distinct types, and
343
+ *lambda-expression*s appearing in a default argument of `D` may still
344
+ denote different types in different translation units. — *end note*]
345
+
346
+ If these definitions do not satisfy these requirements, then the program
347
+ is ill-formed; a diagnostic is required only if the entity is attached
348
+ to a named module and a prior definition is reachable at the point where
349
+ a later definition occurs.
350
+
351
+ [*Example 6*:
352
+
353
+ ``` cpp
354
+ inline void f(bool cond, void (*p)()) {
355
+ if (cond) f(false, []{});
356
+ }
357
+ inline void g(bool cond, void (*p)() = []{}) {
358
+ if (cond) g(false);
359
+ }
360
+ struct X {
361
+ void h(bool cond, void (*p)() = []{}) {
362
+ if (cond) h(false);
363
+ }
364
+ };
365
+ ```
366
+
367
+ If the definition of `f` appears in multiple translation units, the
368
+ behavior of the program is as if there is only one definition of `f`. If
369
+ the definition of `g` appears in multiple translation units, the program
370
+ is ill-formed (no diagnostic required) because each such definition uses
371
+ a default argument that refers to a distinct *lambda-expression* closure
372
+ type. The definition of `X` can appear in multiple translation units of
373
+ a valid program; the *lambda-expression*s defined within the default
374
+ argument of `X::h` within the definition of `X` denote the same closure
375
+ type in each translation unit.
376
+
377
+ — *end example*]
378
+
379
+ If, at any point in the program, there is more than one reachable
380
+ unnamed enumeration definition in the same scope that have the same
381
+ first enumerator name and do not have typedef names for linkage purposes
382
+ [[dcl.enum]], those unnamed enumeration types shall be the same; no
383
+ diagnostic required.
384