diff --git a/rules/S817/cfamily/rule.adoc b/rules/S817/cfamily/rule.adoc index e68ccbf6c85..d89446d7586 100644 --- a/rules/S817/cfamily/rule.adoc +++ b/rules/S817/cfamily/rule.adoc @@ -1,26 +1,34 @@ == Why is this an issue? -Concatenation of wide and narrow string literals has not always been supported in C or {cpp}, and even when supported, the meaning may be unclear to the reader. Concatenation of string literals with different encodings is only conditionally supported, and may be removed in a future version of the language. - +Concatenation of wide and narrow string literals has not always been supported in C or {cpp}, and even when supported, the meaning may be unclear to the reader. Furthermore, concatenation of string literals with different encodings was only conditionally supported prior to {cpp}23, and is now explicitly ill-formed as of {cpp}23. Therefore, only string literals with the same prefix should be concatenated together. === Noncompliant code example -[source,cpp] +[source,cpp,diff-id=1,diff-type=noncompliant] ---- wchar_t n_array[] = "Hello" L"World"; // Noncompliant wchar_t w_array[] = L"Hello" "World"; // Noncompliant +auto u8_array = "Hello" u8"World"; // Noncompliant +auto u_array = u"Hello" "World"; // Noncompliant + +// Mixed encoding prefixes (ill-formed as of C++23) +auto mixed1 = L"Hello" u8"World"; // Noncompliant +auto mixed2 = u"Hello" U"World"; // Noncompliant +auto mixed3 = u8"Hello" u"World"; // Noncompliant ---- === Compliant solution -[source,cpp] +[source,cpp,diff-id=1,diff-type=compliant] ---- -char_t n_array[] = "Hello" "World"; // Compliant -wchar_t w_array[] = L"Hello" L"World"; // Compliant +char n_array[] = "Hello" "World"; // Compliant +wchar_t w_array[] = L"Hello" L"World"; // Compliant +auto u8_array = u8"Hello" u8"World"; // Compliant +auto u_array = u"Hello" u"World"; // Compliant ----