Annex C (informative) Compatibility [diff] (original) (raw)

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"; void f(char*) { char* p = (char*)"abc"; f(p); f((char*)"def"); }

How widely used: Programs that have a legitimate reason to treat string literal objects as potentially modifiable memory are probably rare.