Fix ticket #191 (semicolon after #endif stop tokenizing of function)

http://apps.sourceforge.net/trac/cppcheck/ticket/191
This commit is contained in:
Reijo Tomperi 2009-03-18 01:10:26 +02:00
parent 819953006c
commit ca055dc830
2 changed files with 25 additions and 1 deletions

View File

@ -433,7 +433,7 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg)
matching_ifdef.back() = ! matched_ifdef.back();
}
else if (line == "#endif")
else if (line.compare(0, 6, "#endif") == 0)
{
if (! matched_ifdef.empty())
matched_ifdef.pop_back();

View File

@ -111,6 +111,7 @@ private:
TEST_CASE(stringify3);
TEST_CASE(ifdefwithfile);
TEST_CASE(pragma);
TEST_CASE(endifsemicolon);
}
@ -792,6 +793,29 @@ private:
ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("\nvoid f()\n{\n}\n", actual[""]);
}
void endifsemicolon()
{
const char filedata[] = "void f()\n"
"{\n"
"#ifdef A\n"
"#endif;\n"
"}\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Preprocessor preprocessor;
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS(2, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("void f()\n"
"{\n"
"\n"
"\n"
"}\n", actual[""]);
}
};
REGISTER_TEST(TestPreprocessor)