From ca055dc830cabb6810631c39fc28a1076546673d Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Wed, 18 Mar 2009 01:10:26 +0200 Subject: [PATCH] Fix ticket #191 (semicolon after #endif stop tokenizing of function) http://apps.sourceforge.net/trac/cppcheck/ticket/191 --- src/preprocessor.cpp | 2 +- test/testpreprocessor.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index 84d9c0fae..d50d76414 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -433,7 +433,7 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg) matching_ifdef.back() = ! matched_ifdef.back(); } - else if (line == "#endif") + else if (line.compare(0, 6, "#endif") == 0) { if (! matched_ifdef.empty()) matched_ifdef.pop_back(); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 2a45ffa8f..ca8656061 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -111,6 +111,7 @@ private: TEST_CASE(stringify3); TEST_CASE(ifdefwithfile); TEST_CASE(pragma); + TEST_CASE(endifsemicolon); } @@ -792,6 +793,29 @@ private: ASSERT_EQUALS(1, static_cast(actual.size())); ASSERT_EQUALS("\nvoid f()\n{\n}\n", actual[""]); } + + void endifsemicolon() + { + const char filedata[] = "void f()\n" + "{\n" + "#ifdef A\n" + "#endif;\n" + "}\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Preprocessor preprocessor; + preprocessor.preprocess(istr, actual, "file.c"); + + // Compare results.. + ASSERT_EQUALS(2, static_cast(actual.size())); + ASSERT_EQUALS("void f()\n" + "{\n" + "\n" + "\n" + "}\n", actual[""]); + } }; REGISTER_TEST(TestPreprocessor)