tmp/tmpj1sj6jcc/{from.md → to.md}
RENAMED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
## C++ and ISO C <a id="diff.iso">[[diff.iso]]</a>
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
### [[lex]]: lexical conventions <a id="diff.lex">[[diff.lex]]</a>
|
| 7 |
|
| 8 |
**Change:** New Keywords
|
| 9 |
New keywords are added to C++; see [[lex.key]]. **Rationale:** These
|
|
@@ -34,10 +36,16 @@ 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 |
**Change:** String literals made const.
|
| 40 |
The type of a *string-literal* is changed from “array of `char`” to
|
| 41 |
“array of `const char`”. The type of a UTF-8 string literal is changed
|
| 42 |
from “array of `char`” to “array of `const char8_t`”. The type of a
|
| 43 |
UTF-16 string literal is changed from “array of *some-integer-type*” to
|
|
@@ -51,13 +59,13 @@ Change to semantics of well-defined feature. Syntactic transformation.
|
|
| 51 |
The fix is to add a cast:
|
| 52 |
|
| 53 |
``` cpp
|
| 54 |
char* p = "abc"; // valid in C, invalid in C++{}
|
| 55 |
void f(char*) {
|
| 56 |
-
char* p = (char*)"abc"; // OK
|
| 57 |
f(p);
|
| 58 |
-
f((char*)"def"); // OK
|
| 59 |
}
|
| 60 |
```
|
| 61 |
|
| 62 |
Programs that have a legitimate reason to treat string literal objects
|
| 63 |
as potentially modifiable memory are probably rare.
|
|
@@ -89,16 +97,26 @@ 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 objects with static storage duration
|
| 92 |
must invoke a function call to achieve the initialization. Seldom.
|
| 93 |
|
| 94 |
-
**Change:** A `struct` is a scope in C++, not in C.
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
\[also [[dcl.type]]\] **Change:** A name of file scope that is
|
| 102 |
explicitly declared `const`, and not explicitly declared `extern`, has
|
| 103 |
internal linkage, while in C it would have external linkage.
|
| 104 |
**Rationale:** Because const objects may be used as values during
|
|
@@ -136,14 +154,14 @@ void* b=a;
|
|
| 136 |
void foo() {
|
| 137 |
char* c=b;
|
| 138 |
}
|
| 139 |
```
|
| 140 |
|
| 141 |
-
ISO C
|
| 142 |
-
pointer to object type. C++
|
| 143 |
than C to enforce compile-time type safety. **Effect on original
|
| 144 |
-
feature:** Deletion of semantically well-defined feature.
|
| 145 |
automated. Violations will be diagnosed by the C++ translator. The fix
|
| 146 |
is to add a cast. For example:
|
| 147 |
|
| 148 |
``` cpp
|
| 149 |
char* c = (char*) b;
|
|
@@ -151,26 +169,20 @@ char* c = (char*) b;
|
|
| 151 |
|
| 152 |
This is fairly widely used but it is good programming practice to add
|
| 153 |
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 |
-
**Change:** Implicit declaration of functions is not allowed.
|
| 157 |
-
**Rationale:** The type-safe nature of C++. **Effect on original
|
| 158 |
-
feature:** Deletion of semantically well-defined feature. Note: the
|
| 159 |
-
original feature was labeled as “obsolescent” in ISO C. Syntactic
|
| 160 |
-
transformation. Facilities for producing explicit function declarations
|
| 161 |
-
are fairly widespread commercially. Common.
|
| 162 |
-
|
| 163 |
**Change:** Decrement operator is not allowed with `bool` operand.
|
| 164 |
**Rationale:** Feature with surprising semantics. **Effect on original
|
| 165 |
feature:** A valid ISO C expression utilizing the decrement operator on
|
| 166 |
-
a `bool` lvalue (for instance, via the C typedef in ) is
|
| 167 |
-
|
| 168 |
|
| 169 |
-
**Change:**
|
| 170 |
-
|
| 171 |
-
|
|
|
|
| 172 |
|
| 173 |
``` cpp
|
| 174 |
p = (void*)(struct x {int i;} *)0;
|
| 175 |
```
|
| 176 |
|
|
@@ -200,13 +212,13 @@ casts to the appropriate rvalue. Rare.
|
|
| 200 |
**Change:** It is now invalid to jump past a declaration with explicit
|
| 201 |
or implicit initializer (except across entire block not entered).
|
| 202 |
**Rationale:** Constructors used in initializers may allocate resources
|
| 203 |
which need to be de-allocated upon leaving the block. Allowing jump past
|
| 204 |
initializers would require complicated runtime determination of
|
| 205 |
-
allocation. Furthermore,
|
| 206 |
-
|
| 207 |
-
initialized variable is in scope, then it has assuredly been
|
| 208 |
initialized. **Effect on original feature:** Deletion of semantically
|
| 209 |
well-defined feature. Semantic transformation. Seldom.
|
| 210 |
|
| 211 |
**Change:** It is now invalid to return (explicitly or implicitly) from
|
| 212 |
a function which is declared to return a value without actually
|
|
@@ -214,16 +226,16 @@ returning a value. **Rationale:** The caller and callee may assume
|
|
| 214 |
fairly elaborate return-value mechanisms for the return of class
|
| 215 |
objects. If some flow paths execute a return without specifying any
|
| 216 |
value, the implementation must embody many more complications. Besides,
|
| 217 |
promising to return a value of a given type, and then not returning such
|
| 218 |
a value, has always been recognized to be a questionable practice,
|
| 219 |
-
tolerated only because very-old C had no distinction between
|
| 220 |
-
|
| 221 |
-
semantically well-defined feature. Semantic transformation.
|
| 222 |
-
appropriate return value to the source code, such as zero.
|
| 223 |
-
several years, many existing C implementations have produced
|
| 224 |
-
this case.
|
| 225 |
|
| 226 |
### [[dcl.dcl]]: declarations <a id="diff.dcl">[[diff.dcl]]</a>
|
| 227 |
|
| 228 |
**Change:** In C++, the `static` or `extern` specifiers can only be
|
| 229 |
applied to names of objects or functions.
|
|
@@ -238,23 +250,23 @@ static struct S { // valid C, invalid in C++{}
|
|
| 238 |
};
|
| 239 |
```
|
| 240 |
|
| 241 |
**Rationale:** Storage class specifiers don’t have any meaning when
|
| 242 |
associated with a type. In C++, class members can be declared with the
|
| 243 |
-
`static` storage class specifier.
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
|
| 248 |
**Change:** In C++, `register` is not a storage class specifier.
|
| 249 |
**Rationale:** The storage class specifier had no effect in C++.
|
| 250 |
**Effect on original feature:** Deletion of semantically well-defined
|
| 251 |
feature. Syntactic transformation. Common.
|
| 252 |
|
| 253 |
-
**Change:** A C++ typedef
|
| 254 |
name declared in the same scope (except if the typedef is a synonym of
|
| 255 |
-
the class name with the same name). In C, a typedef
|
| 256 |
tag name declared in the same scope can have the same name (because they
|
| 257 |
have different name spaces).
|
| 258 |
|
| 259 |
Example:
|
| 260 |
|
|
@@ -283,35 +295,15 @@ Seldom.
|
|
| 283 |
initialized in C++ but can be left uninitialized in C. **Rationale:** A
|
| 284 |
const object cannot be assigned to so it must be initialized to hold a
|
| 285 |
useful value. **Effect on original feature:** Deletion of semantically
|
| 286 |
well-defined feature. Semantic transformation. Seldom.
|
| 287 |
|
| 288 |
-
**Change:** Banning implicit `int`.
|
| 289 |
-
|
| 290 |
-
In C++ a *decl-specifier-seq* must contain a *type-specifier*, unless it
|
| 291 |
-
is followed by a declarator for a constructor, a destructor, or a
|
| 292 |
-
conversion function. In the following example, the left-hand column
|
| 293 |
-
presents valid C; the right-hand column presents equivalent C++:
|
| 294 |
-
|
| 295 |
-
``` cpp
|
| 296 |
-
void f(const parm); void f(const int parm);
|
| 297 |
-
const n = 3; const int n = 3;
|
| 298 |
-
main() int main()
|
| 299 |
-
... ...
|
| 300 |
-
```
|
| 301 |
-
|
| 302 |
-
**Rationale:** In C++, implicit int creates several opportunities for
|
| 303 |
-
ambiguity between expressions involving function-like casts and
|
| 304 |
-
declarations. Explicit declaration is increasingly considered to be
|
| 305 |
-
proper style. Liaison with WG14 (C) indicated support for (at least)
|
| 306 |
-
deprecating implicit int in the next revision of C. **Effect on original
|
| 307 |
-
feature:** Deletion of semantically well-defined feature. Syntactic
|
| 308 |
-
transformation. Could be automated. Common.
|
| 309 |
-
|
| 310 |
**Change:** The keyword `auto` cannot be used as a storage class
|
| 311 |
specifier.
|
| 312 |
|
|
|
|
|
|
|
| 313 |
``` cpp
|
| 314 |
void f() {
|
| 315 |
auto int x; // valid C, invalid C++{}
|
| 316 |
}
|
| 317 |
```
|
|
@@ -446,10 +438,25 @@ sizeof(A) == sizeof(e) // in C++{}
|
|
| 446 |
original feature:** Change to semantics of well-defined feature.
|
| 447 |
Semantic transformation. Seldom. The only time this affects existing C
|
| 448 |
code is when the size of an enumerator is taken. Taking the size of an
|
| 449 |
enumerator is not a common C coding practice.
|
| 450 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
### [[class]]: classes <a id="diff.class">[[diff.class]]</a>
|
| 452 |
|
| 453 |
\[see also [[dcl.typedef]]\] **Change:** In C++, a class declaration
|
| 454 |
introduces the class name into the scope where it is declared and hides
|
| 455 |
any object, function or other declaration of that name in an enclosing
|
|
@@ -508,15 +515,15 @@ semantically well-defined feature. Semantic transformation. If volatile
|
|
| 508 |
semantics are required for the copy, a user-declared constructor or
|
| 509 |
assignment must be provided. If non-volatile semantics are required, an
|
| 510 |
explicit `const_cast` can be used. Seldom.
|
| 511 |
|
| 512 |
**Change:** Bit-fields of type plain `int` are signed. **Rationale:**
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
|
| 519 |
**Change:** In C++, the name of a nested class is local to its enclosing
|
| 520 |
class. In C the name of the nested class belongs to the same scope as
|
| 521 |
the name of the outermost enclosing class.
|
| 522 |
|
|
@@ -536,27 +543,27 @@ maintaining locality within a class. A coherent set of scope rules for
|
|
| 536 |
C++ based on the C rule would be very complicated and C++ programmers
|
| 537 |
would be unable to predict reliably the meanings of nontrivial examples
|
| 538 |
involving nested or local functions. **Effect on original feature:**
|
| 539 |
Change to semantics of well-defined feature. Semantic transformation. To
|
| 540 |
make the struct type name visible in the scope of the enclosing struct,
|
| 541 |
-
the struct tag
|
| 542 |
before the enclosing struct is defined. Example:
|
| 543 |
|
| 544 |
``` cpp
|
| 545 |
struct Y; // struct Y and struct X are at the same scope
|
| 546 |
struct X {
|
| 547 |
struct Y { ... } y;
|
| 548 |
};
|
| 549 |
```
|
| 550 |
|
| 551 |
All the definitions of C struct types enclosed in other struct
|
| 552 |
-
definitions and accessed outside the scope of the enclosing struct
|
| 553 |
be exported to the scope of the enclosing struct. Note: this is a
|
| 554 |
consequence of the difference in scope rules, which is documented in
|
| 555 |
[[basic.scope]]. Seldom.
|
| 556 |
|
| 557 |
-
**Change:** In C++, a typedef
|
| 558 |
definition after being used in that definition.
|
| 559 |
|
| 560 |
Example:
|
| 561 |
|
| 562 |
``` cpp
|
|
@@ -577,11 +584,9 @@ renamed. Seldom.
|
|
| 577 |
### [[cpp]]: preprocessing directives <a id="diff.cpp">[[diff.cpp]]</a>
|
| 578 |
|
| 579 |
**Change:** Whether `__STDC__` is defined and if so, what its value is,
|
| 580 |
are *implementation-defined*. **Rationale:** C++ is not identical to ISO
|
| 581 |
C. Mandating that `__STDC__` be defined would require that translators
|
| 582 |
-
make an incorrect claim.
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
transformation. Programs and headers that reference `__STDC__` are quite
|
| 586 |
-
common.
|
| 587 |
|
|
|
|
| 1 |
## C++ and ISO C <a id="diff.iso">[[diff.iso]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="diff.iso.general">[[diff.iso.general]]</a>
|
| 4 |
+
|
| 5 |
+
Subclause [[diff.iso]] lists the differences between C++ and ISO C, in
|
| 6 |
+
addition to those listed above, by the chapters of this document.
|
| 7 |
|
| 8 |
### [[lex]]: lexical conventions <a id="diff.lex">[[diff.lex]]</a>
|
| 9 |
|
| 10 |
**Change:** New Keywords
|
| 11 |
New keywords are added to C++; see [[lex.key]]. **Rationale:** These
|
|
|
|
| 36 |
```
|
| 37 |
|
| 38 |
will not work the same as C++ programs. Simple. Programs which depend
|
| 39 |
upon `sizeof('x')` are probably rare.
|
| 40 |
|
| 41 |
+
**Change:** Concatenated *string-literal*s can no longer have
|
| 42 |
+
conflicting *encoding-prefix*es. **Rationale:** Removal of non-portable
|
| 43 |
+
feature. **Effect on original feature:** Concatenation of
|
| 44 |
+
*string-literal*s with different *encoding-prefix*es is now ill-formed.
|
| 45 |
+
Syntactic transformation. Seldom.
|
| 46 |
+
|
| 47 |
**Change:** String literals made const.
|
| 48 |
The type of a *string-literal* is changed from “array of `char`” to
|
| 49 |
“array of `const char`”. The type of a UTF-8 string literal is changed
|
| 50 |
from “array of `char`” to “array of `const char8_t`”. The type of a
|
| 51 |
UTF-16 string literal is changed from “array of *some-integer-type*” to
|
|
|
|
| 59 |
The fix is to add a cast:
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
char* p = "abc"; // valid in C, invalid in C++{}
|
| 63 |
void f(char*) {
|
| 64 |
+
char* p = (char*)"abc"; // OK, cast added
|
| 65 |
f(p);
|
| 66 |
+
f((char*)"def"); // OK, cast added
|
| 67 |
}
|
| 68 |
```
|
| 69 |
|
| 70 |
Programs that have a legitimate reason to treat string literal objects
|
| 71 |
as potentially modifiable memory are probably rare.
|
|
|
|
| 97 |
feature:** Deletion of semantically well-defined feature. Semantic
|
| 98 |
transformation. In C++, the initializer for one of a set of
|
| 99 |
mutually-referential file-local objects with static storage duration
|
| 100 |
must invoke a function call to achieve the initialization. Seldom.
|
| 101 |
|
| 102 |
+
**Change:** A `struct` is a scope in C++, not in C. For example,
|
| 103 |
+
|
| 104 |
+
``` cpp
|
| 105 |
+
struct X {
|
| 106 |
+
struct Y { int a; } b;
|
| 107 |
+
};
|
| 108 |
+
struct Y c;
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
is valid in C but not in C++, which would require `X::Y c;`.
|
| 112 |
+
**Rationale:** Class scope is crucial to C++, and a struct is a class.
|
| 113 |
+
**Effect on original feature:** Change to semantics of well-defined
|
| 114 |
+
feature. Semantic transformation. C programs use `struct` extremely
|
| 115 |
+
frequently, but the change is only noticeable when `struct`,
|
| 116 |
+
enumeration, or enumerator names are referred to outside the `struct`.
|
| 117 |
+
The latter is probably rare.
|
| 118 |
|
| 119 |
\[also [[dcl.type]]\] **Change:** A name of file scope that is
|
| 120 |
explicitly declared `const`, and not explicitly declared `extern`, has
|
| 121 |
internal linkage, while in C it would have external linkage.
|
| 122 |
**Rationale:** Because const objects may be used as values during
|
|
|
|
| 154 |
void foo() {
|
| 155 |
char* c=b;
|
| 156 |
}
|
| 157 |
```
|
| 158 |
|
| 159 |
+
ISO C accepts this usage of pointer to `void` being assigned to a
|
| 160 |
+
pointer to object type. C++ does not. **Rationale:** C++ tries harder
|
| 161 |
than C to enforce compile-time type safety. **Effect on original
|
| 162 |
+
feature:** Deletion of semantically well-defined feature. Can be
|
| 163 |
automated. Violations will be diagnosed by the C++ translator. The fix
|
| 164 |
is to add a cast. For example:
|
| 165 |
|
| 166 |
``` cpp
|
| 167 |
char* c = (char*) b;
|
|
|
|
| 169 |
|
| 170 |
This is fairly widely used but it is good programming practice to add
|
| 171 |
the cast when assigning pointer-to-void to pointer-to-object. Some ISO C
|
| 172 |
translators will give a warning if the cast is not used.
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
**Change:** Decrement operator is not allowed with `bool` operand.
|
| 175 |
**Rationale:** Feature with surprising semantics. **Effect on original
|
| 176 |
feature:** A valid ISO C expression utilizing the decrement operator on
|
| 177 |
+
a `bool` lvalue (for instance, via the C typedef in `<stdbool.h>`) is
|
| 178 |
+
ill-formed in C++.
|
| 179 |
|
| 180 |
+
**Change:** In C++, types can only be defined in declarations, not in
|
| 181 |
+
expressions.
|
| 182 |
+
In C, a `sizeof` expression or cast expression may define a new type.
|
| 183 |
+
For example,
|
| 184 |
|
| 185 |
``` cpp
|
| 186 |
p = (void*)(struct x {int i;} *)0;
|
| 187 |
```
|
| 188 |
|
|
|
|
| 212 |
**Change:** It is now invalid to jump past a declaration with explicit
|
| 213 |
or implicit initializer (except across entire block not entered).
|
| 214 |
**Rationale:** Constructors used in initializers may allocate resources
|
| 215 |
which need to be de-allocated upon leaving the block. Allowing jump past
|
| 216 |
initializers would require complicated runtime determination of
|
| 217 |
+
allocation. Furthermore, many operations on such an uninitialized object
|
| 218 |
+
have undefined behavior. With this simple compile-time rule, C++ assures
|
| 219 |
+
that if an initialized variable is in scope, then it has assuredly been
|
| 220 |
initialized. **Effect on original feature:** Deletion of semantically
|
| 221 |
well-defined feature. Semantic transformation. Seldom.
|
| 222 |
|
| 223 |
**Change:** It is now invalid to return (explicitly or implicitly) from
|
| 224 |
a function which is declared to return a value without actually
|
|
|
|
| 226 |
fairly elaborate return-value mechanisms for the return of class
|
| 227 |
objects. If some flow paths execute a return without specifying any
|
| 228 |
value, the implementation must embody many more complications. Besides,
|
| 229 |
promising to return a value of a given type, and then not returning such
|
| 230 |
a value, has always been recognized to be a questionable practice,
|
| 231 |
+
tolerated only because very-old C had no distinction between functions
|
| 232 |
+
with `void` and `int` return types. **Effect on original feature:**
|
| 233 |
+
Deletion of semantically well-defined feature. Semantic transformation.
|
| 234 |
+
Add an appropriate return value to the source code, such as zero.
|
| 235 |
+
Seldom. For several years, many existing C implementations have produced
|
| 236 |
+
warnings in this case.
|
| 237 |
|
| 238 |
### [[dcl.dcl]]: declarations <a id="diff.dcl">[[diff.dcl]]</a>
|
| 239 |
|
| 240 |
**Change:** In C++, the `static` or `extern` specifiers can only be
|
| 241 |
applied to names of objects or functions.
|
|
|
|
| 250 |
};
|
| 251 |
```
|
| 252 |
|
| 253 |
**Rationale:** Storage class specifiers don’t have any meaning when
|
| 254 |
associated with a type. In C++, class members can be declared with the
|
| 255 |
+
`static` storage class specifier. Storage class specifiers on type
|
| 256 |
+
declarations can be confusing for users. **Effect on original feature:**
|
| 257 |
+
Deletion of semantically well-defined feature. Syntactic transformation.
|
| 258 |
+
Seldom.
|
| 259 |
|
| 260 |
**Change:** In C++, `register` is not a storage class specifier.
|
| 261 |
**Rationale:** The storage class specifier had no effect in C++.
|
| 262 |
**Effect on original feature:** Deletion of semantically well-defined
|
| 263 |
feature. Syntactic transformation. Common.
|
| 264 |
|
| 265 |
+
**Change:** A C++ *typedef-name* must be different from any class type
|
| 266 |
name declared in the same scope (except if the typedef is a synonym of
|
| 267 |
+
the class name with the same name). In C, a *typedef-name* and a struct
|
| 268 |
tag name declared in the same scope can have the same name (because they
|
| 269 |
have different name spaces).
|
| 270 |
|
| 271 |
Example:
|
| 272 |
|
|
|
|
| 295 |
initialized in C++ but can be left uninitialized in C. **Rationale:** A
|
| 296 |
const object cannot be assigned to so it must be initialized to hold a
|
| 297 |
useful value. **Effect on original feature:** Deletion of semantically
|
| 298 |
well-defined feature. Semantic transformation. Seldom.
|
| 299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
**Change:** The keyword `auto` cannot be used as a storage class
|
| 301 |
specifier.
|
| 302 |
|
| 303 |
+
Example:
|
| 304 |
+
|
| 305 |
``` cpp
|
| 306 |
void f() {
|
| 307 |
auto int x; // valid C, invalid C++{}
|
| 308 |
}
|
| 309 |
```
|
|
|
|
| 438 |
original feature:** Change to semantics of well-defined feature.
|
| 439 |
Semantic transformation. Seldom. The only time this affects existing C
|
| 440 |
code is when the size of an enumerator is taken. Taking the size of an
|
| 441 |
enumerator is not a common C coding practice.
|
| 442 |
|
| 443 |
+
**Change:** In C++, an *alignment-specifier* is an
|
| 444 |
+
*attribute-specifier*. In C, an *alignment-specifier* is a .
|
| 445 |
+
|
| 446 |
+
Example:
|
| 447 |
+
|
| 448 |
+
``` cpp
|
| 449 |
+
#include <stdalign.h>
|
| 450 |
+
unsigned alignas(8) int x; // valid C, invalid C++{}
|
| 451 |
+
unsigned int y alignas(8); // valid C++{}, invalid C
|
| 452 |
+
```
|
| 453 |
+
|
| 454 |
+
**Rationale:** C++ requires unambiguous placement of the
|
| 455 |
+
*alignment-specifier*. **Effect on original feature:** Deletion of
|
| 456 |
+
semantically well-defined feature. Syntactic transformation. Seldom.
|
| 457 |
+
|
| 458 |
### [[class]]: classes <a id="diff.class">[[diff.class]]</a>
|
| 459 |
|
| 460 |
\[see also [[dcl.typedef]]\] **Change:** In C++, a class declaration
|
| 461 |
introduces the class name into the scope where it is declared and hides
|
| 462 |
any object, function or other declaration of that name in an enclosing
|
|
|
|
| 515 |
semantics are required for the copy, a user-declared constructor or
|
| 516 |
assignment must be provided. If non-volatile semantics are required, an
|
| 517 |
explicit `const_cast` can be used. Seldom.
|
| 518 |
|
| 519 |
**Change:** Bit-fields of type plain `int` are signed. **Rationale:**
|
| 520 |
+
The signedness needs to be consistent among template specializations.
|
| 521 |
+
For consistency, the implementation freedom was eliminated for
|
| 522 |
+
non-dependent types, too. **Effect on original feature:** The choice is
|
| 523 |
+
implementation-defined in C, but not so in C++. Syntactic
|
| 524 |
+
transformation. Seldom.
|
| 525 |
|
| 526 |
**Change:** In C++, the name of a nested class is local to its enclosing
|
| 527 |
class. In C the name of the nested class belongs to the same scope as
|
| 528 |
the name of the outermost enclosing class.
|
| 529 |
|
|
|
|
| 543 |
C++ based on the C rule would be very complicated and C++ programmers
|
| 544 |
would be unable to predict reliably the meanings of nontrivial examples
|
| 545 |
involving nested or local functions. **Effect on original feature:**
|
| 546 |
Change to semantics of well-defined feature. Semantic transformation. To
|
| 547 |
make the struct type name visible in the scope of the enclosing struct,
|
| 548 |
+
the struct tag can be declared in the scope of the enclosing struct,
|
| 549 |
before the enclosing struct is defined. Example:
|
| 550 |
|
| 551 |
``` cpp
|
| 552 |
struct Y; // struct Y and struct X are at the same scope
|
| 553 |
struct X {
|
| 554 |
struct Y { ... } y;
|
| 555 |
};
|
| 556 |
```
|
| 557 |
|
| 558 |
All the definitions of C struct types enclosed in other struct
|
| 559 |
+
definitions and accessed outside the scope of the enclosing struct can
|
| 560 |
be exported to the scope of the enclosing struct. Note: this is a
|
| 561 |
consequence of the difference in scope rules, which is documented in
|
| 562 |
[[basic.scope]]. Seldom.
|
| 563 |
|
| 564 |
+
**Change:** In C++, a *typedef-name* may not be redeclared in a class
|
| 565 |
definition after being used in that definition.
|
| 566 |
|
| 567 |
Example:
|
| 568 |
|
| 569 |
``` cpp
|
|
|
|
| 584 |
### [[cpp]]: preprocessing directives <a id="diff.cpp">[[diff.cpp]]</a>
|
| 585 |
|
| 586 |
**Change:** Whether `__STDC__` is defined and if so, what its value is,
|
| 587 |
are *implementation-defined*. **Rationale:** C++ is not identical to ISO
|
| 588 |
C. Mandating that `__STDC__` be defined would require that translators
|
| 589 |
+
make an incorrect claim. **Effect on original feature:** Change to
|
| 590 |
+
semantics of well-defined feature. Semantic transformation. Programs and
|
| 591 |
+
headers that reference `__STDC__` are quite common.
|
|
|
|
|
|
|
| 592 |
|