From 2bd80a73359edcdce124996a2fc558ffabc8d79e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 17 May 2009 18:51:29 +0200 Subject: [PATCH] Fix for ticket 291 - preprocessor: better handling of defines http://apps.sourceforge.net/trac/cppcheck/ticket/291 --- src/preprocessor.cpp | 12 +++++++++--- test/testpreprocessor.cpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index ba2a288af..eec7e76e3 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -508,9 +508,15 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg, match &= bool(*it); } - if (line.find("#file \"") == 0 || - line.find("#endfile") == 0 || - line.find("#define") == 0) + + if (!match && line.find("#define") == 0) + { + // Remove define that is not part of this configuration + line = ""; + } + else if (line.find("#file \"") == 0 || + line.find("#endfile") == 0 || + line.find("#define") == 0) { // We must not remove #file tags or line numbers // are corrupted. File tags are removed by the tokenizer. diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 64a26ca20..ec994fa12 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -984,7 +984,7 @@ private: // Compare results.. ASSERT_EQUALS(2, static_cast(actual.size())); ASSERT_EQUALS("\n\n\n\n\n20\n", actual[""]); - TODO_ASSERT_EQUALS("\n\n\n\n\n10\n", actual["A"]); + ASSERT_EQUALS("\n\n\n\n\n10\n", actual["A"]); ASSERT_EQUALS("", errout.str()); }