- 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,
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
An expression is *potentially evaluated* unless it is an
|
| 7 |
-
operand
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
- If
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
contains the potential results of
|
| 16 |
-
- If
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
operands.
|
| 24 |
-
- If
|
| 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
|
| 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 |
-
|
| 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 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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]]
|
| 87 |
-
|
| 88 |
-
function
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
[[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
[[class.copy]]).
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 125 |
-
- a non-static class data member of type `T` is declared
|
| 126 |
-
|
| 127 |
- `T` is used as the allocated type or array element type in a
|
| 128 |
-
*new-expression*
|
| 129 |
- an lvalue-to-rvalue conversion is applied to a glvalue referring to an
|
| 130 |
-
object of type `T`
|
| 131 |
- an expression is converted (either implicitly or explicitly) to type
|
| 132 |
-
`T` (
|
| 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
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
-
|
| 146 |
-
|
| 147 |
-
|
| 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`
|
| 152 |
|
| 153 |
— *end note*]
|
| 154 |
|
| 155 |
-
There can be more than one definition of a
|
| 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 |
-
-
|
| 169 |
-
|
| 170 |
-
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
object
|
| 177 |
- has the same literal type in all definitions of `D`,
|
| 178 |
-
- is initialized with a constant expression
|
| 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 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
| 191 |
implicit calls to conversion functions, constructors, operator new
|
| 192 |
functions and operator delete functions, shall refer to the same
|
| 193 |
-
function
|
| 194 |
-
-
|
| 195 |
-
explicit) function call
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
-
|
| 201 |
-
[[class.ctor]]), it is as if the
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
for a subobject of `D`.
|
| 205 |
-
\[*Example
|
| 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]]
|
| 237 |
-
instantiation
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|