Skip to content

Commit 6c20dbe

Browse files
authored
Add tests for #14479 & #14480: False negatives with member pointers (danmar#8244)
These were fixed by a5db405
1 parent 923430d commit 6c20dbe

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

test/testuninitvar.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class TestUninitVar : public TestFixture {
9797
TEST_CASE(uninitvar_memberfunction);
9898
TEST_CASE(uninitvar_nonmember); // crash in ycmd test
9999
TEST_CASE(uninitvarDesignatedInitializers);
100+
TEST_CASE(uninitvarMemberPointer);
100101

101102
TEST_CASE(isVariableUsageDeref); // *p
102103
TEST_CASE(isVariableUsageDerefValueflow); // *p
@@ -7825,6 +7826,16 @@ class TestUninitVar : public TestFixture {
78257826
ASSERT_EQUALS("", errout_str());
78267827
}
78277828

7829+
void uninitvarMemberPointer() {
7830+
checkUninitVar("void f()\n"
7831+
"{\n"
7832+
" struct S {};\n"
7833+
" int S::* mp;\n"
7834+
" if (mp) {}\n"
7835+
"}\n");
7836+
ASSERT_EQUALS("[test.cpp:5:7]: (error) Uninitialized variable: mp [legacyUninitvar]\n", errout_str());
7837+
}
7838+
78287839
void isVariableUsageDeref() {
78297840
// *p
78307841
checkUninitVar("void f() {\n"

test/testunusedvar.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class TestUnusedVar : public TestFixture {
154154
TEST_CASE(localvar69);
155155
TEST_CASE(localvar70);
156156
TEST_CASE(localvar71);
157+
TEST_CASE(localvar72);
157158
TEST_CASE(localvarloops); // loops
158159
TEST_CASE(localvaralias1);
159160
TEST_CASE(localvaralias2); // ticket #1637
@@ -4046,6 +4047,15 @@ class TestUnusedVar : public TestFixture {
40464047
ASSERT_EQUALS("", errout_str());
40474048
}
40484049

4050+
void localvar72() {
4051+
functionVariableUsage("void f()\n"
4052+
"{\n"
4053+
" struct S {};\n"
4054+
" int S::* mp;\n"
4055+
"}\n");
4056+
ASSERT_EQUALS("[test.cpp:4:12]: (style) Unused variable: mp [unusedVariable]\n", errout_str());
4057+
}
4058+
40494059
void localvarloops() {
40504060
// loops
40514061
functionVariableUsage("void fun(int c) {\n"

0 commit comments

Comments
 (0)