Fixed #2570 (Preprocessor: #define parsing when there is no whitespace between a macro symbol and its double-quoted string expansion)

This commit is contained in:
Greg Hewgill 2011-02-11 18:01:27 +01:00 committed by Daniel Marjamäki
parent b8c5426bb8
commit 751f8d46e5
2 changed files with 12 additions and 2 deletions

View File

@ -2124,12 +2124,14 @@ public:
else if (_params.empty())
{
std::string::size_type pos = _macro.find(" ");
std::string::size_type pos = _macro.find_first_of(" \"");
if (pos == std::string::npos)
macrocode = "";
else
{
macrocode = _macro.substr(pos + 1);
if (_macro[pos] == ' ')
pos++;
macrocode = _macro.substr(pos);
if ((pos = macrocode.find_first_of("\r\n")) != std::string::npos)
macrocode.erase(pos);
}

View File

@ -149,6 +149,7 @@ private:
TEST_CASE(macro_simple12);
TEST_CASE(macro_simple13);
TEST_CASE(macro_simple14);
TEST_CASE(macro_simple15);
TEST_CASE(macroInMacro);
TEST_CASE(macro_mismatch);
TEST_CASE(macro_linenumbers);
@ -1589,6 +1590,13 @@ private:
ASSERT_EQUALS("\nprintf(\" a \");\n", OurPreprocessor::expandMacros(filedata));
}
void macro_simple15()
{
const char filedata[] = "#define FOO\"foo\"\n"
"FOO\n";
ASSERT_EQUALS("\n\"foo\"\n", OurPreprocessor::expandMacros(filedata));
}
void macroInMacro()
{
{