String literal concatenation fails when prefixed string is adjacent to non-prefixed string?

前端 未结 2 1563
臣服心动
臣服心动 2021-01-21 00:03

In MSVS2013, which I believe to be C++11 compliant, the compiler doesn\'t like the following:

LPCTSTR str = _T(\"boo \" \"hoo\");

which transla

2条回答
  •  佛祖请我去吃肉
    2021-01-21 00:32

    From N3797, §2.14.5/13 [lex.string]

    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.

    The table following that even lists an example that's the same as what you've shown

    // Source         Means
    L"a" "b"          L"ab"
    

    So I'd say your code is well-formed and this is a VisualStudio bug.

提交回复
热议问题