From Jason Turner

[basic.types]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp8hw1cylt/{from.md → to.md} +264 -137
tmp/tmp8hw1cylt/{from.md → to.md} RENAMED
@@ -1,20 +1,23 @@
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);
@@ -24,15 +27,16 @@ std::memcpy(buf, &obj, N); // between these two calls to std::memcpy, obj m
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;
@@ -51,32 +55,38 @@ The *object representation* of an object of type `T` is the sequence of
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
68
  array of incomplete class type and therefore incomplete; if the class
69
  type is completed later on in the translation unit, the array type
70
  becomes complete; the array type at those two points is the same type.
71
- The declared type of an array object might be an array of unknown bound
72
  and therefore be incomplete at one point in a translation unit and
73
  complete later on; the array types at those two points (“array of
74
- unknown bound of `T`” and “array of `N` `T`”) are different types. The
75
- type of a pointer to array of unknown bound, or of a type defined by a
76
- `typedef` declaration to be an array of unknown bound, cannot be
77
- completed.
 
 
 
78
 
79
  [*Example 3*:
80
 
81
  ``` cpp
82
  class X; // X is an incomplete type
@@ -87,28 +97,28 @@ 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
 
109
- [*Note 2*: The rules for declarations and expressions describe in which
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
 
@@ -134,27 +144,30 @@ A type is a *literal type* if it is:
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>
@@ -190,32 +203,32 @@ arithmetic yields undefined behavior [[expr.pre]]. — *end note*]
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
 
@@ -242,30 +255,25 @@ 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>`.
@@ -276,58 +284,140 @@ value representation, and alignment requirements as an
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]];
@@ -343,17 +433,16 @@ Compound types can be constructed in the following ways:
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]]
@@ -384,28 +473,29 @@ allowed although there are restrictions on what can be done with them
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*]
@@ -414,13 +504,12 @@ 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
@@ -429,48 +518,53 @@ 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*:
@@ -485,12 +579,12 @@ const CA arr2 = { 0 };
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
 
@@ -516,40 +610,73 @@ 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ## Types <a id="basic.types">[[basic.types]]</a>
2
 
3
+ ### General <a id="basic.types.general">[[basic.types.general]]</a>
4
+
5
  [*Note 1*: [[basic.types]] and the subclauses thereof impose
6
  requirements on implementations regarding the representation of types.
7
  There are two kinds of types: fundamental types and compound types.
8
  Types describe objects [[intro.object]], references [[dcl.ref]], or
9
  functions [[dcl.fct]]. — *end note*]
10
 
11
  For any object (other than a potentially-overlapping subobject) of
12
  trivially copyable type `T`, whether or not the object holds a valid
13
  value of type `T`, the underlying bytes [[intro.memory]] making up the
14
  object can be copied into an array of `char`, `unsigned char`, or
15
+ `std::byte` [[cstddef.syn]].[^14]
16
+
17
+ If the content of that array is copied back into the object, the object
18
+ shall subsequently hold its original value.
19
 
20
  [*Example 1*:
21
 
22
  ``` cpp
23
  constexpr std::size_t N = sizeof(T);
 
27
  std::memcpy(&obj, buf, N); // at this point, each subobject of obj of scalar type holds its original value
28
  ```
29
 
30
  — *end example*]
31
 
32
+ For two distinct objects `obj1` and `obj2` of trivially copyable type
33
+ `T`, where neither `obj1` nor `obj2` is a potentially-overlapping
34
+ subobject, if the underlying bytes [[intro.memory]] making up `obj1` are
35
+ copied into `obj2`,[^15]
36
+
37
+ `obj2` shall subsequently hold the same value as `obj1`.
38
 
39
  [*Example 2*:
40
 
41
  ``` cpp
42
  T* t1p;
 
55
  `T` is the set of bits that participate in representing a value of type
56
  `T`. Bits in the object representation that are not part of the value
57
  representation are *padding bits*. For trivially copyable types, the
58
  value representation is a set of bits in the object representation that
59
  determines a *value*, which is one discrete element of an
60
+ *implementation-defined* set of values.[^16]
61
 
62
  A class that has been declared but not defined, an enumeration type in
63
  certain contexts [[dcl.enum]], or an array of unknown bound or of
64
+ incomplete element type, is an *incompletely-defined object type*.[^17]
65
+
66
  Incompletely-defined object types and cv `void` are *incomplete types*
67
+ [[basic.fundamental]].
 
68
 
69
+ [*Note 2*: Objects cannot be defined to have an incomplete type
70
+ [[basic.def]]. — *end note*]
71
+
72
+ A class type (such as “`class X`”) can be incomplete at one point in a
73
  translation unit and complete later on; the type “`class X`” is the same
74
+ type at both points. The declared type of an array object can be an
75
  array of incomplete class type and therefore incomplete; if the class
76
  type is completed later on in the translation unit, the array type
77
  becomes complete; the array type at those two points is the same type.
78
+ The declared type of an array object can be an array of unknown bound
79
  and therefore be incomplete at one point in a translation unit and
80
  complete later on; the array types at those two points (“array of
81
+ unknown bound of `T`” and “array of `N` `T`”) are different types.
82
+
83
+ [*Note 3*: The type of a pointer or reference to array of unknown bound
84
+ permanently points to or refers to an incomplete type. An array of
85
+ unknown bound named by a `typedef` declaration permanently refers to an
86
+ incomplete type. In either case, the array type cannot be
87
+ completed. — *end note*]
88
 
89
  [*Example 3*:
90
 
91
  ``` cpp
92
  class X; // X is an incomplete type
 
97
  UNKA** arrpp;
98
 
99
  void foo() {
100
  xp++; // error: X is incomplete
101
  arrp++; // error: incomplete type
102
+ arrpp++; // OK, sizeof UNKA* is known
103
  }
104
 
105
  struct X { int i; }; // now X is a complete type
106
  int arr[10]; // now the type of arr is complete
107
 
108
  X x;
109
  void bar() {
110
  xp = &x; // OK; type is ``pointer to X''
111
+ arrp = &arr; // OK; qualification conversion[conv.qual]
112
+ xp++; // OK, X is complete
113
  arrp++; // error: UNKA can't be completed
114
  }
115
  ```
116
 
117
  — *end example*]
118
 
119
+ [*Note 4*: The rules for declarations and expressions describe in which
120
  contexts incomplete types are prohibited. — *end note*]
121
 
122
  An *object type* is a (possibly cv-qualified) type that is not a
123
  function type, not a reference type, and not cv `void`.
124
 
 
144
  - a reference type; or
145
  - an array of literal type; or
146
  - a possibly cv-qualified class type [[class]] that has all of the
147
  following properties:
148
  - it has a constexpr destructor [[dcl.constexpr]],
149
+ - all of its non-static non-variant data members and base classes are
150
+ of non-volatile literal types, and
151
+ - it
152
+ - is a closure type [[expr.prim.lambda.closure]],
153
+ - is an aggregate union type that has either no variant members or
154
+ at least one variant member of non-volatile literal type,
155
+ - is a non-union aggregate type for which each of its anonymous
156
+ union members satisfies the above requirements for an aggregate
157
+ union type, or
158
+ - has at least one constexpr constructor or constructor template
159
+ (possibly inherited [[namespace.udecl]] from a base class) that is
160
+ not a copy or move constructor.
161
 
162
+ [*Note 5*: A literal type is one for which it might be possible to
163
  create an object within a constant expression. It is not a guarantee
164
  that it is possible to create such an object, nor is it a guarantee that
165
  any object of that type will be usable in a constant
166
  expression. — *end note*]
167
 
168
+ Two types *cv1* `T1` and *cv2* `T2` are *layout-compatible types* if
169
  `T1` and `T2` are the same type, layout-compatible enumerations
170
  [[dcl.enum]], or layout-compatible standard-layout class types
171
  [[class.mem]].
172
 
173
  ### Fundamental types <a id="basic.fundamental">[[basic.fundamental]]</a>
 
203
  An unsigned integer type has the same object representation, value
204
  representation, and alignment requirements [[basic.align]] as the
205
  corresponding signed integer type. For each value x of a signed integer
206
  type, the value of the corresponding unsigned integer type congruent to
207
  x modulo 2ᴺ has the same value of corresponding bits in its value
208
+ representation.[^18]
209
 
210
  [*Example 1*: The value -1 of a signed integer type has the same
211
  representation as the largest value of the corresponding unsigned
212
  type. — *end example*]
213
 
214
  **Table: Minimum width** <a id="basic.fundamental.width">[basic.fundamental.width]</a>
215
 
216
  | Type | Minimum width $N$ |
217
+ | --------------- | ----------------- |
218
  | `signed char` | 8 |
219
+ | `short int` | 16 |
220
  | `int` | 16 |
221
+ | `long int` | 32 |
222
+ | `long long int` | 64 |
223
 
224
 
225
  The width of each signed integer type shall not be less than the values
226
  specified in [[basic.fundamental.width]]. The value representation of a
227
  signed or unsigned integer type comprises N bits, where N is the
228
  respective width. Each set of values for any padding bits
229
+ [[basic.types.general]] in the object representation are alternative
230
  representations of the value specified by the value representation.
231
 
232
  [*Note 3*: Padding bits have unspecified value, but cannot cause traps.
233
  In contrast, see ISO C 6.2.6.2. — *end note*]
234
 
 
255
  representable values as the underlying type. Further, each value has the
256
  same representation in both types.
257
 
258
  Type `char` is a distinct type that has an *implementation-defined*
259
  choice of “`signed char`” or “`unsigned char`” as its underlying type.
260
+ The three types `char`, `signed char`, and `unsigned char` are
261
+ collectively called *ordinary character types*. The ordinary character
262
+ types and `char8_t` are collectively called *narrow character types*.
263
+ For narrow character types, each possible bit pattern of the object
264
+ representation represents a distinct value.
 
 
265
 
266
  [*Note 5*: This requirement does not hold for other
267
  types. — *end note*]
268
 
269
  [*Note 6*: A bit-field of narrow character type whose width is larger
270
  than the width of that type has padding bits; see
271
+ [[basic.types.general]]. — *end note*]
272
 
273
  Type `wchar_t` is a distinct type that has an *implementation-defined*
274
+ signed or unsigned integer type as its underlying type.
 
 
 
275
 
276
  Type `char8_t` denotes a distinct type whose underlying type is
277
  `unsigned char`. Types `char16_t` and `char32_t` denote distinct types
278
  whose underlying types are `uint_least16_t` and `uint_least32_t`,
279
  respectively, in `<cstdint>`.
 
284
  `bool` are `true` and `false`.
285
 
286
  [*Note 7*: There are no `signed`, `unsigned`, `short`, or `long bool`
287
  types or values. — *end note*]
288
 
289
+ The types `char`, `wchar_t`, `char8_t`, `char16_t`, and `char32_t` are
290
+ collectively called *character types*. The character types, `bool`, the
291
+ signed and unsigned integer types, and cv-qualified versions
292
+ [[basic.type.qualifier]] thereof, are collectively termed *integral
293
  types*. A synonym for integral type is *integer type*.
294
 
295
  [*Note 8*: Enumerations [[dcl.enum]] are not integral; however,
296
  unscoped enumerations can be promoted to integral types as specified in
297
  [[conv.prom]]. — *end note*]
298
 
299
+ The three distinct types `float`, `double`, and `long double` can
300
+ represent floating-point numbers. The type `double` provides at least as
301
+ much precision as `float`, and the type `long double` provides at least
302
+ as much precision as `double`. The set of values of the type `float` is
303
+ a subset of the set of values of the type `double`; the set of values of
304
+ the type `double` is a subset of the set of values of the type
305
+ `long double`. The types `float`, `double`, and `long double`, and
306
+ cv-qualified versions [[basic.type.qualifier]] thereof, are collectively
307
+ termed *standard floating-point types*. An implementation may also
308
+ provide additional types that represent floating-point values and define
309
+ them (and cv-qualified versions thereof) to be *extended floating-point
310
+ types*. The standard and extended floating-point types are collectively
311
+ termed *floating-point types*.
312
+
313
+ [*Note 9*: Any additional implementation-specific types representing
314
+ floating-point values that are not defined by the implementation to be
315
+ extended floating-point types are not considered to be floating-point
316
+ types, and this document imposes no requirements on them or their
317
+ interactions with floating-point types. — *end note*]
318
+
319
+ Except as specified in [[basic.extended.fp]], the object and value
320
+ representations and accuracy of operations of floating-point types are
321
  *implementation-defined*.
322
 
323
+ Integral and floating-point types are collectively termed *arithmetic
324
+ types*.
325
 
326
+ [*Note 10*: Properties of the arithmetic types, such as their minimum
327
+ and maximum representable value, can be queried using the facilities in
328
+ the standard library headers `<limits>`, `<climits>`, and
329
+ `<cfloat>`. *end note*]
330
 
331
  A type cv `void` is an incomplete type that cannot be completed; such a
332
  type has an empty set of values. It is used as the return type for
333
  functions that do not return a value. Any expression can be explicitly
334
+ converted to type cv `void`
335
+ [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]]. An expression
336
+ of type cv `void` shall be used only as an expression statement
337
+ [[stmt.expr]], as an operand of a comma expression [[expr.comma]], as a
338
+ second or third operand of `?:` [[expr.cond]], as the operand of
339
+ `typeid`, `noexcept`, or `decltype`, as the expression in a `return`
340
+ statement [[stmt.return]] for a function with the return type cv `void`,
341
+ or as the operand of an explicit conversion to type cv `void`.
342
 
343
  A value of type `std::nullptr_t` is a null pointer constant
344
  [[conv.ptr]]. Such values participate in the pointer and the
345
+ pointer-to-member conversions [[conv.ptr]], [[conv.mem]].
346
  `sizeof(std::nullptr_t)` shall be equal to `sizeof(void*)`.
347
 
348
  The types described in this subclause are called *fundamental types*.
349
 
350
+ [*Note 11*: Even if the implementation defines two or more fundamental
351
  types to have the same value representation, they are nevertheless
352
  different types. — *end note*]
353
 
354
+ ### Optional extended floating-point types <a id="basic.extended.fp">[[basic.extended.fp]]</a>
355
+
356
+ If the implementation supports an extended floating-point type
357
+ [[basic.fundamental]] whose properties are specified by the ISO/IEC/IEEE
358
+ 60559 floating-point interchange format binary16, then the
359
+ *typedef-name* `std::float16_t` is defined in the header `<stdfloat>`
360
+ and names such a type, the macro `__STDCPP_FLOAT16_T__` is defined
361
+ [[cpp.predefined]], and the floating-point literal suffixes `f16` and
362
+ `F16` are supported [[lex.fcon]].
363
+
364
+ If the implementation supports an extended floating-point type whose
365
+ properties are specified by the ISO/IEC/IEEE 60559 floating-point
366
+ interchange format binary32, then the *typedef-name* `std::float32_t` is
367
+ defined in the header `<stdfloat>` and names such a type, the macro
368
+ `__STDCPP_FLOAT32_T__` is defined, and the floating-point literal
369
+ suffixes `f32` and `F32` are supported.
370
+
371
+ If the implementation supports an extended floating-point type whose
372
+ properties are specified by the ISO/IEC/IEEE 60559 floating-point
373
+ interchange format binary64, then the *typedef-name* `std::float64_t` is
374
+ defined in the header `<stdfloat>` and names such a type, the macro
375
+ `__STDCPP_FLOAT64_T__` is defined, and the floating-point literal
376
+ suffixes `f64` and `F64` are supported.
377
+
378
+ If the implementation supports an extended floating-point type whose
379
+ properties are specified by the ISO/IEC/IEEE 60559 floating-point
380
+ interchange format binary128, then the *typedef-name* `std::float128_t`
381
+ is defined in the header `<stdfloat>` and names such a type, the macro
382
+ `__STDCPP_FLOAT128_T__` is defined, and the floating-point literal
383
+ suffixes `f128` and `F128` are supported.
384
+
385
+ If the implementation supports an extended floating-point type with the
386
+ properties, as specified by ISO/IEC/IEEE 60559, of radix (b) of 2,
387
+ storage width in bits (k) of 16, precision in bits (p) of 8, maximum
388
+ exponent (emax) of 127, and exponent field width in bits (w) of 8, then
389
+ the *typedef-name* `std::bfloat16_t` is defined in the header
390
+ `<stdfloat>` and names such a type, the macro `__STDCPP_BFLOAT16_T__` is
391
+ defined, and the floating-point literal suffixes `bf16` and `BF16` are
392
+ supported.
393
+
394
+ [*Note 1*: A summary of the parameters for each type is given in
395
+ [[basic.extended.fp]]. The precision p includes the implicit 1 bit at
396
+ the beginning of the mantissa, so the storage used for the mantissa is
397
+ p-1 bits. ISO/IEC/IEEE 60559 does not assign a name for a type having
398
+ the parameters specified for `std::bfloat16_t`. — *end note*]
399
+
400
+ **Table: Properties of named extended floating-point types** <a id="basic.extended.fp">[basic.extended.fp]</a>
401
+
402
+ | Parameter | `float16_t` | `float32_t` | `float64_t` | `float128_t` | `bfloat16_t` |
403
+ | --------------------------------- | ----------- | ----------- | ----------- | ------------ | ------------ |
404
+ | ISO/IEC/IEEE 60559 name | binary16 | binary32 | binary64 | binary128 | |
405
+ | $k$, storage width in bits | 16 | 32 | 64 | 128 | 16 |
406
+ | $p$, precision in bits | 11 | 24 | 53 | 113 | 8 |
407
+ | $emax$, maximum exponent | 15 | 127 | 1023 | 16383 | 127 |
408
+ | $w$, exponent field width in bits | 5 | 8 | 11 | 15 | 8 |
409
+
410
+
411
+ *Recommended practice:* Any names that the implementation provides for
412
+ the extended floating-point types described in this subsection that are
413
+ in addition to the names defined in the `<stdfloat>` header should be
414
+ chosen to increase compatibility and interoperability with the
415
+ interchange types `_Float16`, `_Float32`, `_Float64`, and `_Float128`
416
+ defined in ISO/IEC TS 18661-3 and with future versions of the C
417
+ standard.
418
+
419
  ### Compound types <a id="basic.compound">[[basic.compound]]</a>
420
 
421
  Compound types can be constructed in the following ways:
422
 
423
  - *arrays* of objects of a given type, [[dcl.array]];
 
433
  a set of types, enumerations and functions for manipulating these
434
  objects [[class.mfct]], and a set of restrictions on the access to
435
  these entities [[class.access]];
436
  - *unions*, which are classes capable of containing objects of different
437
  types at different times, [[class.union]];
438
+ - *enumerations*, which comprise a set of named constant values,
 
439
  [[dcl.enum]];
440
+ - *pointers to non-static class members*,[^19] which identify members of
441
+ a given type within objects of a given class, [[dcl.mptr]]. Pointers
442
+ to data members and pointers to member functions are collectively
443
+ called *pointer-to-member* types.
444
 
445
  These methods of constructing types can be applied recursively;
446
  restrictions are mentioned in  [[dcl.meaning]]. Constructing a type such
447
  that the number of bytes in its object representation exceeds the
448
  maximum value representable in the type `std::size_t` [[support.types]]
 
473
  - the *null pointer value* for that type, or
474
  - an *invalid pointer value*.
475
 
476
  A value of a pointer type that is a pointer to or past the end of an
477
  object *represents the address* of the first byte in memory
478
+ [[intro.memory]] occupied by the object[^20]
479
+
480
+ or the first byte in memory after the end of the storage occupied by the
481
+ object, respectively.
482
 
483
  [*Note 2*: A pointer past the end of an object [[expr.add]] is not
484
+ considered to point to an unrelated object of the object’s type, even if
485
+ the unrelated object is located at that address. A pointer value becomes
486
+ invalid when the storage it denotes reaches the end of its storage
487
+ duration; see [[basic.stc]]. — *end note*]
488
 
489
+ For purposes of pointer arithmetic [[expr.add]] and comparison
490
+ [[expr.rel]], [[expr.eq]], a pointer past the end of the last element of
491
+ an array `x` of n elements is considered to be equivalent to a pointer
492
+ to a hypothetical array element n of `x` and an object of type `T` that
493
+ is not an array element is considered to belong to an array with one
494
+ element of type `T`. The value representation of pointer types is
495
+ *implementation-defined*. Pointers to layout-compatible types shall have
496
+ the same value representation and alignment requirements
497
  [[basic.align]].
498
 
499
  [*Note 3*: Pointers to over-aligned types [[basic.align]] have no
500
  special representation, but their range of valid values is restricted by
501
  the extended alignment requirement. — *end note*]
 
504
 
505
  - they are the same object, or
506
  - one is a union object and the other is a non-static data member of
507
  that object [[class.union]], or
508
  - one is a standard-layout class object and the other is the first
509
+ non-static data member of that object or any base class subobject of
510
+ that object [[class.mem]], or
 
511
  - there exists an object *c* such that *a* and *c* are
512
  pointer-interconvertible, and *c* and *b* are
513
  pointer-interconvertible.
514
 
515
  If two objects are pointer-interconvertible, then they have the same
 
518
 
519
  [*Note 4*: An array object and its first element are not
520
  pointer-interconvertible, even though they have the same
521
  address. — *end note*]
522
 
523
+ A byte of storage *b* is *reachable through* a pointer value that points
524
+ to an object *x* if there is an object *y*, pointer-interconvertible
525
+ with *x*, such that *b* is within the storage occupied by *y*, or the
526
+ immediately-enclosing array object if *y* is an array element.
527
+
528
  A pointer to cv `void` can be used to point to objects of unknown type.
529
  Such a pointer shall be able to hold any object pointer. An object of
530
+ type “pointer to cv `void` shall have the same representation and
531
+ alignment requirements as an object of type “pointer to cv `char`.
532
 
533
  ### CV-qualifiers <a id="basic.type.qualifier">[[basic.type.qualifier]]</a>
534
 
535
+ Each type other than a function or reference type is part of a group of
536
+ four distinct, but related, types: a *cv-unqualified* version, a
537
+ *const-qualified* version, a *volatile-qualified* version, and a
538
+ *const-volatile-qualified* version. The types in each such group shall
539
+ have the same representation and alignment requirements
540
+ [[basic.align]].[^21]
541
+
542
+ A function or reference type is always cv-unqualified.
 
543
 
544
  - A *const object* is an object of type `const T` or a non-mutable
545
  subobject of a const object.
546
  - A *volatile object* is an object of type `volatile T` or a subobject
547
  of a volatile object.
548
  - A *const volatile object* is an object of type `const volatile T`, a
549
  non-mutable subobject of a const volatile object, a const subobject of
550
  a volatile object, or a non-mutable volatile subobject of a const
551
  object.
552
 
553
+ [*Note 1*: The type of an object [[intro.object]] includes the
554
+ *cv-qualifier*s specified in the *decl-specifier-seq* [[dcl.spec]],
555
+ *declarator* [[dcl.decl]], *type-id* [[dcl.name]], or *new-type-id*
556
+ [[expr.new]] when the object is created. — *end note*]
557
 
558
  Except for array types, a compound type [[basic.compound]] is not
559
  cv-qualified by the cv-qualifiers (if any) of the types from which it is
560
  compounded.
561
 
562
  An array type whose elements are cv-qualified is also considered to have
563
  the same cv-qualifications as its elements.
564
 
565
+ [*Note 2*: Cv-qualifiers applied to an array type attach to the
566
  underlying element type, so the notation “cv `T`”, where `T` is an array
567
  type, refers to an array whose elements are so-qualified
568
  [[dcl.array]]. — *end note*]
569
 
570
  [*Example 1*:
 
579
  The type of both `arr1` and `arr2` is “array of 5 `const char`”, and the
580
  array type is considered to be const-qualified.
581
 
582
  — *end example*]
583
 
584
+ [*Note 3*: See  [[dcl.fct]] and  [[over.match.funcs]] regarding
585
+ function types that have *cv-qualifier*s. — *end note*]
586
 
587
  There is a partial ordering on cv-qualifiers, so that a type can be said
588
  to be *more cv-qualified* than another. [[basic.type.qualifier.rel]]
589
  shows the relations that constitute this ordering.
590
 
 
610
  `volatile int * const` has the top-level cv-qualifier `const`. For a
611
  class type `C`, the type corresponding to the *type-id*
612
  `void (C::* volatile)(int) const` has the top-level cv-qualifier
613
  `volatile`. — *end example*]
614
 
615
+ ### Conversion ranks <a id="conv.rank">[[conv.rank]]</a>
616
 
617
  Every integer type has an *integer conversion rank* defined as follows:
618
 
619
  - No two signed integer types other than `char` and `signed
620
+ char` (if `char` is signed) have the same rank, even if they have the
621
+ same representation.
622
+ - The rank of a signed integer type is greater than the rank of any
623
+ signed integer type with a smaller width.
624
+ - The rank of `long long int` is greater than the rank of `long int`,
625
+ which is greater than the rank of `int`, which is greater than the
626
+ rank of `short int`, which is greater than the rank of `signed char`.
627
+ - The rank of any unsigned integer type equals the rank of the
 
628
  corresponding signed integer type.
629
+ - The rank of any standard integer type is greater than the rank of any
630
+ extended integer type with the same width.
631
+ - The rank of `char` equals the rank of `signed char` and
632
  `unsigned char`.
633
+ - The rank of `bool` is less than the rank of all standard integer
634
+ types.
635
+ - The ranks of `char8_t`, `char16_t`, `char32_t`, and `wchar_t` equal
636
+ the ranks of their underlying types [[basic.fundamental]].
637
  - The rank of any extended signed integer type relative to another
638
  extended signed integer type with the same width is
639
  *implementation-defined*, but still subject to the other rules for
640
  determining the integer conversion rank.
641
  - For all integer types `T1`, `T2`, and `T3`, if `T1` has greater rank
642
+ than `T2` and `T2` has greater rank than `T3`, then `T1` has greater
643
+ rank than `T3`.
644
 
645
  [*Note 1*: The integer conversion rank is used in the definition of the
646
  integral promotions [[conv.prom]] and the usual arithmetic conversions
647
  [[expr.arith.conv]]. — *end note*]
648
 
649
+ Every floating-point type has a *floating-point conversion rank* defined
650
+ as follows:
651
+
652
+ - The rank of a floating point type `T` is greater than the rank of any
653
+ floating-point type whose set of values is a proper subset of the set
654
+ of values of `T`.
655
+ - The rank of `long double` is greater than the rank of `double`, which
656
+ is greater than the rank of `float`.
657
+ - Two extended floating-point types with the same set of values have
658
+ equal ranks.
659
+ - An extended floating-point type with the same set of values as exactly
660
+ one cv-unqualified standard floating-point type has a rank equal to
661
+ the rank of that standard floating-point type.
662
+ - An extended floating-point type with the same set of values as more
663
+ than one cv-unqualified standard floating-point type has a rank equal
664
+ to the rank of `double`.
665
+
666
+ [*Note 2*: The conversion ranks of floating-point types `T1` and `T2`
667
+ are unordered if the set of values of `T1` is neither a subset nor a
668
+ superset of the set of values of `T2`. This can happen when one type has
669
+ both a larger range and a lower precision than the other. — *end note*]
670
+
671
+ Floating-point types that have equal floating-point conversion ranks are
672
+ ordered by floating-point conversion subrank. The subrank forms a total
673
+ order among types with equal ranks. The types `std::float16_t`,
674
+ `std::float32_t`, `std::float64_t`, and `std::float128_t`
675
+ [[stdfloat.syn]] have a greater conversion subrank than any standard
676
+ floating-point type with equal conversion rank. Otherwise, the
677
+ conversion subrank order is *implementation-defined*.
678
+
679
+ [*Note 3*: The floating-point conversion rank and subrank are used in
680
+ the definition of the usual arithmetic conversions
681
+ [[expr.arith.conv]]. — *end note*]
682
+