4.7 KiB
[diff.lex]
Annex C (informative) Compatibility [diff]
C.7 C++ and C [diff.iso]
C.7.2 [lex]: lexical conventions [diff.lex]
Affected subclause: [lex.key]
Change: New Keywords.
New keywords are added to C++; see [lex.key].
Rationale: These keywords were added in order to implement the new semantics of C++.
Effect on original feature: Change to semantics of well-defined feature.
Any C programs that used any of these keywords as identifiers are not valid C++ programs.
Difficulty of converting: Syntactic transformation.
Converting one specific program is easy.
Converting a large collection of related programs takes more work.
How widely used: Common.
Affected subclause: [lex.ccon]
Change: Type of character-literal is changed from int to char.
Rationale: This is needed for improved overloaded function argument type matching.
[Example 1: int function( int i );int function( char c );
function( 'x' );
It is preferable that this call match the second version of function rather than the first.
â end example]
Effect on original feature: Change to semantics of well-defined feature.
C programs which depend onsizeof('x') == sizeof(int) will not work the same as C++ programs.
Difficulty of converting: Simple.
How widely used: Programs which depend upon sizeof('x') are probably rare.
Affected subclause: [lex.string]
Change: Concatenated string-literals can no longer have conflicting encoding-prefixes.
Rationale: Removal of non-portable feature.
Effect on original feature: Concatenation of string-literals with different encoding-prefixes is now ill-formed.
Difficulty of converting: Syntactic transformation.
How widely used: Seldom.
Affected subclause: [lex.string]
Change: String literals made const.
The type of a string-literal is changed from âarray of charâ to âarray of const charâ.
The type of a UTF-8 string literal is changed from âarray of charâ to âarray of const char8_tâ.
The type of a UTF-16 string literal is changed from âarray of some-integer-typeâ to âarray of const char16_tâ.
The type of a UTF-32 string literal is changed from âarray of some-integer-typeâ to âarray of const char32_tâ.
The type of a wide string literal is changed from âarray of wchar_tâ to âarray of const wchar_tâ.
Rationale: This avoids calling an inappropriate overloaded function, which might expect to be able to modify its argument.
Effect on original feature: Change to semantics of well-defined feature.
Difficulty of converting: Syntactic transformation.
The fix is to add a cast:char* p = "abc"; // valid in C, invalid in C++void f(char*) {char* p = (char*)"abc"; // OK, cast added f(p); f((char*)"def"); // OK, cast added}
How widely used: Programs that have a legitimate reason to treat string literal objects as potentially modifiable memory are probably rare.