diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index d20e43572..c26475fdb 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1894,7 +1894,7 @@ public: * @param macrocode output string * @return true if the expanding was successful */ - bool code(const std::vector ¶ms2, const std::map macros, std::string ¯ocode) const + bool code(const std::vector ¶ms2, const std::map ¯os, std::string ¯ocode) const { if (_nopar || (_params.empty() && _variadic)) { @@ -2008,6 +2008,17 @@ public: break; } } + + // expand nopar macro + 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 1941363d8..49a54f1db 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -1411,7 +1411,7 @@ private: const char filedata[] = "#define A 4\n" "#define B(a) a,A\n" "B(2);\n"; - ASSERT_EQUALS("\n\n2,4;\n", OurPreprocessor::expandMacros(filedata)); + ASSERT_EQUALS("\n\n2, 4;\n", OurPreprocessor::expandMacros(filedata)); } { @@ -1642,6 +1642,14 @@ private: "#define ab(A,B) AB(A,B)\n" "ab(a,AB(b,c))\n"; ASSERT_EQUALS("\n\nabc\n", OurPreprocessor::expandMacros(filedata5)); + + // Ticket #1802 + const char filedata6[] = "#define AB_(A,B) A ## B\n" + "#define AB(A,B) AB_(A,B)\n" + "#define ab(suf) AB(X, AB_(_, suf))\n" + "#define X x\n" + "ab(y)\n"; + ASSERT_EQUALS("\n\n\n\nx_y\n", OurPreprocessor::expandMacros(filedata6)); }