From Jason Turner

[expr.sizeof]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp93f_zmsn/{from.md → to.md} +33 -37
tmp/tmp93f_zmsn/{from.md → to.md} RENAMED
@@ -1,48 +1,43 @@
1
- ### Sizeof <a id="expr.sizeof">[[expr.sizeof]]</a>
2
 
3
- The `sizeof` operator yields the number of bytes in the object
4
- representation of its operand. The operand is either an expression,
5
- which is an unevaluated operand (Clause  [[expr]]), or a parenthesized
6
- *type-id*. The `sizeof` operator shall not be applied to an expression
7
- that has function or incomplete type, to the parenthesized name of such
8
- types, or to a glvalue that designates a bit-field. `sizeof(char)`,
9
- `sizeof(signed char)` and `sizeof(unsigned char)` are `1`. The result of
10
- `sizeof` applied to any other fundamental type ([[basic.fundamental]])
11
- is *implementation-defined*.
12
 
13
  [*Note 1*: In particular, `sizeof(bool)`, `sizeof(char16_t)`,
14
  `sizeof(char32_t)`, and `sizeof(wchar_t)` are
15
- implementation-defined.[^16] — *end note*]
16
 
17
- [*Note 2*: See  [[intro.memory]] for the definition of *byte* and 
18
- [[basic.types]] for the definition of *object
19
- representation*. — *end note*]
20
 
21
- When applied to a reference or a reference type, the result is the size
22
- of the referenced type. When applied to a class, the result is the
23
- number of bytes in an object of that class including any padding
24
- required for placing objects of that type in an array. The size of a
25
- most derived class shall be greater than zero ([[intro.object]]). The
26
- result of applying `sizeof` to a base class subobject is the size of the
27
- base class type.[^17] When applied to an array, the result is the total
28
- number of bytes in the array. This implies that the size of an array of
29
- *n* elements is *n* times the size of an element.
30
 
31
- The `sizeof` operator can be applied to a pointer to a function, but
32
- shall not be applied directly to a function.
 
 
33
 
34
- The lvalue-to-rvalue ([[conv.lval]]), array-to-pointer (
35
- [[conv.array]]), and function-to-pointer ([[conv.func]]) standard
36
- conversions are not applied to the operand of `sizeof`. If the operand
37
- is a prvalue, the temporary materialization conversion ([[conv.rval]])
38
- is applied.
39
-
40
- The identifier in a `sizeof...` expression shall name a parameter pack.
41
- The `sizeof...` operator yields the number of arguments provided for the
42
- parameter pack *identifier*. A `sizeof...` expression is a pack
43
- expansion ([[temp.variadic]]).
44
 
45
  [*Example 1*:
46
 
47
  ``` cpp
48
  template<class... Types>
@@ -51,11 +46,12 @@ struct count {
51
  };
52
  ```
53
 
54
  — *end example*]
55
 
56
- The result of `sizeof` and `sizeof...` is a constant of type
57
  `std::size_t`.
58
 
59
- [*Note 3*: `std::size_t` is defined in the standard header
 
60
  `<cstddef>` ([[cstddef.syn]], [[support.types.layout]]). — *end note*]
61
 
 
1
+ #### Sizeof <a id="expr.sizeof">[[expr.sizeof]]</a>
2
 
3
+ The `sizeof` operator yields the number of bytes occupied by a
4
+ non-potentially-overlapping object of the type of its operand. The
5
+ operand is either an expression, which is an unevaluated operand
6
+ [[expr.prop]], or a parenthesized *type-id*. The `sizeof` operator shall
7
+ not be applied to an expression that has function or incomplete type, to
8
+ the parenthesized name of such types, or to a glvalue that designates a
9
+ bit-field. The result of `sizeof` applied to any of the narrow character
10
+ types is `1`. The result of `sizeof` applied to any other fundamental
11
+ type [[basic.fundamental]] is *implementation-defined*.
12
 
13
  [*Note 1*: In particular, `sizeof(bool)`, `sizeof(char16_t)`,
14
  `sizeof(char32_t)`, and `sizeof(wchar_t)` are
15
+ implementation-defined.[^21] — *end note*]
16
 
17
+ [*Note 2*: See  [[intro.memory]] for the definition of byte and 
18
+ [[basic.types]] for the definition of object
19
+ representation. — *end note*]
20
 
21
+ When applied to a reference type, the result is the size of the
22
+ referenced type. When applied to a class, the result is the number of
23
+ bytes in an object of that class including any padding required for
24
+ placing objects of that type in an array. The result of applying
25
+ `sizeof` to a potentially-overlapping subobject is the size of the type,
26
+ not the size of the subobject. [^22] When applied to an array, the
27
+ result is the total number of bytes in the array. This implies that the
28
+ size of an array of n elements is n times the size of an element.
 
29
 
30
+ The lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
31
+ function-to-pointer [[conv.func]] standard conversions are not applied
32
+ to the operand of `sizeof`. If the operand is a prvalue, the temporary
33
+ materialization conversion [[conv.rval]] is applied.
34
 
35
+ The identifier in a `sizeof...` expression shall name a pack. The
36
+ `sizeof...` operator yields the number of elements in the pack
37
+ [[temp.variadic]]. A `sizeof...` expression is a pack expansion
38
+ [[temp.variadic]].
 
 
 
 
 
 
39
 
40
  [*Example 1*:
41
 
42
  ``` cpp
43
  template<class... Types>
 
46
  };
47
  ```
48
 
49
  — *end example*]
50
 
51
+ The result of `sizeof` and `sizeof...` is a prvalue of type
52
  `std::size_t`.
53
 
54
+ [*Note 3*: A `sizeof` expression is an integral constant expression
55
+ [[expr.const]]. The type `std::size_t` is defined in the standard header
56
  `<cstddef>` ([[cstddef.syn]], [[support.types.layout]]). — *end note*]
57