diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index c0ee2cce6..8988ad6de 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1890,11 +1890,11 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file // #define B(x) ( // #define A() B(xx) // B(1) A() ) ) - unsigned int macroEnd = line.length() - (pos1 + macrocode.length()); + unsigned int macroEnd = line.length() - pos2; for (std::map::iterator iter = limits.begin(); iter != limits.end();) { - if (macroEnd < iter->second) + if (pos1 < iter->second) { // We have gone past this limit, so just delete it limits.erase(iter++); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 3c7299cac..efd1f44ae 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -1165,6 +1165,21 @@ private: "B(1) A() ) )\n"; ASSERT_EQUALS("\n\n( ( ) )\n", OurPreprocessor::expandMacros(filedata)); } + + { + const char filedata[] = + "#define PTR1 (\n" + "#define PTR2 PTR1 PTR1\n" + "int PTR2 PTR2 foo )))) = 0;\n"; + ASSERT_EQUALS("\n\nint ( ( ( ( foo )))) = 0;\n", OurPreprocessor::expandMacros(filedata)); + } + + { + const char filedata[] = + "#define PTR1 (\n" + "PTR1 PTR1\n"; + ASSERT_EQUALS("\n( (\n", OurPreprocessor::expandMacros(filedata)); + } } void macro_mismatch()