Skip to content

Commit e2764f0

Browse files
committed
add tests relating to struct members
1 parent a9e1a66 commit e2764f0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

test/testconstructors.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class TestConstructors : public TestFixture {
172172
TEST_CASE(uninitVar33); // ticket #10295
173173
TEST_CASE(uninitVar34); // ticket #10841
174174
TEST_CASE(uninitVar35);
175+
TEST_CASE(uninitVar36);
175176
TEST_CASE(uninitVarEnum1);
176177
TEST_CASE(uninitVarEnum2); // ticket #8146
177178
TEST_CASE(uninitVarStream);
@@ -3020,6 +3021,16 @@ class TestConstructors : public TestFixture {
30203021
ASSERT_EQUALS("", errout_str());
30213022
}
30223023

3024+
void uninitVar36() {
3025+
check("struct S {\n"
3026+
" unsigned int a : 16;\n"
3027+
" unsigned int : 8;\n"
3028+
" unsigned int b : 8;\n"
3029+
" S() : a(0) {}\n"
3030+
"};\n");
3031+
ASSERT_EQUALS("[test.cpp:5:5]: (warning) Member variable 'S::b' is not initialized in the constructor. [uninitMemberVar]\n", errout_str());
3032+
}
3033+
30233034
void uninitVarArray1() {
30243035
check("class John\n"
30253036
"{\n"

test/testunusedvar.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class TestUnusedVar : public TestFixture {
7070
TEST_CASE(structmember25);
7171
TEST_CASE(structmember26); // #13345
7272
TEST_CASE(structmember27); // #13367
73+
TEST_CASE(structmember28);
7374
TEST_CASE(structmember_macro);
7475
TEST_CASE(structmember_template_argument); // #13887 - do not report that member used in template argument is unused
7576
TEST_CASE(classmember);
@@ -1998,6 +1999,14 @@ class TestUnusedVar : public TestFixture {
19981999
errout_str());
19992000
}
20002001

2002+
void structmember28() {
2003+
checkStructMemberUsage("struct S {\n"
2004+
" unsigned int a : 16;\n"
2005+
" unsigned int : 16;\n"
2006+
"};\n");
2007+
ASSERT_EQUALS("[test.cpp:2:18]: (style) struct member 'S::a' is never used. [unusedStructMember]\n", errout_str());
2008+
}
2009+
20012010
void structmember_macro() {
20022011
checkStructMemberUsageP("#define S(n) struct n { int a, b, c; };\n"
20032012
"S(unused);\n");

0 commit comments

Comments
 (0)