AutosarC++19_03-A2.13.2

String literals with different encoding prefixes shall not be concatenated

Required inputs: IR

Concatenating narrow and wide string literals is ill-formed in C++ and produces undefined behavior in C. They have incompatible character widths and encodings and must not be mixed. Each string should use a consistent prefix or be handled separately.
Bad code (mixing narrow and wide strings):
const char* msg = "Hello" L"World";      // ERROR: narrow + wide concatenation
const wchar_t* wstr = L"Part1" "Part2";  // ERROR: wide + narrow
Good code (consistent narrow strings):
const char* msg = "Hello" "World";   // OK: both narrow
// Result: "HelloWorld"
Good code (consistent wide strings):
const wchar_t* msg = L"Hello" L"World";  // OK: both wide
// Result: L"HelloWorld"
Good code (separate handling):
const char* narrow = "Hello";
const wchar_t* wide = L"World";
// Handle separately with proper string operations

Possible Messages

Key

Text

Severity

Disabled

mixed_string_concatenation

Concatenation of mixed string encodings

None

False

narrow_wide_concat

Concatenation of narrow and wide string literal

None

False

Options

cpp11_mode

cpp11_mode : bool = True

Use rules as defined in the C++11 standard. If false, only L and unprefixed literals are reported. If true, prefixes of length two and unprefixed literals are conforming; but additionally, mixed_string_concatenation compiler messages are reported.
 

report_all_prefix_differences

report_all_prefix_differences : bool = False

Report all prefix difference (i.e. do not exclude those with and without cpp11_mode).