From c65ac603e9406354e895391e322a80436423f0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 30 Sep 2012 09:35:32 +0200 Subject: [PATCH] Fixed #3837 (False positive: national locale inline asm comments are reported as unsupported) --- lib/preprocessor.cpp | 13 +++++++++++++ lib/preprocessor.h | 2 -- test/testpreprocessor.cpp | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index d5f897e45..66e18c80a 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -446,6 +446,19 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri suppressionIDs.push_back(word); } } + } else if ((i==0 || std::isspace(str[i-1])) && str.compare(i,5,"__asm",0,5) == 0) { + while (i < str.size() && !std::isspace(str[i])) + code << str[i++]; + while (i < str.size() && std::isspace(str[i])) + code << str[i++]; + if (str[i] == '{') { + while (i < str.size() && str[i] != '}') { + if (str[i] == ';') + i = str.find("\n", i); + code << str[i++]; + } + code << '}'; + } } else if (ch == '#' && previous == '\n') { code << ch; previous = ch; diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 6d6c2fbaf..029130b4f 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -126,8 +126,6 @@ public: void handleUndef(std::list &configurations) const; -protected: - /** * report error * @param fileName name of file that the error was found in diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index f3b2e42e9..f7d4ad68f 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -72,6 +72,9 @@ private: // reading utf-16 file TEST_CASE(utf16); + // remove comments + TEST_CASE(removeComments); + // The bug that started the whole work with the new preprocessor TEST_CASE(Bug2190219); @@ -365,6 +368,24 @@ private: } + void removeComments() { + Settings settings; + Preprocessor preprocessor(&settings, this); + + // #3837 - asm comments + const char code[] = "void test(void) {\n" + " __asm\n" + " {\n" + " ;---- ั‚ะตัั‚\n" + " }\n" + "}\n"; + ASSERT_EQUALS(true, std::string::npos == preprocessor.removeComments(code, "3837.c").find("----")); + + ASSERT_EQUALS(" __asm123", preprocessor.removeComments(" __asm123", "3837.cpp")); + ASSERT_EQUALS("\" __asm { ; } \"", preprocessor.removeComments("\" __asm { ; } \"", "3837.cpp")); + } + + void Bug2190219() { const char filedata[] = "int main()\n" "{\n"