Index: test/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp =================================================================== --- test/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp +++ test/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.dtor/dtor.pass.cpp @@ -13,45 +13,31 @@ // ~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; + delete_array_called = 0; std::locale l(std::locale::classic(), new std::ctype); - assert(delete_called == 0); + COUNT_NEW_ASSERT(delete_array_called == 0); } - assert(delete_called == 0); + COUNT_NEW_ASSERT(delete_array_called == 0); { std::ctype::mask table[256]; - delete_called = 0; + delete_array_called = 0; std::locale l(std::locale::classic(), new std::ctype(table)); - assert(delete_called == 0); + COUNT_NEW_ASSERT(delete_array_called == 0); } - assert(delete_called == 0); + COUNT_NEW_ASSERT(delete_array_called == 0); { - delete_called = 0; + delete_array_called = 0; std::locale l(std::locale::classic(), new std::ctype(new std::ctype::mask[256], true)); - assert(delete_called == 0); + COUNT_NEW_ASSERT(delete_array_called == 0); } - assert(delete_called == 1); + COUNT_NEW_ASSERT(delete_array_called == 1); } Index: test/localization/locale.stdcvt/codecvt_utf16.pass.cpp =================================================================== --- test/localization/locale.stdcvt/codecvt_utf16.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { typedef std::codecvt_utf16 C; C c; - assert(outstanding_news == 0); + COUNT_NEW_ASSERT(new_called == 0); } { typedef std::codecvt_utf16 C; std::locale loc(std::locale::classic(), new C); - assert(outstanding_news != 0); + COUNT_NEW_ASSERT(new_called != 0); } - assert(outstanding_news == 0); + COUNT_NEW_ASSERT(new_called == 0); } Index: test/localization/locale.stdcvt/codecvt_utf8.pass.cpp =================================================================== --- test/localization/locale.stdcvt/codecvt_utf8.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { typedef std::codecvt_utf8 C; C c; - assert(outstanding_news == 0); + COUNT_NEW_ASSERT(new_called == 0); } { typedef std::codecvt_utf8 C; std::locale loc(std::locale::classic(), new C); - assert(outstanding_news != 0); + COUNT_NEW_ASSERT(new_called != 0); } - assert(outstanding_news == 0); + COUNT_NEW_ASSERT(new_called == 0); } Index: test/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp =================================================================== --- test/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called != 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::stringstream s; B b(s.rdbuf()); assert(b.rdbuf() == s.rdbuf()); - assert(new_called != 0); + COUNT_NEW_ASSERT(new_called != 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::stringstream s; B b(s.rdbuf(), new std::codecvt_utf8); assert(b.rdbuf() == s.rdbuf()); - assert(new_called != 0); + COUNT_NEW_ASSERT(new_called != 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::stringstream s; B b(s.rdbuf(), new std::codecvt_utf8, std::mbstate_t()); assert(b.rdbuf() == s.rdbuf()); - assert(new_called != 0); + COUNT_NEW_ASSERT(new_called != 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); } Index: test/localization/locales/locale/locale.cons/default.pass.cpp =================================================================== --- test/localization/locales/locale/locale.cons/default.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); assert(loc.name() == "C"); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); check(loc); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(std::locale::global(std::locale(LOCALE_en_US_UTF_8)) == loc); ok = new_called; std::locale loc2; - assert(new_called == ok); + COUNT_NEW_ASSERT(new_called == ok); check(loc2); - assert(new_called == ok); + COUNT_NEW_ASSERT(new_called == ok); assert(loc2 == std::locale(LOCALE_en_US_UTF_8)); - assert(new_called == ok); + COUNT_NEW_ASSERT(new_called == ok); } - assert(new_called == ok); + COUNT_NEW_ASSERT(new_called == ok); } Index: test/localization/locales/locale/locale.members/combine.pass.cpp =================================================================== --- test/localization/locales/locale/locale.members/combine.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); } { { @@ -104,6 +89,6 @@ { } } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); } } Index: test/support/count_new.hpp =================================================================== --- /dev/null +++ test/support/count_new.hpp @@ -0,0 +1,58 @@ +#ifndef COUNT_NEW_HPP +#define COUNT_NEW_HPP + +# include +# include +# include + +int new_called = 0; +int delete_called = 0; +int last_new_size = 0; + +int new_array_called = 0; +int delete_array_called = 0; +int last_new_array_size = 0; + +#if !__has_feature(address_sanitizer) \ + && !__has_feature(memory_sanitizer) + +#define COUNT_NEW_ASSERT(Pred) assert(Pred) + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + ++new_called; + last_new_size = s; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + ++delete_called; + --new_called; + std::free(p); +} + + +void* operator new[](std::size_t s) throw(std::bad_alloc) +{ + ++new_array_called; + last_new_array_size = s; + return operator new(s); +} + + +void operator delete[](void* p) throw() +{ + --new_array_called; + ++delete_array_called; + operator delete(p); +} + + +#else + +#define COUNT_NEW_ASSERT(Pred) ((void)0) + +#endif // __has_feature(sanitizer) + +#endif /* COUNT_NEW_HPP */ Index: test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp =================================================================== --- test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.alg/swap.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { std::function f1 = A(1); std::function f2 = A(2); assert(A::count == 2); - assert(new_called == 2); + COUNT_NEW_ASSERT(new_called == 2); assert(f1.target()->id() == 1); assert(f2.target()->id() == 2); swap(f1, f2); assert(A::count == 2); - assert(new_called == 2); + COUNT_NEW_ASSERT(new_called == 2); assert(f1.target()->id() == 2); assert(f2.target()->id() == 1); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f1 = A(1); std::function f2 = g; assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f1.target()->id() == 1); assert(*f2.target() == g); swap(f1, f2); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(*f1.target() == g); assert(f2.target()->id() == 1); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f1 = g; std::function f2 = A(1); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(*f1.target() == g); assert(f2.target()->id() == 1); swap(f1, f2); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f1.target()->id() == 1); assert(*f2.target() == g); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f1 = g; std::function f2 = h; assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(*f1.target() == g); assert(*f2.target() == h); swap(f1, f2); assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(*f1.target() == h); assert(*f2.target() == g); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); } Index: test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp =================================================================== --- test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f.target()); assert(f.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = g; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target()); assert(f.target() == 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = (int (*)(int))0; assert(!f); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target() == 0); assert(f.target() == 0); } { std::function f = &A::foo; assert(f); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target() != 0); } } Index: test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp =================================================================== --- test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { std::function f; f = A(); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f.target()); assert(f.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f; f = g; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target()); assert(f.target() == 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f; f = (int (*)(int))0; assert(!f); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 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); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target() != 0); } } Index: test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp =================================================================== --- test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 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); + COUNT_NEW_ASSERT(new_called == 2); assert(f2.target()); assert(f2.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = g; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target()); assert(f.target() == 0); std::function f2(std::allocator_arg, test_allocator(), f); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f2.target()); assert(f2.target() == 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); non_default_test_allocator> al(1); std::function f2(std::allocator_arg, al, g); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f2.target()); assert(f2.target() == 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target() == 0); assert(f.target() == 0); std::function f2(std::allocator_arg, test_allocator(), f); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f2.target() == 0); assert(f2.target() == 0); } Index: test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp =================================================================== --- test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 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); + COUNT_NEW_ASSERT(new_called == 1); assert(f2.target()); assert(f2.target() == 0); assert(f.target() == 0); Index: test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp =================================================================== --- test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f.target()); assert(f.target() == 0); std::function f2 = f; assert(A::count == 2); - assert(new_called == 2); + COUNT_NEW_ASSERT(new_called == 2); assert(f2.target()); assert(f2.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = g; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target()); assert(f.target() == 0); std::function f2 = f; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f2.target()); assert(f2.target() == 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target() == 0); assert(f.target() == 0); std::function f2 = f; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f2.target() == 0); assert(f2.target() == 0); } { std::function f; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target() == 0); assert(f.target() == 0); assert(!f); std::function g = f; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(g.target() == 0); assert(g.target() == 0); assert(!g); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f.target()); assert(f.target() == 0); std::function f2 = std::move(f); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f2.target()); assert(f2.target() == 0); assert(f.target() == 0); Index: test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp =================================================================== --- test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/copy_assign.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f.target()); assert(f.target() == 0); std::function f2; f2 = f; assert(A::count == 2); - assert(new_called == 2); + COUNT_NEW_ASSERT(new_called == 2); assert(f2.target()); assert(f2.target() == 0); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = g; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target()); assert(f.target() == 0); std::function f2; f2 = f; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f2.target()); assert(f2.target() == 0); } - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target() == 0); assert(f.target() == 0); std::function f2; f2 = f; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f2.target() == 0); assert(f2.target() == 0); } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f.target()); assert(f.target() == 0); std::function f2; f2 = std::move(f); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f2.target()); assert(f2.target() == 0); assert(f.target() == 0); Index: test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp =================================================================== --- test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/nullptr_t_assign.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { std::function f = A(); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f.target()); f = nullptr; assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target() == 0); } { std::function f = g; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target()); assert(f.target() == 0); f = nullptr; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(f.target() == 0); } } Index: test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp =================================================================== --- test/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.mod/swap.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); { std::function f1 = A(1); std::function f2 = A(2); assert(A::count == 2); - assert(new_called == 2); + COUNT_NEW_ASSERT(new_called == 2); assert(f1.target()->id() == 1); assert(f2.target()->id() == 2); f1.swap(f2); assert(A::count == 2); - assert(new_called == 2); + COUNT_NEW_ASSERT(new_called == 2); assert(f1.target()->id() == 2); assert(f2.target()->id() == 1); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f1 = A(1); std::function f2 = g; assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f1.target()->id() == 1); assert(*f2.target() == g); f1.swap(f2); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(*f1.target() == g); assert(f2.target()->id() == 1); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f1 = g; std::function f2 = A(1); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(*f1.target() == g); assert(f2.target()->id() == 1); f1.swap(f2); assert(A::count == 1); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(f1.target()->id() == 1); assert(*f2.target() == g); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); { std::function f1 = g; std::function f2 = h; assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(*f1.target() == g); assert(*f2.target() == h); f1.swap(f2); assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(*f1.target() == h); assert(*f2.target() == g); } assert(A::count == 0); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); } Index: test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp =================================================================== --- test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp +++ test/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; @@ -49,17 +32,21 @@ std::allocator a; assert(new_called == 0); assert(A_constructed == 0); + last_new_size = 0; A* ap = a.allocate(3); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); + COUNT_NEW_ASSERT(last_new_size == 3 * sizeof(int)); assert(A_constructed == 0); a.deallocate(ap, 3); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(A_constructed == 0); + last_new_size = 0; A* ap2 = a.allocate(3, (const void*)5); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); + COUNT_NEW_ASSERT(last_new_size == 3 * sizeof(int)); assert(A_constructed == 0); a.deallocate(ap2, 3); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(A_constructed == 0); } Index: test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp =================================================================== --- test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp +++ test/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); + COUNT_NEW_ASSERT(new_called == 0); assert(A_constructed == 0); + last_new_size = 0; A* ap = a.allocate(3); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); + COUNT_NEW_ASSERT(last_new_size == 3 * sizeof(int)); assert(A_constructed == 0); a.construct(ap); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(A_constructed == 1); a.destroy(ap); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(A_constructed == 0); a.construct(ap, A()); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(A_constructed == 1); a.destroy(ap); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(A_constructed == 0); a.construct(ap, 5); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(A_constructed == 1); a.destroy(ap); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(A_constructed == 0); a.construct(ap, 5, (int*)0); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(A_constructed == 1); a.destroy(ap); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(A_constructed == 0); a.deallocate(ap, 3); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(A_constructed == 0); } { std::allocator a; - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(move_only_constructed == 0); + last_new_size = 0; move_only* ap = a.allocate(3); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); + COUNT_NEW_ASSERT(last_new_size == 3 * sizeof(int)); assert(move_only_constructed == 0); a.construct(ap); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(move_only_constructed == 1); a.destroy(ap); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(move_only_constructed == 0); a.construct(ap, move_only()); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(move_only_constructed == 1); a.destroy(ap); - assert(new_called == 1); + COUNT_NEW_ASSERT(new_called == 1); assert(move_only_constructed == 0); a.deallocate(ap, 3); - assert(new_called == 0); + COUNT_NEW_ASSERT(new_called == 0); assert(move_only_constructed == 0); } } Index: test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp =================================================================== --- test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp +++ test/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 = new_called; { int i = 67; char c = 'e'; std::shared_ptr p = std::make_shared(i, c); - assert(new_count == nc+1); + COUNT_NEW_ASSERT(new_called == 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 = new_called; { char c = 'e'; std::shared_ptr p = std::make_shared(67, c); - assert(new_count == nc+1); + COUNT_NEW_ASSERT(new_called == nc+1); assert(A::count == 1); assert(p->get_int() == 67); assert(p->get_char() == 'e');