Skip to content

Commit 6dc606f

Browse files
Add tests for #8446, #10750, #10894 (#4287)
1 parent cc9c5a2 commit 6dc606f

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

test/testautovariables.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,6 +3947,22 @@ class TestAutoVariables : public TestFixture {
39473947
" f(bar);\n"
39483948
"}\n");
39493949
ASSERT_EQUALS("[test.cpp:11]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
3950+
3951+
check("class Foo {};\n" // #10750
3952+
"struct Bar {\n"
3953+
" Foo *_foo;\n"
3954+
"};\n"
3955+
"int f(Bar *bar);\n"
3956+
"void g(Bar *bar) {\n"
3957+
" {\n"
3958+
" Foo foo;\n"
3959+
" {\n"
3960+
" bar->_foo = &foo;\n"
3961+
" }\n"
3962+
" }\n"
3963+
" f(bar);\n"
3964+
"}\n");
3965+
ASSERT_EQUALS("[test.cpp:10]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str());
39503966
}
39513967

39523968
void deadPointer() {

test/testcondition.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,6 +4219,15 @@ class TestCondition : public TestFixture {
42194219
" if (i == 1) {}\n"
42204220
"}\n");
42214221
ASSERT_EQUALS("[test.cpp:20]: (style) Condition 'i==1' is always true\n", errout.str());
4222+
4223+
check("typedef struct { bool x; } s_t;\n" // #8446
4224+
"unsigned f(bool a, bool b) {\n"
4225+
" s_t s;\n"
4226+
" const unsigned col = a ? (s.x = false) : (b = true);\n"
4227+
" if (!s.x) {}\n"
4228+
" return col;\n"
4229+
"}\n");
4230+
ASSERT_EQUALS("", errout.str());
42224231
}
42234232

42244233
void alwaysTrueSymbolic()

test/testunusedvar.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,6 +3292,16 @@ class TestUnusedVar : public TestFixture {
32923292
" auto b { RAII() };\n"
32933293
"}\n");
32943294
ASSERT_EQUALS("", errout.str());
3295+
3296+
functionVariableUsage("struct RAIIWrapper {\n" // #10894
3297+
" RAIIWrapper();\n"
3298+
" ~RAIIWrapper();\n"
3299+
"};\n"
3300+
"static void foo() {\n"
3301+
" auto const guard = RAIIWrapper();\n"
3302+
" auto const& guard2 = RAIIWrapper();\n"
3303+
"}\n");
3304+
ASSERT_EQUALS("", errout.str());
32953305
}
32963306

32973307
void localvar47() { // #6603

0 commit comments

Comments
 (0)