From ea6c48b2bdfc33f34acea1c6467f19da05730c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 11 Jan 2009 16:06:37 +0000 Subject: [PATCH] preprocessor: fixed a small bug when expanding macro without parameter --- src/preprocessor.cpp | 2 +- test/testpreprocessor.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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"