From Jason Turner

[basic.types]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp7w7dxbtb/{from.md → to.md} +312 -238
tmp/tmp7w7dxbtb/{from.md → to.md} RENAMED
@@ -1,37 +1,38 @@
1
  ## Types <a id="basic.types">[[basic.types]]</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]]),
7
- or functions ([[dcl.fct]]). — *end note*]
8
 
9
- For any object (other than a base-class subobject) of trivially copyable
10
- type `T`, whether or not the object holds a valid value of type `T`, the
11
- underlying bytes ([[intro.memory]]) making up the object can be copied
12
- into an array of `char`, `unsigned char`, or `std::byte` (
13
- [[cstddef.syn]]). [^18] If the content of that array is copied back into
14
- the object, the object shall subsequently hold its original value.
 
15
 
16
  [*Example 1*:
17
 
18
  ``` cpp
19
- #define N sizeof(T)
20
  char buf[N];
21
  T obj; // obj initialized to its original value
22
  std::memcpy(buf, &obj, N); // between these two calls to std::memcpy, obj might be modified
23
  std::memcpy(&obj, buf, N); // at this point, each subobject of obj of scalar type holds its original value
24
  ```
25
 
26
  — *end example*]
27
 
28
  For any trivially copyable type `T`, if two pointers to `T` point to
29
  distinct `T` objects `obj1` and `obj2`, where neither `obj1` nor `obj2`
30
- is a base-class subobject, if the underlying bytes ([[intro.memory]])
31
- making up `obj1` are copied into `obj2`,[^19] `obj2` shall subsequently
32
- hold the same value as `obj1`.
33
 
34
  [*Example 2*:
35
 
36
  ``` cpp
37
  T* t1p;
@@ -44,21 +45,23 @@ std::memcpy(t1p, t2p, sizeof(T));
44
 
45
  — *end example*]
46
 
47
  The *object representation* of an object of type `T` is the sequence of
48
  *N* `unsigned char` objects taken up by the object of type `T`, where
49
- *N* equals `sizeof(T)`. The *value representation* of an object is the
50
- set of bits that hold the value of type `T`. For trivially copyable
51
- types, the value representation is a set of bits in the object
52
- representation that determines a *value*, which is one discrete element
53
- of an *implementation-defined* set of values.[^20]
 
 
54
 
55
  A class that has been declared but not defined, an enumeration type in
56
- certain contexts ([[dcl.enum]]), or an array of unknown bound or of
57
  incomplete element type, is an *incompletely-defined object type*. [^21]
58
- Incompletely-defined object types and cv `void` are *incomplete types* (
59
- [[basic.fundamental]]). Objects shall not be defined to have an
60
  incomplete type.
61
 
62
  A class type (such as “`class X`”) might be incomplete at one point in a
63
  translation unit and complete later on; the type “`class X`” is the same
64
  type at both points. The declared type of an array object might be an
@@ -82,24 +85,24 @@ extern int arr[]; // the type of arr is incomplete
82
  typedef int UNKA[]; // UNKA is an incomplete type
83
  UNKA* arrp; // arrp is a pointer to an incomplete type
84
  UNKA** arrpp;
85
 
86
  void foo() {
87
- xp++; // ill-formed: X is incomplete
88
- arrp++; // ill-formed: incomplete type
89
  arrpp++; // OK: sizeof UNKA* is known
90
  }
91
 
92
  struct X { int i; }; // now X is a complete type
93
  int arr[10]; // now the type of arr is complete
94
 
95
  X x;
96
  void bar() {
97
  xp = &x; // OK; type is ``pointer to X''
98
- arrp = &arr; // ill-formed: different types
99
  xp++; // OK: X is complete
100
- arrp++; // ill-formed: UNKA can't be completed
101
  }
102
  ```
103
 
104
  — *end example*]
105
 
@@ -107,375 +110,446 @@ void bar() {
107
  contexts incomplete types are prohibited. — *end note*]
108
 
109
  An *object type* is a (possibly cv-qualified) type that is not a
110
  function type, not a reference type, and not cv `void`.
111
 
112
- Arithmetic types ([[basic.fundamental]]), enumeration types, pointer
113
- types, pointer to member types ([[basic.compound]]), `std::nullptr_t`,
114
- and cv-qualified ([[basic.type.qualifier]]) versions of these types are
115
- collectively called *scalar types*. Scalar types, POD classes (Clause 
116
- [[class]]), arrays of such types and cv-qualified versions of these
117
- types are collectively called *POD types*. Cv-unqualified scalar types,
118
- trivially copyable class types (Clause  [[class]]), arrays of such
119
- types, and cv-qualified versions of these types are collectively called
120
- *trivially copyable types*. Scalar types, trivial class types (Clause 
121
- [[class]]), arrays of such types and cv-qualified versions of these
122
- types are collectively called *trivial types*. Scalar types,
123
- standard-layout class types (Clause  [[class]]), arrays of such types
124
- and cv-qualified versions of these types are collectively called
125
- *standard-layout types*.
126
 
127
  A type is a *literal type* if it is:
128
 
129
- - possibly cv-qualified `void`; or
130
  - a scalar type; or
131
  - a reference type; or
132
  - an array of literal type; or
133
- - a possibly cv-qualified class type (Clause  [[class]]) that has all of
134
- the following properties:
135
- - it has a trivial destructor,
136
- - it is either a closure type ([[expr.prim.lambda.closure]]), an
137
- aggregate type ([[dcl.init.aggr]]), or has at least one constexpr
138
- constructor or constructor template (possibly inherited (
139
- [[namespace.udecl]]) from a base class) that is not a copy or move
140
  constructor,
141
  - if it is a union, at least one of its non-static data members is of
142
  non-volatile literal type, and
143
  - if it is not a union, all of its non-static data members and base
144
  classes are of non-volatile literal types.
145
 
146
  [*Note 3*: A literal type is one for which it might be possible to
147
  create an object within a constant expression. It is not a guarantee
148
  that it is possible to create such an object, nor is it a guarantee that
149
- any object of that type will usable in a constant
150
  expression. — *end note*]
151
 
152
  Two types *cv1* `T1` and *cv2* `T2` are *layout-compatible* types if
153
- `T1` and `T2` are the same type, layout-compatible enumerations (
154
- [[dcl.enum]]), or layout-compatible standard-layout class types (
155
- [[class.mem]]).
156
 
157
  ### Fundamental types <a id="basic.fundamental">[[basic.fundamental]]</a>
158
 
159
- Objects declared as characters (`char`) shall be large enough to store
160
- any member of the implementation’s basic character set. If a character
161
- from this set is stored in a character object, the integral value of
162
- that character object is equal to the value of the single character
163
- literal form of that character. It is *implementation-defined* whether a
164
- `char` object can hold negative values. Characters can be explicitly
165
- declared `unsigned` or `signed`. Plain `char`, `signed char`, and
166
- `unsigned char` are three distinct types, collectively called *narrow
167
- character types*. A `char`, a `signed char`, and an `unsigned char`
168
- occupy the same amount of storage and have the same alignment
169
- requirements ([[basic.align]]); that is, they have the same object
170
- representation. For narrow character types, all bits of the object
171
- representation participate in the value representation.
172
-
173
- [*Note 1*: A bit-field of narrow character type whose length is larger
174
- than the number of bits in the object representation of that type has
175
- padding bits; see  [[class.bit]]. — *end note*]
176
-
177
- For unsigned narrow character types, each possible bit pattern of the
178
- value representation represents a distinct number. These requirements do
179
- not hold for other types. In any particular implementation, a plain
180
- `char` object can take on either the same values as a `signed char` or
181
- an `unsigned
182
- char`; which one is *implementation-defined*. For each value *i* of type
183
- `unsigned char` in the range 0 to 255 inclusive, there exists a value
184
- *j* of type `char` such that the result of an integral conversion (
185
- [[conv.integral]]) from *i* to `char` is *j*, and the result of an
186
- integral conversion from *j* to `unsigned char` is *i*.
187
-
188
  There are five *standard signed integer types* : “`signed char`”,
189
  “`short int`”, “`int`”, “`long int`”, and “`long long int`”. In this
190
  list, each type provides at least as much storage as those preceding it
191
  in the list. There may also be *implementation-defined* *extended signed
192
  integer types*. The standard and extended signed integer types are
193
- collectively called *signed integer types*. Plain `int`s have the
194
- natural size suggested by the architecture of the execution environment
195
- [^22]; the other signed integer types are provided to meet special
196
- needs.
 
 
 
197
 
198
  For each of the standard signed integer types, there exists a
199
  corresponding (but different) *standard unsigned integer type*:
200
  “`unsigned char`”, “`unsigned short int`”, “`unsigned int`”,
201
- “`unsigned long int`”, and “`unsigned long long int`”, each of which
202
- occupies the same amount of storage and has the same alignment
203
- requirements ([[basic.align]]) as the corresponding signed integer
204
- type[^23]; that is, each signed integer type has the same object
205
- representation as its corresponding unsigned integer type. Likewise, for
206
- each of the extended signed integer types there exists a corresponding
207
- *extended unsigned integer type* with the same amount of storage and
208
- alignment requirements. The standard and extended unsigned integer types
209
- are collectively called *unsigned integer types*. The range of
210
- non-negative values of a signed integer type is a subrange of the
211
- corresponding unsigned integer type, the representation of the same
212
- value in each of the two types is the same, and the value representation
213
- of each corresponding signed/unsigned type shall be the same. The
214
- standard signed integer types and standard unsigned integer types are
215
- collectively called the *standard integer types*, and the extended
216
- signed integer types and extended unsigned integer types are
217
- collectively called the *extended integer types*. The signed and
218
- unsigned integer types shall satisfy the constraints given in the C
219
- standard, section 5.2.4.2.1.
220
-
221
- Unsigned integers shall obey the laws of arithmetic modulo 2ⁿ where n is
222
- the number of bits in the value representation of that particular size
223
- of integer.[^24]
224
-
225
- Type `wchar_t` is a distinct type whose values can represent distinct
226
- codes for all members of the largest extended character set specified
227
- among the supported locales ([[locale]]). Type `wchar_t` shall have the
228
- same size, signedness, and alignment requirements ([[basic.align]]) as
229
- one of the other integral types, called its *underlying type*. Types
230
- `char16_t` and `char32_t` denote distinct types with the same size,
231
- signedness, and alignment as `uint_least16_t` and `uint_least32_t`,
232
- respectively, in `<cstdint>`, called the underlying types.
233
-
234
- Values of type `bool` are either `true` or `false`.[^25]
235
-
236
- [*Note 2*: There are no `signed`, `unsigned`, `short`, or `long bool`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  types or values. — *end note*]
238
 
239
- Values of type `bool` participate in integral promotions (
240
- [[conv.prom]]).
 
241
 
242
- Types `bool`, `char`, `char16_t`, `char32_t`, `wchar_t`, and the signed
243
- and unsigned integer types are collectively called *integral*
244
- types.[^26] A synonym for integral type is *integer type*. The
245
- representations of integral types shall define values by use of a pure
246
- binary numeration system.[^27]
247
 
248
- [*Example 1*: This International Standard permits two’s complement,
249
- ones’ complement and signed magnitude representations for integral
250
- types. — *end example*]
251
-
252
- There are three *floating-point* types: `float`, `double`, and
253
  `long double`. The type `double` provides at least as much precision as
254
  `float`, and the type `long double` provides at least as much precision
255
  as `double`. The set of values of the type `float` is a subset of the
256
  set of values of the type `double`; the set of values of the type
257
  `double` is a subset of the set of values of the type `long double`. The
258
  value representation of floating-point types is
259
  *implementation-defined*.
260
 
261
- [*Note 3*: This International Standard imposes no requirements on the
262
- accuracy of floating-point operations; see also 
263
- [[support.limits]]. — *end note*]
264
 
265
- Integral and floating types are collectively called *arithmetic* types.
266
- Specializations of the standard library template `std::numeric_limits` (
267
- [[support.limits]]) shall specify the maximum and minimum values of each
268
- arithmetic type for an implementation.
269
 
270
  A type cv `void` is an incomplete type that cannot be completed; such a
271
  type has an empty set of values. It is used as the return type for
272
  functions that do not return a value. Any expression can be explicitly
273
- converted to type cv `void` ([[expr.cast]]). An expression of type
274
- cv `void` shall be used only as an expression statement (
275
- [[stmt.expr]]), as an operand of a comma expression ([[expr.comma]]),
276
- as a second or third operand of `?:` ([[expr.cond]]), as the operand of
277
- `typeid`, `noexcept`, or `decltype`, as the expression in a return
278
- statement ([[stmt.return]]) for a function with the return type
279
  cv `void`, or as the operand of an explicit conversion to type
280
  cv `void`.
281
 
282
- A value of type `std::nullptr_t` is a null pointer constant (
283
- [[conv.ptr]]). Such values participate in the pointer and the pointer to
284
- member conversions ([[conv.ptr]], [[conv.mem]]).
285
  `sizeof(std::nullptr_t)` shall be equal to `sizeof(void*)`.
286
 
287
- [*Note 4*: Even if the implementation defines two or more basic types
288
- to have the same value representation, they are nevertheless different
289
- types. — *end note*]
 
 
290
 
291
  ### Compound types <a id="basic.compound">[[basic.compound]]</a>
292
 
293
  Compound types can be constructed in the following ways:
294
 
295
- - *arrays* of objects of a given type,  [[dcl.array]];
296
  - *functions*, which have parameters of given types and return `void` or
297
- references or objects of a given type,  [[dcl.fct]];
298
  - *pointers* to cv `void` or objects or functions (including static
299
- members of classes) of a given type,  [[dcl.ptr]];
300
- - *references* to objects or functions of a given type,  [[dcl.ref]].
301
  There are two types of references:
302
- - *lvalue reference*
303
- - *rvalue reference*
304
- - *classes* containing a sequence of objects of various types (Clause 
305
- [[class]]), a set of types, enumerations and functions for
306
- manipulating these objects ([[class.mfct]]), and a set of
307
- restrictions on the access to these entities (Clause 
308
- [[class.access]]);
309
  - *unions*, which are classes capable of containing objects of different
310
- types at different times,  [[class.union]];
311
  - *enumerations*, which comprise a set of named constant values. Each
312
- distinct enumeration constitutes a different *enumerated type*, 
313
  [[dcl.enum]];
314
- - *pointers to non-static class members*, [^28] which identify members
315
- of a given type within objects of a given class,  [[dcl.mptr]].
 
 
316
 
317
  These methods of constructing types can be applied recursively;
318
- restrictions are mentioned in  [[dcl.ptr]], [[dcl.array]], [[dcl.fct]],
319
- and  [[dcl.ref]]. Constructing a type such that the number of bytes in
320
- its object representation exceeds the maximum value representable in the
321
- type `std::size_t` ([[support.types]]) is ill-formed.
322
 
323
  The type of a pointer to cv `void` or a pointer to an object type is
324
  called an *object pointer type*.
325
 
326
  [*Note 1*: A pointer to `void` does not have a pointer-to-object type,
327
  however, because `void` is not an object type. — *end note*]
328
 
329
  The type of a pointer that can designate a function is called a
330
- *function pointer type*. A pointer to objects of type `T` is referred to
331
- as a “pointer to `T`”.
332
 
333
  [*Example 1*: A pointer to an object of type `int` is referred to as
334
  “pointer to `int`” and a pointer to an object of class `X` is called a
335
  “pointer to `X`”. — *end example*]
336
 
337
  Except for pointers to static members, text referring to “pointers” does
338
  not apply to pointers to members. Pointers to incomplete types are
339
- allowed although there are restrictions on what can be done with them (
340
- [[basic.align]]). Every value of pointer type is one of the following:
341
 
342
  - a *pointer to* an object or function (the pointer is said to *point*
343
  to the object or function), or
344
- - a *pointer past the end of* an object ([[expr.add]]), or
345
- - the *null pointer value* ([[conv.ptr]]) for that type, or
346
  - an *invalid pointer value*.
347
 
348
  A value of a pointer type that is a pointer to or past the end of an
349
- object *represents the address* of the first byte in memory (
350
- [[intro.memory]]) occupied by the object [^29] or the first byte in
351
  memory after the end of the storage occupied by the object,
352
  respectively.
353
 
354
- [*Note 2*: A pointer past the end of an object ([[expr.add]]) is not
355
  considered to point to an unrelated object of the object’s type that
356
  might be located at that address. A pointer value becomes invalid when
357
  the storage it denotes reaches the end of its storage duration; see
358
  [[basic.stc]]. — *end note*]
359
 
360
- For purposes of pointer arithmetic ([[expr.add]]) and comparison (
361
  [[expr.rel]], [[expr.eq]]), a pointer past the end of the last element
362
  of an array `x` of n elements is considered to be equivalent to a
363
- pointer to a hypothetical element `x[n]`. The value representation of
364
- pointer types is *implementation-defined*. Pointers to layout-compatible
365
- types shall have the same value representation and alignment
366
- requirements ([[basic.align]]).
 
 
367
 
368
- [*Note 3*: Pointers to over-aligned types ([[basic.align]]) have no
369
  special representation, but their range of valid values is restricted by
370
  the extended alignment requirement. — *end note*]
371
 
372
  Two objects *a* and *b* are *pointer-interconvertible* if:
373
 
374
  - they are the same object, or
375
- - one is a standard-layout union object and the other is a non-static
376
- data member of that object ([[class.union]]), or
377
  - one is a standard-layout class object and the other is the first
378
  non-static data member of that object, or, if the object has no
379
- non-static data members, the first base class subobject of that
380
- object ([[class.mem]]), or
381
  - there exists an object *c* such that *a* and *c* are
382
  pointer-interconvertible, and *c* and *b* are
383
  pointer-interconvertible.
384
 
385
  If two objects are pointer-interconvertible, then they have the same
386
  address, and it is possible to obtain a pointer to one from a pointer to
387
- the other via a `reinterpret_cast` ([[expr.reinterpret.cast]]).
388
 
389
  [*Note 4*: An array object and its first element are not
390
  pointer-interconvertible, even though they have the same
391
  address. — *end note*]
392
 
393
- A pointer to cv-qualified ([[basic.type.qualifier]]) or cv-unqualified
394
- `void` can be used to point to objects of unknown type. Such a pointer
395
- shall be able to hold any object pointer. An object of type cv `void*`
396
- shall have the same representation and alignment requirements as
397
- cv `char*`.
398
 
399
  ### CV-qualifiers <a id="basic.type.qualifier">[[basic.type.qualifier]]</a>
400
 
401
  A type mentioned in  [[basic.fundamental]] and  [[basic.compound]] is a
402
  *cv-unqualified type*. Each type which is a cv-unqualified complete or
403
- incomplete object type or is `void` ([[basic.types]]) has three
404
  corresponding cv-qualified versions of its type: a *const-qualified*
405
  version, a *volatile-qualified* version, and a
406
- *const-volatile-qualified* version. The type of an object (
407
- [[intro.object]]) includes the *cv-qualifier*s specified in the
408
- *decl-specifier-seq* ([[dcl.spec]]), *declarator* (Clause 
409
- [[dcl.decl]]), *type-id* ([[dcl.name]]), or *new-type-id* (
410
- [[expr.new]]) when the object is created.
411
 
412
  - A *const object* is an object of type `const T` or a non-mutable
413
- subobject of such an object.
414
- - A *volatile object* is an object of type `volatile T`, a subobject of
415
- such an object, or a mutable subobject of a const volatile object.
416
  - A *const volatile object* is an object of type `const volatile T`, a
417
- non-mutable subobject of such an object, a const subobject of a
418
- volatile object, or a non-mutable volatile subobject of a const
419
  object.
420
 
421
  The cv-qualified or cv-unqualified versions of a type are distinct
422
  types; however, they shall have the same representation and alignment
423
- requirements ([[basic.align]]).[^30]
424
 
425
- A compound type ([[basic.compound]]) is not cv-qualified by the
426
- cv-qualifiers (if any) of the types from which it is compounded. Any
427
- cv-qualifiers applied to an array type affect the array element type (
428
- [[dcl.array]]).
429
 
430
- See  [[dcl.fct]] and  [[class.this]] regarding function types that have
431
- *cv-qualifier*s.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
 
433
  There is a partial ordering on cv-qualifiers, so that a type can be said
434
- to be *more cv-qualified* than another. Table 
435
- [[tab:relations.on.const.and.volatile]] shows the relations that
436
- constitute this ordering.
437
 
438
- **Table: Relations on `const` and `volatile`** <a id="tab:relations.on.const.and.volatile">[tab:relations.on.const.and.volatile]</a>
439
 
440
  | | | |
441
  | --------------- | --- | ---------------- |
442
  | no cv-qualifier | < | `const` |
443
  | no cv-qualifier | < | `volatile` |
444
  | no cv-qualifier | < | `const volatile` |
445
  | `const` | < | `const volatile` |
446
  | `volatile` | < | `const volatile` |
447
 
448
 
449
- In this International Standard, the notation cv (or *cv1*, *cv2*, etc.),
450
- used in the description of types, represents an arbitrary set of
451
- cv-qualifiers, i.e., one of {`const`}, {`volatile`}, {`const`,
452
- `volatile`}, or the empty set. For a type cv `T`, the *top-level
453
- cv-qualifiers* of that type are those denoted by cv.
454
 
455
- [*Example 1*: The type corresponding to the *type-id* `const int&` has
456
  no top-level cv-qualifiers. The type corresponding to the *type-id*
457
  `volatile int * const` has the top-level cv-qualifier `const`. For a
458
  class type `C`, the type corresponding to the *type-id*
459
  `void (C::* volatile)(int) const` has the top-level cv-qualifier
460
  `volatile`. — *end example*]
461
 
462
- Cv-qualifiers applied to an array type attach to the underlying element
463
- type, so the notation “cv `T`”, where `T` is an array type, refers to an
464
- array whose elements are so-qualified. An array type whose elements are
465
- cv-qualified is also considered to have the same cv-qualifications as
466
- its elements.
467
 
468
- [*Example 2*:
469
 
470
- ``` cpp
471
- typedef char CA[5];
472
- typedef const char CC;
473
- CC arr1[5] = { 0 };
474
- const CA arr2 = { 0 };
475
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
476
 
477
- The type of both `arr1` and `arr2` is “array of 5 `const char`”, and the
478
- array type is considered to be const-qualified.
479
-
480
- — *end example*]
481
 
 
1
  ## Types <a id="basic.types">[[basic.types]]</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]]. [^18] If the content of that array is
14
+ copied back into the object, the object shall subsequently hold its
15
+ original value.
16
 
17
  [*Example 1*:
18
 
19
  ``` cpp
20
+ constexpr std::size_t N = sizeof(T);
21
  char buf[N];
22
  T obj; // obj initialized to its original value
23
  std::memcpy(buf, &obj, N); // between these two calls to std::memcpy, obj might be modified
24
  std::memcpy(&obj, buf, N); // at this point, each subobject of obj of scalar type holds its original value
25
  ```
26
 
27
  — *end example*]
28
 
29
  For any trivially copyable type `T`, if two pointers to `T` point to
30
  distinct `T` objects `obj1` and `obj2`, where neither `obj1` nor `obj2`
31
+ is a potentially-overlapping subobject, if the underlying bytes
32
+ [[intro.memory]] making up `obj1` are copied into `obj2`,[^19] `obj2`
33
+ shall subsequently hold the same value as `obj1`.
34
 
35
  [*Example 2*:
36
 
37
  ``` cpp
38
  T* t1p;
 
45
 
46
  — *end example*]
47
 
48
  The *object representation* of an object of type `T` is the sequence of
49
  *N* `unsigned char` objects taken up by the object of type `T`, where
50
+ *N* equals `sizeof(T)`. The *value representation* of an object of type
51
+ `T` is the set of bits that participate in representing a value of type
52
+ `T`. Bits in the object representation that are not part of the value
53
+ representation are *padding bits*. For trivially copyable types, the
54
+ value representation is a set of bits in the object representation that
55
+ determines a *value*, which is one discrete element of an
56
+ *implementation-defined* set of values.[^20]
57
 
58
  A class that has been declared but not defined, an enumeration type in
59
+ certain contexts [[dcl.enum]], or an array of unknown bound or of
60
  incomplete element type, is an *incompletely-defined object type*. [^21]
61
+ Incompletely-defined object types and cv `void` are *incomplete types*
62
+ [[basic.fundamental]]. Objects shall not be defined to have an
63
  incomplete type.
64
 
65
  A class type (such as “`class X`”) might be incomplete at one point in a
66
  translation unit and complete later on; the type “`class X`” is the same
67
  type at both points. The declared type of an array object might be an
 
85
  typedef int UNKA[]; // UNKA is an incomplete type
86
  UNKA* arrp; // arrp is a pointer to an incomplete type
87
  UNKA** arrpp;
88
 
89
  void foo() {
90
+ xp++; // error: X is incomplete
91
+ arrp++; // error: incomplete type
92
  arrpp++; // OK: sizeof UNKA* is known
93
  }
94
 
95
  struct X { int i; }; // now X is a complete type
96
  int arr[10]; // now the type of arr is complete
97
 
98
  X x;
99
  void bar() {
100
  xp = &x; // OK; type is ``pointer to X''
101
+ arrp = &arr; // error: different types
102
  xp++; // OK: X is complete
103
+ arrp++; // error: UNKA can't be completed
104
  }
105
  ```
106
 
107
  — *end example*]
108
 
 
110
  contexts incomplete types are prohibited. — *end note*]
111
 
112
  An *object type* is a (possibly cv-qualified) type that is not a
113
  function type, not a reference type, and not cv `void`.
114
 
115
+ Arithmetic types [[basic.fundamental]], enumeration types, pointer
116
+ types, pointer-to-member types [[basic.compound]], `std::nullptr_t`, and
117
+ cv-qualified [[basic.type.qualifier]] versions of these types are
118
+ collectively called *scalar types*. Scalar types, trivially copyable
119
+ class types [[class.prop]], arrays of such types, and cv-qualified
120
+ versions of these types are collectively called *trivially copyable
121
+ types*. Scalar types, trivial class types [[class.prop]], arrays of such
122
+ types and cv-qualified versions of these types are collectively called
123
+ *trivial types*. Scalar types, standard-layout class types
124
+ [[class.prop]], arrays of such types and cv-qualified versions of these
125
+ types are collectively called *standard-layout types*. Scalar types,
126
+ implicit-lifetime class types [[class.prop]], array types, and
127
+ cv-qualified versions of these types are collectively called
128
+ *implicit-lifetime types*.
129
 
130
  A type is a *literal type* if it is:
131
 
132
+ - cv `void`; or
133
  - a scalar type; or
134
  - a reference type; or
135
  - an array of literal type; or
136
+ - a possibly cv-qualified class type [[class]] that has all of the
137
+ following properties:
138
+ - it has a constexpr destructor [[dcl.constexpr]],
139
+ - it is either a closure type [[expr.prim.lambda.closure]], an
140
+ aggregate type [[dcl.init.aggr]], or has at least one constexpr
141
+ constructor or constructor template (possibly inherited
142
+ [[namespace.udecl]] from a base class) that is not a copy or move
143
  constructor,
144
  - if it is a union, at least one of its non-static data members is of
145
  non-volatile literal type, and
146
  - if it is not a union, all of its non-static data members and base
147
  classes are of non-volatile literal types.
148
 
149
  [*Note 3*: A literal type is one for which it might be possible to
150
  create an object within a constant expression. It is not a guarantee
151
  that it is possible to create such an object, nor is it a guarantee that
152
+ any object of that type will be usable in a constant
153
  expression. — *end note*]
154
 
155
  Two types *cv1* `T1` and *cv2* `T2` are *layout-compatible* types if
156
+ `T1` and `T2` are the same type, layout-compatible enumerations
157
+ [[dcl.enum]], or layout-compatible standard-layout class types
158
+ [[class.mem]].
159
 
160
  ### Fundamental types <a id="basic.fundamental">[[basic.fundamental]]</a>
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  There are five *standard signed integer types* : “`signed char`”,
163
  “`short int`”, “`int`”, “`long int`”, and “`long long int`”. In this
164
  list, each type provides at least as much storage as those preceding it
165
  in the list. There may also be *implementation-defined* *extended signed
166
  integer types*. The standard and extended signed integer types are
167
+ collectively called *signed integer types*. The range of representable
168
+ values for a signed integer type is -2ᴺ⁻¹ to 2ᴺ⁻¹-1 (inclusive), where
169
+ *N* is called the *width* of the type.
170
+
171
+ [*Note 1*: Plain `int`s are intended to have the natural width
172
+ suggested by the architecture of the execution environment; the other
173
+ signed integer types are provided to meet special needs. — *end note*]
174
 
175
  For each of the standard signed integer types, there exists a
176
  corresponding (but different) *standard unsigned integer type*:
177
  “`unsigned char`”, “`unsigned short int`”, “`unsigned int`”,
178
+ “`unsigned long int`”, and “`unsigned long long int`”. Likewise, for
179
+ each of the extended signed integer types, there exists a corresponding
180
+ *extended unsigned integer type*. The standard and extended unsigned
181
+ integer types are collectively called *unsigned integer types*. An
182
+ unsigned integer type has the same width *N* as the corresponding signed
183
+ integer type. The range of representable values for the unsigned type is
184
+ 0 to 2ᴺ-1 (inclusive); arithmetic for the unsigned type is performed
185
+ modulo 2ᴺ.
186
+
187
+ [*Note 2*: Unsigned arithmetic does not overflow. Overflow for signed
188
+ arithmetic yields undefined behavior [[expr.pre]]. *end note*]
189
+
190
+ An unsigned integer type has the same object representation, value
191
+ representation, and alignment requirements [[basic.align]] as the
192
+ corresponding signed integer type. For each value x of a signed integer
193
+ type, the value of the corresponding unsigned integer type congruent to
194
+ x modulo 2ᴺ has the same value of corresponding bits in its value
195
+ representation.[^22]
196
+
197
+ [*Example 1*: The value -1 of a signed integer type has the same
198
+ representation as the largest value of the corresponding unsigned
199
+ type. *end example*]
200
+
201
+ **Table: Minimum width** <a id="basic.fundamental.width">[basic.fundamental.width]</a>
202
+
203
+ | Type | Minimum width $N$ |
204
+ | ------------- | ----------------- |
205
+ | `signed char` | 8 |
206
+ | `short` | 16 |
207
+ | `int` | 16 |
208
+ | `long` | 32 |
209
+ | `long long` | 64 |
210
+
211
+
212
+ The width of each signed integer type shall not be less than the values
213
+ specified in [[basic.fundamental.width]]. The value representation of a
214
+ signed or unsigned integer type comprises N bits, where N is the
215
+ respective width. Each set of values for any padding bits
216
+ [[basic.types]] in the object representation are alternative
217
+ representations of the value specified by the value representation.
218
+
219
+ [*Note 3*: Padding bits have unspecified value, but cannot cause traps.
220
+ In contrast, see ISO C 6.2.6.2. — *end note*]
221
+
222
+ [*Note 4*: The signed and unsigned integer types satisfy the
223
+ constraints given in ISO C 5.2.4.2.1. — *end note*]
224
+
225
+ Except as specified above, the width of a signed or unsigned integer
226
+ type is *implementation-defined*.
227
+
228
+ Each value x of an unsigned integer type with width N has a unique
229
+ representation $x = x_0 2^0 + x_1 2^1 + \ldots + x_{N-1} 2^{N-1}$, where
230
+ each coefficient xᵢ is either 0 or 1; this is called the *base-2
231
+ representation* of x. The base-2 representation of a value of signed
232
+ integer type is the base-2 representation of the congruent value of the
233
+ corresponding unsigned integer type. The standard signed integer types
234
+ and standard unsigned integer types are collectively called the
235
+ *standard integer types*, and the extended signed integer types and
236
+ extended unsigned integer types are collectively called the *extended
237
+ integer types*.
238
+
239
+ A fundamental type specified to have a signed or unsigned integer type
240
+ as its *underlying type* has the same object representation, value
241
+ representation, alignment requirements [[basic.align]], and range of
242
+ representable values as the underlying type. Further, each value has the
243
+ same representation in both types.
244
+
245
+ Type `char` is a distinct type that has an *implementation-defined*
246
+ choice of “`signed char`” or “`unsigned char`” as its underlying type.
247
+ The values of type `char` can represent distinct codes for all members
248
+ of the implementation’s basic character set. The three types `char`,
249
+ `signed char`, and `unsigned char` are collectively called *ordinary
250
+ character types*. The ordinary character types and `char8_t` are
251
+ collectively called *narrow character types*. For narrow character
252
+ types, each possible bit pattern of the object representation represents
253
+ a distinct value.
254
+
255
+ [*Note 5*: This requirement does not hold for other
256
+ types. — *end note*]
257
+
258
+ [*Note 6*: A bit-field of narrow character type whose width is larger
259
+ than the width of that type has padding bits; see
260
+ [[basic.types]]. — *end note*]
261
+
262
+ Type `wchar_t` is a distinct type that has an *implementation-defined*
263
+ signed or unsigned integer type as its underlying type. The values of
264
+ type `wchar_t` can represent distinct codes for all members of the
265
+ largest extended character set specified among the supported locales
266
+ [[locale]].
267
+
268
+ Type `char8_t` denotes a distinct type whose underlying type is
269
+ `unsigned char`. Types `char16_t` and `char32_t` denote distinct types
270
+ whose underlying types are `uint_least16_t` and `uint_least32_t`,
271
+ respectively, in `<cstdint>`.
272
+
273
+ Type `bool` is a distinct type that has the same object representation,
274
+ value representation, and alignment requirements as an
275
+ *implementation-defined* unsigned integer type. The values of type
276
+ `bool` are `true` and `false`.
277
+
278
+ [*Note 7*: There are no `signed`, `unsigned`, `short`, or `long bool`
279
  types or values. — *end note*]
280
 
281
+ Types `bool`, `char`, `wchar_t`, `char8_t`, `char16_t`, `char32_t`, and
282
+ the signed and unsigned integer types are collectively called *integral
283
+ types*. A synonym for integral type is *integer type*.
284
 
285
+ [*Note 8*: Enumerations [[dcl.enum]] are not integral; however,
286
+ unscoped enumerations can be promoted to integral types as specified in
287
+ [[conv.prom]]. *end note*]
 
 
288
 
289
+ There are three *floating-point types*: `float`, `double`, and
 
 
 
 
290
  `long double`. The type `double` provides at least as much precision as
291
  `float`, and the type `long double` provides at least as much precision
292
  as `double`. The set of values of the type `float` is a subset of the
293
  set of values of the type `double`; the set of values of the type
294
  `double` is a subset of the set of values of the type `long double`. The
295
  value representation of floating-point types is
296
  *implementation-defined*.
297
 
298
+ [*Note 9*: This document imposes no requirements on the accuracy of
299
+ floating-point operations; see also  [[support.limits]]. — *end note*]
 
300
 
301
+ Integral and floating-point types are collectively called *arithmetic*
302
+ types. Specializations of the standard library template
303
+ `std::numeric_limits` [[support.limits]] shall specify the maximum and
304
+ minimum values of each arithmetic type for an implementation.
305
 
306
  A type cv `void` is an incomplete type that cannot be completed; such a
307
  type has an empty set of values. It is used as the return type for
308
  functions that do not return a value. Any expression can be explicitly
309
+ converted to type cv `void` ([[expr.type.conv]], [[expr.static.cast]],
310
+ [[expr.cast]]). An expression of type cv `void` shall be used only as an
311
+ expression statement [[stmt.expr]], as an operand of a comma expression
312
+ [[expr.comma]], as a second or third operand of `?:` [[expr.cond]], as
313
+ the operand of `typeid`, `noexcept`, or `decltype`, as the expression in
314
+ a `return` statement [[stmt.return]] for a function with the return type
315
  cv `void`, or as the operand of an explicit conversion to type
316
  cv `void`.
317
 
318
+ A value of type `std::nullptr_t` is a null pointer constant
319
+ [[conv.ptr]]. Such values participate in the pointer and the
320
+ pointer-to-member conversions ([[conv.ptr]], [[conv.mem]]).
321
  `sizeof(std::nullptr_t)` shall be equal to `sizeof(void*)`.
322
 
323
+ The types described in this subclause are called *fundamental types*.
324
+
325
+ [*Note 10*: Even if the implementation defines two or more fundamental
326
+ types to have the same value representation, they are nevertheless
327
+ different types. — *end note*]
328
 
329
  ### Compound types <a id="basic.compound">[[basic.compound]]</a>
330
 
331
  Compound types can be constructed in the following ways:
332
 
333
+ - *arrays* of objects of a given type, [[dcl.array]];
334
  - *functions*, which have parameters of given types and return `void` or
335
+ references or objects of a given type, [[dcl.fct]];
336
  - *pointers* to cv `void` or objects or functions (including static
337
+ members of classes) of a given type, [[dcl.ptr]];
338
+ - *references* to objects or functions of a given type, [[dcl.ref]].
339
  There are two types of references:
340
+ - lvalue reference
341
+ - rvalue reference
342
+ - *classes* containing a sequence of objects of various types [[class]],
343
+ a set of types, enumerations and functions for manipulating these
344
+ objects [[class.mfct]], and a set of restrictions on the access to
345
+ these entities [[class.access]];
 
346
  - *unions*, which are classes capable of containing objects of different
347
+ types at different times, [[class.union]];
348
  - *enumerations*, which comprise a set of named constant values. Each
349
+ distinct enumeration constitutes a different *enumerated type*,
350
  [[dcl.enum]];
351
+ - *pointers to non-static class members*, [^23] which identify members
352
+ of a given type within objects of a given class, [[dcl.mptr]].
353
+ Pointers to data members and pointers to member functions are
354
+ collectively called *pointer-to-member* types.
355
 
356
  These methods of constructing types can be applied recursively;
357
+ restrictions are mentioned in  [[dcl.meaning]]. Constructing a type such
358
+ that the number of bytes in its object representation exceeds the
359
+ maximum value representable in the type `std::size_t` [[support.types]]
360
+ is ill-formed.
361
 
362
  The type of a pointer to cv `void` or a pointer to an object type is
363
  called an *object pointer type*.
364
 
365
  [*Note 1*: A pointer to `void` does not have a pointer-to-object type,
366
  however, because `void` is not an object type. — *end note*]
367
 
368
  The type of a pointer that can designate a function is called a
369
+ *function pointer type*. A pointer to an object of type `T` is referred
370
+ to as a “pointer to `T`”.
371
 
372
  [*Example 1*: A pointer to an object of type `int` is referred to as
373
  “pointer to `int`” and a pointer to an object of class `X` is called a
374
  “pointer to `X`”. — *end example*]
375
 
376
  Except for pointers to static members, text referring to “pointers” does
377
  not apply to pointers to members. Pointers to incomplete types are
378
+ allowed although there are restrictions on what can be done with them
379
+ [[basic.align]]. Every value of pointer type is one of the following:
380
 
381
  - a *pointer to* an object or function (the pointer is said to *point*
382
  to the object or function), or
383
+ - a *pointer past the end of* an object [[expr.add]], or
384
+ - the *null pointer value* for that type, or
385
  - an *invalid pointer value*.
386
 
387
  A value of a pointer type that is a pointer to or past the end of an
388
+ object *represents the address* of the first byte in memory
389
+ [[intro.memory]] occupied by the object [^24] or the first byte in
390
  memory after the end of the storage occupied by the object,
391
  respectively.
392
 
393
+ [*Note 2*: A pointer past the end of an object [[expr.add]] is not
394
  considered to point to an unrelated object of the object’s type that
395
  might be located at that address. A pointer value becomes invalid when
396
  the storage it denotes reaches the end of its storage duration; see
397
  [[basic.stc]]. — *end note*]
398
 
399
+ For purposes of pointer arithmetic [[expr.add]] and comparison (
400
  [[expr.rel]], [[expr.eq]]), a pointer past the end of the last element
401
  of an array `x` of n elements is considered to be equivalent to a
402
+ pointer to a hypothetical array element n of `x` and an object of type
403
+ `T` that is not an array element is considered to belong to an array
404
+ with one element of type `T`. The value representation of pointer types
405
+ is *implementation-defined*. Pointers to layout-compatible types shall
406
+ have the same value representation and alignment requirements
407
+ [[basic.align]].
408
 
409
+ [*Note 3*: Pointers to over-aligned types [[basic.align]] have no
410
  special representation, but their range of valid values is restricted by
411
  the extended alignment requirement. — *end note*]
412
 
413
  Two objects *a* and *b* are *pointer-interconvertible* if:
414
 
415
  - they are the same object, or
416
+ - one is a union object and the other is a non-static data member of
417
+ that object [[class.union]], or
418
  - one is a standard-layout class object and the other is the first
419
  non-static data member of that object, or, if the object has no
420
+ non-static data members, any base class subobject of that object
421
+ [[class.mem]], or
422
  - there exists an object *c* such that *a* and *c* are
423
  pointer-interconvertible, and *c* and *b* are
424
  pointer-interconvertible.
425
 
426
  If two objects are pointer-interconvertible, then they have the same
427
  address, and it is possible to obtain a pointer to one from a pointer to
428
+ the other via a `reinterpret_cast` [[expr.reinterpret.cast]].
429
 
430
  [*Note 4*: An array object and its first element are not
431
  pointer-interconvertible, even though they have the same
432
  address. — *end note*]
433
 
434
+ A pointer to cv `void` can be used to point to objects of unknown type.
435
+ Such a pointer shall be able to hold any object pointer. An object of
436
+ type cv `void*` shall have the same representation and alignment
437
+ requirements as cv `char*`.
 
438
 
439
  ### CV-qualifiers <a id="basic.type.qualifier">[[basic.type.qualifier]]</a>
440
 
441
  A type mentioned in  [[basic.fundamental]] and  [[basic.compound]] is a
442
  *cv-unqualified type*. Each type which is a cv-unqualified complete or
443
+ incomplete object type or is `void` [[basic.types]] has three
444
  corresponding cv-qualified versions of its type: a *const-qualified*
445
  version, a *volatile-qualified* version, and a
446
+ *const-volatile-qualified* version. The type of an object
447
+ [[intro.object]] includes the *cv-qualifier*s specified in the
448
+ *decl-specifier-seq* [[dcl.spec]], *declarator* [[dcl.decl]], *type-id*
449
+ [[dcl.name]], or *new-type-id* [[expr.new]] when the object is created.
 
450
 
451
  - A *const object* is an object of type `const T` or a non-mutable
452
+ subobject of a const object.
453
+ - A *volatile object* is an object of type `volatile T` or a subobject
454
+ of a volatile object.
455
  - A *const volatile object* is an object of type `const volatile T`, a
456
+ non-mutable subobject of a const volatile object, a const subobject of
457
+ a volatile object, or a non-mutable volatile subobject of a const
458
  object.
459
 
460
  The cv-qualified or cv-unqualified versions of a type are distinct
461
  types; however, they shall have the same representation and alignment
462
+ requirements [[basic.align]].[^25]
463
 
464
+ Except for array types, a compound type [[basic.compound]] is not
465
+ cv-qualified by the cv-qualifiers (if any) of the types from which it is
466
+ compounded.
 
467
 
468
+ An array type whose elements are cv-qualified is also considered to have
469
+ the same cv-qualifications as its elements.
470
+
471
+ [*Note 1*: Cv-qualifiers applied to an array type attach to the
472
+ underlying element type, so the notation “cv `T`”, where `T` is an array
473
+ type, refers to an array whose elements are so-qualified
474
+ [[dcl.array]]. — *end note*]
475
+
476
+ [*Example 1*:
477
+
478
+ ``` cpp
479
+ typedef char CA[5];
480
+ typedef const char CC;
481
+ CC arr1[5] = { 0 };
482
+ const CA arr2 = { 0 };
483
+ ```
484
+
485
+ The type of both `arr1` and `arr2` is “array of 5 `const char`”, and the
486
+ array type is considered to be const-qualified.
487
+
488
+ — *end example*]
489
+
490
+ [*Note 2*: See  [[dcl.fct]] and  [[class.this]] regarding function
491
+ types that have *cv-qualifier*s. — *end note*]
492
 
493
  There is a partial ordering on cv-qualifiers, so that a type can be said
494
+ to be *more cv-qualified* than another. [[basic.type.qualifier.rel]]
495
+ shows the relations that constitute this ordering.
 
496
 
497
+ **Table: Relations on `const` and `volatile`** <a id="basic.type.qualifier.rel">[basic.type.qualifier.rel]</a>
498
 
499
  | | | |
500
  | --------------- | --- | ---------------- |
501
  | no cv-qualifier | < | `const` |
502
  | no cv-qualifier | < | `volatile` |
503
  | no cv-qualifier | < | `const volatile` |
504
  | `const` | < | `const volatile` |
505
  | `volatile` | < | `const volatile` |
506
 
507
 
508
+ In this document, the notation cv (or *cv1*, *cv2*, etc.), used in the
509
+ description of types, represents an arbitrary set of cv-qualifiers,
510
+ i.e., one of {`const`}, {`volatile`}, {`const`, `volatile`}, or the
511
+ empty set. For a type cv `T`, the *top-level cv-qualifiers* of that type
512
+ are those denoted by cv.
513
 
514
+ [*Example 2*: The type corresponding to the *type-id* `const int&` has
515
  no top-level cv-qualifiers. The type corresponding to the *type-id*
516
  `volatile int * const` has the top-level cv-qualifier `const`. For a
517
  class type `C`, the type corresponding to the *type-id*
518
  `void (C::* volatile)(int) const` has the top-level cv-qualifier
519
  `volatile`. — *end example*]
520
 
521
+ ### Integer conversion rank <a id="conv.rank">[[conv.rank]]</a>
 
 
 
 
522
 
523
+ Every integer type has an *integer conversion rank* defined as follows:
524
 
525
+ - No two signed integer types other than `char` and `signed
526
+ char` (if `char` is signed) shall have the same rank, even if they
527
+ have the same representation.
528
+ - The rank of a signed integer type shall be greater than the rank of
529
+ any signed integer type with a smaller width.
530
+ - The rank of `long long int` shall be greater than the rank of
531
+ `long int`, which shall be greater than the rank of `int`, which shall
532
+ be greater than the rank of `short int`, which shall be greater than
533
+ the rank of `signed char`.
534
+ - The rank of any unsigned integer type shall equal the rank of the
535
+ corresponding signed integer type.
536
+ - The rank of any standard integer type shall be greater than the rank
537
+ of any extended integer type with the same width.
538
+ - The rank of `char` shall equal the rank of `signed char` and
539
+ `unsigned char`.
540
+ - The rank of `bool` shall be less than the rank of all other standard
541
+ integer types.
542
+ - The ranks of `char8_t`, `char16_t`, `char32_t`, and `wchar_t` shall
543
+ equal the ranks of their underlying types [[basic.fundamental]].
544
+ - The rank of any extended signed integer type relative to another
545
+ extended signed integer type with the same width is
546
+ *implementation-defined*, but still subject to the other rules for
547
+ determining the integer conversion rank.
548
+ - For all integer types `T1`, `T2`, and `T3`, if `T1` has greater rank
549
+ than `T2` and `T2` has greater rank than `T3`, then `T1` shall have
550
+ greater rank than `T3`.
551
 
552
+ [*Note 1*: The integer conversion rank is used in the definition of the
553
+ integral promotions [[conv.prom]] and the usual arithmetic conversions
554
+ [[expr.arith.conv]]. — *end note*]
 
555