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 71d3932
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: test/testclass.cpp
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2857,6 +2857,36 @@ class TestClass : public TestFixture {
2857
2857
checkVirtualDestructor("class Base { public: ~Base(); };\n"
2858
2858
"class Derived : public Base { public: ~Derived() { (void)11; } };\n");
2859
2859
ASSERT_EQUALS("", errout_str());
2860
+
2861
+
// the pointer is deleted before it points at the derived class, or another pointer is deleted
2862
+
checkVirtualDestructor("class Base { public: ~Base(); };\n"
2863
+
"class Derived : public Base { public: ~Derived() { (void)11; } };\n"
2864
+
"void f(Base *p, Base *q) {\n"
2865
+
" delete p;\n"
2866
+
" p = new Derived;\n"
2867
+
" delete q;\n"
2868
+
"}\n");
2869
+
ASSERT_EQUALS("", errout_str());
2870
+
2871
+
// only the derived class that the deleted pointer points at
2872
+
checkVirtualDestructor("class Base { public: ~Base(); };\n"
2873
+
"class Derived1 : public Base { public: ~Derived1() { (void)11; } };\n"
2874
+
"class Derived2 : public Base { public: ~Derived2() { (void)11; } };\n"
2875
+
"void f(Base *p, Base *q) {\n"
2876
+
" p = new Derived1;\n"
2877
+
" q = new Derived2;\n"
2878
+
" delete q;\n"
2879
+
"}\n");
2880
+
ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived2' does not have a virtual destructor. [virtualDestructor]\n", errout_str());
2881
+
2882
+
// the derived class is a template instantiation, its name contains spaces
2883
+
checkVirtualDestructor("class Base { public: ~Base(); };\n"
2884
+
"template<class T> class Derived : public Base { public: ~Derived() { (void)11; } };\n"
2885
+
"void f(Base *p) {\n"
2886
+
" p = new Derived<unsigned int>;\n"
2887
+
" delete p;\n"
2888
+
"}\n");
2889
+
ASSERT_EQUALS("[test.cpp:1:23]: (error) Class 'Base' which is inherited by class 'Derived < unsigned int >' does not have a virtual destructor. [virtualDestructor]\n", errout_str());
0 commit comments