开发者

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

It is valid in C and C++ to break a string literal because the preprocessor or the compiler will concatenate adjacent string literals.

const char *zStr = "a" "b"; // valid

What happens when string literals are prefixed with L (wide characters), u (UTF-16), U (UTF-32), u8 (UTF-8), and raw string l开发者_运维知识库iterals (R"foo(this is a "raw string literal" with double quotes)foo")?

For example, is the following allowed:

const wchar_t *zStr = L"a" "b"; // valid?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜