From 322f46c761c8fcf77c339c171fd1737463cb8bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 17 Dec 2011 15:23:55 +0100 Subject: [PATCH] Fixed #3426 ((error) Invalid number of character ({) when these macros are defined:) --- lib/preprocessor.cpp | 2 +- test/testpreprocessor.cpp | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index dc8f34d06..324268b49 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1838,7 +1838,7 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str suppressCurrentCodePath = false; indentmatch = indent; } - } else if (line == "#endif") { + } else if (line.compare(0, 6, "#endif") == 0) { if (indent > 0) --indent; if (indentmatch > indent || indent == 0) { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 29af8225c..7af906165 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -2159,8 +2159,7 @@ private: } void endifsemicolon() { - const char filedata[] = "void f()\n" - "{\n" + const char filedata[] = "void f() {\n" "#ifdef A\n" "#endif;\n" "}\n"; @@ -2174,11 +2173,9 @@ private: // Compare results.. ASSERT_EQUALS(2, static_cast(actual.size())); - ASSERT_EQUALS("void f()\n" - "{\n" - "\n" - "\n" - "}\n", actual[""]); + const std::string expected("void f() {\n\n\n}\n"); + ASSERT_EQUALS(expected, actual[""]); + ASSERT_EQUALS(expected, actual["A"]); } void handle_error() { @@ -2960,6 +2957,16 @@ private: } } + // #endif + { + // see also endifsemicolon + const std::string code("{\n#ifdef X\n#endif;\n}"); + defs.clear(); + defs["Z"] = ""; + const std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs)); + ASSERT_EQUALS("{\n\n\n}\n", actual); + } + // #undef { const std::string code("#ifndef X\n"