From Jason Turner

[class.static.data]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpf3a14yoo/{from.md → to.md} +62 -44
tmp/tmpf3a14yoo/{from.md → to.md} RENAMED
@@ -1,21 +1,24 @@
1
- ### Static data members <a id="class.static.data">[[class.static.data]]</a>
2
 
3
- A `static` data member is not part of the subobjects of a class. If a
4
- `static` data member is declared `thread_local` there is one copy of the
5
- member per thread. If a `static` data member is not declared
6
  `thread_local` there is one copy of the data member that is shared by
7
  all the objects of the class.
8
 
9
- The declaration of a `static` data member in its class definition is not
10
- a definition and may be of an incomplete type other than cv-qualified
11
- `void`. The definition for a `static` data member shall appear in a
12
- namespace scope enclosing the member’s class definition. In the
13
- definition at namespace scope, the name of the `static` data member
14
- shall be qualified by its class name using the `::` operator. The
15
- *initializer* expression in the definition of a `static` data member is
16
- in the scope of its class ([[basic.scope.class]]).
 
 
 
17
 
18
  ``` cpp
19
  class process {
20
  static process* run_chain;
21
  static process* running;
@@ -23,44 +26,59 @@ class process {
23
 
24
  process* process::running = get_main();
25
  process* process::run_chain = running;
26
  ```
27
 
28
- The `static` data member `run_chain` of class `process` is defined in
29
  global scope; the notation `process::run_chain` specifies that the
30
  member `run_chain` is a member of class `process` and in the scope of
31
- class `process`. In the `static` data member definition, the
32
- *initializer* expression refers to the `static` data member `running` of
33
- class `process`.
34
-
35
- Once the `static` data member has been defined, it exists even if no
36
- objects of its class have been created. in the example above,
37
- `run_chain` and `running` exist even if no objects of class `process`
38
- are created by the program.
39
-
40
- If a non-volatile `const` `static` data member is of integral or
41
- enumeration type, its declaration in the class definition can specify a
42
- *brace-or-equal-initializer* in which every *initializer-clause* that is
43
- an *assignment-expression* is a constant expression ([[expr.const]]). A
44
- `static` data member of literal type can be declared in the class
45
- definition with the `constexpr` specifier; if so, its declaration shall
46
- specify a *brace-or-equal-initializer* in which every
47
- *initializer-clause* that is an *assignment-expression* is a constant
48
- expression. In both these cases, the member may appear in constant
49
- expressions. The member shall still be defined in a namespace scope if
50
- it is odr-used ([[basic.def.odr]]) in the program and the namespace
51
- scope definition shall not contain an *initializer*.
52
-
53
- There shall be exactly one definition of a `static` data member that is
54
- odr-used ([[basic.def.odr]]) in a program; no diagnostic is required.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  Unnamed classes and classes contained directly or indirectly within
56
- unnamed classes shall not contain `static` data members.
57
 
58
- `Static` data members of a class in namespace scope have external
59
- linkage ([[basic.link]]). A local class shall not have `static` data
60
- members.
61
 
62
- `Static` data members are initialized and destroyed exactly like
63
- non-local variables ([[basic.start.init]],  [[basic.start.term]]).
 
64
 
65
- A `static` data member shall not be `mutable` ([[dcl.stc]]).
66
 
 
1
+ #### Static data members <a id="class.static.data">[[class.static.data]]</a>
2
 
3
+ A static data member is not part of the subobjects of a class. If a
4
+ static data member is declared `thread_local` there is one copy of the
5
+ member per thread. If a static data member is not declared
6
  `thread_local` there is one copy of the data member that is shared by
7
  all the objects of the class.
8
 
9
+ The declaration of a non-inline static data member in its class
10
+ definition is not a definition and may be of an incomplete type other
11
+ than cv `void`. The definition for a static data member that is not
12
+ defined inline in the class definition shall appear in a namespace scope
13
+ enclosing the member’s class definition. In the definition at namespace
14
+ scope, the name of the static data member shall be qualified by its
15
+ class name using the `::` operator. The *initializer* expression in the
16
+ definition of a static data member is in the scope of its class (
17
+ [[basic.scope.class]]).
18
+
19
+ [*Example 1*:
20
 
21
  ``` cpp
22
  class process {
23
  static process* run_chain;
24
  static process* running;
 
26
 
27
  process* process::running = get_main();
28
  process* process::run_chain = running;
29
  ```
30
 
31
+ The static data member `run_chain` of class `process` is defined in
32
  global scope; the notation `process::run_chain` specifies that the
33
  member `run_chain` is a member of class `process` and in the scope of
34
+ class `process`. In the static data member definition, the *initializer*
35
+ expression refers to the static data member `running` of class
36
+ `process`.
37
+
38
+ *end example*]
39
+
40
+ [*Note 1*:
41
+
42
+ Once the static data member has been defined, it exists even if no
43
+ objects of its class have been created.
44
+
45
+ [*Example 2*:
46
+
47
+ In the example above, `run_chain` and `running` exist even if no objects
48
+ of class `process` are created by the program.
49
+
50
+ *end example*]
51
+
52
+ *end note*]
53
+
54
+ If a non-volatile non-inline `const` static data member is of integral
55
+ or enumeration type, its declaration in the class definition can specify
56
+ a *brace-or-equal-initializer* in which every *initializer-clause* that
57
+ is an *assignment-expression* is a constant expression (
58
+ [[expr.const]]). The member shall still be defined in a namespace scope
59
+ if it is odr-used ([[basic.def.odr]]) in the program and the namespace
60
+ scope definition shall not contain an *initializer*. An inline static
61
+ data member may be defined in the class definition and may specify a
62
+ *brace-or-equal-initializer*. If the member is declared with the
63
+ `constexpr` specifier, it may be redeclared in namespace scope with no
64
+ initializer (this usage is deprecated; see [[depr.static_constexpr]]).
65
+ Declarations of other static data members shall not specify a
66
+ *brace-or-equal-initializer*.
67
+
68
+ [*Note 2*: There shall be exactly one definition of a static data
69
+ member that is odr-used ([[basic.def.odr]]) in a program; no diagnostic
70
+ is required. — *end note*]
71
+
72
  Unnamed classes and classes contained directly or indirectly within
73
+ unnamed classes shall not contain static data members.
74
 
75
+ [*Note 3*: Static data members of a class in namespace scope have the
76
+ linkage of that class ([[basic.link]]). A local class cannot have
77
+ static data members ([[class.local]]). — *end note*]
78
 
79
+ Static data members are initialized and destroyed exactly like non-local
80
+ variables ([[basic.start.static]], [[basic.start.dynamic]],
81
+ [[basic.start.term]]).
82
 
83
+ A static data member shall not be `mutable` ([[dcl.stc]]).
84