From Jason Turner

[basic.types.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmgid9e_i/{from.md → to.md} +170 -0
tmp/tmpmgid9e_i/{from.md → to.md} RENAMED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### General <a id="basic.types.general">[[basic.types.general]]</a>
2
+
3
+ [*Note 1*: [[basic.types]] and the subclauses thereof impose
4
+ requirements on implementations regarding the representation of types.
5
+ There are two kinds of types: fundamental types and compound types.
6
+ Types describe objects [[intro.object]], references [[dcl.ref]], or
7
+ functions [[dcl.fct]]. — *end note*]
8
+
9
+ For any object (other than a potentially-overlapping subobject) of
10
+ trivially copyable type `T`, whether or not the object holds a valid
11
+ value of type `T`, the underlying bytes [[intro.memory]] making up the
12
+ object can be copied into an array of `char`, `unsigned char`, or
13
+ `std::byte` [[cstddef.syn]].[^14]
14
+
15
+ If the content of that array is copied back into the object, the object
16
+ shall subsequently hold its original value.
17
+
18
+ [*Example 1*:
19
+
20
+ ``` cpp
21
+ constexpr std::size_t N = sizeof(T);
22
+ char buf[N];
23
+ T obj; // obj initialized to its original value
24
+ std::memcpy(buf, &obj, N); // between these two calls to std::memcpy, obj might be modified
25
+ std::memcpy(&obj, buf, N); // at this point, each subobject of obj of scalar type holds its original value
26
+ ```
27
+
28
+ — *end example*]
29
+
30
+ For two distinct objects `obj1` and `obj2` of trivially copyable type
31
+ `T`, where neither `obj1` nor `obj2` is a potentially-overlapping
32
+ subobject, if the underlying bytes [[intro.memory]] making up `obj1` are
33
+ copied into `obj2`,[^15]
34
+
35
+ `obj2` shall subsequently hold the same value as `obj1`.
36
+
37
+ [*Example 2*:
38
+
39
+ ``` cpp
40
+ T* t1p;
41
+ T* t2p;
42
+ // provided that t2p points to an initialized object ...
43
+ std::memcpy(t1p, t2p, sizeof(T));
44
+ // at this point, every subobject of trivially copyable type in *t1p contains
45
+ // the same value as the corresponding subobject in *t2p
46
+ ```
47
+
48
+ — *end example*]
49
+
50
+ The *object representation* of an object of type `T` is the sequence of
51
+ *N* `unsigned char` objects taken up by the object of type `T`, where
52
+ *N* equals `sizeof(T)`. The *value representation* of an object of type
53
+ `T` is the set of bits that participate in representing a value of type
54
+ `T`. Bits in the object representation that are not part of the value
55
+ representation are *padding bits*. For trivially copyable types, the
56
+ value representation is a set of bits in the object representation that
57
+ determines a *value*, which is one discrete element of an
58
+ *implementation-defined* set of values.[^16]
59
+
60
+ A class that has been declared but not defined, an enumeration type in
61
+ certain contexts [[dcl.enum]], or an array of unknown bound or of
62
+ incomplete element type, is an *incompletely-defined object type*.[^17]
63
+
64
+ Incompletely-defined object types and cv `void` are *incomplete types*
65
+ [[basic.fundamental]].
66
+
67
+ [*Note 2*: Objects cannot be defined to have an incomplete type
68
+ [[basic.def]]. — *end note*]
69
+
70
+ A class type (such as “`class X`”) can be incomplete at one point in a
71
+ translation unit and complete later on; the type “`class X`” is the same
72
+ type at both points. The declared type of an array object can be an
73
+ array of incomplete class type and therefore incomplete; if the class
74
+ type is completed later on in the translation unit, the array type
75
+ becomes complete; the array type at those two points is the same type.
76
+ The declared type of an array object can be an array of unknown bound
77
+ and therefore be incomplete at one point in a translation unit and
78
+ complete later on; the array types at those two points (“array of
79
+ unknown bound of `T`” and “array of `N` `T`”) are different types.
80
+
81
+ [*Note 3*: The type of a pointer or reference to array of unknown bound
82
+ permanently points to or refers to an incomplete type. An array of
83
+ unknown bound named by a `typedef` declaration permanently refers to an
84
+ incomplete type. In either case, the array type cannot be
85
+ completed. — *end note*]
86
+
87
+ [*Example 3*:
88
+
89
+ ``` cpp
90
+ class X; // X is an incomplete type
91
+ extern X* xp; // xp is a pointer to an incomplete type
92
+ extern int arr[]; // the type of arr is incomplete
93
+ typedef int UNKA[]; // UNKA is an incomplete type
94
+ UNKA* arrp; // arrp is a pointer to an incomplete type
95
+ UNKA** arrpp;
96
+
97
+ void foo() {
98
+ xp++; // error: X is incomplete
99
+ arrp++; // error: incomplete type
100
+ arrpp++; // OK, sizeof UNKA* is known
101
+ }
102
+
103
+ struct X { int i; }; // now X is a complete type
104
+ int arr[10]; // now the type of arr is complete
105
+
106
+ X x;
107
+ void bar() {
108
+ xp = &x; // OK; type is ``pointer to X''
109
+ arrp = &arr; // OK; qualification conversion[conv.qual]
110
+ xp++; // OK, X is complete
111
+ arrp++; // error: UNKA can't be completed
112
+ }
113
+ ```
114
+
115
+ — *end example*]
116
+
117
+ [*Note 4*: The rules for declarations and expressions describe in which
118
+ contexts incomplete types are prohibited. — *end note*]
119
+
120
+ An *object type* is a (possibly cv-qualified) type that is not a
121
+ function type, not a reference type, and not cv `void`.
122
+
123
+ Arithmetic types [[basic.fundamental]], enumeration types, pointer
124
+ types, pointer-to-member types [[basic.compound]], `std::nullptr_t`, and
125
+ cv-qualified [[basic.type.qualifier]] versions of these types are
126
+ collectively called *scalar types*. Scalar types, trivially copyable
127
+ class types [[class.prop]], arrays of such types, and cv-qualified
128
+ versions of these types are collectively called *trivially copyable
129
+ types*. Scalar types, trivial class types [[class.prop]], arrays of such
130
+ types and cv-qualified versions of these types are collectively called
131
+ *trivial types*. Scalar types, standard-layout class types
132
+ [[class.prop]], arrays of such types and cv-qualified versions of these
133
+ types are collectively called *standard-layout types*. Scalar types,
134
+ implicit-lifetime class types [[class.prop]], array types, and
135
+ cv-qualified versions of these types are collectively called
136
+ *implicit-lifetime types*.
137
+
138
+ A type is a *literal type* if it is:
139
+
140
+ - cv `void`; or
141
+ - a scalar type; or
142
+ - a reference type; or
143
+ - an array of literal type; or
144
+ - a possibly cv-qualified class type [[class]] that has all of the
145
+ following properties:
146
+ - it has a constexpr destructor [[dcl.constexpr]],
147
+ - all of its non-static non-variant data members and base classes are
148
+ of non-volatile literal types, and
149
+ - it
150
+ - is a closure type [[expr.prim.lambda.closure]],
151
+ - is an aggregate union type that has either no variant members or
152
+ at least one variant member of non-volatile literal type,
153
+ - is a non-union aggregate type for which each of its anonymous
154
+ union members satisfies the above requirements for an aggregate
155
+ union type, or
156
+ - has at least one constexpr constructor or constructor template
157
+ (possibly inherited [[namespace.udecl]] from a base class) that is
158
+ not a copy or move constructor.
159
+
160
+ [*Note 5*: A literal type is one for which it might be possible to
161
+ create an object within a constant expression. It is not a guarantee
162
+ that it is possible to create such an object, nor is it a guarantee that
163
+ any object of that type will be usable in a constant
164
+ expression. — *end note*]
165
+
166
+ Two types *cv1* `T1` and *cv2* `T2` are *layout-compatible types* if
167
+ `T1` and `T2` are the same type, layout-compatible enumerations
168
+ [[dcl.enum]], or layout-compatible standard-layout class types
169
+ [[class.mem]].
170
+