From Jason Turner

[dcl.align]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpwinkj5ri/{from.md → to.md} +37 -26
tmp/tmpwinkj5ri/{from.md → to.md} RENAMED
@@ -1,11 +1,10 @@
1
  ### Alignment specifier <a id="dcl.align">[[dcl.align]]</a>
2
 
3
  An *alignment-specifier* may be applied to a variable or to a class data
4
  member, but it shall not be applied to a bit-field, a function
5
- parameter, an *exception-declaration* ([[except.handle]]), or a
6
- variable declared with the `register` storage class specifier. An
7
  *alignment-specifier* may also be applied to the declaration or
8
  definition of a class (in an *elaborated-type-specifier* (
9
  [[dcl.type.elab]]) or *class-head* (Clause  [[class]]), respectively)
10
  and to the declaration or definition of an enumeration (in an
11
  *opaque-enum-declaration* or *enum-head*, respectively ([[dcl.enum]])).
@@ -14,69 +13,81 @@ An *alignment-specifier* with an ellipsis is a pack expansion (
14
 
15
  When the *alignment-specifier* is of the form `alignas(`
16
  *constant-expression* `)`:
17
 
18
  - the *constant-expression* shall be an integral constant expression
19
- - if the constant expression evaluates to a fundamental alignment, the
20
- alignment requirement of the declared entity shall be the specified
21
- fundamental alignment
22
- - if the constant expression evaluates to an extended alignment and the
23
- implementation supports that alignment in the context of the
24
- declaration, the alignment of the declared entity shall be that
25
- alignment
26
- - if the constant expression evaluates to an extended alignment and the
27
  implementation does not support that alignment in the context of the
28
- declaration, the program is ill-formed
29
- - if the constant expression evaluates to zero, the alignment specifier
30
- shall have no effect
31
- - otherwise, the program is ill-formed.
32
 
33
- When the *alignment-specifier* is of the form `alignas(` *type-id* `)`,
34
- it shall have the same effect as `alignas({}alignof(`*type-id*`))` (
35
- [[expr.alignof]]).
36
 
37
- When multiple *alignment-specifier*s are specified for an entity, the
38
- alignment requirement shall be set to the strictest specified alignment.
 
39
 
40
  The combined effect of all *alignment-specifier*s in a declaration shall
41
  not specify an alignment that is less strict than the alignment that
42
  would be required for the entity being declared if all
43
- *alignment-specifier*s were omitted (including those in other
44
- declarations).
 
 
 
 
 
 
 
 
 
 
45
 
46
  If the defining declaration of an entity has an *alignment-specifier*,
47
  any non-defining declaration of that entity shall either specify
48
  equivalent alignment or have no *alignment-specifier*. Conversely, if
49
  any declaration of an entity has an *alignment-specifier*, every
50
  defining declaration of that entity shall specify an equivalent
51
  alignment. No diagnostic is required if declarations of an entity have
52
  different *alignment-specifier*s in different translation units.
53
 
 
 
54
  ``` cpp
55
  // Translation unit #1:
56
- struct S { int x; } s, p = &s;
57
 
58
  // Translation unit #2:
59
- struct alignas(16) S; // error: definition of S lacks alignment; no
60
- extern S* p; // diagnostic required
61
  ```
62
 
 
 
 
 
63
  An aligned buffer with an alignment requirement of `A` and holding `N`
64
- elements of type `T` other than `char`, `signed char`, or
65
- `unsigned char` can be declared as:
66
 
67
  ``` cpp
68
  alignas(T) alignas(A) T buffer[N];
69
  ```
70
 
71
  Specifying `alignas(T)` ensures that the final requested alignment will
72
  not be weaker than `alignof(T)`, and therefore the program will not be
73
  ill-formed.
74
 
 
 
 
 
75
  ``` cpp
76
  alignas(double) void f(); // error: alignment applied to function
77
  alignas(double) unsigned char c[sizeof(double)]; // array of characters, suitably aligned for a double
78
  extern unsigned char c[sizeof(double)]; // no alignas necessary
79
  alignas(float)
80
  extern unsigned char c[sizeof(double)]; // error: different alignment in declaration
81
  ```
82
 
 
 
 
1
  ### Alignment specifier <a id="dcl.align">[[dcl.align]]</a>
2
 
3
  An *alignment-specifier* may be applied to a variable or to a class data
4
  member, but it shall not be applied to a bit-field, a function
5
+ parameter, or an *exception-declaration* ([[except.handle]]). An
 
6
  *alignment-specifier* may also be applied to the declaration or
7
  definition of a class (in an *elaborated-type-specifier* (
8
  [[dcl.type.elab]]) or *class-head* (Clause  [[class]]), respectively)
9
  and to the declaration or definition of an enumeration (in an
10
  *opaque-enum-declaration* or *enum-head*, respectively ([[dcl.enum]])).
 
13
 
14
  When the *alignment-specifier* is of the form `alignas(`
15
  *constant-expression* `)`:
16
 
17
  - the *constant-expression* shall be an integral constant expression
18
+ - if the constant expression does not evaluate to an alignment value (
19
+ [[basic.align]]), or evaluates to an extended alignment and the
 
 
 
 
 
 
20
  implementation does not support that alignment in the context of the
21
+ declaration, the program is ill-formed.
 
 
 
22
 
23
+ An *alignment-specifier* of the form `alignas(` *type-id* `)` has the
24
+ same effect as `alignas({}alignof(` *type-id* `))` ([[expr.alignof]]).
 
25
 
26
+ The alignment requirement of an entity is the strictest nonzero
27
+ alignment specified by its *alignment-specifier*s, if any; otherwise,
28
+ the *alignment-specifier*s have no effect.
29
 
30
  The combined effect of all *alignment-specifier*s in a declaration shall
31
  not specify an alignment that is less strict than the alignment that
32
  would be required for the entity being declared if all
33
+ *alignment-specifier*s appertaining to that entity were omitted.
34
+
35
+ [*Example 1*:
36
+
37
+ ``` cpp
38
+ struct alignas(8) S {};
39
+ struct alignas(1) U {
40
+ S s;
41
+ }; // error: U specifies an alignment that is less strict than if the alignas(1) were omitted.
42
+ ```
43
+
44
+ — *end example*]
45
 
46
  If the defining declaration of an entity has an *alignment-specifier*,
47
  any non-defining declaration of that entity shall either specify
48
  equivalent alignment or have no *alignment-specifier*. Conversely, if
49
  any declaration of an entity has an *alignment-specifier*, every
50
  defining declaration of that entity shall specify an equivalent
51
  alignment. No diagnostic is required if declarations of an entity have
52
  different *alignment-specifier*s in different translation units.
53
 
54
+ [*Example 2*:
55
+
56
  ``` cpp
57
  // Translation unit #1:
58
+ struct S { int x; } s, *p = &s;
59
 
60
  // Translation unit #2:
61
+ struct alignas(16) S; // error: definition of S lacks alignment, no diagnostic required
62
+ extern S* p;
63
  ```
64
 
65
+ — *end example*]
66
+
67
+ [*Example 3*:
68
+
69
  An aligned buffer with an alignment requirement of `A` and holding `N`
70
+ elements of type `T` can be declared as:
 
71
 
72
  ``` cpp
73
  alignas(T) alignas(A) T buffer[N];
74
  ```
75
 
76
  Specifying `alignas(T)` ensures that the final requested alignment will
77
  not be weaker than `alignof(T)`, and therefore the program will not be
78
  ill-formed.
79
 
80
+ — *end example*]
81
+
82
+ [*Example 4*:
83
+
84
  ``` cpp
85
  alignas(double) void f(); // error: alignment applied to function
86
  alignas(double) unsigned char c[sizeof(double)]; // array of characters, suitably aligned for a double
87
  extern unsigned char c[sizeof(double)]; // no alignas necessary
88
  alignas(float)
89
  extern unsigned char c[sizeof(double)]; // error: different alignment in declaration
90
  ```
91
 
92
+ — *end example*]
93
+