It seems there is a bug in Visual Studio 2013 compiler concerning the support of C++11 raw strings.
The new raw strings in C++11 look for example like R"(\s(\d+))"
; they are very handy for regular expressions and multi-line strings. Visual Studio 2013 (and VS 2012 November CTP) supports them, but if you place a raw string inside a macro (even a simple one), bad things can happen.
This simple code compiles but fails on the assertion:
#include <assert.h>
#include <string.h>
#define M(s) s
int main(int argc, char* argv[])
{
const char* s1 = M(R"()\s)");
const char* s2 = R"()\s)";
assert(strcmp(s1, s2) == 0);
return 0;
}
Notes:
- The macro is as simple as it can be.
- If inside the string the right parenthesis is removed, everything works.
- If inside the string the backslash or the
's'
letter is removed, the code doesn't compile!
Is it really a compiler bug ? If yes, is it a known bug ? Are there workarounds ?