Error C1071: Unexpected end of file found in comment due to /* in #ifdeffed out raw string literal

Viewed 154

Why does this code give a "Error C1071: Unexpected end of file found in comment" error?

#include <iostream>

int main()
{
#if 0
   std::string script = R"(#!/bin/sh
ls /mnt/*.txt
)";
#endif
}

I am using Visual Studio 16.7.5.

1 Answers

It appears to be a compiler bug. I have submitted a ticket: https://developercommunity.visualstudio.com/t/Error-C1071:-Unexpected-end-of-file-foun/1592300?entry=myfeedback

Here is some more data. A workaround would be to not use a raw string literal with this character sequence.

#include <iostream>

// VS 16.7.5

int main()
{
#if 1
   std::string script = R"(#!/bin/sh
ls /ok/*.txt
)";
#endif

#if 0
   std::string script = R"(#!/bin/sh
ls /not_ok/*.txt
)";
#endif

#if 0
   std::string script = R"(#!/bin/sh
//ls /compiles_but_invalid_script/*.txt
)";
#endif

#if 0
   std::string script = "(#!/bin/sh\nls /and_this_is_ok/*.txt";
#endif
}
Related