Skip to content

Commit

Permalink
Fixed danmar#4873 (Preprocessor: Cppcheck is unable to scan a file wi…
Browse files Browse the repository at this point in the history
…th a single quote in a comment inside assembler section)
  • Loading branch information
simartin authored and danmar committed Jun 25, 2013
1 parent d6be455 commit 75c8dcc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ class TestPreprocessor : public TestFixture {
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"));
}


Expand Down

0 comments on commit 75c8dcc

Please sign in to comment.