From Jason Turner

[class.local]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp00tsx85r/{from.md → to.md} +14 -9
tmp/tmp00tsx85r/{from.md → to.md} RENAMED
@@ -1,47 +1,52 @@
1
  ## Local class declarations <a id="class.local">[[class.local]]</a>
2
 
3
  A class can be declared within a function definition; such a class is
4
- called a *local* class. The name of a local class is local to its
5
  enclosing scope. The local class is in the scope of the enclosing scope,
6
  and has the same access to names outside the function as does the
7
- enclosing function. Declarations in a local class shall not odr-use (
8
- [[basic.def.odr]]) a variable with automatic storage duration from an
9
- enclosing scope.
 
10
 
11
  [*Example 1*:
12
 
13
  ``` cpp
14
  int x;
15
  void f() {
16
  static int s;
17
  int x;
18
  const int N = 5;
19
  extern int q();
 
 
20
 
21
  struct local {
22
- int g() { return x; } // error: odr-use of automatic variable x
23
  int h() { return s; } // OK
24
  int k() { return ::x; } // OK
25
  int l() { return q(); } // OK
26
  int m() { return N; } // OK: not an odr-use
27
- int* n() { return &N; } // error: odr-use of automatic variable N
 
28
  };
29
  }
30
 
31
  local* p = 0; // error: local not in scope
32
  ```
33
 
34
  — *end example*]
35
 
36
  An enclosing function has no special access to members of the local
37
- class; it obeys the usual access rules (Clause  [[class.access]]).
38
- Member functions of a local class shall be defined within their class
39
  definition, if they are defined at all.
40
 
41
  If class `X` is a local class a nested class `Y` may be declared in
42
  class `X` and later defined in the definition of class `X` or be later
43
  defined in the same scope as the definition of class `X`. A class nested
44
  within a local class is a local class.
45
 
46
- A local class shall not have static data members.
 
47
 
 
1
  ## Local class declarations <a id="class.local">[[class.local]]</a>
2
 
3
  A class can be declared within a function definition; such a class is
4
+ called a *local class*. The name of a local class is local to its
5
  enclosing scope. The local class is in the scope of the enclosing scope,
6
  and has the same access to names outside the function as does the
7
+ enclosing function.
8
+
9
+ [*Note 1*: A declaration in a local class cannot odr-use
10
+ [[basic.def.odr]] a local entity from an enclosing scope. — *end note*]
11
 
12
  [*Example 1*:
13
 
14
  ``` cpp
15
  int x;
16
  void f() {
17
  static int s;
18
  int x;
19
  const int N = 5;
20
  extern int q();
21
+ int arr[2];
22
+ auto [y, z] = arr;
23
 
24
  struct local {
25
+ int g() { return x; } // error: odr-use of non-odr-usable variable x
26
  int h() { return s; } // OK
27
  int k() { return ::x; } // OK
28
  int l() { return q(); } // OK
29
  int m() { return N; } // OK: not an odr-use
30
+ int* n() { return &N; } // error: odr-use of non-odr-usable variable N
31
+ int p() { return y; } // error: odr-use of non-odr-usable structured binding y
32
  };
33
  }
34
 
35
  local* p = 0; // error: local not in scope
36
  ```
37
 
38
  — *end example*]
39
 
40
  An enclosing function has no special access to members of the local
41
+ class; it obeys the usual access rules [[class.access]]. Member
42
+ functions of a local class shall be defined within their class
43
  definition, if they are defined at all.
44
 
45
  If class `X` is a local class a nested class `Y` may be declared in
46
  class `X` and later defined in the definition of class `X` or be later
47
  defined in the same scope as the definition of class `X`. A class nested
48
  within a local class is a local class.
49
 
50
+ [*Note 2*: A local class cannot have static data members
51
+ [[class.static.data]]. — *end note*]
52