Fixed #4873 (Preprocessor: Cppcheck is unable to scan a file with a single quote in a comment inside assembler section)

This commit is contained in:
Simon Martin 2013-06-25 06:45:11 +02:00 committed by Daniel Marjamäki
parent d6be4559cd
commit 75c8dcc664
2 changed files with 7 additions and 1 deletions

View File

@ -491,11 +491,14 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
while (i < str.size() && std::isspace(str[i]))
code << str[i++];
if (str[i] == '{') {
// Ticket 4873: Extract comments from the __asm / __asm__'s content
std::string asmBody;
while (i < str.size() && str[i] != '}') {
if (str[i] == ';')
i = str.find("\n", i);
code << str[i++];
asmBody += str[i++];
}
code << removeComments(asmBody, filename);
code << '}';
} else
--i;

View File

@ -402,6 +402,9 @@ private:
ASSERT_EQUALS(" __asm123", preprocessor.removeComments(" __asm123", "3837.cpp"));
ASSERT_EQUALS("\" __asm { ; } \"", preprocessor.removeComments("\" __asm { ; } \"", "3837.cpp"));
ASSERT_EQUALS("__asm__ volatile { \"\" }", preprocessor.removeComments("__asm__ volatile { \"\" }", "3837.cpp"));
// #4873
ASSERT_EQUALS("__asm { }", preprocessor.removeComments("__asm { /* This is a comment */ }", "4873.cpp"));
}