What happens with adjacent string literal concatenation when there is a modifier(L, u8, etc.)

随声附和 提交于 2019-12-01 16:16:50

In C++0x your example is valid according to [lex.string]/p13:

... If one string literal has no encoding-prefix, it is treated as a string literal of the same encoding-prefix as the other operand. ...

In C++03 this same section said that this code had undefined behavior:

... If a narrow string literal token is adjacent to a wide string literal token, the behavior is undefined. ...

Yes, that particular example is allowed by C++0x. Any combination of prefixless and L-prefixed literals will be treated as though all are L-prefixed.

EDIT: Citation -- N3242 (current C++0x working draft) §2.14.5/13:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!