preprocessor: fixed a small bug when expanding macro without parameter

This commit is contained in:
Daniel Marjamäki 2009-01-11 16:06:37 +00:00
parent da881fdd0a
commit ea6c48b2bd
2 changed files with 14 additions and 1 deletions

View File

@ -493,7 +493,7 @@ std::string Preprocessor::expandMacros(std::string code)
std::vector<std::string> params;
std::string::size_type pos2 = pos1 + macroname.length();
if (pos2 >= macro.length())
if (macroparams.size() && pos2 >= code.length())
continue;
if (macroparams.size())
{

View File

@ -72,6 +72,7 @@ private:
TEST_CASE(macro_simple2);
TEST_CASE(macro_simple3);
TEST_CASE(macro_simple4);
TEST_CASE(macro_simple5);
TEST_CASE(macro_mismatch);
TEST_CASE(preprocessor_inside_string);
}
@ -458,6 +459,18 @@ private:
ASSERT_EQUALS("\nif( temp > 0 ) return 1;\n", Preprocessor::expandMacros(filedata));
}
void macro_simple5()
{
const char filedata[] = "#define ABC if( temp > 0 ) return 1;\n"
"\n"
"void foo()\n"
"{\n"
" int temp = 0;\n"
" ABC\n"
"}\n";
ASSERT_EQUALS("\n\nvoid foo()\n{\n int temp = 0;\n if( temp > 0 ) return 1;\n}\n", Preprocessor::expandMacros(filedata));
}
void macro_mismatch()
{
const char filedata[] = "#define AAA(aa,bb) f(aa)\n"