Files
cppdraft_translate/cppdraft/diff/lex.md
2025-10-25 03:02:53 +03:00

4.7 KiB
Raw Blame History

[diff.lex]

Annex C (informative) Compatibility [diff]

C.7 C++ and C [diff.iso]

C.7.2 [lex]: lexical conventions [diff.lex]

1

#

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.

2

#

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.

3

#

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.

4

#

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.