diff --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp --- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp +++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_nothrow_replace.pass.cpp @@ -17,24 +17,9 @@ #include #include +#include "count_new.h" #include "test_macros.h" -int new_called = 0; - -void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc) -{ - ++new_called; - void* ret = std::malloc(s); - if (!ret) std::abort(); // placate MSVC's unchecked malloc warning - return ret; -} - -void operator delete(void* p) TEST_NOEXCEPT -{ - --new_called; - std::free(p); -} - int A_constructed = 0; struct A @@ -45,15 +30,17 @@ int main(int, char**) { + globalMemCounter.reset(); + assert(globalMemCounter.checkOutstandingNewEq(0)); A *ap = new (std::nothrow) A[3]; DoNotOptimize(ap); assert(ap); assert(A_constructed == 3); - assert(new_called); + assert(globalMemCounter.checkOutstandingNewNotEq(0)); delete [] ap; DoNotOptimize(ap); assert(A_constructed == 0); - assert(!new_called); + assert(globalMemCounter.checkOutstandingNewEq(0)); return 0; } diff --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp --- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp +++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_array_replace.pass.cpp @@ -18,24 +18,9 @@ #include #include +#include "count_new.h" #include "test_macros.h" -int new_called = 0; - -void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc) -{ - ++new_called; - void* ret = std::malloc(s); - if (!ret) std::abort(); // placate MSVC's unchecked malloc warning - return ret; -} - -void operator delete(void* p) TEST_NOEXCEPT -{ - --new_called; - std::free(p); -} - int A_constructed = 0; struct A @@ -46,15 +31,17 @@ int main(int, char**) { + globalMemCounter.reset(); + assert(globalMemCounter.checkOutstandingNewEq(0)); A *ap = new A[3]; DoNotOptimize(ap); assert(ap); assert(A_constructed == 3); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); delete [] ap; DoNotOptimize(ap); assert(A_constructed == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); return 0; } diff --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp --- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp +++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_nothrow_replace.pass.cpp @@ -17,24 +17,9 @@ #include #include +#include "count_new.h" #include "test_macros.h" -int new_called = 0; - -void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc) -{ - ++new_called; - void* ret = std::malloc(s); - if (!ret) std::abort(); // placate MSVC's unchecked malloc warning - return ret; -} - -void operator delete(void* p) TEST_NOEXCEPT -{ - --new_called; - std::free(p); -} - bool A_constructed = false; struct A @@ -45,15 +30,17 @@ int main(int, char**) { + globalMemCounter.reset(); + assert(globalMemCounter.checkOutstandingNewEq(0)); A *ap = new (std::nothrow) A; DoNotOptimize(ap); assert(ap); assert(A_constructed); - assert(new_called); + assert(globalMemCounter.checkOutstandingNewNotEq(0)); delete ap; DoNotOptimize(ap); assert(!A_constructed); - assert(!new_called); + assert(globalMemCounter.checkOutstandingNewEq(0)); return 0; } diff --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp --- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp +++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_replace.pass.cpp @@ -16,24 +16,9 @@ #include #include +#include "count_new.h" #include "test_macros.h" -int new_called = 0; - -void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc) -{ - ++new_called; - void* ret = std::malloc(s); - if (!ret) std::abort(); // placate MSVC's unchecked malloc warning - return ret; -} - -void operator delete(void* p) TEST_NOEXCEPT -{ - --new_called; - std::free(p); -} - bool A_constructed = false; struct A @@ -44,15 +29,17 @@ int main(int, char**) { + globalMemCounter.reset(); + assert(globalMemCounter.checkOutstandingNewEq(0)); A *ap = new A; DoNotOptimize(ap); assert(ap); assert(A_constructed); - assert(new_called); + assert(globalMemCounter.checkOutstandingNewEq(1)); delete ap; DoNotOptimize(ap); assert(!A_constructed); - assert(!new_called); + assert(globalMemCounter.checkOutstandingNewEq(0)); return 0; } diff --git a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp --- a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp +++ b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp @@ -28,6 +28,7 @@ int main(int, char**) { + globalMemCounter.reset(); assert(globalMemCounter.checkOutstandingNewEq(0)); { typedef std::codecvt_utf16 C; diff --git a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp --- a/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp +++ b/libcxx/test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp @@ -28,6 +28,7 @@ int main(int, char**) { + globalMemCounter.reset(); assert(globalMemCounter.checkOutstandingNewEq(0)); { typedef std::codecvt_utf8 C; diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp --- a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp +++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp @@ -23,6 +23,7 @@ int main(int, char**) { + globalMemCounter.reset(); typedef std::wbuffer_convert > B; #if TEST_STD_VER > 11 static_assert(!std::is_convertible::value, ""); diff --git a/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp b/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp --- a/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp +++ b/libcxx/test/std/localization/locales/locale/locale.members/combine.pass.cpp @@ -66,6 +66,7 @@ int main(int, char**) { { + globalMemCounter.reset(); { std::locale loc; std::locale loc2(loc, new my_facet); diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp @@ -59,6 +59,7 @@ int main(int, char**) { + globalMemCounter.reset(); assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = A(1); diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp @@ -62,6 +62,7 @@ int main(int, char**) { + globalMemCounter.reset(); assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp @@ -65,6 +65,7 @@ int main(int, char**) { + globalMemCounter.reset(); assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f; diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp @@ -49,6 +49,7 @@ int g3(int, int, int) { return 3; } int main(int, char**) { + globalMemCounter.reset(); assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_move.pass.cpp @@ -52,6 +52,7 @@ int main(int, char**) { + globalMemCounter.reset(); assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp @@ -50,6 +50,7 @@ int main(int, char**) { + globalMemCounter.reset(); assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); diff --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp --- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp @@ -60,6 +60,7 @@ int g3(int, int, int) { return 3; } int main(int, char**) { + globalMemCounter.reset(); assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = A(1); diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -54,6 +54,7 @@ int main(int, char**) { + globalMemCounter.reset(); { // https://bugs.llvm.org/show_bug.cgi?id=18843 std::shared_ptr t1(new T); std::shared_ptr t2(std::make_shared()); diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp @@ -37,6 +37,7 @@ int main(int, char**) { + globalMemCounter.reset(); A* ptr = new A; globalMemCounter.throw_after = 0; try diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp @@ -37,6 +37,7 @@ int main(int, char**) { + globalMemCounter.reset(); A* ptr = new A; assert(A::count == 1); globalMemCounter.throw_after = 0;