I have a Unicode string literal, let’s say like this.
const char8_t x = u8"aaanbbb©ncccn";
I would like to split it over multiple lines for readability.
Which of the notations below are correct and equivalent to the one above?
const char8_t x = u8"aaan" u8"bbb©n" u8"cccn";
const char8_t x = u8"aaan" "bbb©n" "cccn";
const char8_t x = "aaan" u8"bbb©n" "cccn";
All seem to compile but I’m afraid some of them may be implementation-defined.
From this cppreference page, it would appear that all your code snippets are equivalent and well-defined:
If one of the strings has an encoding prefix and the other doesn’t, the one that doesn’t will be considered to have the same encoding prefix as the other.
Or, from this Draft C++17 Standard:
5.13.5 String literals [lex.string]
13 In translation phase 6 (5.2), adjacent string-literals are concatenated. If both string-literals have the same encoding-prefix, the resulting concatenated string literal has that encoding-prefix. If one string-literal has no encoding-prefix, it is treated as a string-literal of the same encoding-prefix as the other operand. …