Added a test case and fixed bug. If #include was inside a string, cppcheck hanged in preprocessor.
This commit is contained in:
parent
adc116d0ef
commit
4d0e3dac45
|
@ -473,7 +473,10 @@ std::string Preprocessor::handleIncludes(std::string code)
|
|||
{
|
||||
// Accept only includes that are at the start of a line
|
||||
if (pos > 0 && code[pos-1] != '\n')
|
||||
{
|
||||
pos += 8; // length of "#include"
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string::size_type end = code.find("\n", pos);
|
||||
std::string filename = code.substr(pos, end - pos);
|
||||
|
|
|
@ -78,6 +78,7 @@ private:
|
|||
TEST_CASE(string1);
|
||||
TEST_CASE(string2);
|
||||
TEST_CASE(preprocessor_undef);
|
||||
TEST_CASE(preprocessor_include_in_str);
|
||||
}
|
||||
|
||||
|
||||
|
@ -521,6 +522,25 @@ private:
|
|||
// Compare results..
|
||||
ASSERT_EQUALS("\n\n\nchar b=0;\n", Preprocessor::expandMacros(filedata));
|
||||
}
|
||||
|
||||
void preprocessor_include_in_str()
|
||||
{
|
||||
const char filedata[] = "int main()\n"
|
||||
"{\n"
|
||||
"const char *a = \"#include <string>\n\";\n"
|
||||
"return 0;\n"
|
||||
"}\n";
|
||||
|
||||
// Preprocess => actual result..
|
||||
std::istringstream istr(filedata);
|
||||
std::map<std::string, std::string> actual;
|
||||
Preprocessor preprocessor;
|
||||
preprocessor.preprocess(istr, actual);
|
||||
|
||||
// Compare results..
|
||||
ASSERT_EQUALS(1, actual.size());
|
||||
ASSERT_EQUALS("int main()\n{\nconst char *a = \"#include <string>\n\";\nreturn 0;\n}\n", actual[""]);
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestPreprocessor)
|
||||
|
|
Loading…
Reference in New Issue