Fixed #3837 (False positive: national locale inline asm comments are reported as unsupported)

This commit is contained in:
Daniel Marjamäki 2012-09-30 09:35:32 +02:00
parent 4e1bef5535
commit c65ac603e9
3 changed files with 34 additions and 2 deletions

View File

@ -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;

View File

@ -126,8 +126,6 @@ public:
void handleUndef(std::list<std::string> &configurations) const;
protected:
/**
* report error
* @param fileName name of file that the error was found in

View File

@ -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"