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:
parent
d6be4559cd
commit
75c8dcc664
|
@ -491,11 +491,14 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
|
||||||
while (i < str.size() && std::isspace(str[i]))
|
while (i < str.size() && std::isspace(str[i]))
|
||||||
code << str[i++];
|
code << str[i++];
|
||||||
if (str[i] == '{') {
|
if (str[i] == '{') {
|
||||||
|
// Ticket 4873: Extract comments from the __asm / __asm__'s content
|
||||||
|
std::string asmBody;
|
||||||
while (i < str.size() && str[i] != '}') {
|
while (i < str.size() && str[i] != '}') {
|
||||||
if (str[i] == ';')
|
if (str[i] == ';')
|
||||||
i = str.find("\n", i);
|
i = str.find("\n", i);
|
||||||
code << str[i++];
|
asmBody += str[i++];
|
||||||
}
|
}
|
||||||
|
code << removeComments(asmBody, filename);
|
||||||
code << '}';
|
code << '}';
|
||||||
} else
|
} else
|
||||||
--i;
|
--i;
|
||||||
|
|
|
@ -402,6 +402,9 @@ private:
|
||||||
ASSERT_EQUALS(" __asm123", preprocessor.removeComments(" __asm123", "3837.cpp"));
|
ASSERT_EQUALS(" __asm123", preprocessor.removeComments(" __asm123", "3837.cpp"));
|
||||||
ASSERT_EQUALS("\" __asm { ; } \"", preprocessor.removeComments("\" __asm { ; } \"", "3837.cpp"));
|
ASSERT_EQUALS("\" __asm { ; } \"", preprocessor.removeComments("\" __asm { ; } \"", "3837.cpp"));
|
||||||
ASSERT_EQUALS("__asm__ volatile { \"\" }", preprocessor.removeComments("__asm__ volatile { \"\" }", "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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue