Fixed #1231 (Preprocessor: Fail to evaluate '#if ! defined _ABCD_')
This commit is contained in:
parent
c48eb090e0
commit
0908728601
|
@ -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);
|
||||
|
|
|
@ -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<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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue