When we have either of these:
auto city1 = "New " L"Delhi";
auto city2 = L"New " "York";
Any pre-VS2015 compiler would raise error:
error C2308: concatenating mismatched strings
But with VC2015 compiler, it compiles well and the resultant type (auto
deduction) is a wide-char string.
My question is: When and How this is made possible - any standard specification?
In C++03 this behaviour would be undefined.
ISO 14882-2003: 2.13.4.3 states that
In translation phase 6 (2.1), adjacent narrow string literals are concatenated and adjacent wide string literals are concatenated. If a narrow string literal token is adjacent to a wide string literal token, the behavior is undefined. Characters in concatenated strings are kept distinct.
Not sure exactly when the change was introduced but the behaviour is at least well defined in the draft N3242 of the standard.
ISO 14882-2011: 2.14.5.13 states that
In translation phase 6 (2.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.
Therefore, in your case, auto
is correctly deduced as a wide string literal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With