diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index bc56563f3..5a3a36ea8 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -2577,7 +2577,7 @@ bool Preprocessor::validateCfg(const std::string &code, const std::string &cfg) for (std::set::const_iterator it = macros.begin(); it != macros.end(); ++it) { const std::string ¯o = *it; std::string::size_type pos = 0; - while ((pos = code.find_first_of(std::string("\"'")+macro[0], pos)) != std::string::npos) { + while ((pos = code.find_first_of(std::string("#\"'")+macro[0], pos)) != std::string::npos) { const std::string::size_type pos1 = pos; const std::string::size_type pos2 = pos + macro.size(); pos++; @@ -2592,6 +2592,12 @@ bool Preprocessor::validateCfg(const std::string &code, const std::string &cfg) ++pos; } + // skip preprocessor statement.. + else if (code[pos1] == '#') { + if (pos1 == 0 || code[pos1-1] == '\n') + pos = code.find("\n",pos); + } + // is macro used in code? else if (code.compare(pos1,macro.size(),macro) == 0) { if (pos1 > 0 && (std::isalnum(code[pos1-1U]) || code[pos1-1U] == '_')) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index d4b8b2fdc..e96794732 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -3546,6 +3546,7 @@ private: ASSERT_EQUALS(true, preprocessor.validateCfg("\"DEBUG()\"", "DEBUG")); ASSERT_EQUALS(true, preprocessor.validateCfg("\"\\\"DEBUG()\"", "DEBUG")); ASSERT_EQUALS(false, preprocessor.validateCfg("\"DEBUG()\" DEBUG", "DEBUG")); + ASSERT_EQUALS(true, preprocessor.validateCfg("#undef DEBUG", "DEBUG")); } };