From 412078d0518f0bec85f4b40051edfdd979f15e24 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 18 Jul 2022 12:09:42 +0200 Subject: [PATCH] Add tests for #8446, #10750, #10894 --- 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 055d65174d9..5a509492a59 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3947,6 +3947,22 @@ class TestAutoVariables : public TestFixture { " 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 5a2fb09a8d8..e6b028c1633 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4219,6 +4219,15 @@ class TestCondition : public TestFixture { " 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 8ff2097f159..1a5d7ca7549 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -3284,6 +3284,16 @@ class TestUnusedVar : public TestFixture { " 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