Skip to content

Commit c64fd89

Browse files
committed
Fix #13864, #13766, #13867 add missing tests for error IDs
1 parent a4faec0 commit c64fd89

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

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
@@ -255,6 +255,8 @@ class TestOther : public TestFixture {
255255
TEST_CASE(raceAfterInterlockedDecrement);
256256

257257
TEST_CASE(testUnusedLabel);
258+
TEST_CASE(testUnusedLabelConfiguration);
259+
TEST_CASE(testUnusedLabelSwitchConfiguration);
258260

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

11798+
11799+
void testUnusedLabelConfiguration() {
11800+
checkP("void f() {\n"
11801+
"#ifdef X\n"
11802+
" goto END;\n"
11803+
"#endif\n"
11804+
"END:\n"
11805+
"}");
11806+
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",
11807+
errout_str());
11808+
}
11809+
11810+
void testUnusedLabelSwitchConfiguration() {
11811+
checkP("void f(int i) {\n"
11812+
" switch (i) {\n"
11813+
" default:\n"
11814+
" break;\n"
11815+
"#ifdef X\n"
11816+
" case 1:\n"
11817+
" goto END;\n"
11818+
"#endif\n"
11819+
" case 2:\n"
11820+
" END:\n"
11821+
" return;\n"
11822+
" }\n"
11823+
"}");
11824+
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",
11825+
errout_str());
11826+
}
11827+
1179611828
// TODO: only used in a single place
1179711829
#define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)
1179811830
template<size_t size>

0 commit comments

Comments
 (0)