tmp/tmpbv0m3r8n/{from.md → to.md}
RENAMED
|
@@ -1,19 +1,19 @@
|
|
| 1 |
-
###
|
| 2 |
|
| 3 |
-
|
| 4 |
New keywords are added to C++; see [[lex.key]]. **Rationale:** These
|
| 5 |
keywords were added in order to implement the new semantics of C++.
|
| 6 |
**Effect on original feature:** Change to semantics of well-defined
|
| 7 |
feature. Any ISO C programs that used any of these keywords as
|
| 8 |
identifiers are not valid C++ programs. Syntactic transformation.
|
| 9 |
Converting one specific program is easy. Converting a large collection
|
| 10 |
of related programs takes more work. Common.
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
``` cpp
|
| 17 |
int function( int i );
|
| 18 |
int function( char c );
|
| 19 |
|
|
@@ -29,30 +29,31 @@ sizeof('x') == sizeof(int)
|
|
| 29 |
```
|
| 30 |
|
| 31 |
will not work the same as C++ programs. Simple. Programs which depend
|
| 32 |
upon `sizeof('x')` are probably rare.
|
| 33 |
|
| 34 |
-
|
| 35 |
-
The type of a string
|
| 36 |
-
of `const char`”. The type of a
|
| 37 |
-
from “array of
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
`const
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
``` cpp
|
| 48 |
-
char* p = "abc"; // valid in C, invalid in C++
|
| 49 |
void f(char*) {
|
| 50 |
char* p = (char*)"abc"; // OK: cast added
|
| 51 |
f(p);
|
| 52 |
f((char*)"def"); // OK: cast added
|
| 53 |
}
|
| 54 |
```
|
| 55 |
|
| 56 |
-
Programs that have a legitimate reason to treat string
|
| 57 |
-
|
| 58 |
|
|
|
|
| 1 |
+
### [[lex]]: lexical conventions <a id="diff.lex">[[diff.lex]]</a>
|
| 2 |
|
| 3 |
+
**Change:** New Keywords
|
| 4 |
New keywords are added to C++; see [[lex.key]]. **Rationale:** These
|
| 5 |
keywords were added in order to implement the new semantics of C++.
|
| 6 |
**Effect on original feature:** Change to semantics of well-defined
|
| 7 |
feature. Any ISO C programs that used any of these keywords as
|
| 8 |
identifiers are not valid C++ programs. Syntactic transformation.
|
| 9 |
Converting one specific program is easy. Converting a large collection
|
| 10 |
of related programs takes more work. Common.
|
| 11 |
|
| 12 |
+
**Change:** Type of *character-literal* is changed from `int` to `char`.
|
| 13 |
+
**Rationale:** This is needed for improved overloaded function argument
|
| 14 |
+
type matching. For example:
|
| 15 |
|
| 16 |
``` cpp
|
| 17 |
int function( int i );
|
| 18 |
int function( char c );
|
| 19 |
|
|
|
|
| 29 |
```
|
| 30 |
|
| 31 |
will not work the same as C++ programs. Simple. Programs which depend
|
| 32 |
upon `sizeof('x')` are probably rare.
|
| 33 |
|
| 34 |
+
**Change:** String literals made const.
|
| 35 |
+
The type of a *string-literal* is changed from “array of `char`” to
|
| 36 |
+
“array of `const char`”. The type of a UTF-8 string literal is changed
|
| 37 |
+
from “array of `char`” to “array of `const char8_t`”. The type of a
|
| 38 |
+
UTF-16 string literal is changed from “array of *some-integer-type*” to
|
| 39 |
+
“array of `const char16_t`”. The type of a UTF-32 string literal is
|
| 40 |
+
changed from “array of *some-integer-type*” to “array of
|
| 41 |
+
`const char32_t`”. The type of a wide string literal is changed from
|
| 42 |
+
“array of `wchar_t`” to “array of `const wchar_t`”. **Rationale:** This
|
| 43 |
+
avoids calling an inappropriate overloaded function, which might expect
|
| 44 |
+
to be able to modify its argument. **Effect on original feature:**
|
| 45 |
+
Change to semantics of well-defined feature. Syntactic transformation.
|
| 46 |
+
The fix is to add a cast:
|
| 47 |
|
| 48 |
``` cpp
|
| 49 |
+
char* p = "abc"; // valid in C, invalid in C++{}
|
| 50 |
void f(char*) {
|
| 51 |
char* p = (char*)"abc"; // OK: cast added
|
| 52 |
f(p);
|
| 53 |
f((char*)"def"); // OK: cast added
|
| 54 |
}
|
| 55 |
```
|
| 56 |
|
| 57 |
+
Programs that have a legitimate reason to treat string literal objects
|
| 58 |
+
as potentially modifiable memory are probably rare.
|
| 59 |
|