Fixed #1231 (Preprocessor: Fail to evaluate '#if ! defined _ABCD_')

This commit is contained in:
Daniel Marjamäki 2010-01-09 21:54:20 +01:00
parent c48eb090e0
commit 0908728601
2 changed files with 21 additions and 1 deletions

View File

@ -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 chprev = (pos > 0) ? line[pos-1] : (unsigned char)0;
const unsigned char chnext = (pos + 1 < line.length()) ? 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; ++pos;
else else
line.erase(pos, 1); line.erase(pos, 1);

View File

@ -104,6 +104,7 @@ private:
TEST_CASE(if_cond6); TEST_CASE(if_cond6);
TEST_CASE(if_cond7); TEST_CASE(if_cond7);
TEST_CASE(if_cond8); TEST_CASE(if_cond8);
TEST_CASE(if_cond9);
TEST_CASE(if_or); 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<std::string, std::string> 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() void if_or()
{ {