You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e8a1b2c
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: test/testconstructors.cpp
+150Lines changed: 150 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -232,6 +232,18 @@ class TestConstructors : public TestFixture {
232
232
TEST_CASE(uninitTemplate1); // ticket #7372
233
233
234
234
TEST_CASE(unknownTemplateType);
235
+
236
+
TEST_CASE(inheritedCtor1);
237
+
TEST_CASE(inheritedCtor2);
238
+
TEST_CASE(inheritedCtor3);
239
+
TEST_CASE(inheritedCtor4);
240
+
TEST_CASE(inheritedCtor5);
241
+
TEST_CASE(inheritedCtor6);
242
+
TEST_CASE(inheritedCtor7);
243
+
TEST_CASE(inheritedCtor8);
244
+
TEST_CASE(inheritedCtor9);
245
+
TEST_CASE(inheritedCtor10);
246
+
TEST_CASE(inheritedCtor11);
235
247
}
236
248
237
249
@@ -4732,6 +4744,144 @@ class TestConstructors : public TestFixture {
4732
4744
ASSERT_EQUALS("", errout_str());
4733
4745
}
4734
4746
4747
+
voidinheritedCtor1() {
4748
+
check("struct Base { Base(int); };\n"
4749
+
"struct Derived : Base {\n"
4750
+
" using Base::Base;\n"
4751
+
" int x;\n"
4752
+
"};\n");
4753
+
ASSERT_EQUALS("[test.cpp:3:17]: (warning) Member variable 'Derived::x' is not initialized in the constructor inherited from 'Base'. [uninitMemberVar]\n", errout_str());
4754
+
}
4755
+
4756
+
voidinheritedCtor2() {
4757
+
check("struct Base { Base(int); };\n"
4758
+
"struct Derived : Base {\n"
4759
+
" using Base::Base;\n"
4760
+
" int x = 0;\n"
4761
+
" int y{};\n"
4762
+
"};\n");
4763
+
ASSERT_EQUALS("", errout_str());
4764
+
}
4765
+
4766
+
voidinheritedCtor3() {
4767
+
check("struct Base { Base(int); };\n"
4768
+
"struct S { S(); int i; };\n"
4769
+
"struct Derived : Base {\n"
4770
+
" using Base::Base;\n"
4771
+
" S s;\n"
4772
+
"};\n");
4773
+
ASSERT_EQUALS("", errout_str());
4774
+
}
4775
+
4776
+
voidinheritedCtor4() {
4777
+
check("struct Base { Base(int); };\n"
4778
+
"struct Derived : Base {\n"
4779
+
" using Base::Base;\n"
4780
+
" int x = 0;\n"
4781
+
" int y;\n"
4782
+
"};\n");
4783
+
ASSERT_EQUALS("[test.cpp:3:17]: (warning) Member variable 'Derived::y' is not initialized in the constructor inherited from 'Base'. [uninitMemberVar]\n", errout_str());
4784
+
}
4785
+
4786
+
voidinheritedCtor5() {
4787
+
check("struct Base { Base(int); };\n"
4788
+
"struct Derived : Base {\n"
4789
+
" using Base::Base;\n"
4790
+
" Derived() : x(0) {}\n"
4791
+
" int x;\n"
4792
+
"};\n");
4793
+
ASSERT_EQUALS("[test.cpp:3:17]: (warning) Member variable 'Derived::x' is not initialized in the constructor inherited from 'Base'. [uninitMemberVar]\n", errout_str());
4794
+
}
4795
+
4796
+
voidinheritedCtor6() {
4797
+
check("struct A { A(int); };\n"
4798
+
"struct B { B(double); };\n"
4799
+
"struct D : A, B {\n"
4800
+
" using A::A;\n"
4801
+
" using B::B;\n"
4802
+
" int x;\n"
4803
+
"};\n");
4804
+
ASSERT_EQUALS("[test.cpp:4:14]: (warning) Member variable 'D::x' is not initialized in the constructor inherited from 'A'. [uninitMemberVar]\n"
4805
+
"[test.cpp:5:14]: (warning) Member variable 'D::x' is not initialized in the constructor inherited from 'B'. [uninitMemberVar]\n",
4806
+
errout_str());
4807
+
}
4808
+
4809
+
voidinheritedCtor7() {
4810
+
check("struct Base { void f(); };\n"
4811
+
"struct Derived : Base {\n"
4812
+
" using Base::f;\n"
4813
+
" int x = 0;\n"
4814
+
" int y;\n"
4815
+
"};\n");
4816
+
ASSERT_EQUALS("[test.cpp:5:9]: (warning) Member variable 'Derived::y' has no initializer. [uninitMemberVarNoCtor]\n", errout_str());
4817
+
}
4818
+
4819
+
voidinheritedCtor8() {
4820
+
check("struct Base { Base(int); };\n"
4821
+
"struct Derived : Base {\n"
4822
+
" using Base::Base;\n"
4823
+
" Derived(int i) : Base(i), x(0) {}\n"
4824
+
" int x;\n"
4825
+
"};\n");
4826
+
ASSERT_EQUALS("", errout_str());
4827
+
4828
+
check("struct Base { Base(int); Base(double); };\n"
4829
+
"struct Derived : Base {\n"
4830
+
" using Base::Base;\n"
4831
+
" Derived(int i) : Base(i), x(0) {}\n"
4832
+
" int x;\n"
4833
+
"};\n");
4834
+
ASSERT_EQUALS("[test.cpp:3:17]: (warning) Member variable 'Derived::x' is not initialized in the constructor inherited from 'Base'. [uninitMemberVar]\n", errout_str());
4835
+
}
4836
+
4837
+
voidinheritedCtor9() {
4838
+
check("struct Base { Base(); };\n"
4839
+
"struct Derived : Base {\n"
4840
+
" using Base::Base;\n"
4841
+
" int x;\n"
4842
+
"};\n");
4843
+
ASSERT_EQUALS("", errout_str());
4844
+
4845
+
check("struct Base {};\n"
4846
+
"struct Derived : Base {\n"
4847
+
" using Base::Base;\n"
4848
+
" int x;\n"
4849
+
"};\n");
4850
+
ASSERT_EQUALS("", errout_str());
4851
+
4852
+
check("struct Base { Base(const Base&); Base(Base&&); };\n"
4853
+
"struct Derived : Base {\n"
4854
+
" using Base::Base;\n"
4855
+
" int x;\n"
4856
+
"};\n");
4857
+
ASSERT_EQUALS("", errout_str());
4858
+
}
4859
+
4860
+
voidinheritedCtor10() {
4861
+
check("struct Base { Base(int) = delete; };\n"
4862
+
"struct Derived : Base {\n"
4863
+
" using Base::Base;\n"
4864
+
" int x;\n"
4865
+
"};\n");
4866
+
ASSERT_EQUALS("", errout_str());
4867
+
4868
+
check("class Base { Base(int); };\n"
4869
+
"struct Derived : Base {\n"
4870
+
" using Base::Base;\n"
4871
+
" int x;\n"
4872
+
"};\n");
4873
+
ASSERT_EQUALS("", errout_str());
4874
+
}
4875
+
4876
+
voidinheritedCtor11() {
4877
+
check("namespace X { struct Base { Base(int); }; }\n"
4878
+
"struct Derived : X::Base {\n"
4879
+
" using X::Base::Base;\n"
4880
+
" int x;\n"
4881
+
"};\n");
4882
+
ASSERT_EQUALS("[test.cpp:3:20]: (warning) Member variable 'Derived::x' is not initialized in the constructor inherited from 'Base'. [uninitMemberVar]\n", errout_str());
0 commit comments