MISRA C++:2023 Rule 5.13.7
String literals with different encoding prefixes shall not be concatenated
Since R2024b
Description
Rule Definition
String literals with different encoding prefixes shall not be concatenated.
Rationale
Narrow string literals are enclosed in double quotes without a prefix. Wide string
literals are enclosed in double quotes with a prefix L
outside the
quotes. See string literals.
Concatenation of narrow and wide string literals can lead to undefined behavior.
Polyspace Implementation
The rule checker reports violations on concatenations of wide string literals and narrow string literals.
If you do not specify the encoding of a string, Polyspace® assumes that the encoding of the string is UTF-8. Polyspace does not report a violation when you concatenate an explicitly UTF-8 string with a string that does not specify any encoding:
const char* myStr = u8R"#(My)#" "String"; // No violation
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Lexical Conventions |
Category: Required |
Version History
Introduced in R2024b