- tmp/tmpt3cbx8f9/{from.md → to.md} +104 -91
tmp/tmpt3cbx8f9/{from.md → to.md}
RENAMED
|
@@ -13,12 +13,12 @@ feature. Any ISO C programs that used any of these keywords as
|
|
| 13 |
identifiers are not valid C++programs. Syntactic transformation.
|
| 14 |
Converting one specific program is easy. Converting a large collection
|
| 15 |
of related programs takes more work. Common.
|
| 16 |
|
| 17 |
[[lex.ccon]] **Change:** Type of character literal is changed from `int`
|
| 18 |
-
to `char` **Rationale:** This is needed for improved overloaded
|
| 19 |
-
argument type matching. For example:
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
int function( int i );
|
| 23 |
int function( char c );
|
| 24 |
|
|
@@ -34,18 +34,18 @@ sizeof('x') == sizeof(int)
|
|
| 34 |
```
|
| 35 |
|
| 36 |
will not work the same as C++programs. Simple. Programs which depend
|
| 37 |
upon `sizeof('x')` are probably rare.
|
| 38 |
|
| 39 |
-
Subclause [[lex.string]]: **Change:** String literals made const
|
| 40 |
The type of a string literal is changed from “array of `char`” to “array
|
| 41 |
-
of `const char`
|
| 42 |
-
from “array of *some-integer-type*” to “array of `const char16_t`
|
| 43 |
type of a `char32_t` string literal is changed from “array of
|
| 44 |
-
*some-integer-type*” to “array of `const char32_t`
|
| 45 |
string literal is changed from “array of `wchar_t`” to “array of
|
| 46 |
-
`const wchar_t`
|
| 47 |
overloaded function, which might expect to be able to modify its
|
| 48 |
argument. **Effect on original feature:** Change to semantics of
|
| 49 |
well-defined feature. Syntactic transformation. The fix is to add a
|
| 50 |
cast:
|
| 51 |
|
|
@@ -62,11 +62,12 @@ Programs that have a legitimate reason to treat string literals as
|
|
| 62 |
pointers to potentially modifiable memory are probably rare.
|
| 63 |
|
| 64 |
### Clause [[basic]]: basic concepts <a id="diff.basic">[[diff.basic]]</a>
|
| 65 |
|
| 66 |
[[basic.def]] **Change:** C++does not have “tentative definitions” as in
|
| 67 |
-
C
|
|
|
|
| 68 |
|
| 69 |
``` cpp
|
| 70 |
int i;
|
| 71 |
int i;
|
| 72 |
```
|
|
@@ -84,53 +85,53 @@ static struct X a = { 1, &b };
|
|
| 84 |
```
|
| 85 |
|
| 86 |
**Rationale:** This avoids having different initialization rules for
|
| 87 |
fundamental types and user-defined types. **Effect on original
|
| 88 |
feature:** Deletion of semantically well-defined feature. Semantic
|
| 89 |
-
transformation.
|
| 90 |
-
|
| 91 |
call to achieve the initialization. Seldom.
|
| 92 |
|
| 93 |
-
[[basic.scope]] **Change:** A `struct` is a scope in C++, not in C
|
| 94 |
**Rationale:** Class scope is crucial to C++, and a struct is a class.
|
| 95 |
**Effect on original feature:** Change to semantics of well-defined
|
| 96 |
feature. Semantic transformation. C programs use `struct` extremely
|
| 97 |
frequently, but the change is only noticeable when `struct`,
|
| 98 |
enumeration, or enumerator names are referred to outside the `struct`.
|
| 99 |
The latter is probably rare.
|
| 100 |
|
| 101 |
[[basic.link]] \[also [[dcl.type]]\] **Change:** A name of file scope
|
| 102 |
that is explicitly declared `const`, and not explicitly declared
|
| 103 |
`extern`, has internal linkage, while in C it would have external
|
| 104 |
-
linkage **Rationale:** Because `const` objects
|
| 105 |
-
|
| 106 |
-
explicit initializer
|
| 107 |
-
user to put `const`objects in
|
| 108 |
-
|
| 109 |
-
of well-defined feature. Semantic transformation Seldom
|
| 110 |
|
| 111 |
-
[[basic.start]] **Change:**
|
| 112 |
-
have its address taken **Rationale:** The main
|
| 113 |
-
special actions. **Effect on original feature:**
|
| 114 |
-
semantically well-defined feature Trivial: create an
|
| 115 |
-
function such as `mymain(argc, argv)`. Seldom
|
| 116 |
|
| 117 |
[[basic.types]] **Change:** C allows “compatible types” in several
|
| 118 |
-
places, C++does not
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
C++. **Effect on
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
not
|
| 125 |
-
|
| 126 |
-
Standard. Common.
|
| 127 |
|
| 128 |
### Clause [[conv]]: standard conversions <a id="diff.conv">[[diff.conv]]</a>
|
| 129 |
|
| 130 |
[[conv.ptr]] **Change:** Converting `void*` to a pointer-to-object type
|
| 131 |
-
requires casting
|
| 132 |
|
| 133 |
``` cpp
|
| 134 |
char a[10];
|
| 135 |
void* b=a;
|
| 136 |
void foo() {
|
|
@@ -154,38 +155,44 @@ the cast when assigning pointer-to-void to pointer-to-object. Some ISO C
|
|
| 154 |
translators will give a warning if the cast is not used.
|
| 155 |
|
| 156 |
### Clause [[expr]]: expressions <a id="diff.expr">[[diff.expr]]</a>
|
| 157 |
|
| 158 |
[[expr.call]] **Change:** Implicit declaration of functions is not
|
| 159 |
-
allowed **Rationale:** The type-safe nature of C++. **Effect on
|
| 160 |
-
feature:** Deletion of semantically well-defined feature. Note:
|
| 161 |
-
original feature was labeled as “obsolescent” in ISO C. Syntactic
|
| 162 |
transformation. Facilities for producing explicit function declarations
|
| 163 |
are fairly widespread commercially. Common.
|
| 164 |
|
| 165 |
-
[[expr.
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
``` cpp
|
| 170 |
p = (void*)(struct x {int i;} *)0;
|
| 171 |
```
|
| 172 |
|
| 173 |
-
|
| 174 |
-
clarify the location of
|
| 175 |
-
original feature:** Deletion of
|
| 176 |
Syntactic transformation. Seldom.
|
| 177 |
|
| 178 |
-
[[expr.cond]], [[expr.ass]], [[expr.comma]]
|
| 179 |
-
|
| 180 |
-
**
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
expressions that implicitly rely on lvalue-to-rvalue conversions will
|
| 186 |
-
yield different results. For example,
|
| 187 |
|
| 188 |
``` cpp
|
| 189 |
char arr[100];
|
| 190 |
sizeof(0, arr)
|
| 191 |
```
|
|
@@ -195,23 +202,23 @@ casts to the appropriate rvalue. Rare.
|
|
| 195 |
|
| 196 |
### Clause [[stmt.stmt]]: statements <a id="diff.stat">[[diff.stat]]</a>
|
| 197 |
|
| 198 |
[[stmt.switch]], [[stmt.goto]] **Change:** It is now invalid to jump
|
| 199 |
past a declaration with explicit or implicit initializer (except across
|
| 200 |
-
entire block not entered) **Rationale:** Constructors used in
|
| 201 |
initializers may allocate resources which need to be de-allocated upon
|
| 202 |
leaving the block. Allowing jump past initializers would require
|
| 203 |
-
complicated
|
| 204 |
-
|
| 205 |
compile-time rule, C++assures that if an initialized variable is in
|
| 206 |
scope, then it has assuredly been initialized. **Effect on original
|
| 207 |
feature:** Deletion of semantically well-defined feature. Semantic
|
| 208 |
transformation. Seldom.
|
| 209 |
|
| 210 |
[[stmt.return]] **Change:** It is now invalid to return (explicitly or
|
| 211 |
implicitly) from a function which is declared to return a value without
|
| 212 |
-
actually returning a value **Rationale:** The caller and callee may
|
| 213 |
assume fairly elaborate return-value mechanisms for the return of class
|
| 214 |
objects. If some flow paths execute a return without specifying any
|
| 215 |
value, the implementation must embody many more complications. Besides,
|
| 216 |
promising to return a value of a given type, and then not returning such
|
| 217 |
a value, has always been recognized to be a questionable practice,
|
|
@@ -223,13 +230,13 @@ several years, many existing C implementations have produced warnings in
|
|
| 223 |
this case.
|
| 224 |
|
| 225 |
### Clause [[dcl.dcl]]: declarations <a id="diff.dcl">[[diff.dcl]]</a>
|
| 226 |
|
| 227 |
[[dcl.stc]] **Change:** In C++, the `static` or `extern` specifiers can
|
| 228 |
-
only be applied to names of objects or functions
|
| 229 |
-
with type declarations is illegal in C++. In C,
|
| 230 |
-
ignored when used on type declarations.
|
| 231 |
|
| 232 |
Example:
|
| 233 |
|
| 234 |
``` cpp
|
| 235 |
static struct S { // valid C, invalid in C++
|
|
@@ -242,57 +249,63 @@ associated with a type. In C++, class members can be declared with the
|
|
| 242 |
`static` storage class specifier. Allowing storage class specifiers on
|
| 243 |
type declarations could render the code confusing for users. **Effect on
|
| 244 |
original feature:** Deletion of semantically well-defined feature.
|
| 245 |
Syntactic transformation. Seldom.
|
| 246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
[[dcl.typedef]] **Change:** A C++typedef name must be different from any
|
| 248 |
class type name declared in the same scope (except if the typedef is a
|
| 249 |
synonym of the class name with the same name). In C, a typedef name and
|
| 250 |
a struct tag name declared in the same scope can have the same name
|
| 251 |
-
(because they have different name spaces)
|
| 252 |
|
| 253 |
Example:
|
| 254 |
|
| 255 |
``` cpp
|
| 256 |
-
typedef struct name1 {
|
| 257 |
-
struct name {
|
| 258 |
typedef int name; // valid C, invalid C++
|
| 259 |
```
|
| 260 |
|
| 261 |
**Rationale:** For ease of use, C++doesn’t require that a type name be
|
| 262 |
prefixed with the keywords `class`, `struct` or `union` when used in
|
| 263 |
object declarations or type casts.
|
| 264 |
|
| 265 |
Example:
|
| 266 |
|
| 267 |
``` cpp
|
| 268 |
-
class name {
|
| 269 |
name i; // i has type class name
|
| 270 |
```
|
| 271 |
|
| 272 |
**Effect on original feature:** Deletion of semantically well-defined
|
| 273 |
feature. Semantic transformation. One of the 2 types has to be renamed.
|
| 274 |
Seldom.
|
| 275 |
|
| 276 |
-
[[dcl.type]] \[see also [[basic.link]]\] **Change:** const objects
|
| 277 |
-
be initialized in C++but can be left uninitialized in C
|
| 278 |
-
const object cannot be assigned to so it must be
|
| 279 |
-
useful value. **Effect on original feature:**
|
| 280 |
-
well-defined feature. Semantic transformation.
|
|
|
|
| 281 |
|
| 282 |
-
[[dcl.type]] **Change:** Banning implicit int
|
| 283 |
|
| 284 |
In C++a *decl-specifier-seq* must contain a *type-specifier*, unless it
|
| 285 |
is followed by a declarator for a constructor, a destructor, or a
|
| 286 |
conversion function. In the following example, the left-hand column
|
| 287 |
presents valid C; the right-hand column presents equivalent C++:
|
| 288 |
|
| 289 |
``` cpp
|
| 290 |
void f(const parm); void f(const int parm);
|
| 291 |
const n = 3; const int n = 3;
|
| 292 |
main() int main()
|
| 293 |
-
|
| 294 |
```
|
| 295 |
|
| 296 |
**Rationale:** In C++, implicit int creates several opportunities for
|
| 297 |
ambiguity between expressions involving function-like casts and
|
| 298 |
declarations. Explicit declaration is increasingly considered to be
|
|
@@ -316,11 +329,11 @@ variable from its initializer results in undesired interpretations of
|
|
| 316 |
original feature:** Deletion of semantically well-defined feature.
|
| 317 |
Syntactic transformation. Rare.
|
| 318 |
|
| 319 |
[[dcl.enum]] **Change:** C++objects of enumeration type can only be
|
| 320 |
assigned values of the same enumeration type. In C, objects of
|
| 321 |
-
enumeration type can be assigned values of any integral type
|
| 322 |
|
| 323 |
Example:
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
enum color { red, blue, green };
|
|
@@ -373,50 +386,50 @@ further if different calls to the same (non-prototype) function have
|
|
| 373 |
different numbers of arguments or if the type of corresponding arguments
|
| 374 |
differed. Common.
|
| 375 |
|
| 376 |
[[dcl.fct]] \[see [[expr.sizeof]]\] **Change:** In C++, types may not be
|
| 377 |
defined in return or parameter types. In C, these type definitions are
|
| 378 |
-
allowed
|
| 379 |
|
| 380 |
Example:
|
| 381 |
|
| 382 |
``` cpp
|
| 383 |
void f( struct S { int a; } arg ) {} // valid C, invalid C++
|
| 384 |
enum E { A, B, C } f() {} // valid C, invalid C++
|
| 385 |
```
|
| 386 |
|
| 387 |
-
**Rationale:** When comparing types in different
|
| 388 |
C++relies on name equivalence when C relies on structural equivalence.
|
| 389 |
-
Regarding parameter types: since the type defined in
|
| 390 |
would be in the scope of the function, the only legal calls in C++ would
|
| 391 |
be from within the function itself. **Effect on original feature:**
|
| 392 |
Deletion of semantically well-defined feature. Semantic transformation.
|
| 393 |
The type definitions must be moved to file scope, or in header files.
|
| 394 |
-
Seldom. This style of type
|
| 395 |
|
| 396 |
[[dcl.fct.def]] **Change:** In C++, the syntax for function definition
|
| 397 |
excludes the “old-style” C function. In C, “old-style” syntax is
|
| 398 |
-
allowed, but deprecated as “obsolescent
|
| 399 |
essential to type safety. **Effect on original feature:** Deletion of
|
| 400 |
semantically well-defined feature. Syntactic transformation. Common in
|
| 401 |
old programs, but already known to be obsolescent.
|
| 402 |
|
| 403 |
[[dcl.init.string]] **Change:** In C++, when initializing an array of
|
| 404 |
character with a string, the number of characters in the string
|
| 405 |
(including the terminating `'\0'`) must not exceed the number of
|
| 406 |
elements in the array. In C, an array can be initialized with a string
|
| 407 |
even if the array is not large enough to contain the string-terminating
|
| 408 |
-
`'\0'`
|
| 409 |
|
| 410 |
Example:
|
| 411 |
|
| 412 |
``` cpp
|
| 413 |
char array[4] = "abcd"; // valid C, invalid C++
|
| 414 |
```
|
| 415 |
|
| 416 |
**Rationale:** When these non-terminated arrays are manipulated by
|
| 417 |
-
standard string
|
| 418 |
**Effect on original feature:** Deletion of semantically well-defined
|
| 419 |
feature. Semantic transformation. The arrays must be declared one
|
| 420 |
element bigger to contain the string terminating `'\0'`. Seldom. This
|
| 421 |
style of array initialization is seen as poor coding style.
|
| 422 |
|
|
@@ -424,11 +437,12 @@ style of array initialization is seen as poor coding style.
|
|
| 424 |
|
| 425 |
[[class.name]] \[see also [[dcl.typedef]]\] **Change:** In C++, a class
|
| 426 |
declaration introduces the class name into the scope where it is
|
| 427 |
declared and hides any object, function or other declaration of that
|
| 428 |
name in an enclosing scope. In C, an inner scope declaration of a struct
|
| 429 |
-
tag name never hides the name of an object or function in an outer
|
|
|
|
| 430 |
|
| 431 |
Example:
|
| 432 |
|
| 433 |
``` cpp
|
| 434 |
int x[99];
|
|
@@ -457,11 +471,11 @@ Seldom.
|
|
| 457 |
|
| 458 |
[[class.bit]] **Change:** Bit-fields of type plain `int` are signed.
|
| 459 |
**Rationale:** Leaving the choice of signedness to implementations could
|
| 460 |
lead to inconsistent definitions of template specializations. For
|
| 461 |
consistency, the implementation freedom was eliminated for non-dependent
|
| 462 |
-
types, too. **Effect on original feature:** The
|
| 463 |
implementation-defined in C, but not so in C++. Syntactic
|
| 464 |
transformation. Seldom.
|
| 465 |
|
| 466 |
[[class.nest]] **Change:** In C++, the name of a nested class is local
|
| 467 |
to its enclosing class. In C the name of the nested class belongs to the
|
|
@@ -469,11 +483,11 @@ same scope as the name of the outermost enclosing class.
|
|
| 469 |
|
| 470 |
Example:
|
| 471 |
|
| 472 |
``` cpp
|
| 473 |
struct X {
|
| 474 |
-
struct Y {
|
| 475 |
};
|
| 476 |
struct Y yy; // valid C, invalid C++
|
| 477 |
```
|
| 478 |
|
| 479 |
**Rationale:** C++classes have member functions which require that
|
|
@@ -481,30 +495,30 @@ classes establish scopes. The C rule would leave classes as an
|
|
| 481 |
incomplete scope mechanism which would prevent C++programmers from
|
| 482 |
maintaining locality within a class. A coherent set of scope rules for
|
| 483 |
C++based on the C rule would be very complicated and C++programmers
|
| 484 |
would be unable to predict reliably the meanings of nontrivial examples
|
| 485 |
involving nested or local functions. **Effect on original feature:**
|
| 486 |
-
Change
|
| 487 |
make the struct type name visible in the scope of the enclosing struct,
|
| 488 |
the struct tag could be declared in the scope of the enclosing struct,
|
| 489 |
before the enclosing struct is defined. Example:
|
| 490 |
|
| 491 |
``` cpp
|
| 492 |
struct Y; // struct Y and struct X are at the same scope
|
| 493 |
struct X {
|
| 494 |
-
struct Y {
|
| 495 |
};
|
| 496 |
```
|
| 497 |
|
| 498 |
All the definitions of C struct types enclosed in other struct
|
| 499 |
definitions and accessed outside the scope of the enclosing struct could
|
| 500 |
be exported to the scope of the enclosing struct. Note: this is a
|
| 501 |
consequence of the difference in scope rules, which is documented in
|
| 502 |
[[basic.scope]]. Seldom.
|
| 503 |
|
| 504 |
[[class.nested.type]] **Change:** In C++, a typedef name may not be
|
| 505 |
-
redeclared in a class definition after being used in that definition
|
| 506 |
|
| 507 |
Example:
|
| 508 |
|
| 509 |
``` cpp
|
| 510 |
typedef int I;
|
|
@@ -514,27 +528,27 @@ struct S {
|
|
| 514 |
};
|
| 515 |
```
|
| 516 |
|
| 517 |
**Rationale:** When classes become complicated, allowing such a
|
| 518 |
redefinition after the type has been used can create confusion for C++
|
| 519 |
-
programmers as to what the meaning of
|
| 520 |
original feature:** Deletion of semantically well-defined feature.
|
| 521 |
Semantic transformation. Either the type or the struct member has to be
|
| 522 |
renamed. Seldom.
|
| 523 |
|
| 524 |
### Clause [[special]]: special member functions <a id="diff.special">[[diff.special]]</a>
|
| 525 |
|
| 526 |
-
[[class.copy]] **Change:** Copying volatile objects
|
| 527 |
|
| 528 |
The implicitly-declared copy constructor and implicitly-declared copy
|
| 529 |
assignment operator cannot make a copy of a volatile lvalue. For
|
| 530 |
example, the following is valid in ISO C:
|
| 531 |
|
| 532 |
``` cpp
|
| 533 |
struct X { int i; };
|
| 534 |
volatile struct X x1 = {0};
|
| 535 |
-
struct X x2
|
| 536 |
struct X x3;
|
| 537 |
x3 = x1; // also invalid C++
|
| 538 |
```
|
| 539 |
|
| 540 |
**Rationale:** Several alternatives were debated at length. Changing the
|
|
@@ -544,20 +558,19 @@ two alternative signatures for these implicitly-defined operations
|
|
| 544 |
raised unanswered concerns about creating ambiguities and complicating
|
| 545 |
the rules that specify the formation of these operators according to the
|
| 546 |
bases and members. **Effect on original feature:** Deletion of
|
| 547 |
semantically well-defined feature. Semantic transformation. If volatile
|
| 548 |
semantics are required for the copy, a user-declared constructor or
|
| 549 |
-
assignment must be provided.
|
| 550 |
-
explicitly defaulted. If non-volatile semantics are required, an
|
| 551 |
explicit `const_cast` can be used. Seldom.
|
| 552 |
|
| 553 |
### Clause [[cpp]]: preprocessing directives <a id="diff.cpp">[[diff.cpp]]</a>
|
| 554 |
|
| 555 |
[[cpp.predefined]] **Change:** Whether `__STDC__` is defined and if so,
|
| 556 |
-
what its value is, are implementation-defined **Rationale:** C++is
|
| 557 |
-
identical to ISO C. Mandating that `__STDC__` be defined would
|
| 558 |
-
that translators make an incorrect claim. Each implementation
|
| 559 |
-
choose the behavior that will be most useful to its marketplace.
|
| 560 |
**Effect on original feature:** Change to semantics of well-defined
|
| 561 |
feature. Semantic transformation. Programs and headers that reference
|
| 562 |
`__STDC__` are quite common.
|
| 563 |
|
|
|
|
| 13 |
identifiers are not valid C++programs. Syntactic transformation.
|
| 14 |
Converting one specific program is easy. Converting a large collection
|
| 15 |
of related programs takes more work. Common.
|
| 16 |
|
| 17 |
[[lex.ccon]] **Change:** Type of character literal is changed from `int`
|
| 18 |
+
to `char`. **Rationale:** This is needed for improved overloaded
|
| 19 |
+
function argument type matching. For example:
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
int function( int i );
|
| 23 |
int function( char c );
|
| 24 |
|
|
|
|
| 34 |
```
|
| 35 |
|
| 36 |
will not work the same as C++programs. Simple. Programs which depend
|
| 37 |
upon `sizeof('x')` are probably rare.
|
| 38 |
|
| 39 |
+
Subclause [[lex.string]]: **Change:** String literals made const.
|
| 40 |
The type of a string literal is changed from “array of `char`” to “array
|
| 41 |
+
of `const char`”. The type of a `char16_t` string literal is changed
|
| 42 |
+
from “array of *some-integer-type*” to “array of `const char16_t`”. The
|
| 43 |
type of a `char32_t` string literal is changed from “array of
|
| 44 |
+
*some-integer-type*” to “array of `const char32_t`”. The type of a wide
|
| 45 |
string literal is changed from “array of `wchar_t`” to “array of
|
| 46 |
+
`const wchar_t`”. **Rationale:** This avoids calling an inappropriate
|
| 47 |
overloaded function, which might expect to be able to modify its
|
| 48 |
argument. **Effect on original feature:** Change to semantics of
|
| 49 |
well-defined feature. Syntactic transformation. The fix is to add a
|
| 50 |
cast:
|
| 51 |
|
|
|
|
| 62 |
pointers to potentially modifiable memory are probably rare.
|
| 63 |
|
| 64 |
### Clause [[basic]]: basic concepts <a id="diff.basic">[[diff.basic]]</a>
|
| 65 |
|
| 66 |
[[basic.def]] **Change:** C++does not have “tentative definitions” as in
|
| 67 |
+
C.
|
| 68 |
+
E.g., at file scope,
|
| 69 |
|
| 70 |
``` cpp
|
| 71 |
int i;
|
| 72 |
int i;
|
| 73 |
```
|
|
|
|
| 85 |
```
|
| 86 |
|
| 87 |
**Rationale:** This avoids having different initialization rules for
|
| 88 |
fundamental types and user-defined types. **Effect on original
|
| 89 |
feature:** Deletion of semantically well-defined feature. Semantic
|
| 90 |
+
transformation. In C++, the initializer for one of a set of
|
| 91 |
+
mutually-referential file-local static objects must invoke a function
|
| 92 |
call to achieve the initialization. Seldom.
|
| 93 |
|
| 94 |
+
[[basic.scope]] **Change:** A `struct` is a scope in C++, not in C.
|
| 95 |
**Rationale:** Class scope is crucial to C++, and a struct is a class.
|
| 96 |
**Effect on original feature:** Change to semantics of well-defined
|
| 97 |
feature. Semantic transformation. C programs use `struct` extremely
|
| 98 |
frequently, but the change is only noticeable when `struct`,
|
| 99 |
enumeration, or enumerator names are referred to outside the `struct`.
|
| 100 |
The latter is probably rare.
|
| 101 |
|
| 102 |
[[basic.link]] \[also [[dcl.type]]\] **Change:** A name of file scope
|
| 103 |
that is explicitly declared `const`, and not explicitly declared
|
| 104 |
`extern`, has internal linkage, while in C it would have external
|
| 105 |
+
linkage. **Rationale:** Because `const` objects may be used as values
|
| 106 |
+
during translation in C++, this feature urges programmers to provide an
|
| 107 |
+
explicit initializer for each `const` object. This feature allows the
|
| 108 |
+
user to put `const` objects in source files that are included in more
|
| 109 |
+
than one translation unit. **Effect on original feature:** Change to
|
| 110 |
+
semantics of well-defined feature. Semantic transformation. Seldom.
|
| 111 |
|
| 112 |
+
[[basic.start.main]] **Change:** The `main` function cannot be called
|
| 113 |
+
recursively and cannot have its address taken. **Rationale:** The `main`
|
| 114 |
+
function may require special actions. **Effect on original feature:**
|
| 115 |
+
Deletion of semantically well-defined feature. Trivial: create an
|
| 116 |
+
intermediary function such as `mymain(argc, argv)`. Seldom.
|
| 117 |
|
| 118 |
[[basic.types]] **Change:** C allows “compatible types” in several
|
| 119 |
+
places, C++does not.
|
| 120 |
+
For example, otherwise-identical `struct` types with different tag names
|
| 121 |
+
are “compatible” in C but are distinctly different types in C++.
|
| 122 |
+
**Rationale:** Stricter type checking is essential for C++. **Effect on
|
| 123 |
+
original feature:** Deletion of semantically well-defined feature.
|
| 124 |
+
Semantic transformation. The “typesafe linkage” mechanism will find
|
| 125 |
+
many, but not all, of such problems. Those problems not found by
|
| 126 |
+
typesafe linkage will continue to function properly, according to the
|
| 127 |
+
“layout compatibility rules” of this International Standard. Common.
|
| 128 |
|
| 129 |
### Clause [[conv]]: standard conversions <a id="diff.conv">[[diff.conv]]</a>
|
| 130 |
|
| 131 |
[[conv.ptr]] **Change:** Converting `void*` to a pointer-to-object type
|
| 132 |
+
requires casting.
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
char a[10];
|
| 136 |
void* b=a;
|
| 137 |
void foo() {
|
|
|
|
| 155 |
translators will give a warning if the cast is not used.
|
| 156 |
|
| 157 |
### Clause [[expr]]: expressions <a id="diff.expr">[[diff.expr]]</a>
|
| 158 |
|
| 159 |
[[expr.call]] **Change:** Implicit declaration of functions is not
|
| 160 |
+
allowed. **Rationale:** The type-safe nature of C++. **Effect on
|
| 161 |
+
original feature:** Deletion of semantically well-defined feature. Note:
|
| 162 |
+
the original feature was labeled as “obsolescent” in ISO C. Syntactic
|
| 163 |
transformation. Facilities for producing explicit function declarations
|
| 164 |
are fairly widespread commercially. Common.
|
| 165 |
|
| 166 |
+
[[expr.post.incr]], [[expr.pre.incr]] **Change:** Decrement operator is
|
| 167 |
+
not allowed with `bool` operand. **Rationale:** Feature with surprising
|
| 168 |
+
semantics. **Effect on original feature:** A valid ISO C expression
|
| 169 |
+
utilizing the decrement operator on a `bool` lvalue (for instance, via
|
| 170 |
+
the C typedef in `<stdbool.h>`) is ill-formed in this International
|
| 171 |
+
Standard.
|
| 172 |
+
|
| 173 |
+
[[expr.sizeof]], [[expr.cast]] **Change:** Types must be defined in
|
| 174 |
+
declarations, not in expressions.
|
| 175 |
+
In C, a sizeof expression or cast expression may define a new type. For
|
| 176 |
+
example,
|
| 177 |
|
| 178 |
``` cpp
|
| 179 |
p = (void*)(struct x {int i;} *)0;
|
| 180 |
```
|
| 181 |
|
| 182 |
+
defines a new type, struct `x`. **Rationale:** This prohibition helps to
|
| 183 |
+
clarify the location of definitions in the source code. **Effect on
|
| 184 |
+
original feature:** Deletion of semantically well-defined feature.
|
| 185 |
Syntactic transformation. Seldom.
|
| 186 |
|
| 187 |
+
[[expr.cond]], [[expr.ass]], [[expr.comma]] **Change:** The result of a
|
| 188 |
+
conditional expression, an assignment expression, or a comma expression
|
| 189 |
+
may be an lvalue. **Rationale:** C++is an object-oriented language,
|
| 190 |
+
placing relatively more emphasis on lvalues. For example, functions may
|
| 191 |
+
return lvalues. **Effect on original feature:** Change to semantics of
|
| 192 |
+
well-defined feature. Some C expressions that implicitly rely on
|
| 193 |
+
lvalue-to-rvalue conversions will yield different results. For example,
|
|
|
|
|
|
|
| 194 |
|
| 195 |
``` cpp
|
| 196 |
char arr[100];
|
| 197 |
sizeof(0, arr)
|
| 198 |
```
|
|
|
|
| 202 |
|
| 203 |
### Clause [[stmt.stmt]]: statements <a id="diff.stat">[[diff.stat]]</a>
|
| 204 |
|
| 205 |
[[stmt.switch]], [[stmt.goto]] **Change:** It is now invalid to jump
|
| 206 |
past a declaration with explicit or implicit initializer (except across
|
| 207 |
+
entire block not entered). **Rationale:** Constructors used in
|
| 208 |
initializers may allocate resources which need to be de-allocated upon
|
| 209 |
leaving the block. Allowing jump past initializers would require
|
| 210 |
+
complicated runtime determination of allocation. Furthermore, any use of
|
| 211 |
+
the uninitialized object could be a disaster. With this simple
|
| 212 |
compile-time rule, C++assures that if an initialized variable is in
|
| 213 |
scope, then it has assuredly been initialized. **Effect on original
|
| 214 |
feature:** Deletion of semantically well-defined feature. Semantic
|
| 215 |
transformation. Seldom.
|
| 216 |
|
| 217 |
[[stmt.return]] **Change:** It is now invalid to return (explicitly or
|
| 218 |
implicitly) from a function which is declared to return a value without
|
| 219 |
+
actually returning a value. **Rationale:** The caller and callee may
|
| 220 |
assume fairly elaborate return-value mechanisms for the return of class
|
| 221 |
objects. If some flow paths execute a return without specifying any
|
| 222 |
value, the implementation must embody many more complications. Besides,
|
| 223 |
promising to return a value of a given type, and then not returning such
|
| 224 |
a value, has always been recognized to be a questionable practice,
|
|
|
|
| 230 |
this case.
|
| 231 |
|
| 232 |
### Clause [[dcl.dcl]]: declarations <a id="diff.dcl">[[diff.dcl]]</a>
|
| 233 |
|
| 234 |
[[dcl.stc]] **Change:** In C++, the `static` or `extern` specifiers can
|
| 235 |
+
only be applied to names of objects or functions.
|
| 236 |
+
Using these specifiers with type declarations is illegal in C++. In C,
|
| 237 |
+
these specifiers are ignored when used on type declarations.
|
| 238 |
|
| 239 |
Example:
|
| 240 |
|
| 241 |
``` cpp
|
| 242 |
static struct S { // valid C, invalid in C++
|
|
|
|
| 249 |
`static` storage class specifier. Allowing storage class specifiers on
|
| 250 |
type declarations could render the code confusing for users. **Effect on
|
| 251 |
original feature:** Deletion of semantically well-defined feature.
|
| 252 |
Syntactic transformation. Seldom.
|
| 253 |
|
| 254 |
+
[[dcl.stc]] **Change:** In C++, `register` is not a storage class
|
| 255 |
+
specifier. **Rationale:** The storage class specifier had no effect in
|
| 256 |
+
C++. **Effect on original feature:** Deletion of semantically
|
| 257 |
+
well-defined feature. Syntactic transformation. Common.
|
| 258 |
+
|
| 259 |
[[dcl.typedef]] **Change:** A C++typedef name must be different from any
|
| 260 |
class type name declared in the same scope (except if the typedef is a
|
| 261 |
synonym of the class name with the same name). In C, a typedef name and
|
| 262 |
a struct tag name declared in the same scope can have the same name
|
| 263 |
+
(because they have different name spaces).
|
| 264 |
|
| 265 |
Example:
|
| 266 |
|
| 267 |
``` cpp
|
| 268 |
+
typedef struct name1 { ... } name1; // valid C and C++
|
| 269 |
+
struct name { ... };
|
| 270 |
typedef int name; // valid C, invalid C++
|
| 271 |
```
|
| 272 |
|
| 273 |
**Rationale:** For ease of use, C++doesn’t require that a type name be
|
| 274 |
prefixed with the keywords `class`, `struct` or `union` when used in
|
| 275 |
object declarations or type casts.
|
| 276 |
|
| 277 |
Example:
|
| 278 |
|
| 279 |
``` cpp
|
| 280 |
+
class name { ... };
|
| 281 |
name i; // i has type class name
|
| 282 |
```
|
| 283 |
|
| 284 |
**Effect on original feature:** Deletion of semantically well-defined
|
| 285 |
feature. Semantic transformation. One of the 2 types has to be renamed.
|
| 286 |
Seldom.
|
| 287 |
|
| 288 |
+
[[dcl.type]] \[see also [[basic.link]]\] **Change:** `const` objects
|
| 289 |
+
must be initialized in C++but can be left uninitialized in C.
|
| 290 |
+
**Rationale:** A const object cannot be assigned to so it must be
|
| 291 |
+
initialized to hold a useful value. **Effect on original feature:**
|
| 292 |
+
Deletion of semantically well-defined feature. Semantic transformation.
|
| 293 |
+
Seldom.
|
| 294 |
|
| 295 |
+
[[dcl.type]] **Change:** Banning implicit `int`.
|
| 296 |
|
| 297 |
In C++a *decl-specifier-seq* must contain a *type-specifier*, unless it
|
| 298 |
is followed by a declarator for a constructor, a destructor, or a
|
| 299 |
conversion function. In the following example, the left-hand column
|
| 300 |
presents valid C; the right-hand column presents equivalent C++:
|
| 301 |
|
| 302 |
``` cpp
|
| 303 |
void f(const parm); void f(const int parm);
|
| 304 |
const n = 3; const int n = 3;
|
| 305 |
main() int main()
|
| 306 |
+
... ...
|
| 307 |
```
|
| 308 |
|
| 309 |
**Rationale:** In C++, implicit int creates several opportunities for
|
| 310 |
ambiguity between expressions involving function-like casts and
|
| 311 |
declarations. Explicit declaration is increasingly considered to be
|
|
|
|
| 329 |
original feature:** Deletion of semantically well-defined feature.
|
| 330 |
Syntactic transformation. Rare.
|
| 331 |
|
| 332 |
[[dcl.enum]] **Change:** C++objects of enumeration type can only be
|
| 333 |
assigned values of the same enumeration type. In C, objects of
|
| 334 |
+
enumeration type can be assigned values of any integral type.
|
| 335 |
|
| 336 |
Example:
|
| 337 |
|
| 338 |
``` cpp
|
| 339 |
enum color { red, blue, green };
|
|
|
|
| 386 |
different numbers of arguments or if the type of corresponding arguments
|
| 387 |
differed. Common.
|
| 388 |
|
| 389 |
[[dcl.fct]] \[see [[expr.sizeof]]\] **Change:** In C++, types may not be
|
| 390 |
defined in return or parameter types. In C, these type definitions are
|
| 391 |
+
allowed.
|
| 392 |
|
| 393 |
Example:
|
| 394 |
|
| 395 |
``` cpp
|
| 396 |
void f( struct S { int a; } arg ) {} // valid C, invalid C++
|
| 397 |
enum E { A, B, C } f() {} // valid C, invalid C++
|
| 398 |
```
|
| 399 |
|
| 400 |
+
**Rationale:** When comparing types in different translation units,
|
| 401 |
C++relies on name equivalence when C relies on structural equivalence.
|
| 402 |
+
Regarding parameter types: since the type defined in a parameter list
|
| 403 |
would be in the scope of the function, the only legal calls in C++ would
|
| 404 |
be from within the function itself. **Effect on original feature:**
|
| 405 |
Deletion of semantically well-defined feature. Semantic transformation.
|
| 406 |
The type definitions must be moved to file scope, or in header files.
|
| 407 |
+
Seldom. This style of type definition is seen as poor coding style.
|
| 408 |
|
| 409 |
[[dcl.fct.def]] **Change:** In C++, the syntax for function definition
|
| 410 |
excludes the “old-style” C function. In C, “old-style” syntax is
|
| 411 |
+
allowed, but deprecated as “obsolescent”. **Rationale:** Prototypes are
|
| 412 |
essential to type safety. **Effect on original feature:** Deletion of
|
| 413 |
semantically well-defined feature. Syntactic transformation. Common in
|
| 414 |
old programs, but already known to be obsolescent.
|
| 415 |
|
| 416 |
[[dcl.init.string]] **Change:** In C++, when initializing an array of
|
| 417 |
character with a string, the number of characters in the string
|
| 418 |
(including the terminating `'\0'`) must not exceed the number of
|
| 419 |
elements in the array. In C, an array can be initialized with a string
|
| 420 |
even if the array is not large enough to contain the string-terminating
|
| 421 |
+
`'\0'`.
|
| 422 |
|
| 423 |
Example:
|
| 424 |
|
| 425 |
``` cpp
|
| 426 |
char array[4] = "abcd"; // valid C, invalid C++
|
| 427 |
```
|
| 428 |
|
| 429 |
**Rationale:** When these non-terminated arrays are manipulated by
|
| 430 |
+
standard string functions, there is potential for major catastrophe.
|
| 431 |
**Effect on original feature:** Deletion of semantically well-defined
|
| 432 |
feature. Semantic transformation. The arrays must be declared one
|
| 433 |
element bigger to contain the string terminating `'\0'`. Seldom. This
|
| 434 |
style of array initialization is seen as poor coding style.
|
| 435 |
|
|
|
|
| 437 |
|
| 438 |
[[class.name]] \[see also [[dcl.typedef]]\] **Change:** In C++, a class
|
| 439 |
declaration introduces the class name into the scope where it is
|
| 440 |
declared and hides any object, function or other declaration of that
|
| 441 |
name in an enclosing scope. In C, an inner scope declaration of a struct
|
| 442 |
+
tag name never hides the name of an object or function in an outer
|
| 443 |
+
scope.
|
| 444 |
|
| 445 |
Example:
|
| 446 |
|
| 447 |
``` cpp
|
| 448 |
int x[99];
|
|
|
|
| 471 |
|
| 472 |
[[class.bit]] **Change:** Bit-fields of type plain `int` are signed.
|
| 473 |
**Rationale:** Leaving the choice of signedness to implementations could
|
| 474 |
lead to inconsistent definitions of template specializations. For
|
| 475 |
consistency, the implementation freedom was eliminated for non-dependent
|
| 476 |
+
types, too. **Effect on original feature:** The choice is
|
| 477 |
implementation-defined in C, but not so in C++. Syntactic
|
| 478 |
transformation. Seldom.
|
| 479 |
|
| 480 |
[[class.nest]] **Change:** In C++, the name of a nested class is local
|
| 481 |
to its enclosing class. In C the name of the nested class belongs to the
|
|
|
|
| 483 |
|
| 484 |
Example:
|
| 485 |
|
| 486 |
``` cpp
|
| 487 |
struct X {
|
| 488 |
+
struct Y { ... } y;
|
| 489 |
};
|
| 490 |
struct Y yy; // valid C, invalid C++
|
| 491 |
```
|
| 492 |
|
| 493 |
**Rationale:** C++classes have member functions which require that
|
|
|
|
| 495 |
incomplete scope mechanism which would prevent C++programmers from
|
| 496 |
maintaining locality within a class. A coherent set of scope rules for
|
| 497 |
C++based on the C rule would be very complicated and C++programmers
|
| 498 |
would be unable to predict reliably the meanings of nontrivial examples
|
| 499 |
involving nested or local functions. **Effect on original feature:**
|
| 500 |
+
Change to semantics of well-defined feature. Semantic transformation. To
|
| 501 |
make the struct type name visible in the scope of the enclosing struct,
|
| 502 |
the struct tag could be declared in the scope of the enclosing struct,
|
| 503 |
before the enclosing struct is defined. Example:
|
| 504 |
|
| 505 |
``` cpp
|
| 506 |
struct Y; // struct Y and struct X are at the same scope
|
| 507 |
struct X {
|
| 508 |
+
struct Y { ... } y;
|
| 509 |
};
|
| 510 |
```
|
| 511 |
|
| 512 |
All the definitions of C struct types enclosed in other struct
|
| 513 |
definitions and accessed outside the scope of the enclosing struct could
|
| 514 |
be exported to the scope of the enclosing struct. Note: this is a
|
| 515 |
consequence of the difference in scope rules, which is documented in
|
| 516 |
[[basic.scope]]. Seldom.
|
| 517 |
|
| 518 |
[[class.nested.type]] **Change:** In C++, a typedef name may not be
|
| 519 |
+
redeclared in a class definition after being used in that definition.
|
| 520 |
|
| 521 |
Example:
|
| 522 |
|
| 523 |
``` cpp
|
| 524 |
typedef int I;
|
|
|
|
| 528 |
};
|
| 529 |
```
|
| 530 |
|
| 531 |
**Rationale:** When classes become complicated, allowing such a
|
| 532 |
redefinition after the type has been used can create confusion for C++
|
| 533 |
+
programmers as to what the meaning of `I` really is. **Effect on
|
| 534 |
original feature:** Deletion of semantically well-defined feature.
|
| 535 |
Semantic transformation. Either the type or the struct member has to be
|
| 536 |
renamed. Seldom.
|
| 537 |
|
| 538 |
### Clause [[special]]: special member functions <a id="diff.special">[[diff.special]]</a>
|
| 539 |
|
| 540 |
+
[[class.copy]] **Change:** Copying volatile objects.
|
| 541 |
|
| 542 |
The implicitly-declared copy constructor and implicitly-declared copy
|
| 543 |
assignment operator cannot make a copy of a volatile lvalue. For
|
| 544 |
example, the following is valid in ISO C:
|
| 545 |
|
| 546 |
``` cpp
|
| 547 |
struct X { int i; };
|
| 548 |
volatile struct X x1 = {0};
|
| 549 |
+
struct X x2 = x1; // invalid C++
|
| 550 |
struct X x3;
|
| 551 |
x3 = x1; // also invalid C++
|
| 552 |
```
|
| 553 |
|
| 554 |
**Rationale:** Several alternatives were debated at length. Changing the
|
|
|
|
| 558 |
raised unanswered concerns about creating ambiguities and complicating
|
| 559 |
the rules that specify the formation of these operators according to the
|
| 560 |
bases and members. **Effect on original feature:** Deletion of
|
| 561 |
semantically well-defined feature. Semantic transformation. If volatile
|
| 562 |
semantics are required for the copy, a user-declared constructor or
|
| 563 |
+
assignment must be provided. If non-volatile semantics are required, an
|
|
|
|
| 564 |
explicit `const_cast` can be used. Seldom.
|
| 565 |
|
| 566 |
### Clause [[cpp]]: preprocessing directives <a id="diff.cpp">[[diff.cpp]]</a>
|
| 567 |
|
| 568 |
[[cpp.predefined]] **Change:** Whether `__STDC__` is defined and if so,
|
| 569 |
+
what its value is, are *implementation-defined*. **Rationale:** C++is
|
| 570 |
+
not identical to ISO C. Mandating that `__STDC__` be defined would
|
| 571 |
+
require that translators make an incorrect claim. Each implementation
|
| 572 |
+
must choose the behavior that will be most useful to its marketplace.
|
| 573 |
**Effect on original feature:** Change to semantics of well-defined
|
| 574 |
feature. Semantic transformation. Programs and headers that reference
|
| 575 |
`__STDC__` are quite common.
|
| 576 |
|