From Jason Turner

[basic.def.odr]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpovgyinle/{from.md → to.md} +80 -46
tmp/tmpovgyinle/{from.md → to.md} RENAMED
@@ -2,47 +2,81 @@
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. A variable whose
8
- name appears as a potentially-evaluated expression is *odr-used* unless
9
- it is an object that satisfies the requirements for appearing in a
10
- constant expression ([[expr.const]]) and the lvalue-to-rvalue
11
- conversion ([[conv.lval]]) is immediately applied. `this` is odr-used
12
- if it appears as a potentially-evaluated expression (including as the
13
- result of the implicit transformation in the body of a non-static member
14
- function ([[class.mfct.non-static]])). A virtual member function is
15
- odr-used if it is not pure. A non-overloaded function whose name appears
16
- as a potentially-evaluated expression or a member of a set of candidate
17
- functions, if selected by overload resolution when referred to from a
18
- potentially-evaluated expression, is odr-used, unless it is a pure
19
- virtual function and its name is not explicitly qualified. This covers
20
- calls to named functions ([[expr.call]]), operator overloading (Clause 
21
- [[over]]), user-defined conversions ([[class.conv.fct]]), allocation
22
- function for placement new ([[expr.new]]), as well as non-default
23
- initialization ([[dcl.init]]). A copy constructor or move constructor
24
- is odr-used even if the call is actually elided by the implementation.
25
- An allocation or deallocation function for a class is odr-used by a new
26
- expression appearing in a potentially-evaluated expression as specified
27
- in  [[expr.new]] and  [[class.free]]. A deallocation function for a
28
- class is odr-used by a delete expression appearing in a
29
- potentially-evaluated expression as specified in  [[expr.delete]] and 
30
- [[class.free]]. A non-placement allocation or deallocation function for
31
- a class is odr-used by the definition of a constructor of that class. A
32
- non-placement deallocation function for a class is odr-used by the
33
- definition of the destructor of that class, or by being selected by the
34
- lookup at the point of definition of a virtual destructor (
35
- [[class.dtor]]).[^2] A copy-assignment function for a class is odr-used
36
- by an implicitly-defined copy-assignment function for another class as
37
- specified in  [[class.copy]]. A move-assignment function for a class is
38
- odr-used by an implicitly-defined move-assignment function for another
39
- class as specified in  [[class.copy]]. A default constructor for a class
40
- is odr-used by default initialization or value initialization as
41
- specified in  [[dcl.init]]. A constructor for a class is odr-used as
42
- specified in  [[dcl.init]]. A destructor for a class is odr-used as
43
- specified in  [[class.dtor]].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  Every program shall contain exactly one definition of every non-inline
46
  function or variable that is odr-used in that program; no diagnostic
47
  required. The definition can appear explicitly in the program, it can be
48
  found in the standard or a user-defined library, or (when appropriate)
@@ -73,12 +107,12 @@ complete class types are required. A class type `T` must be complete if:
73
  object of type `T` ([[conv.lval]]), or
74
  - an expression is converted (either implicitly or explicitly) to type
75
  `T` (Clause  [[conv]], [[expr.type.conv]], [[expr.dynamic.cast]],
76
  [[expr.static.cast]], [[expr.cast]]), or
77
  - an expression that is not a null pointer constant, and has type other
78
- than `void*`, is converted to the type pointer to `T` or reference to
79
- `T` using an implicit conversion (Clause  [[conv]]), a
80
  `dynamic_cast` ([[expr.dynamic.cast]]) or a `static_cast` (
81
  [[expr.static.cast]]), or
82
  - a class member access operator is applied to an expression of type
83
  `T` ([[expr.ref]]), or
84
  - the `typeid` operator ([[expr.typeid]]) or the `sizeof` operator (
@@ -110,15 +144,15 @@ unit, then
110
  - in each definition of `D`, corresponding names, looked up according
111
  to  [[basic.lookup]], shall refer to an entity defined within the
112
  definition of `D`, or shall refer to the same entity, after overload
113
  resolution ([[over.match]]) and after matching of partial template
114
  specialization ([[temp.over]]), except that a name can refer to a
115
- `const` object with internal or no linkage if the object has the same
116
- literal type in all definitions of `D`, and the object is initialized
117
- with a constant expression ([[expr.const]]), and the value (but not
118
- the address) of the object is used, and the object has the same value
119
- in all definitions of `D`; and
120
  - in each definition of `D`, corresponding entities shall have the same
121
  language linkage; and
122
  - in each definition of `D`, the overloaded operators referred to, the
123
  implicit calls to conversion functions, constructors, operator new
124
  functions and operator delete functions, shall refer to the same
@@ -158,9 +192,9 @@ unit, then
158
  If `D` is a template and is defined in more than one translation unit,
159
  then the preceding requirements shall apply both to names from the
160
  template’s enclosing scope used in the template definition (
161
  [[temp.nondep]]), and also to dependent names at the point of
162
  instantiation ([[temp.dep]]). If the definitions of `D` satisfy all
163
- these requirements, then the program shall behave as if there were a
164
- single definition of `D`. If the definitions of `D` do not satisfy these
165
  requirements, then the behavior is undefined.
166
 
 
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.general]]), the set
11
+ contains only `e`.
12
+ - If `e` is a class member access expression ([[expr.ref]]), the set
13
+ contains the potential results of the object expression.
14
+ - If `e` is a pointer-to-member expression ([[expr.mptr.oper]]) whose
15
+ second operand is a constant expression, the set contains the
16
+ potential results of the object expression.
17
+ - If `e` has the form `(e1)`, the set contains the potential results of
18
+ `e1`.
19
+ - If `e` is a glvalue conditional expression ([[expr.cond]]), the set
20
+ is the union of the sets of potential results of the second and third
21
+ operands.
22
+ - If `e` is a comma expression ([[expr.comma]]), the set contains the
23
+ potential results of the right operand.
24
+ - Otherwise, the set is empty.
25
+
26
+ This set is a (possibly-empty) set of *id-expression*s, each of which is
27
+ either `e` or a subexpression of `e`. In the following example, the set
28
+ of potential results of the initializer of `n` contains the first `S::x`
29
+ subexpression, but not the second `S::x` subexpression.
30
+
31
+ ``` cpp
32
+ struct S { static const int x = 0; };
33
+ const int &f(const int &r);
34
+ int n = b ? (1, S::x) // S::x is not odr-used here
35
+ : f(S::x); // S::x is odr-used here, so
36
+ // a definition is required
37
+ ```
38
+
39
+ A variable `x` whose name appears as a potentially-evaluated expression
40
+ `ex` is *odr-used* by `ex` unless applying the lvalue-to-rvalue
41
+ conversion ([[conv.lval]]) to `x` yields a constant expression (
42
+ [[expr.const]]) that does not invoke any non-trivial functions and, if
43
+ `x` is an object, `ex` is an element of the set of potential results of
44
+ an expression `e`, where either the lvalue-to-rvalue conversion (
45
+ [[conv.lval]]) is applied to `e`, or `e` is a discarded-value
46
+ expression (Clause [[expr]]). `this` is odr-used if it appears as a
47
+ potentially-evaluated expression (including as the result of the
48
+ implicit transformation in the body of a non-static member function (
49
+ [[class.mfct.non-static]])). A virtual member function is odr-used if it
50
+ is not pure. A function whose name appears as a potentially-evaluated
51
+ expression is odr-used if it is the unique lookup result or the selected
52
+ member of a set of overloaded functions ([[basic.lookup]],
53
+ [[over.match]], [[over.over]]), unless it is a pure virtual function and
54
+ its name is not explicitly qualified. This covers calls to named
55
+ functions ([[expr.call]]), operator overloading (Clause  [[over]]),
56
+ user-defined conversions ([[class.conv.fct]]), allocation function for
57
+ placement new ([[expr.new]]), as well as non-default initialization (
58
+ [[dcl.init]]). A constructor selected to copy or move an object of class
59
+ type is odr-used even if the call is actually elided by the
60
+ implementation ([[class.copy]]). An allocation or deallocation function
61
+ for a class is odr-used by a new expression appearing in a
62
+ potentially-evaluated expression as specified in  [[expr.new]] and 
63
+ [[class.free]]. A deallocation function for a class is odr-used by a
64
+ delete expression appearing in a potentially-evaluated expression as
65
+ specified in  [[expr.delete]] and  [[class.free]]. A non-placement
66
+ allocation or deallocation function for a class is odr-used by the
67
+ definition of a constructor of that class. A non-placement deallocation
68
+ function for a class is odr-used by the definition of the destructor of
69
+ that class, or by being selected by the lookup at the point of
70
+ definition of a virtual destructor ([[class.dtor]]).[^2] An assignment
71
+ operator function in a class is odr-used by an implicitly-defined
72
+ copy-assignment or move-assignment function for another class as
73
+ specified in  [[class.copy]]. A default constructor for a class is
74
+ odr-used by default initialization or value initialization as specified
75
+ in  [[dcl.init]]. A constructor for a class is odr-used as specified in 
76
+ [[dcl.init]]. A destructor for a class is odr-used if it is potentially
77
+ invoked ([[class.dtor]]).
78
 
79
  Every program shall contain exactly one definition of every non-inline
80
  function or variable that is odr-used in that program; no diagnostic
81
  required. The definition can appear explicitly in the program, it can be
82
  found in the standard or a user-defined library, or (when appropriate)
 
107
  object of type `T` ([[conv.lval]]), or
108
  - an expression is converted (either implicitly or explicitly) to type
109
  `T` (Clause  [[conv]], [[expr.type.conv]], [[expr.dynamic.cast]],
110
  [[expr.static.cast]], [[expr.cast]]), or
111
  - an expression that is not a null pointer constant, and has type other
112
+ than *cv* `void*`, is converted to the type pointer to `T` or
113
+ reference to `T` using a standard conversion (Clause  [[conv]]), a
114
  `dynamic_cast` ([[expr.dynamic.cast]]) or a `static_cast` (
115
  [[expr.static.cast]]), or
116
  - a class member access operator is applied to an expression of type
117
  `T` ([[expr.ref]]), or
118
  - the `typeid` operator ([[expr.typeid]]) or the `sizeof` operator (
 
144
  - in each definition of `D`, corresponding names, looked up according
145
  to  [[basic.lookup]], shall refer to an entity defined within the
146
  definition of `D`, or shall refer to the same entity, after overload
147
  resolution ([[over.match]]) and after matching of partial template
148
  specialization ([[temp.over]]), except that a name can refer to a
149
+ non-volatile `const` object with internal or no linkage if the object
150
+ has the same literal type in all definitions of `D`, and the object is
151
+ initialized with a constant expression ([[expr.const]]), and the
152
+ object is not odr-used, and the object has the same value in all
153
+ definitions of `D`; and
154
  - in each definition of `D`, corresponding entities shall have the same
155
  language linkage; and
156
  - in each definition of `D`, the overloaded operators referred to, the
157
  implicit calls to conversion functions, constructors, operator new
158
  functions and operator delete functions, shall refer to the same
 
192
  If `D` is a template and is defined in more than one translation unit,
193
  then the preceding requirements shall apply both to names from the
194
  template’s enclosing scope used in the template definition (
195
  [[temp.nondep]]), and also to dependent names at the point of
196
  instantiation ([[temp.dep]]). If the definitions of `D` satisfy all
197
+ these requirements, then the behavior is as if there were a single
198
+ definition of `D`. If the definitions of `D` do not satisfy these
199
  requirements, then the behavior is undefined.
200