From 7f9ef8c3216d9196e7257a33f27b5fb505aa12e7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 20 Jan 2022 16:15:38 +0100 Subject: [PATCH] Add test cases for #7899, #7974, #9256 (#3726) * Add test case for #7899 and #7974 * Add test case for ##9256 --- test/testcondition.cpp | 8 ++++++++ test/testother.cpp | 8 ++++++++ test/testunusedfunctions.cpp | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 4a11c83b3..5d5602a5f 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3858,6 +3858,14 @@ private: " return foo < bar;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #9256 + check("bool f() {\n" + " bool b = false;\n" + " b = true;\n" + " return b;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueSymbolic() diff --git a/test/testother.cpp b/test/testother.cpp index a728b0a22..12d95126b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -147,6 +147,7 @@ private: TEST_CASE(duplicateExpression10); // #9485 TEST_CASE(duplicateExpression11); // #8916 (function call) TEST_CASE(duplicateExpression12); // #10026 + TEST_CASE(duplicateExpression13); // #7899 TEST_CASE(duplicateExpressionLoop); TEST_CASE(duplicateValueTernary); TEST_CASE(duplicateExpressionTernary); // #6391 @@ -5451,6 +5452,13 @@ private: ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Same expression on both sides of '-'.\n", errout.str()); } + void duplicateExpression13() { //#7899 + check("void f() {\n" + " if (sizeof(long) == sizeof(long long)) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void duplicateExpressionLoop() { check("void f() {\n" " int a = 1;\n" diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index e7f9de509..b2aafbcae 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -53,6 +53,7 @@ private: TEST_CASE(unusedMain); TEST_CASE(initializationIsNotAFunction); TEST_CASE(operator1); // #3195 + TEST_CASE(operator2); // #7974 TEST_CASE(returnRef); TEST_CASE(attribute); // #3471 - FP __attribute__(constructor) TEST_CASE(initializer_list); @@ -327,6 +328,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void operator2() { // #7974 + check("bool operator==(const data_t& a, const data_t& b) {\n" + " return (a.fd == b.fd);\n" + "}\n" + "bool operator==(const event& a, const event& b) {\n" + " return ((a.events == b.events) && (a.data == b.data));\n" + "}\n" + "int main(event a, event b) {\n" + " return a == b;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void returnRef() { check("int& foo() {return x;}"); ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());