diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 7ebc742ff..a648e76ea 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -2378,14 +2378,17 @@ public: } // expand nopar macro - const std::map::const_iterator it = macros.find(str); - if (it != macros.end() && it->second->_macro.find("(") == std::string::npos) + if (tok->strAt(-1) != "##") { - str = it->second->_macro; - if (str.find(" ") != std::string::npos) - str.erase(0, str.find(" ")); - else - str = ""; + const std::map::const_iterator it = macros.find(str); + if (it != macros.end() && it->second->_macro.find("(") == std::string::npos) + { + str = it->second->_macro; + if (str.find(" ") != std::string::npos) + str.erase(0, str.find(" ")); + else + str = ""; + } } } if (_variadic && tok->str() == "," && tok->next() && tok->next()->str() == "##") diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 96e1a33cf..aa341688f 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -159,7 +159,8 @@ private: TEST_CASE(macro_simple13); TEST_CASE(macro_simple14); TEST_CASE(macro_simple15); - TEST_CASE(macroInMacro); + TEST_CASE(macroInMacro1); + TEST_CASE(macroInMacro2); TEST_CASE(macro_mismatch); TEST_CASE(macro_linenumbers); TEST_CASE(macro_nopar); @@ -1692,7 +1693,7 @@ private: ASSERT_EQUALS("\n\"foo\"\n", OurPreprocessor::expandMacros(filedata)); } - void macroInMacro() + void macroInMacro1() { { const char filedata[] = "#define A(m) long n = m; n++;\n" @@ -1793,6 +1794,14 @@ private: } } + void macroInMacro2() + { + const char filedata[] = "#define A(x) a##x\n" + "#define B 0\n" + "A(B)\n"; + ASSERT_EQUALS("\n\naB\n", OurPreprocessor::expandMacros(filedata)); + } + void macro_mismatch() { const char filedata[] = "#define AAA(aa,bb) f(aa)\n"