From 977e31786d403df22b5ecb914e013f60b48e2194 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 24 May 2009 23:57:12 +0300 Subject: [PATCH] Fix ticket #332 (White space between macro name and '(' causes macro simplification to fail) http://apps.sourceforge.net/trac/cppcheck/ticket/332 --- src/preprocessor.cpp | 3 +++ test/testpreprocessor.cpp | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index f4a310d16..6f5e66099 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -1111,6 +1111,9 @@ std::string Preprocessor::expandMacros(std::string code, const std::string &file if (macro.params().size()) { + if (code[pos2] == ' ') + pos2++; + if (code[pos2] != '(') continue; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 26e0045ff..6c1413f0a 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -598,9 +598,17 @@ private: void macro_simple1() { - const char filedata[] = "#define AAA(aa) f(aa)\n" - "AAA(5);\n"; - ASSERT_EQUALS("\nf(5);\n", OurPreprocessor::expandMacros(filedata)); + { + const char filedata[] = "#define AAA(aa) f(aa)\n" + "AAA(5);\n"; + ASSERT_EQUALS("\nf(5);\n", OurPreprocessor::expandMacros(filedata)); + } + + { + const char filedata[] = "#define AAA(aa) f(aa)\n" + "AAA (5);\n"; + ASSERT_EQUALS("\nf(5);\n", OurPreprocessor::expandMacros(filedata)); + } } void macro_simple2()