Preprocessor: Handling newlines when using # to stringify parameters (#281)

This commit is contained in:
Daniel Marjamäki 2009-05-05 17:19:06 +02:00
parent 96ebf343f1
commit fd0e592767
2 changed files with 15 additions and 0 deletions

View File

@ -934,6 +934,7 @@ std::string Preprocessor::expandMacros(std::string code, const std::string &file
else if (code[pos2] == '\n')
{
++numberOfNewlines;
continue;
}
if (parlevel == 1 && code[pos2] == ',')

View File

@ -113,6 +113,7 @@ private:
TEST_CASE(stringify);
TEST_CASE(stringify2);
TEST_CASE(stringify3);
TEST_CASE(stringify4);
TEST_CASE(ifdefwithfile);
TEST_CASE(pragma);
TEST_CASE(endifsemicolon);
@ -783,6 +784,19 @@ private:
ASSERT_EQUALS("\ng(\"abc\");", actual);
}
void stringify4()
{
const char filedata[] = "#define A(x) #x\n"
"1 A(\n"
"abc\n"
") 2";
// expand macros..
std::string actual = OurPreprocessor::expandMacros(filedata);
ASSERT_EQUALS("\n1 \n\n\"abc\" 2", actual);
}
void pragma()
{
const char filedata[] = "#pragma once\n"