Preprocessor: When #error is encountered the result is an empty string => don't check configuration

This commit is contained in:
Daniel Marjamäki 2009-11-13 22:12:29 +01:00
parent 1187587521
commit a36c410d45
2 changed files with 31 additions and 2 deletions

View File

@ -1088,7 +1088,6 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
continue;
}
std::string def = getdef(line, true);
std::string ndef = getdef(line, false);
@ -1150,6 +1149,9 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
match &= bool(*it);
}
// #error => return ""
if (match && line.compare(0, 6, "#error") == 0)
return "";
if (!match && line.find("#define") == 0)
{

View File

@ -73,6 +73,10 @@ private:
TEST_CASE(test4);
TEST_CASE(test5);
TEST_CASE(test6);
TEST_CASE(test7);
// #error => don't extract any code
TEST_CASE(error1);
// Handling include guards (don't create extra configuration for it)
TEST_CASE(includeguard);
@ -384,6 +388,29 @@ private:
}
void error1()
{
const char filedata[] = "#ifdef A\n"
";\n"
"#else\n"
"#error abcd\n"
"#endif\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Preprocessor preprocessor;
errout.str("");
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS(2, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("", actual[""]);
ASSERT_EQUALS("\n;\n\n\n\n", actual["A"]);
}
void includeguard()
{
// Handling include guards..
@ -1286,7 +1313,7 @@ private:
{
{
const char filedata[] = "#define A \n"
"#error don't want to \\\n"
"#define B don't want to \\\n"
"more text\n"
"void f()\n"
"{\n"