简体   繁体   中英

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

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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM