- tmp/tmpuw98q6dn/{from.md → to.md} +123 -32
tmp/tmpuw98q6dn/{from.md → to.md}
RENAMED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
-
###
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
Using these specifiers with type declarations is illegal in C++. In C,
|
| 6 |
these specifiers are ignored when used on type declarations.
|
| 7 |
|
| 8 |
Example:
|
| 9 |
|
| 10 |
``` cpp
|
| 11 |
-
static struct S { // valid C, invalid in C++
|
| 12 |
int i;
|
| 13 |
};
|
| 14 |
```
|
| 15 |
|
| 16 |
**Rationale:** Storage class specifiers don’t have any meaning when
|
|
@@ -18,27 +18,27 @@ associated with a type. In C++, class members can be declared with the
|
|
| 18 |
`static` storage class specifier. Allowing storage class specifiers on
|
| 19 |
type declarations could render the code confusing for users. **Effect on
|
| 20 |
original feature:** Deletion of semantically well-defined feature.
|
| 21 |
Syntactic transformation. Seldom.
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
Example:
|
| 35 |
|
| 36 |
``` cpp
|
| 37 |
-
typedef struct name1 { ... } name1; // valid C and C++
|
| 38 |
struct name { ... };
|
| 39 |
-
typedef int name; // valid C, invalid C++
|
| 40 |
```
|
| 41 |
|
| 42 |
**Rationale:** For ease of use, C++ doesn’t require that a type name be
|
| 43 |
prefixed with the keywords `class`, `struct` or `union` when used in
|
| 44 |
object declarations or type casts.
|
|
@@ -52,18 +52,17 @@ name i; // i has type class name
|
|
| 52 |
|
| 53 |
**Effect on original feature:** Deletion of semantically well-defined
|
| 54 |
feature. Semantic transformation. One of the 2 types has to be renamed.
|
| 55 |
Seldom.
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
Seldom.
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
In C++ a *decl-specifier-seq* must contain a *type-specifier*, unless it
|
| 67 |
is followed by a declarator for a constructor, a destructor, or a
|
| 68 |
conversion function. In the following example, the left-hand column
|
| 69 |
presents valid C; the right-hand column presents equivalent C++:
|
|
@@ -81,50 +80,142 @@ declarations. Explicit declaration is increasingly considered to be
|
|
| 81 |
proper style. Liaison with WG14 (C) indicated support for (at least)
|
| 82 |
deprecating implicit int in the next revision of C. **Effect on original
|
| 83 |
feature:** Deletion of semantically well-defined feature. Syntactic
|
| 84 |
transformation. Could be automated. Common.
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
|
| 89 |
``` cpp
|
| 90 |
void f() {
|
| 91 |
-
auto int x;
|
| 92 |
}
|
| 93 |
```
|
| 94 |
|
| 95 |
**Rationale:** Allowing the use of `auto` to deduce the type of a
|
| 96 |
variable from its initializer results in undesired interpretations of
|
| 97 |
`auto` as a storage class specifier in certain contexts. **Effect on
|
| 98 |
original feature:** Deletion of semantically well-defined feature.
|
| 99 |
Syntactic transformation. Rare.
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
Example:
|
| 106 |
|
| 107 |
``` cpp
|
| 108 |
enum color { red, blue, green };
|
| 109 |
-
enum color c = 1; // valid C, invalid C++
|
| 110 |
```
|
| 111 |
|
| 112 |
**Rationale:** The type-safe nature of C++. **Effect on original
|
| 113 |
feature:** Deletion of semantically well-defined feature. Syntactic
|
| 114 |
transformation. (The type error produced by the assignment can be
|
| 115 |
automatically corrected by applying an explicit cast.) Common.
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
Example:
|
| 121 |
|
| 122 |
``` cpp
|
| 123 |
enum e { A };
|
| 124 |
sizeof(A) == sizeof(int) // in C
|
| 125 |
-
sizeof(A) == sizeof(e) // in C++
|
| 126 |
/* and sizeof(int) is not necessarily equal to sizeof(e) */
|
| 127 |
```
|
| 128 |
|
| 129 |
**Rationale:** In C++, an enumeration is a distinct type. **Effect on
|
| 130 |
original feature:** Change to semantics of well-defined feature.
|
|
|
|
| 1 |
+
### [[dcl.dcl]]: declarations <a id="diff.dcl">[[diff.dcl]]</a>
|
| 2 |
|
| 3 |
+
**Change:** In C++, the `static` or `extern` specifiers can only be
|
| 4 |
+
applied to names of objects or functions.
|
| 5 |
Using these specifiers with type declarations is illegal in C++. In C,
|
| 6 |
these specifiers are ignored when used on type declarations.
|
| 7 |
|
| 8 |
Example:
|
| 9 |
|
| 10 |
``` cpp
|
| 11 |
+
static struct S { // valid C, invalid in C++{}
|
| 12 |
int i;
|
| 13 |
};
|
| 14 |
```
|
| 15 |
|
| 16 |
**Rationale:** Storage class specifiers don’t have any meaning when
|
|
|
|
| 18 |
`static` storage class specifier. Allowing storage class specifiers on
|
| 19 |
type declarations could render the code confusing for users. **Effect on
|
| 20 |
original feature:** Deletion of semantically well-defined feature.
|
| 21 |
Syntactic transformation. Seldom.
|
| 22 |
|
| 23 |
+
**Change:** In C++, `register` is not a storage class specifier.
|
| 24 |
+
**Rationale:** The storage class specifier had no effect in C++.
|
| 25 |
+
**Effect on original feature:** Deletion of semantically well-defined
|
| 26 |
+
feature. Syntactic transformation. Common.
|
| 27 |
|
| 28 |
+
**Change:** A C++ typedef name must be different from any class type
|
| 29 |
+
name declared in the same scope (except if the typedef is a synonym of
|
| 30 |
+
the class name with the same name). In C, a typedef name and a struct
|
| 31 |
+
tag name declared in the same scope can have the same name (because they
|
| 32 |
+
have different name spaces).
|
| 33 |
|
| 34 |
Example:
|
| 35 |
|
| 36 |
``` cpp
|
| 37 |
+
typedef struct name1 { ... } name1; // valid C and C++{}
|
| 38 |
struct name { ... };
|
| 39 |
+
typedef int name; // valid C, invalid C++{}
|
| 40 |
```
|
| 41 |
|
| 42 |
**Rationale:** For ease of use, C++ doesn’t require that a type name be
|
| 43 |
prefixed with the keywords `class`, `struct` or `union` when used in
|
| 44 |
object declarations or type casts.
|
|
|
|
| 52 |
|
| 53 |
**Effect on original feature:** Deletion of semantically well-defined
|
| 54 |
feature. Semantic transformation. One of the 2 types has to be renamed.
|
| 55 |
Seldom.
|
| 56 |
|
| 57 |
+
\[see also [[basic.link]]\] **Change:** Const objects must be
|
| 58 |
+
initialized in C++ but can be left uninitialized in C. **Rationale:** A
|
| 59 |
+
const object cannot be assigned to so it must be initialized to hold a
|
| 60 |
+
useful value. **Effect on original feature:** Deletion of semantically
|
| 61 |
+
well-defined feature. Semantic transformation. Seldom.
|
|
|
|
| 62 |
|
| 63 |
+
**Change:** Banning implicit `int`.
|
| 64 |
|
| 65 |
In C++ a *decl-specifier-seq* must contain a *type-specifier*, unless it
|
| 66 |
is followed by a declarator for a constructor, a destructor, or a
|
| 67 |
conversion function. In the following example, the left-hand column
|
| 68 |
presents valid C; the right-hand column presents equivalent C++:
|
|
|
|
| 80 |
proper style. Liaison with WG14 (C) indicated support for (at least)
|
| 81 |
deprecating implicit int in the next revision of C. **Effect on original
|
| 82 |
feature:** Deletion of semantically well-defined feature. Syntactic
|
| 83 |
transformation. Could be automated. Common.
|
| 84 |
|
| 85 |
+
**Change:** The keyword `auto` cannot be used as a storage class
|
| 86 |
+
specifier.
|
| 87 |
|
| 88 |
``` cpp
|
| 89 |
void f() {
|
| 90 |
+
auto int x; // valid C, invalid C++{}
|
| 91 |
}
|
| 92 |
```
|
| 93 |
|
| 94 |
**Rationale:** Allowing the use of `auto` to deduce the type of a
|
| 95 |
variable from its initializer results in undesired interpretations of
|
| 96 |
`auto` as a storage class specifier in certain contexts. **Effect on
|
| 97 |
original feature:** Deletion of semantically well-defined feature.
|
| 98 |
Syntactic transformation. Rare.
|
| 99 |
|
| 100 |
+
**Change:** In C++, a function declared with an empty parameter list
|
| 101 |
+
takes no arguments. In C, an empty parameter list means that the number
|
| 102 |
+
and type of the function arguments are unknown.
|
| 103 |
+
|
| 104 |
+
Example:
|
| 105 |
+
|
| 106 |
+
``` cpp
|
| 107 |
+
int f(); // means int f(void) in C++{}
|
| 108 |
+
// int f( unknown ) in C
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
**Rationale:** This is to avoid erroneous function calls (i.e., function
|
| 112 |
+
calls with the wrong number or type of arguments). **Effect on original
|
| 113 |
+
feature:** Change to semantics of well-defined feature. This feature was
|
| 114 |
+
marked as “obsolescent” in C. Syntactic transformation. The function
|
| 115 |
+
declarations using C incomplete declaration style must be completed to
|
| 116 |
+
become full prototype declarations. A program may need to be updated
|
| 117 |
+
further if different calls to the same (non-prototype) function have
|
| 118 |
+
different numbers of arguments or if the type of corresponding arguments
|
| 119 |
+
differed. Common.
|
| 120 |
+
|
| 121 |
+
\[see [[expr.sizeof]]\] **Change:** In C++, types may not be defined in
|
| 122 |
+
return or parameter types. In C, these type definitions are allowed.
|
| 123 |
+
|
| 124 |
+
Example:
|
| 125 |
+
|
| 126 |
+
``` cpp
|
| 127 |
+
void f( struct S { int a; } arg ) {} // valid C, invalid C++{}
|
| 128 |
+
enum E { A, B, C } f() {} // valid C, invalid C++{}
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
**Rationale:** When comparing types in different translation units, C++
|
| 132 |
+
relies on name equivalence when C relies on structural equivalence.
|
| 133 |
+
Regarding parameter types: since the type defined in a parameter list
|
| 134 |
+
would be in the scope of the function, the only legal calls in C++ would
|
| 135 |
+
be from within the function itself. **Effect on original feature:**
|
| 136 |
+
Deletion of semantically well-defined feature. Semantic transformation.
|
| 137 |
+
The type definitions must be moved to file scope, or in header files.
|
| 138 |
+
Seldom. This style of type definition is seen as poor coding style.
|
| 139 |
+
|
| 140 |
+
**Change:** In C++, the syntax for function definition excludes the
|
| 141 |
+
“old-style” C function. In C, “old-style” syntax is allowed, but
|
| 142 |
+
deprecated as “obsolescent”. **Rationale:** Prototypes are essential to
|
| 143 |
+
type safety. **Effect on original feature:** Deletion of semantically
|
| 144 |
+
well-defined feature. Syntactic transformation. Common in old programs,
|
| 145 |
+
but already known to be obsolescent.
|
| 146 |
+
|
| 147 |
+
**Change:** In C++, designated initialization support is restricted
|
| 148 |
+
compared to the corresponding functionality in C. In C++, designators
|
| 149 |
+
for non-static data members must be specified in declaration order,
|
| 150 |
+
designators for array elements and nested designators are not supported,
|
| 151 |
+
and designated and non-designated initializers cannot be mixed in the
|
| 152 |
+
same initializer list.
|
| 153 |
+
|
| 154 |
+
Example:
|
| 155 |
+
|
| 156 |
+
``` cpp
|
| 157 |
+
struct A { int x, y; };
|
| 158 |
+
struct B { struct A a; };
|
| 159 |
+
struct A a = {.y = 1, .x = 2}; // valid C, invalid C++{}
|
| 160 |
+
int arr[3] = {[1] = 5}; // valid C, invalid C++{}
|
| 161 |
+
struct B b = {.a.x = 0}; // valid C, invalid C++{}
|
| 162 |
+
struct A c = {.x = 1, 2}; // valid C, invalid C++{}
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
**Rationale:** In C++, members are destroyed in reverse construction
|
| 166 |
+
order and the elements of an initializer list are evaluated in lexical
|
| 167 |
+
order, so field initializers must be specified in order. Array
|
| 168 |
+
designators conflict with *lambda-expression* syntax. Nested designators
|
| 169 |
+
are seldom used. **Effect on original feature:** Deletion of feature
|
| 170 |
+
that is incompatible with C++. Syntactic transformation. Out-of-order
|
| 171 |
+
initializers are common. The other features are seldom used.
|
| 172 |
+
|
| 173 |
+
**Change:** In C++, when initializing an array of character with a
|
| 174 |
+
string, the number of characters in the string (including the
|
| 175 |
+
terminating `'\0'`) must not exceed the number of elements in the array.
|
| 176 |
+
In C, an array can be initialized with a string even if the array is not
|
| 177 |
+
large enough to contain the string-terminating `'\0'`.
|
| 178 |
+
|
| 179 |
+
Example:
|
| 180 |
+
|
| 181 |
+
``` cpp
|
| 182 |
+
char array[4] = "abcd"; // valid C, invalid C++{}
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
**Rationale:** When these non-terminated arrays are manipulated by
|
| 186 |
+
standard string functions, there is potential for major catastrophe.
|
| 187 |
+
**Effect on original feature:** Deletion of semantically well-defined
|
| 188 |
+
feature. Semantic transformation. The arrays must be declared one
|
| 189 |
+
element bigger to contain the string terminating `'\0'`. Seldom. This
|
| 190 |
+
style of array initialization is seen as poor coding style.
|
| 191 |
+
|
| 192 |
+
**Change:** C++ objects of enumeration type can only be assigned values
|
| 193 |
+
of the same enumeration type. In C, objects of enumeration type can be
|
| 194 |
+
assigned values of any integral type.
|
| 195 |
|
| 196 |
Example:
|
| 197 |
|
| 198 |
``` cpp
|
| 199 |
enum color { red, blue, green };
|
| 200 |
+
enum color c = 1; // valid C, invalid C++{}
|
| 201 |
```
|
| 202 |
|
| 203 |
**Rationale:** The type-safe nature of C++. **Effect on original
|
| 204 |
feature:** Deletion of semantically well-defined feature. Syntactic
|
| 205 |
transformation. (The type error produced by the assignment can be
|
| 206 |
automatically corrected by applying an explicit cast.) Common.
|
| 207 |
|
| 208 |
+
**Change:** In C++, the type of an enumerator is its enumeration. In C,
|
| 209 |
+
the type of an enumerator is `int`.
|
| 210 |
|
| 211 |
Example:
|
| 212 |
|
| 213 |
``` cpp
|
| 214 |
enum e { A };
|
| 215 |
sizeof(A) == sizeof(int) // in C
|
| 216 |
+
sizeof(A) == sizeof(e) // in C++{}
|
| 217 |
/* and sizeof(int) is not necessarily equal to sizeof(e) */
|
| 218 |
```
|
| 219 |
|
| 220 |
**Rationale:** In C++, an enumeration is a distinct type. **Effect on
|
| 221 |
original feature:** Change to semantics of well-defined feature.
|