diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index f247c47c7ac..1aaccce83d6 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -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 @@ -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" diff --git a/test/testother.cpp b/test/testother.cpp index 3f2af3c0f9a..6cb7a19d7b6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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); @@ -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