diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 34761731e..06929c7e0 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -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; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index dfee67cf3..b6d8eef86 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -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")); }