It’s pretty common to use macros and token concatenation to switch between wide and narrow strings at compile time.
#define _T(x) L##x
const wchar_t *wide1 = _T("hello");
const wchar_t *wide2 = L"hello";
And in C++11 it should be valid to concoct a similar thing with raw strings:
#define RAW(x) R##x
const char *raw1 = RAW("(Hello)");
const char *raw2 = R"(Hello)";
Since macro expansion and token concatenation happens before escape sequence substitution, this should prevent escape sequences being replaced in the quoted string.
But how does this apply to trigraphs? Are raw strings formed through concatenation with normal strings still subject to having their trigraph substitutions reverted?
const char *trigraph = RAW("(??=)"); // Is this "#" or "??="?
No, the trigraph is not reverted in your example.
[lex.phases]p1identifies three phases of translation relevant to your question:Phase 1 is defined by
[lex.trigraph]p1. At this stage, your code is translated toconst char *trigraph = RAW("(#)").Phase 3 is defined by
[lex.pptoken]. This is the stage where trigraphs are reverted in raw string literals. Paragraph 3 says:That is not the case in your example, therefore the trigraph is not reverted. Your code is transformed into the preprocessing-token sequence
constchar*trigraph=RAW("(#)")Finally, in phase 4, the
RAWmacro is expanded and the token-paste occurs, resulting in the following sequence of preprocessing-tokens:constchar*trigraph=R"(#)". The r-char-sequence of the string literal comprises a#. Phase 3 has already occurred, and there is no other point at which reversion of trigraphs occurs.