From daf633ef781b49f7ba189714ec13adb519df91c9 Mon Sep 17 00:00:00 2001 From: Malcolm Parsons Date: Wed, 12 Aug 2015 13:11:55 +0100 Subject: [PATCH] Fixed #5028 Fix parsing of C++11 raw string literals --- lib/preprocessor.cpp | 6 ++++-- test/testpreprocessor.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 340c7a0eb..809553cfb 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -690,7 +690,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri else if (str.compare(i,2,"R\"")==0) { std::string delim; for (std::string::size_type i2 = i+2; i2 < str.length(); ++i2) { - if (i2 > 16 || + if (i2 > 16 + i || std::isspace(str[i2]) || std::iscntrl(str[i2]) || str[i2] == ')' || @@ -713,7 +713,9 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri } else if (std::iscntrl((unsigned char)str[p]) || std::isspace((unsigned char)str[p])) { code << " "; - } else if (str[p] == '\"' || str[p] == '\'') { + } else if (str[p] == '\\') { + code << "\\\\"; + } else if (str[p] == '\"') { code << "\\" << (char)str[p]; } else { code << (char)str[p]; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index aa32fdb7d..b17b56e7b 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -316,12 +316,12 @@ private: } void readCode2() { - const char code[] = "R\"( \" /* abc */ \n)\";"; + const char code[] = "R\"( \" \\ ' /* abc */ \n)\";"; Settings settings; Preprocessor preprocessor(settings, this); std::istringstream istr(code); std::string codestr(preprocessor.read(istr,"test.c")); - ASSERT_EQUALS("\" \\\" /* abc */ \\n\"\n;", codestr); + ASSERT_EQUALS("\" \\\" \\\\ ' /* abc */ \\n\"\n;", codestr); } void readCode3() {