Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/testconstructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TestConstructors : public TestFixture {
TEST_CASE(initvar_derived_pod_struct_with_union); // #11101

TEST_CASE(initvar_private_constructor); // BUG 2354171 - private constructor
TEST_CASE(initvar_derived_private_constructor);
TEST_CASE(initvar_copy_constructor); // ticket #1611
TEST_CASE(initvar_nested_constructor); // ticket #1375
TEST_CASE(initvar_nocopy1); // ticket #2474
Expand Down Expand Up @@ -1609,6 +1610,15 @@ class TestConstructors : public TestFixture {
ASSERT_EQUALS("", errout_str());
}
}
void initvar_derived_private_constructor() {
check("class B { int i; };\n"
"class D : B {\n"
" explicit D(int) {}\n"
"};\n");
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"
"[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",
errout_str());
}

void initvar_copy_constructor() { // ticket #1611
check("class Fred\n"
Expand Down
32 changes: 32 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ class TestOther : public TestFixture {
TEST_CASE(raceAfterInterlockedDecrement);

TEST_CASE(testUnusedLabel);
TEST_CASE(testUnusedLabelConfiguration);
TEST_CASE(testUnusedLabelSwitchConfiguration);

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


void testUnusedLabelConfiguration() {
checkP("void f() {\n"
"#ifdef X\n"
" goto END;\n"
"#endif\n"
"END:\n"
"}");
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",
errout_str());
}

void testUnusedLabelSwitchConfiguration() {
checkP("void f(int i) {\n"
" switch (i) {\n"
" default:\n"
" break;\n"
"#ifdef X\n"
" case 1:\n"
" goto END;\n"
"#endif\n"
" case 2:\n"
" END:\n"
" return;\n"
" }\n"
"}");
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",
errout_str());
}

// TODO: only used in a single place
#define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__)
template<size_t size>
Expand Down