tmp/tmp41ivih7m/{from.md → to.md}
RENAMED
|
@@ -4,21 +4,23 @@
|
|
| 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
|
| 22 |
name can be declared as a type and as a non-type in a single scope
|
| 23 |
causing the non-type name to hide the type name and requiring that the
|
| 24 |
keywords `class`, `struct`, `union` or `enum` be used to refer to the
|
|
@@ -34,21 +36,26 @@ 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.
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 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
|
|
@@ -68,57 +75,65 @@ 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
|
| 85 |
maintaining locality within a class. A coherent set of scope rules for
|
| 86 |
C++ based on the C rule would be very complicated and C++ programmers
|
| 87 |
would be unable to predict reliably the meanings of nontrivial examples
|
| 88 |
involving nested or local functions. **Effect on original feature:**
|
| 89 |
Change to semantics of well-defined feature. Semantic transformation. To
|
| 90 |
make the struct type name visible in the scope of the enclosing struct,
|
| 91 |
the struct tag can be declared in the scope of the enclosing struct,
|
| 92 |
-
before the enclosing struct is defined.
|
|
|
|
|
|
|
| 93 |
|
| 94 |
``` cpp
|
| 95 |
struct Y; // struct Y and struct X are at the same scope
|
| 96 |
struct X {
|
| 97 |
struct Y { ... } y;
|
| 98 |
};
|
| 99 |
```
|
| 100 |
|
|
|
|
|
|
|
| 101 |
All the definitions of C struct types enclosed in other struct
|
| 102 |
definitions and accessed outside the scope of the enclosing struct can
|
| 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++
|
| 122 |
programmers as to what the meaning of `I` really is. **Effect on
|
| 123 |
original feature:** Deletion of semantically well-defined feature.
|
| 124 |
Semantic transformation. Either the type or the struct member has to be
|
|
|
|
| 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 1*:
|
| 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 |
+
— *end example*]
|
| 21 |
+
|
| 22 |
**Rationale:** This is one of the few incompatibilities between C and
|
| 23 |
C++ that can be attributed to the new C++ name space definition where a
|
| 24 |
name can be declared as a type and as a non-type in a single scope
|
| 25 |
causing the non-type name to hide the type name and requiring that the
|
| 26 |
keywords `class`, `struct`, `union` or `enum` be used to refer to the
|
|
|
|
| 36 |
Seldom.
|
| 37 |
|
| 38 |
**Change:** Copying volatile objects.
|
| 39 |
|
| 40 |
The implicitly-declared copy constructor and implicitly-declared copy
|
| 41 |
+
assignment operator cannot make a copy of a volatile lvalue.
|
| 42 |
+
|
| 43 |
+
[*Example 2*:
|
| 44 |
+
|
| 45 |
+
The following is valid in C:
|
| 46 |
|
| 47 |
``` cpp
|
| 48 |
struct X { int i; };
|
| 49 |
volatile struct X x1 = {0};
|
| 50 |
struct X x2 = x1; // invalid C++{}
|
| 51 |
struct X x3;
|
| 52 |
x3 = x1; // also invalid C++{}
|
| 53 |
```
|
| 54 |
|
| 55 |
+
— *end example*]
|
| 56 |
+
|
| 57 |
**Rationale:** Several alternatives were debated at length. Changing the
|
| 58 |
parameter to `volatile` `const` `X&` would greatly complicate the
|
| 59 |
generation of efficient code for class objects. Discussion of providing
|
| 60 |
two alternative signatures for these implicitly-defined operations
|
| 61 |
raised unanswered concerns about creating ambiguities and complicating
|
|
|
|
| 75 |
|
| 76 |
**Change:** In C++, the name of a nested class is local to its enclosing
|
| 77 |
class. In C the name of the nested class belongs to the same scope as
|
| 78 |
the name of the outermost enclosing class.
|
| 79 |
|
| 80 |
+
[*Example 3*:
|
| 81 |
|
| 82 |
``` cpp
|
| 83 |
struct X {
|
| 84 |
struct Y { ... } y;
|
| 85 |
};
|
| 86 |
struct Y yy; // valid C, invalid C++{}
|
| 87 |
```
|
| 88 |
|
| 89 |
+
— *end example*]
|
| 90 |
+
|
| 91 |
**Rationale:** C++ classes have member functions which require that
|
| 92 |
classes establish scopes. The C rule would leave classes as an
|
| 93 |
incomplete scope mechanism which would prevent C++ programmers from
|
| 94 |
maintaining locality within a class. A coherent set of scope rules for
|
| 95 |
C++ based on the C rule would be very complicated and C++ programmers
|
| 96 |
would be unable to predict reliably the meanings of nontrivial examples
|
| 97 |
involving nested or local functions. **Effect on original feature:**
|
| 98 |
Change to semantics of well-defined feature. Semantic transformation. To
|
| 99 |
make the struct type name visible in the scope of the enclosing struct,
|
| 100 |
the struct tag can be declared in the scope of the enclosing struct,
|
| 101 |
+
before the enclosing struct is defined.
|
| 102 |
+
|
| 103 |
+
[*Example 4*:
|
| 104 |
|
| 105 |
``` cpp
|
| 106 |
struct Y; // struct Y and struct X are at the same scope
|
| 107 |
struct X {
|
| 108 |
struct Y { ... } y;
|
| 109 |
};
|
| 110 |
```
|
| 111 |
|
| 112 |
+
— *end example*]
|
| 113 |
+
|
| 114 |
All the definitions of C struct types enclosed in other struct
|
| 115 |
definitions and accessed outside the scope of the enclosing struct can
|
| 116 |
be exported to the scope of the enclosing struct. Note: this is a
|
| 117 |
consequence of the difference in scope rules, which is documented in
|
| 118 |
[[basic.scope]]. Seldom.
|
| 119 |
|
| 120 |
**Change:** In C++, a *typedef-name* may not be redeclared in a class
|
| 121 |
definition after being used in that definition.
|
| 122 |
|
| 123 |
+
[*Example 5*:
|
| 124 |
|
| 125 |
``` cpp
|
| 126 |
typedef int I;
|
| 127 |
struct S {
|
| 128 |
I i;
|
| 129 |
int I; // valid C, invalid C++{}
|
| 130 |
};
|
| 131 |
```
|
| 132 |
|
| 133 |
+
— *end example*]
|
| 134 |
+
|
| 135 |
**Rationale:** When classes become complicated, allowing such a
|
| 136 |
redefinition after the type has been used can create confusion for C++
|
| 137 |
programmers as to what the meaning of `I` really is. **Effect on
|
| 138 |
original feature:** Deletion of semantically well-defined feature.
|
| 139 |
Semantic transformation. Either the type or the struct member has to be
|