diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index 88bb6dddd..a77d0903b 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -637,13 +637,22 @@ public: std::string str = tok->str(); if (str == "##") continue; - if (tok->isName()) + if (str[0] == '#' || tok->isName()) { + bool stringify = false; + if (str[0] == '#') + { + str = str.erase(0, 1); + stringify = true; + } for (unsigned int i = 0; i < _params.size(); ++i) { if (str == _params[i]) { - str = params2[i]; + if (stringify) + str = "\"" + params2[i] + "\""; + else + str = params2[i]; break; } } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index f04f3b038..1b1c6e105 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -91,6 +91,8 @@ private: // TODO TEST_CASE(fmt); TEST_CASE(multi_character_character); // TODO TEST_CASE(preprocessor_and_operation); + + TEST_CASE(stringify); } @@ -682,6 +684,17 @@ private: } + void stringify() + { + const char filedata[] = "#define STRINGIFY(x) #x\n" + "STRINGIFY(abc)"; + + // expand macros.. + std::string actual = Preprocessor::expandMacros(filedata); + + ASSERT_EQUALS("\n\"abc\"", actual); + } + }; REGISTER_TEST(TestPreprocessor)