1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <memory> 10 11 // default_delete 12 13 #include <memory> 14 #include <cassert> 15 16 #include "test_macros.h" 17 18 struct A 19 { 20 static int count; AA21 A() {++count;} AA22 A(const A&) {++count;} ~AA23 virtual ~A() {--count;} 24 }; 25 26 int A::count = 0; 27 28 struct B 29 : public A 30 { 31 static int count; BB32 B() {++count;} BB33 B(const B& other) : A(other) {++count;} ~BB34 virtual ~B() {--count;} 35 }; 36 37 int B::count = 0; 38 main(int,char **)39int main(int, char**) 40 { 41 std::default_delete<B> d2; 42 std::default_delete<A> d1 = d2; 43 A* p = new B; 44 assert(A::count == 1); 45 assert(B::count == 1); 46 d1(p); 47 assert(A::count == 0); 48 assert(B::count == 0); 49 50 return 0; 51 } 52