2015-08-04 16 views
5

Gdy mamy jeden z nich:Łączenie niedopasowanych ciągów DZIAŁA w VC2015 - jak?

auto city1 = "New " L"Delhi"; 
auto city2 = L"New " "York"; 

Wszelkie kompilator pre-VS2015 podniesie błąd:

error C2308: concatenating mismatched strings

Ale z VC2015 kompilator kompiluje dobrze i rodzaju wypadkową (auto odliczenie) jest szeroki ciąg znaków.

Moje pytanie brzmi: kiedy i jak jest to możliwe - każda standardowa specyfikacja?

+0

Może to pomóc: http://en.cppreference.com/w/cpp/language/string_literal – Mithrandir

Odpowiedz

8

W C++ 03 takie zachowanie byłoby niezdefiniowane.

ISO 14882-2003: 2.13.4.3 stwierdza, że ​​

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.

Nie wiem dokładnie kiedy zmiana została wprowadzona, ale zachowanie jest co najmniej dobrze zdefiniowane w projekcie N3242 normy.

ISO 14882-2011: 2.14.5.13 stwierdza, że ​​

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.

Dlatego też, w przypadku, auto jest prawidłowo wywnioskować jak szeroki ciąg dosłownym.

Powiązane problemy