Index: test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp =================================================================== --- test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp +++ test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp @@ -13,45 +13,28 @@ // ~ctype(); -// UNSUPPORTED: asan, msan - #include #include -#include - -unsigned delete_called = 0; -void* operator new[](size_t sz) throw(std::bad_alloc) -{ - return operator new(sz); -} - -void operator delete[](void* p) throw() -{ - operator delete(p); - ++delete_called; -} +#include "count_new.hpp" int main() { { - delete_called = 0; std::locale l(std::locale::classic(), new std::ctype); - assert(delete_called == 0); + assert(globalMemCounter.checkDeleteArrayCalledEq(0)); } - assert(delete_called == 0); + assert(globalMemCounter.checkDeleteArrayCalledEq(0)); { std::ctype::mask table[256]; - delete_called = 0; std::locale l(std::locale::classic(), new std::ctype(table)); - assert(delete_called == 0); + assert(globalMemCounter.checkDeleteArrayCalledEq(0)); } - assert(delete_called == 0); + assert(globalMemCounter.checkDeleteArrayCalledEq(0)); { - delete_called = 0; std::locale l(std::locale::classic(), new std::ctype(new std::ctype::mask[256], true)); - assert(delete_called == 0); + assert(globalMemCounter.checkDeleteArrayCalledEq(0)); } - assert(delete_called == 1); + assert(globalMemCounter.checkDeleteArrayCalledEq(1)); } Index: test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp =================================================================== --- test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp +++ test/std/localization/locale.stdcvt/codecvt_utf16.pass.cpp @@ -17,43 +17,26 @@ // // unspecified // }; -// UNSUPPORTED: asan, msan - // Not a portable test #include #include #include -int outstanding_news = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++outstanding_news; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - if (p) - { - --outstanding_news; - std::free(p); - } -} +#include "count_new.hpp" int main() { - assert(outstanding_news == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { typedef std::codecvt_utf16 C; C c; - assert(outstanding_news == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); } { typedef std::codecvt_utf16 C; std::locale loc(std::locale::classic(), new C); - assert(outstanding_news != 0); + assert(globalMemCounter.checkOutstandingNewNotEq(0)); } - assert(outstanding_news == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); } Index: test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp =================================================================== --- test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp +++ test/std/localization/locale.stdcvt/codecvt_utf8.pass.cpp @@ -17,43 +17,26 @@ // // unspecified // }; -// UNSUPPORTED: asan, msan - // Not a portable test #include #include #include -int outstanding_news = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++outstanding_news; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - if (p) - { - --outstanding_news; - std::free(p); - } -} +#include "count_new.hpp" int main() { - assert(outstanding_news == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { typedef std::codecvt_utf8 C; C c; - assert(outstanding_news == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); } { typedef std::codecvt_utf8 C; std::locale loc(std::locale::classic(), new C); - assert(outstanding_news != 0); + assert(globalMemCounter.checkOutstandingNewNotEq(0)); } - assert(outstanding_news == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); } Index: test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp =================================================================== --- test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp +++ test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp @@ -14,27 +14,12 @@ // wbuffer_convert(streambuf *bytebuf = 0, Codecvt *pcvt = new Codecvt, // state_type state = state_type()); -// UNSUPPORTED: asan, msan - #include #include #include #include -#include - -int new_called = 0; -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" int main() { @@ -46,28 +31,28 @@ { B b; assert(b.rdbuf() == nullptr); - assert(new_called != 0); + assert(globalMemCounter.checkOutstandingNewNotEq(0)); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::stringstream s; B b(s.rdbuf()); assert(b.rdbuf() == s.rdbuf()); - assert(new_called != 0); + assert(globalMemCounter.checkOutstandingNewNotEq(0)); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::stringstream s; B b(s.rdbuf(), new std::codecvt_utf8); assert(b.rdbuf() == s.rdbuf()); - assert(new_called != 0); + assert(globalMemCounter.checkOutstandingNewNotEq(0)); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::stringstream s; B b(s.rdbuf(), new std::codecvt_utf8, std::mbstate_t()); assert(b.rdbuf() == s.rdbuf()); - assert(new_called != 0); + assert(globalMemCounter.checkOutstandingNewNotEq(0)); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); } Index: test/std/localization/locales/locale/locale.cons/default.pass.cpp =================================================================== --- test/std/localization/locales/locale/locale.cons/default.pass.cpp +++ test/std/localization/locales/locale/locale.cons/default.pass.cpp @@ -11,27 +11,11 @@ // locale() throw(); -// UNSUPPORTED: asan, msan - #include -#include #include #include "platform_support.h" // locale name macros - -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" void check(const std::locale& loc) { @@ -73,19 +57,19 @@ int ok; { std::locale loc; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(loc.name() == "C"); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); check(loc); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(std::locale::global(std::locale(LOCALE_en_US_UTF_8)) == loc); - ok = new_called; + ok = globalMemCounter.outstanding_new; std::locale loc2; - assert(new_called == ok); + assert(globalMemCounter.checkOutstandingNewEq(ok)); check(loc2); - assert(new_called == ok); + assert(globalMemCounter.checkOutstandingNewEq(ok)); assert(loc2 == std::locale(LOCALE_en_US_UTF_8)); - assert(new_called == ok); + assert(globalMemCounter.checkOutstandingNewEq(ok)); } - assert(new_called == ok); + assert(globalMemCounter.checkOutstandingNewEq(ok)); } Index: test/std/localization/locales/locale/locale.members/combine.pass.cpp =================================================================== --- test/std/localization/locales/locale/locale.members/combine.pass.cpp +++ test/std/localization/locales/locale/locale.members/combine.pass.cpp @@ -11,25 +11,10 @@ // template locale combine(const locale& other) const; -// UNSUPPORTED: asan, msan - #include -#include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" void check(const std::locale& loc) { @@ -89,7 +74,7 @@ const my_facet& f = std::use_facet(loc3); assert(f.test() == 5); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); } { { @@ -104,6 +89,6 @@ { } } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); } } Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp =================================================================== --- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp +++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp @@ -14,26 +14,12 @@ // template // void swap(function&, function&); -// UNSUPPORTED: asan, msan #include -#include #include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" class A { @@ -73,65 +59,65 @@ int main() { - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = A(1); std::function f2 = A(2); assert(A::count == 2); - assert(new_called == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); assert(f1.target()->id() == 1); assert(f2.target()->id() == 2); swap(f1, f2); assert(A::count == 2); - assert(new_called == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); assert(f1.target()->id() == 2); assert(f2.target()->id() == 1); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = A(1); std::function f2 = g; assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f1.target()->id() == 1); assert(*f2.target() == g); swap(f1, f2); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(*f1.target() == g); assert(f2.target()->id() == 1); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = g; std::function f2 = A(1); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(*f1.target() == g); assert(f2.target()->id() == 1); swap(f1, f2); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f1.target()->id() == 1); assert(*f2.target() == g); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = g; std::function f2 = h; assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(*f1.target() == g); assert(*f2.target() == h); swap(f1, f2); assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(*f1.target() == h); assert(*f2.target() == g); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); } Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp =================================================================== --- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp +++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp @@ -13,26 +13,10 @@ // function(nullptr_t); -// UNSUPPORTED: asan, msan - #include -#include -#include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" class A { @@ -67,34 +51,34 @@ int main() { - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target()); assert(f.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = g; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target()); assert(f.target() == 0); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = (int (*)(int))0; assert(!f); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() == 0); assert(f.target() == 0); } { std::function f = &A::foo; assert(f); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() != 0); } } Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp =================================================================== --- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp +++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp @@ -16,26 +16,10 @@ // && Convertible::result_type // operator=(F f); -// UNSUPPORTED: asan, msan - #include -#include -#include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" class A { @@ -70,30 +54,30 @@ int main() { - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f; f = A(); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target()); assert(f.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f; f = g; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target()); assert(f.target() == 0); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f; f = (int (*)(int))0; assert(!f); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() == 0); assert(f.target() == 0); } @@ -101,7 +85,7 @@ std::function f; f = &A::foo; assert(f); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() != 0); } } Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp =================================================================== --- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp +++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp @@ -13,28 +13,12 @@ // template function(allocator_arg_t, const A&, const function&); -// UNSUPPORTED: asan, msan #include -#include -#include #include #include "test_allocator.h" - -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" class A { @@ -67,48 +51,48 @@ int main() { - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target()); assert(f.target() == 0); std::function f2(std::allocator_arg, test_allocator(), f); assert(A::count == 2); - assert(new_called == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); assert(f2.target()); assert(f2.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = g; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target()); assert(f.target() == 0); std::function f2(std::allocator_arg, test_allocator(), f); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f2.target()); assert(f2.target() == 0); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); non_default_test_allocator> al(1); std::function f2(std::allocator_arg, al, g); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f2.target()); assert(f2.target() == 0); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() == 0); assert(f.target() == 0); std::function f2(std::allocator_arg, test_allocator(), f); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f2.target() == 0); assert(f2.target() == 0); } Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp =================================================================== --- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp +++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp @@ -13,26 +13,11 @@ // template function(allocator_arg_t, const A&, function&&); -// UNSUPPORTED: asan, msan - #include #include #include "test_allocator.h" - -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" class A { @@ -64,16 +49,16 @@ int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target()); assert(f.target() == 0); std::function f2(std::allocator_arg, test_allocator(), std::move(f)); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f2.target()); assert(f2.target() == 0); assert(f.target() == 0); Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp =================================================================== --- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp +++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp @@ -13,26 +13,11 @@ // function(const function& f); -// UNSUPPORTED: asan, msan - #include -#include #include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" class A { @@ -65,65 +50,65 @@ int main() { - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target()); assert(f.target() == 0); std::function f2 = f; assert(A::count == 2); - assert(new_called == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); assert(f2.target()); assert(f2.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = g; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target()); assert(f.target() == 0); std::function f2 = f; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f2.target()); assert(f2.target() == 0); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() == 0); assert(f.target() == 0); std::function f2 = f; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f2.target() == 0); assert(f2.target() == 0); } { std::function f; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() == 0); assert(f.target() == 0); assert(!f); std::function g = f; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(g.target() == 0); assert(g.target() == 0); assert(!g); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target()); assert(f.target() == 0); std::function f2 = std::move(f); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f2.target()); assert(f2.target() == 0); assert(f.target() == 0); Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp =================================================================== --- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp +++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp @@ -13,26 +13,10 @@ // function& operator=(const function& f); -// UNSUPPORTED: asan, msan - #include -#include -#include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" class A { @@ -65,57 +49,57 @@ int main() { - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target()); assert(f.target() == 0); std::function f2; f2 = f; assert(A::count == 2); - assert(new_called == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); assert(f2.target()); assert(f2.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = g; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target()); assert(f.target() == 0); std::function f2; f2 = f; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f2.target()); assert(f2.target() == 0); } - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() == 0); assert(f.target() == 0); std::function f2; f2 = f; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f2.target() == 0); assert(f2.target() == 0); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target()); assert(f.target() == 0); std::function f2; f2 = std::move(f); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f2.target()); assert(f2.target() == 0); assert(f.target() == 0); Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp =================================================================== --- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp +++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp @@ -13,26 +13,10 @@ // function& operator=(nullptr_t); -// UNSUPPORTED: asan, msan - #include -#include -#include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" class A { @@ -65,24 +49,24 @@ int main() { - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f.target()); f = nullptr; assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() == 0); } { std::function f = g; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target()); assert(f.target() == 0); f = nullptr; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(f.target() == 0); } } Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp =================================================================== --- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp +++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp @@ -13,26 +13,10 @@ // void swap(function& other); -// UNSUPPORTED: asan, msan - #include -#include -#include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" class A { @@ -72,65 +56,65 @@ int main() { - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = A(1); std::function f2 = A(2); assert(A::count == 2); - assert(new_called == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); assert(f1.target()->id() == 1); assert(f2.target()->id() == 2); f1.swap(f2); assert(A::count == 2); - assert(new_called == 2); + assert(globalMemCounter.checkOutstandingNewEq(2)); assert(f1.target()->id() == 2); assert(f2.target()->id() == 1); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = A(1); std::function f2 = g; assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f1.target()->id() == 1); assert(*f2.target() == g); f1.swap(f2); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(*f1.target() == g); assert(f2.target()->id() == 1); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = g; std::function f2 = A(1); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(*f1.target() == g); assert(f2.target()->id() == 1); f1.swap(f2); assert(A::count == 1); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(f1.target()->id() == 1); assert(*f2.target() == g); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); { std::function f1 = g; std::function f2 = h; assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(*f1.target() == g); assert(*f2.target() == h); f1.swap(f2); assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(*f1.target() == h); assert(*f2.target() == g); } assert(A::count == 0); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); } Index: test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp =================================================================== --- test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp +++ test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp @@ -12,27 +12,10 @@ // allocator: // pointer allocate(size_type n, allocator::const_pointer hint=0); -// UNSUPPORTED: asan, msan - #include -#include -#include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - assert(s == 3 * sizeof(int)); - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" int A_constructed = 0; @@ -47,19 +30,23 @@ int main() { std::allocator a; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(A_constructed == 0); + globalMemCounter.last_new_size = 0; A* ap = a.allocate(3); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); assert(A_constructed == 0); a.deallocate(ap, 3); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(A_constructed == 0); + globalMemCounter.last_new_size = 0; A* ap2 = a.allocate(3, (const void*)5); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); assert(A_constructed == 0); a.deallocate(ap2, 3); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(A_constructed == 0); } Index: test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp =================================================================== --- test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp +++ test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp @@ -12,27 +12,10 @@ // allocator: // template void construct(pointer p, Args&&... args); -// UNSUPPORTED: asan, msan - #include -#include -#include #include -int new_called = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_called; - assert(s == 3 * sizeof(int)); - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - --new_called; - std::free(p); -} +#include "count_new.hpp" int A_constructed = 0; @@ -80,76 +63,80 @@ { { std::allocator a; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(A_constructed == 0); + globalMemCounter.last_new_size = 0; A* ap = a.allocate(3); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); assert(A_constructed == 0); a.construct(ap); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(A_constructed == 1); a.destroy(ap); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(A_constructed == 0); a.construct(ap, A()); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(A_constructed == 1); a.destroy(ap); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(A_constructed == 0); a.construct(ap, 5); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(A_constructed == 1); a.destroy(ap); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(A_constructed == 0); a.construct(ap, 5, (int*)0); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(A_constructed == 1); a.destroy(ap); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(A_constructed == 0); a.deallocate(ap, 3); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(A_constructed == 0); } { std::allocator a; - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(move_only_constructed == 0); + globalMemCounter.last_new_size = 0; move_only* ap = a.allocate(3); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); + assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int))); assert(move_only_constructed == 0); a.construct(ap); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(move_only_constructed == 1); a.destroy(ap); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(move_only_constructed == 0); a.construct(ap, move_only()); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(move_only_constructed == 1); a.destroy(ap); - assert(new_called == 1); + assert(globalMemCounter.checkOutstandingNewEq(1)); assert(move_only_constructed == 0); a.deallocate(ap, 3); - assert(new_called == 0); + assert(globalMemCounter.checkOutstandingNewEq(0)); assert(move_only_constructed == 0); } } Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp @@ -13,25 +13,10 @@ // template shared_ptr make_shared(Args&&... args); -// UNSUPPORTED: asan, msan - #include -#include -#include #include -int new_count = 0; - -void* operator new(std::size_t s) throw(std::bad_alloc) -{ - ++new_count; - return std::malloc(s); -} - -void operator delete(void* p) throw() -{ - std::free(p); -} +#include "count_new.hpp" struct A { @@ -54,22 +39,22 @@ int main() { - int nc = new_count; + int nc = globalMemCounter.outstanding_new; { int i = 67; char c = 'e'; std::shared_ptr p = std::make_shared(i, c); - assert(new_count == nc+1); + assert(globalMemCounter.checkOutstandingNewEq(nc+1)); assert(A::count == 1); assert(p->get_int() == 67); assert(p->get_char() == 'e'); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - nc = new_count; + nc = globalMemCounter.outstanding_new; { char c = 'e'; std::shared_ptr p = std::make_shared(67, c); - assert(new_count == nc+1); + assert(globalMemCounter.checkOutstandingNewEq(nc+1)); assert(A::count == 1); assert(p->get_int() == 67); assert(p->get_char() == 'e'); Index: test/support/count_new.hpp =================================================================== --- /dev/null +++ test/support/count_new.hpp @@ -0,0 +1,201 @@ +#ifndef COUNT_NEW_HPP +#define COUNT_NEW_HPP + +# include +# include +# include + +#if __has_feature(address_sanitizer) \ + || __has_feature(memory_sanitizer) +#define DISABLE_NEW_COUNT +#endif + +class MemCounter +{ +public: + // Make MemCounter super hard to accidentally construct or copy. + class MemCounterCtorArg_ {}; + explicit MemCounter(MemCounterCtorArg_) {} + +private: + MemCounter(MemCounter const &); + MemCounter & operator=(MemCounter const &); + +public: + // All checks return true when disable_checking is enabled. + static const bool disable_checking; + + int outstanding_new = 0; + int new_called = 0; + int delete_called = 0; + int last_new_size = 0; + + int outstanding_array_new = 0; + int new_array_called = 0; + int delete_array_called = 0; + int last_new_array_size = 0; + +public: + void newCalled(std::size_t s) + { + assert(s); + ++new_called; + ++outstanding_new; + last_new_size = s; + } + + void deleteCalled(void * p) + { + assert(p); + --outstanding_new; + ++delete_called; + } + + void newArrayCalled(std::size_t s) + { + assert(s); + ++outstanding_array_new; + ++new_array_called; + last_new_array_size = s; + } + + void deleteArrayCalled(void * p) + { + assert(p); + --outstanding_array_new; + ++delete_array_called; + } + + void reset() + { + outstanding_new = 0; + new_called = 0; + delete_called = 0; + last_new_size = 0; + + outstanding_array_new = 0; + new_array_called = 0; + delete_array_called = 0; + last_new_array_size = 0; + } + +public: + bool checkOutstandingNewEq(int n) const + { + return disable_checking || n == outstanding_new; + } + + bool checkOutstandingNewNotEq(int n) const + { + return disable_checking || n != outstanding_new; + } + + bool checkNewCalledEq(int n) const + { + return disable_checking || n == new_called; + } + + bool checkNewCalledNotEq(int n) const + { + return disable_checking || n != new_called; + } + + bool checkDeleteCalledEq(int n) const + { + return disable_checking || n == delete_called; + } + + bool checkDeleteCalledNotEq(int n) const + { + return disable_checking || n != delete_called; + } + + bool checkLastNewSizeEq(int n) const + { + return disable_checking || n == last_new_size; + } + + bool checkLastNewSizeNotEq(int n) const + { + return disable_checking || n != last_new_size; + } + + bool checkOutstandingArrayNewEq(int n) const + { + return disable_checking || n == outstanding_array_new; + } + + bool checkOutstandingArrayNewNotEq(int n) const + { + return disable_checking || n != outstanding_array_new; + } + + bool checkNewArrayCalledEq(int n) const + { + return disable_checking || n == new_array_called; + } + + bool checkNewArrayCalledNotEq(int n) const + { + return disable_checking || n != new_array_called; + } + + bool checkDeleteArrayCalledEq(int n) const + { + return disable_checking || n == delete_array_called; + } + + bool checkDeleteArrayCalledNotEq(int n) const + { + return disable_checking || n != delete_array_called; + } + + bool checkLastNewArraySizeEq(int n) const + { + return disable_checking || n == last_new_array_size; + } + + bool checkLastNewArraySizeNotEq(int n) const + { + return disable_checking || n != last_new_array_size; + } +}; + +#ifdef DISABLE_NEW_COUNT + const bool MemCounter::disable_checking = true; +#else + const bool MemCounter::disable_checking = false; +#endif + +MemCounter globalMemCounter((MemCounter::MemCounterCtorArg_())); + +#ifndef DISABLE_NEW_COUNT +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + globalMemCounter.newCalled(s); + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + globalMemCounter.deleteCalled(p); + std::free(p); +} + + +void* operator new[](std::size_t s) throw(std::bad_alloc) +{ + globalMemCounter.newArrayCalled(s); + return operator new(s); +} + + +void operator delete[](void* p) throw() +{ + globalMemCounter.deleteArrayCalled(p); + operator delete(p); +} + +#endif // DISABLE_NEW_COUNT + +#endif /* COUNT_NEW_HPP */