From 49848fd752fd242c37338f82cbed453e477729ac Mon Sep 17 00:00:00 2001 From: Raphael Geissert Date: Sun, 30 Jan 2011 02:09:12 -0600 Subject: [PATCH] Remove duplicated defines After simplifying define(A) conditionals, the final list of configurations could end up containing duplicate items. Ticket #1468 --- lib/preprocessor.cpp | 1 + test/testpreprocessor.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 7a7ac1c74..ddf0b6128 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1040,6 +1040,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const // Re-constitute the configuration after sorting the defines defs.sort(); + defs.unique(); *it = join(defs, ';'); } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 4a49ce42a..92ca11320 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -173,6 +173,7 @@ private: TEST_CASE(endifsemicolon); TEST_CASE(missing_doublequote); TEST_CASE(handle_error); + TEST_CASE(dup_defines); TEST_CASE(unicodeInCode); TEST_CASE(unicodeInComment); @@ -2380,6 +2381,42 @@ private: ASSERT_EQUALS("char a[] = \"#endfile\";\nchar b[] = \"#endfile\";\n\n", actual[""]); ASSERT_EQUALS(1, (int)actual.size()); } + + void dup_defines() + { + const char filedata[] = "#ifdef A\n" + "#define B\n" + "#if defined(B) && defined(A)\n" + "a\n" + "#else\n" + "b\n" + "#endif\n" + "#endif\n"; + + // Preprocess => actual result.. + std::istringstream istr(filedata); + std::map actual; + Settings settings; + Preprocessor preprocessor(&settings, this); + preprocessor.preprocess(istr, actual, "file.c"); + + // B will always be defined if A is defined; the following test + // cases should be fixed whenever this other bug is fixed + TODO_ASSERT_EQUALS(2, static_cast(actual.size())); + ASSERT_EQUALS(3, static_cast(actual.size())); + + if (actual.find("A") == actual.end()) { + ASSERT_EQUALS("A is checked", "failed"); + } else { + ASSERT_EQUALS("A is checked", "A is checked"); + } + + if (actual.find("A;A;B") != actual.end()) { + ASSERT_EQUALS("A;A;B is NOT checked", "failed"); + } else { + ASSERT_EQUALS("A;A;B is NOT checked", "A;A;B is NOT checked"); + } + } }; REGISTER_TEST(TestPreprocessor)