From Jason Turner

[class.static]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpm_hsujro/{from.md → to.md} +26 -53
tmp/tmpm_hsujro/{from.md → to.md} RENAMED
@@ -1,7 +1,9 @@
1
  ### Static members <a id="class.static">[[class.static]]</a>
2
 
 
 
3
  A static member `s` of class `X` may be referred to using the
4
  *qualified-id* expression `X::s`; it is not necessary to use the class
5
  member access syntax [[expr.ref]] to refer to a static member. A static
6
  member may be referred to using the class member access syntax, in which
7
  case the object expression is evaluated.
@@ -13,39 +15,17 @@ struct process {
13
  static void reschedule();
14
  };
15
  process& g();
16
 
17
  void f() {
18
- process::reschedule(); // OK: no object necessary
19
  g().reschedule(); // g() is called
20
  }
21
  ```
22
 
23
  — *end example*]
24
 
25
- A static member may be referred to directly in the scope of its class or
26
- in the scope of a class derived [[class.derived]] from its class; in
27
- this case, the static member is referred to as if a *qualified-id*
28
- expression was used, with the *nested-name-specifier* of the
29
- *qualified-id* naming the class scope from which the static member is
30
- referenced.
31
-
32
- [*Example 2*:
33
-
34
- ``` cpp
35
- int g();
36
- struct X {
37
- static int g();
38
- };
39
- struct Y : X {
40
- static int i;
41
- };
42
- int Y::i = g(); // equivalent to Y::g();
43
- ```
44
-
45
- — *end example*]
46
-
47
  Static members obey the usual class member access rules
48
  [[class.access]]. When used in the declaration of a class member, the
49
  `static` specifier shall only be used in the member declarations that
50
  appear within the *member-specification* of the class definition.
51
 
@@ -56,16 +36,12 @@ namespace scope. — *end note*]
56
 
57
  [*Note 1*: The rules described in  [[class.mfct]] apply to static
58
  member functions. — *end note*]
59
 
60
  [*Note 2*: A static member function does not have a `this` pointer
61
- [[class.this]]. *end note*]
62
-
63
- A static member function shall not be `virtual`. There shall not be a
64
- static and a non-static member function with the same name and the same
65
- parameter types [[over.load]]. A static member function shall not be
66
- declared `const`, `volatile`, or `const volatile`.
67
 
68
  #### Static data members <a id="class.static.data">[[class.static.data]]</a>
69
 
70
  A static data member is not part of the subobjects of a class. If a
71
  static data member is declared `thread_local` there is one copy of the
@@ -78,17 +54,14 @@ member shall not be a direct member [[class.mem]] of an unnamed
78
  [[class.pre]] or local [[class.local]] class or of a (possibly
79
  indirectly) nested class [[class.nest]] thereof.
80
 
81
  The declaration of a non-inline static data member in its class
82
  definition is not a definition and may be of an incomplete type other
83
- than cv `void`. The definition for a static data member that is not
84
- defined inline in the class definition shall appear in a namespace scope
85
- enclosing the member’s class definition. In the definition at namespace
86
- scope, the name of the static data member shall be qualified by its
87
- class name using the `::` operator. The *initializer* expression in the
88
- definition of a static data member is in the scope of its class
89
- [[basic.scope.class]].
90
 
91
  [*Example 1*:
92
 
93
  ``` cpp
94
  class process {
@@ -98,20 +71,20 @@ class process {
98
 
99
  process* process::running = get_main();
100
  process* process::run_chain = running;
101
  ```
102
 
103
- The static data member `run_chain` of class `process` is defined in
104
- global scope; the notation `process::run_chain` specifies that the
105
- member `run_chain` is a member of class `process` and in the scope of
106
- class `process`. In the static data member definition, the *initializer*
107
- expression refers to the static data member `running` of class
108
- `process`.
109
 
110
  — *end example*]
111
 
112
- [*Note 1*:
113
 
114
  Once the static data member has been defined, it exists even if no
115
  objects of its class have been created.
116
 
117
  [*Example 2*:
@@ -119,31 +92,31 @@ objects of its class have been created.
119
  In the example above, `run_chain` and `running` exist even if no objects
120
  of class `process` are created by the program.
121
 
122
  — *end example*]
123
 
 
 
 
 
124
  — *end note*]
125
 
126
  If a non-volatile non-inline `const` static data member is of integral
127
  or enumeration type, its declaration in the class definition can specify
128
  a *brace-or-equal-initializer* in which every *initializer-clause* that
129
  is an *assignment-expression* is a constant expression [[expr.const]].
130
  The member shall still be defined in a namespace scope if it is odr-used
131
- [[basic.def.odr]] in the program and the namespace scope definition
132
- shall not contain an *initializer*. An inline static data member may be
133
- defined in the class definition and may specify a
134
  *brace-or-equal-initializer*. If the member is declared with the
135
  `constexpr` specifier, it may be redeclared in namespace scope with no
136
  initializer (this usage is deprecated; see [[depr.static.constexpr]]).
137
  Declarations of other static data members shall not specify a
138
  *brace-or-equal-initializer*.
139
 
140
- [*Note 2*: There is exactly one definition of a static data member that
141
- is odr-used [[basic.def.odr]] in a valid program. — *end note*]
142
 
143
- [*Note 3*: Static data members of a class in namespace scope have the
144
  linkage of the name of the class [[basic.link]]. — *end note*]
145
 
146
- Static data members are initialized and destroyed exactly like non-local
147
- variables ([[basic.start.static]], [[basic.start.dynamic]],
148
- [[basic.start.term]]).
149
-
 
1
  ### Static members <a id="class.static">[[class.static]]</a>
2
 
3
+ #### General <a id="class.static.general">[[class.static.general]]</a>
4
+
5
  A static member `s` of class `X` may be referred to using the
6
  *qualified-id* expression `X::s`; it is not necessary to use the class
7
  member access syntax [[expr.ref]] to refer to a static member. A static
8
  member may be referred to using the class member access syntax, in which
9
  case the object expression is evaluated.
 
15
  static void reschedule();
16
  };
17
  process& g();
18
 
19
  void f() {
20
+ process::reschedule(); // OK, no object necessary
21
  g().reschedule(); // g() is called
22
  }
23
  ```
24
 
25
  — *end example*]
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  Static members obey the usual class member access rules
28
  [[class.access]]. When used in the declaration of a class member, the
29
  `static` specifier shall only be used in the member declarations that
30
  appear within the *member-specification* of the class definition.
31
 
 
36
 
37
  [*Note 1*: The rules described in  [[class.mfct]] apply to static
38
  member functions. — *end note*]
39
 
40
  [*Note 2*: A static member function does not have a `this` pointer
41
+ [[expr.prim.this]]. A static member function cannot be qualified with
42
+ `const`, `volatile`, or `virtual` [[dcl.fct]]. — *end note*]
 
 
 
 
43
 
44
  #### Static data members <a id="class.static.data">[[class.static.data]]</a>
45
 
46
  A static data member is not part of the subobjects of a class. If a
47
  static data member is declared `thread_local` there is one copy of the
 
54
  [[class.pre]] or local [[class.local]] class or of a (possibly
55
  indirectly) nested class [[class.nest]] thereof.
56
 
57
  The declaration of a non-inline static data member in its class
58
  definition is not a definition and may be of an incomplete type other
59
+ than cv `void`.
60
+
61
+ [*Note 1*: The *initializer* in the definition of a static data member
62
+ is in the scope of its class [[basic.scope.class]]. *end note*]
 
 
 
63
 
64
  [*Example 1*:
65
 
66
  ``` cpp
67
  class process {
 
71
 
72
  process* process::running = get_main();
73
  process* process::run_chain = running;
74
  ```
75
 
76
+ The definition of the static data member `run_chain` of class `process`
77
+ inhabits the global scope; the notation `process::run_chain` indicates
78
+ that the member `run_chain` is a member of class `process` and in the
79
+ scope of class `process`. In the static data member definition, the
80
+ *initializer* expression refers to the static data member `running` of
81
+ class `process`.
82
 
83
  — *end example*]
84
 
85
+ [*Note 2*:
86
 
87
  Once the static data member has been defined, it exists even if no
88
  objects of its class have been created.
89
 
90
  [*Example 2*:
 
92
  In the example above, `run_chain` and `running` exist even if no objects
93
  of class `process` are created by the program.
94
 
95
  — *end example*]
96
 
97
+ The initialization and destruction of static data members is described
98
+ in [[basic.start.static]], [[basic.start.dynamic]], and
99
+ [[basic.start.term]].
100
+
101
  — *end note*]
102
 
103
  If a non-volatile non-inline `const` static data member is of integral
104
  or enumeration type, its declaration in the class definition can specify
105
  a *brace-or-equal-initializer* in which every *initializer-clause* that
106
  is an *assignment-expression* is a constant expression [[expr.const]].
107
  The member shall still be defined in a namespace scope if it is odr-used
108
+ [[term.odr.use]] in the program and the namespace scope definition shall
109
+ not contain an *initializer*. The declaration of an inline static data
110
+ member (which is a definition) may specify a
111
  *brace-or-equal-initializer*. If the member is declared with the
112
  `constexpr` specifier, it may be redeclared in namespace scope with no
113
  initializer (this usage is deprecated; see [[depr.static.constexpr]]).
114
  Declarations of other static data members shall not specify a
115
  *brace-or-equal-initializer*.
116
 
117
+ [*Note 3*: There is exactly one definition of a static data member that
118
+ is odr-used [[term.odr.use]] in a valid program. — *end note*]
119
 
120
+ [*Note 4*: Static data members of a class in namespace scope have the
121
  linkage of the name of the class [[basic.link]]. — *end note*]
122