handle embedded whitespace in #if 0 processing

This commit is contained in:
Greg Hewgill 2011-03-01 19:32:47 +13:00
parent 87fd55b155
commit 31c56d7353
2 changed files with 17 additions and 4 deletions

View File

@ -178,15 +178,15 @@ std::string Preprocessor::read(std::istream &istr, const std::string &filename,
// Remove all comments..
result = removeComments(result, filename, settings);
// Remove '#if 0' blocks
if (result.find("#if 0\n") != std::string::npos)
result = removeIf0(result);
// ------------------------------------------------------------------------------------------
//
// Clean up all preprocessor statements
result = preprocessCleanupDirectives(result);
// Remove '#if 0' blocks
if (result.find("#if 0\n") != std::string::npos)
result = removeIf0(result);
// ------------------------------------------------------------------------------------------
//
// Clean up preprocessor #if statements with Parantheses

View File

@ -93,6 +93,7 @@ private:
TEST_CASE(error3);
TEST_CASE(if0_exclude);
TEST_CASE(if0_whitespace);
// Don't handle include in a #if 0 block
TEST_CASE(if0_include_1);
@ -655,6 +656,18 @@ private:
ASSERT_EQUALS("\n\n\nB\n", preprocessor.read(code,"",NULL));
}
void if0_whitespace()
{
Settings settings;
Preprocessor preprocessor(&settings, this);
std::istringstream code(" # if 0 \n"
"A\n"
" # endif \n"
"B\n");
ASSERT_EQUALS("\n\n\nB\n", preprocessor.read(code,"",NULL));
}
void if0_include_1()
{
Settings settings;