diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 763ffe8e9..17ced4f87 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -611,7 +611,7 @@ std::string Preprocessor::getdef(std::string line, bool def) { const unsigned char chprev = (pos > 0) ? line[pos-1] : (unsigned char)0; const unsigned char chnext = (pos + 1 < line.length()) ? line[pos+1] : (unsigned char)0; - if (std::isalnum(chprev) && std::isalnum(chnext)) + if ((std::isalnum(chprev) || chprev == '_') && (std::isalnum(chnext) || chnext == '_')) ++pos; else line.erase(pos, 1); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 44755f532..304bddbcc 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -104,6 +104,7 @@ private: TEST_CASE(if_cond6); TEST_CASE(if_cond7); TEST_CASE(if_cond8); + TEST_CASE(if_cond9); TEST_CASE(if_or); @@ -871,6 +872,25 @@ private: } + void if_cond9() + { + const char filedata[] = "#if !defined _A\n" + "abc\n" + "#endif\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Settings settings; + Preprocessor preprocessor(&settings, this); + preprocessor.preprocess(istr, actual, "file.c"); + + // Compare results.. + ASSERT_EQUALS(1, actual.size()); + ASSERT_EQUALS("\nabc\n\n", actual[""]); + } + + void if_or() {