From 6dc606fd6a8462c3b39c772e961ddbcdb45ebdbb Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 18 Jul 2022 18:03:08 +0200 Subject: [PATCH] Add tests for #8446, #10750, #10894 (#4287) --- test/testautovariables.cpp | 16 ++++++++++++++++ test/testcondition.cpp | 9 +++++++++ test/testunusedvar.cpp | 10 ++++++++++ 3 files changed, 35 insertions(+) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 055d65174..5a509492a 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3947,6 +3947,22 @@ private: " f(bar);\n" "}\n"); ASSERT_EQUALS("[test.cpp:11]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); + + check("class Foo {};\n" // #10750 + "struct Bar {\n" + " Foo *_foo;\n" + "};\n" + "int f(Bar *bar);\n" + "void g(Bar *bar) {\n" + " {\n" + " Foo foo;\n" + " {\n" + " bar->_foo = &foo;\n" + " }\n" + " }\n" + " f(bar);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:10]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); } void deadPointer() { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 931e05ed7..a270641da 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4219,6 +4219,15 @@ private: " if (i == 1) {}\n" "}\n"); ASSERT_EQUALS("[test.cpp:20]: (style) Condition 'i==1' is always true\n", errout.str()); + + check("typedef struct { bool x; } s_t;\n" // #8446 + "unsigned f(bool a, bool b) {\n" + " s_t s;\n" + " const unsigned col = a ? (s.x = false) : (b = true);\n" + " if (!s.x) {}\n" + " return col;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueSymbolic() diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index f4373e3de..fac9be14f 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -3292,6 +3292,16 @@ private: " auto b { RAII() };\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("struct RAIIWrapper {\n" // #10894 + " RAIIWrapper();\n" + " ~RAIIWrapper();\n" + "};\n" + "static void foo() {\n" + " auto const guard = RAIIWrapper();\n" + " auto const& guard2 = RAIIWrapper();\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void localvar47() { // #6603