From Jason Turner

[diff.class]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpl5um4hl4/{from.md → to.md} +49 -25
tmp/tmpl5um4hl4/{from.md → to.md} RENAMED
@@ -1,22 +1,21 @@
1
- ### Clause [[class]]: classes <a id="diff.class">[[diff.class]]</a>
2
 
3
- [[class.name]] \[see also [[dcl.typedef]]\] **Change:** In C++, a class
4
- declaration introduces the class name into the scope where it is
5
- declared and hides any object, function or other declaration of that
6
- name in an enclosing scope. In C, an inner scope declaration of a struct
7
- tag name never hides the name of an object or function in an outer
8
- scope.
9
 
10
  Example:
11
 
12
  ``` cpp
13
  int x[99];
14
  void f() {
15
  struct x { int a; };
16
  sizeof(x); /* size of the array in C */
17
- /* size of the struct in C++ */
18
  }
19
  ```
20
 
21
  **Rationale:** This is one of the few incompatibilities between C and
22
  C++ that can be attributed to the new C++ name space definition where a
@@ -28,33 +27,58 @@ conveniences to C++programmers and helps making the use of the
28
  user-defined types as similar as possible to the use of fundamental
29
  types. The advantages of the new name space definition were judged to
30
  outweigh by far the incompatibility with C described above. **Effect on
31
  original feature:** Change to semantics of well-defined feature.
32
  Semantic transformation. If the hidden name that needs to be accessed is
33
- at global scope, the `::` C++operator can be used. If the hidden name is
34
- at block scope, either the type or the struct tag has to be renamed.
35
  Seldom.
36
 
37
- [[class.bit]] **Change:** Bit-fields of type plain `int` are signed.
38
- **Rationale:** Leaving the choice of signedness to implementations could
39
- lead to inconsistent definitions of template specializations. For
40
- consistency, the implementation freedom was eliminated for non-dependent
41
- types, too. **Effect on original feature:** The choice is
42
- implementation-defined in C, but not so in C++. Syntactic
43
- transformation. Seldom.
44
-
45
- [[class.nest]] **Change:** In C++, the name of a nested class is local
46
- to its enclosing class. In C the name of the nested class belongs to the
47
- same scope as the name of the outermost enclosing class.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  Example:
50
 
51
  ``` cpp
52
  struct X {
53
  struct Y { ... } y;
54
  };
55
- struct Y yy; // valid C, invalid C++
56
  ```
57
 
58
  **Rationale:** C++ classes have member functions which require that
59
  classes establish scopes. The C rule would leave classes as an
60
  incomplete scope mechanism which would prevent C++ programmers from
@@ -78,20 +102,20 @@ All the definitions of C struct types enclosed in other struct
78
  definitions and accessed outside the scope of the enclosing struct could
79
  be exported to the scope of the enclosing struct. Note: this is a
80
  consequence of the difference in scope rules, which is documented in
81
  [[basic.scope]]. Seldom.
82
 
83
- [[class.nested.type]] **Change:** In C++, a typedef name may not be
84
- redeclared in a class definition after being used in that definition.
85
 
86
  Example:
87
 
88
  ``` cpp
89
  typedef int I;
90
  struct S {
91
  I i;
92
- int I; // valid C, invalid C++
93
  };
94
  ```
95
 
96
  **Rationale:** When classes become complicated, allowing such a
97
  redefinition after the type has been used can create confusion for C++
 
1
+ ### [[class]]: classes <a id="diff.class">[[diff.class]]</a>
2
 
3
+ \[see also [[dcl.typedef]]\] **Change:** In C++, a class declaration
4
+ introduces the class name into the scope where it is declared and hides
5
+ any object, function or other declaration of that name in an enclosing
6
+ scope. In C, an inner scope declaration of a struct tag name never hides
7
+ the name of an object or function in an outer scope.
 
8
 
9
  Example:
10
 
11
  ``` cpp
12
  int x[99];
13
  void f() {
14
  struct x { int a; };
15
  sizeof(x); /* size of the array in C */
16
+ /* size of the struct in \textit{\textrm{C++{}}} */
17
  }
18
  ```
19
 
20
  **Rationale:** This is one of the few incompatibilities between C and
21
  C++ that can be attributed to the new C++ name space definition where a
 
27
  user-defined types as similar as possible to the use of fundamental
28
  types. The advantages of the new name space definition were judged to
29
  outweigh by far the incompatibility with C described above. **Effect on
30
  original feature:** Change to semantics of well-defined feature.
31
  Semantic transformation. If the hidden name that needs to be accessed is
32
+ at global scope, the `::` C++ operator can be used. If the hidden name
33
+ is at block scope, either the type or the struct tag has to be renamed.
34
  Seldom.
35
 
36
+ **Change:** Copying volatile objects.
37
+
38
+ The implicitly-declared copy constructor and implicitly-declared copy
39
+ assignment operator cannot make a copy of a volatile lvalue. For
40
+ example, the following is valid in ISO C:
41
+
42
+ ``` cpp
43
+ struct X { int i; };
44
+ volatile struct X x1 = {0};
45
+ struct X x2 = x1; // invalid C++{}
46
+ struct X x3;
47
+ x3 = x1; // also invalid C++{}
48
+ ```
49
+
50
+ **Rationale:** Several alternatives were debated at length. Changing the
51
+ parameter to `volatile` `const` `X&` would greatly complicate the
52
+ generation of efficient code for class objects. Discussion of providing
53
+ two alternative signatures for these implicitly-defined operations
54
+ raised unanswered concerns about creating ambiguities and complicating
55
+ the rules that specify the formation of these operators according to the
56
+ bases and members. **Effect on original feature:** Deletion of
57
+ semantically well-defined feature. Semantic transformation. If volatile
58
+ semantics are required for the copy, a user-declared constructor or
59
+ assignment must be provided. If non-volatile semantics are required, an
60
+ explicit `const_cast` can be used. Seldom.
61
+
62
+ **Change:** Bit-fields of type plain `int` are signed. **Rationale:**
63
+ Leaving the choice of signedness to implementations could lead to
64
+ inconsistent definitions of template specializations. For consistency,
65
+ the implementation freedom was eliminated for non-dependent types, too.
66
+ **Effect on original feature:** The choice is implementation-defined in
67
+ C, but not so in C++. Syntactic transformation. Seldom.
68
+
69
+ **Change:** In C++, the name of a nested class is local to its enclosing
70
+ class. In C the name of the nested class belongs to the same scope as
71
+ the name of the outermost enclosing class.
72
 
73
  Example:
74
 
75
  ``` cpp
76
  struct X {
77
  struct Y { ... } y;
78
  };
79
+ struct Y yy; // valid C, invalid C++{}
80
  ```
81
 
82
  **Rationale:** C++ classes have member functions which require that
83
  classes establish scopes. The C rule would leave classes as an
84
  incomplete scope mechanism which would prevent C++ programmers from
 
102
  definitions and accessed outside the scope of the enclosing struct could
103
  be exported to the scope of the enclosing struct. Note: this is a
104
  consequence of the difference in scope rules, which is documented in
105
  [[basic.scope]]. Seldom.
106
 
107
+ **Change:** In C++, a typedef name may not be redeclared in a class
108
+ definition after being used in that definition.
109
 
110
  Example:
111
 
112
  ``` cpp
113
  typedef int I;
114
  struct S {
115
  I i;
116
+ int I; // valid C, invalid C++{}
117
  };
118
  ```
119
 
120
  **Rationale:** When classes become complicated, allowing such a
121
  redefinition after the type has been used can create confusion for C++