Skip to content

Commit b8c045a

Browse files
Fix #13864, #13766, #13867 Add missing tests for error IDs (#7901)
Co-authored-by: chrchr-github <[email protected]>
1 parent a53c164 commit b8c045a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

test/testconstructors.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class TestConstructors : public TestFixture {
118118
TEST_CASE(initvar_derived_pod_struct_with_union); // #11101
119119

120120
TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor
121+
TEST_CASE(initvar_derived_private_constructor);
121122
TEST_CASE(initvar_copy_constructor); // ticket #1611
122123
TEST_CASE(initvar_nested_constructor); // ticket #1375
123124
TEST_CASE(initvar_nocopy1); // ticket #2474
@@ -1609,6 +1610,15 @@ class TestConstructors : public TestFixture {
16091610
ASSERT_EQUALS("", errout_str());
16101611
}
16111612
}
1613+
void initvar_derived_private_constructor() {
1614+
check("class B { int i; };\n"
1615+
"class D : B {\n"
1616+
" explicit D(int) {}\n"
1617+
"};\n");
1618+
ASSERT_EQUALS("[test.cpp:1:1]: (style) The class 'B' does not declare a constructor although it has private member variables which likely require initialization. [noConstructor]\n"
1619+
"[test.cpp:3:14]: (warning) Member variable 'B::i' is not initialized in the constructor. Maybe it should be initialized directly in the class B? [uninitDerivedMemberVarPrivate]\n",
1620+
errout_str());
1621+
}
16121622

16131623
void initvar_copy_constructor() { // ticket #1611
16141624
check("class Fred\n"

test/testother.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ class TestOther : public TestFixture {
256256
TEST_CASE(raceAfterInterlockedDecrement);
257257

258258
TEST_CASE(testUnusedLabel);
259+
TEST_CASE(testUnusedLabelConfiguration);
260+
TEST_CASE(testUnusedLabelSwitchConfiguration);
259261

260262
TEST_CASE(testEvaluationOrder);
261263
TEST_CASE(testEvaluationOrderSelfAssignment);
@@ -11794,6 +11796,36 @@ class TestOther : public TestFixture {
1179411796
ASSERT_EQUALS("[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str());
1179511797
}
1179611798

11799+
11800+
void testUnusedLabelConfiguration() {
11801+
checkP("void f() {\n"
11802+
"#ifdef X\n"
11803+
" goto END;\n"
11804+
"#endif\n"
11805+
"END:\n"
11806+
"}");
11807+
ASSERT_EQUALS("[test.cpp:5:1]: (style) Label 'END' is not used. There is #if in function body so the label might be used in code that is removed by the preprocessor. [unusedLabelConfiguration]\n",
11808+
errout_str());
11809+
}
11810+
11811+
void testUnusedLabelSwitchConfiguration() {
11812+
checkP("void f(int i) {\n"
11813+
" switch (i) {\n"
11814+
" default:\n"
11815+
" break;\n"
11816+
"#ifdef X\n"
11817+
" case 1:\n"
11818+
" goto END;\n"
11819+
"#endif\n"
11820+
" case 2:\n"
11821+
" END:\n"
11822+
" return;\n"
11823+
" }\n"
11824+
"}");
11825+
ASSERT_EQUALS("[test.cpp:10:5]: (warning) Label 'END' is not used. There is #if in function body so the label might be used in code that is removed by the preprocessor. Should this be a 'case' of the enclosing switch()? [unusedLabelSwitchConfiguration]\n",
11826+
errout_str());
11827+
}
11828+
1179711829
// TODO: only used in a single place
1179811830
#define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)
1179911831
template<size_t size>

0 commit comments

Comments
 (0)