1

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 ?

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
prapin
  • 6,395
  • 5
  • 26
  • 44
  • 2
    It looks like [this bug, What's special about R and L in the C++ preprocessor](http://stackoverflow.com/questions/21098486/whats-special-about-r-and-l-in-the-c-preprocessor) it will be fixed with the next release and there are no real work-arounds. – Shafik Yaghmour Feb 28 '14 at 13:31
  • As far as I can tell this is the same bug, there is a bug report linked in the dup at the top of my answer. – Shafik Yaghmour Feb 28 '14 at 14:00
  • Maybe, but I think it is a different bug. Notably because it also happens with `L` prefix, which is a completely other and older thing, and has something to do with the `#` operator, not with a right parenthesis. Anyway, the MSVC preprocessor seems quite buggy. – prapin Feb 28 '14 at 14:12
  • You can open up a new bug report and mention it looks similar but you don't think it is the same bug. If it is the same they will close as a dup and let you know. Since they don't explain the root cause it is hard to know but my testing indicates the two bugs have similar behavior. – Shafik Yaghmour Feb 28 '14 at 14:15

0 Answers0