diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index a74f6e1d4..8a30db6b6 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -493,7 +493,7 @@ std::string Preprocessor::expandMacros(std::string code) std::vector params; std::string::size_type pos2 = pos1 + macroname.length(); - if (pos2 >= macro.length()) + if (macroparams.size() && pos2 >= code.length()) continue; if (macroparams.size()) { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 19dcd38f9..24fffd76a 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -72,6 +72,7 @@ private: TEST_CASE(macro_simple2); TEST_CASE(macro_simple3); TEST_CASE(macro_simple4); + TEST_CASE(macro_simple5); TEST_CASE(macro_mismatch); TEST_CASE(preprocessor_inside_string); } @@ -458,6 +459,18 @@ private: ASSERT_EQUALS("\nif( temp > 0 ) return 1;\n", Preprocessor::expandMacros(filedata)); } + void macro_simple5() + { + const char filedata[] = "#define ABC if( temp > 0 ) return 1;\n" + "\n" + "void foo()\n" + "{\n" + " int temp = 0;\n" + " ABC\n" + "}\n"; + ASSERT_EQUALS("\n\nvoid foo()\n{\n int temp = 0;\n if( temp > 0 ) return 1;\n}\n", Preprocessor::expandMacros(filedata)); + } + void macro_mismatch() { const char filedata[] = "#define AAA(aa,bb) f(aa)\n"