[libcxx] Consolidate new/delete replacement in tests and disable it when using sanitizers.
Summary: MSAN and ASAN also replace new/delete which leads to a link error in these tests. Currently they are unsupported but I think it would be useful if these tests could run with sanitizers. This patch creates a support header that consolidates the new/delete replacement functionality and checking. When we are using sanitizers new and delete are no longer replaced and the checks always return true. Reviewers: mclow.lists, danalbert, jroelofs, EricWF Reviewed By: EricWF Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6562 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224741 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -13,45 +13,28 @@
|
|||||||
|
|
||||||
// ~ctype();
|
// ~ctype();
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <new>
|
|
||||||
|
|
||||||
unsigned delete_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
delete_called = 0;
|
|
||||||
std::locale l(std::locale::classic(), new std::ctype<char>);
|
std::locale l(std::locale::classic(), new std::ctype<char>);
|
||||||
assert(delete_called == 0);
|
assert(globalMemCounter.checkDeleteArrayCalledEq(0));
|
||||||
}
|
}
|
||||||
assert(delete_called == 0);
|
assert(globalMemCounter.checkDeleteArrayCalledEq(0));
|
||||||
{
|
{
|
||||||
std::ctype<char>::mask table[256];
|
std::ctype<char>::mask table[256];
|
||||||
delete_called = 0;
|
|
||||||
std::locale l(std::locale::classic(), new std::ctype<char>(table));
|
std::locale l(std::locale::classic(), new std::ctype<char>(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(),
|
std::locale l(std::locale::classic(),
|
||||||
new std::ctype<char>(new std::ctype<char>::mask[256], true));
|
new std::ctype<char>(new std::ctype<char>::mask[256], true));
|
||||||
assert(delete_called == 0);
|
assert(globalMemCounter.checkDeleteArrayCalledEq(0));
|
||||||
}
|
}
|
||||||
assert(delete_called == 1);
|
assert(globalMemCounter.checkDeleteArrayCalledEq(1));
|
||||||
}
|
}
|
||||||
|
@@ -17,43 +17,26 @@
|
|||||||
// // unspecified
|
// // unspecified
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
// Not a portable test
|
// Not a portable test
|
||||||
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int outstanding_news = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(outstanding_news == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
typedef std::codecvt_utf16<wchar_t> C;
|
typedef std::codecvt_utf16<wchar_t> C;
|
||||||
C c;
|
C c;
|
||||||
assert(outstanding_news == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
typedef std::codecvt_utf16<wchar_t> C;
|
typedef std::codecvt_utf16<wchar_t> C;
|
||||||
std::locale loc(std::locale::classic(), new 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));
|
||||||
}
|
}
|
||||||
|
@@ -17,43 +17,26 @@
|
|||||||
// // unspecified
|
// // unspecified
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
// Not a portable test
|
// Not a portable test
|
||||||
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int outstanding_news = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(outstanding_news == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
typedef std::codecvt_utf8<wchar_t> C;
|
typedef std::codecvt_utf8<wchar_t> C;
|
||||||
C c;
|
C c;
|
||||||
assert(outstanding_news == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
typedef std::codecvt_utf8<wchar_t> C;
|
typedef std::codecvt_utf8<wchar_t> C;
|
||||||
std::locale loc(std::locale::classic(), new 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));
|
||||||
}
|
}
|
||||||
|
@@ -14,27 +14,12 @@
|
|||||||
// wbuffer_convert(streambuf *bytebuf = 0, Codecvt *pcvt = new Codecvt,
|
// wbuffer_convert(streambuf *bytebuf = 0, Codecvt *pcvt = new Codecvt,
|
||||||
// state_type state = state_type());
|
// state_type state = state_type());
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <new>
|
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@@ -46,28 +31,28 @@ int main()
|
|||||||
{
|
{
|
||||||
B b;
|
B b;
|
||||||
assert(b.rdbuf() == nullptr);
|
assert(b.rdbuf() == nullptr);
|
||||||
assert(new_called != 0);
|
assert(globalMemCounter.checkOutstandingNewNotEq(0));
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
B b(s.rdbuf());
|
B b(s.rdbuf());
|
||||||
assert(b.rdbuf() == 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;
|
std::stringstream s;
|
||||||
B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>);
|
B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>);
|
||||||
assert(b.rdbuf() == 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;
|
std::stringstream s;
|
||||||
B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>, std::mbstate_t());
|
B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>, std::mbstate_t());
|
||||||
assert(b.rdbuf() == s.rdbuf());
|
assert(b.rdbuf() == s.rdbuf());
|
||||||
assert(new_called != 0);
|
assert(globalMemCounter.checkOutstandingNewNotEq(0));
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
}
|
}
|
||||||
|
@@ -11,27 +11,11 @@
|
|||||||
|
|
||||||
// locale() throw();
|
// locale() throw();
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <new>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "platform_support.h" // locale name macros
|
#include "platform_support.h" // locale name macros
|
||||||
|
#include "count_new.hpp"
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void check(const std::locale& loc)
|
void check(const std::locale& loc)
|
||||||
{
|
{
|
||||||
@@ -73,19 +57,19 @@ int main()
|
|||||||
int ok;
|
int ok;
|
||||||
{
|
{
|
||||||
std::locale loc;
|
std::locale loc;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(loc.name() == "C");
|
assert(loc.name() == "C");
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
check(loc);
|
check(loc);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(std::locale::global(std::locale(LOCALE_en_US_UTF_8)) == loc);
|
assert(std::locale::global(std::locale(LOCALE_en_US_UTF_8)) == loc);
|
||||||
ok = new_called;
|
ok = globalMemCounter.outstanding_new;
|
||||||
std::locale loc2;
|
std::locale loc2;
|
||||||
assert(new_called == ok);
|
assert(globalMemCounter.checkOutstandingNewEq(ok));
|
||||||
check(loc2);
|
check(loc2);
|
||||||
assert(new_called == ok);
|
assert(globalMemCounter.checkOutstandingNewEq(ok));
|
||||||
assert(loc2 == std::locale(LOCALE_en_US_UTF_8));
|
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));
|
||||||
}
|
}
|
||||||
|
@@ -11,25 +11,10 @@
|
|||||||
|
|
||||||
// template <class Facet> locale combine(const locale& other) const;
|
// template <class Facet> locale combine(const locale& other) const;
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <new>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void check(const std::locale& loc)
|
void check(const std::locale& loc)
|
||||||
{
|
{
|
||||||
@@ -89,7 +74,7 @@ int main()
|
|||||||
const my_facet& f = std::use_facet<my_facet>(loc3);
|
const my_facet& f = std::use_facet<my_facet>(loc3);
|
||||||
assert(f.test() == 5);
|
assert(f.test() == 5);
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -104,6 +89,6 @@ int main()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,26 +14,12 @@
|
|||||||
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
|
// template <MoveConstructible R, MoveConstructible ... ArgTypes>
|
||||||
// void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
|
// void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
class A
|
class A
|
||||||
{
|
{
|
||||||
@@ -73,65 +59,65 @@ int h(int) {return 1;}
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f1 = A(1);
|
std::function<int(int)> f1 = A(1);
|
||||||
std::function<int(int)> f2 = A(2);
|
std::function<int(int)> f2 = A(2);
|
||||||
assert(A::count == 2);
|
assert(A::count == 2);
|
||||||
assert(new_called == 2);
|
assert(globalMemCounter.checkOutstandingNewEq(2));
|
||||||
assert(f1.target<A>()->id() == 1);
|
assert(f1.target<A>()->id() == 1);
|
||||||
assert(f2.target<A>()->id() == 2);
|
assert(f2.target<A>()->id() == 2);
|
||||||
swap(f1, f2);
|
swap(f1, f2);
|
||||||
assert(A::count == 2);
|
assert(A::count == 2);
|
||||||
assert(new_called == 2);
|
assert(globalMemCounter.checkOutstandingNewEq(2));
|
||||||
assert(f1.target<A>()->id() == 2);
|
assert(f1.target<A>()->id() == 2);
|
||||||
assert(f2.target<A>()->id() == 1);
|
assert(f2.target<A>()->id() == 1);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f1 = A(1);
|
std::function<int(int)> f1 = A(1);
|
||||||
std::function<int(int)> f2 = g;
|
std::function<int(int)> f2 = g;
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f1.target<A>()->id() == 1);
|
assert(f1.target<A>()->id() == 1);
|
||||||
assert(*f2.target<int(*)(int)>() == g);
|
assert(*f2.target<int(*)(int)>() == g);
|
||||||
swap(f1, f2);
|
swap(f1, f2);
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(*f1.target<int(*)(int)>() == g);
|
assert(*f1.target<int(*)(int)>() == g);
|
||||||
assert(f2.target<A>()->id() == 1);
|
assert(f2.target<A>()->id() == 1);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f1 = g;
|
std::function<int(int)> f1 = g;
|
||||||
std::function<int(int)> f2 = A(1);
|
std::function<int(int)> f2 = A(1);
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(*f1.target<int(*)(int)>() == g);
|
assert(*f1.target<int(*)(int)>() == g);
|
||||||
assert(f2.target<A>()->id() == 1);
|
assert(f2.target<A>()->id() == 1);
|
||||||
swap(f1, f2);
|
swap(f1, f2);
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f1.target<A>()->id() == 1);
|
assert(f1.target<A>()->id() == 1);
|
||||||
assert(*f2.target<int(*)(int)>() == g);
|
assert(*f2.target<int(*)(int)>() == g);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f1 = g;
|
std::function<int(int)> f1 = g;
|
||||||
std::function<int(int)> f2 = h;
|
std::function<int(int)> f2 = h;
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(*f1.target<int(*)(int)>() == g);
|
assert(*f1.target<int(*)(int)>() == g);
|
||||||
assert(*f2.target<int(*)(int)>() == h);
|
assert(*f2.target<int(*)(int)>() == h);
|
||||||
swap(f1, f2);
|
swap(f1, f2);
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(*f1.target<int(*)(int)>() == h);
|
assert(*f1.target<int(*)(int)>() == h);
|
||||||
assert(*f2.target<int(*)(int)>() == g);
|
assert(*f2.target<int(*)(int)>() == g);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
}
|
}
|
||||||
|
@@ -13,26 +13,10 @@
|
|||||||
|
|
||||||
// function(nullptr_t);
|
// function(nullptr_t);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
class A
|
class A
|
||||||
{
|
{
|
||||||
@@ -67,34 +51,34 @@ int g(int) {return 0;}
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = A();
|
std::function<int(int)> f = A();
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f.target<A>());
|
assert(f.target<A>());
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = g;
|
std::function<int(int)> f = g;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>());
|
assert(f.target<int(*)(int)>());
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = (int (*)(int))0;
|
std::function<int(int)> f = (int (*)(int))0;
|
||||||
assert(!f);
|
assert(!f);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::function<int(const A*, int)> f = &A::foo;
|
std::function<int(const A*, int)> f = &A::foo;
|
||||||
assert(f);
|
assert(f);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int (A::*)(int) const>() != 0);
|
assert(f.target<int (A::*)(int) const>() != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,26 +16,10 @@
|
|||||||
// && Convertible<Callable<F, ArgTypes...>::result_type
|
// && Convertible<Callable<F, ArgTypes...>::result_type
|
||||||
// operator=(F f);
|
// operator=(F f);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
class A
|
class A
|
||||||
{
|
{
|
||||||
@@ -70,30 +54,30 @@ int g(int) {return 0;}
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f;
|
std::function<int(int)> f;
|
||||||
f = A();
|
f = A();
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f.target<A>());
|
assert(f.target<A>());
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f;
|
std::function<int(int)> f;
|
||||||
f = g;
|
f = g;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>());
|
assert(f.target<int(*)(int)>());
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f;
|
std::function<int(int)> f;
|
||||||
f = (int (*)(int))0;
|
f = (int (*)(int))0;
|
||||||
assert(!f);
|
assert(!f);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
}
|
}
|
||||||
@@ -101,7 +85,7 @@ int main()
|
|||||||
std::function<int(const A*, int)> f;
|
std::function<int(const A*, int)> f;
|
||||||
f = &A::foo;
|
f = &A::foo;
|
||||||
assert(f);
|
assert(f);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int (A::*)(int) const>() != 0);
|
assert(f.target<int (A::*)(int) const>() != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,28 +13,12 @@
|
|||||||
|
|
||||||
// template<class A> function(allocator_arg_t, const A&, const function&);
|
// template<class A> function(allocator_arg_t, const A&, const function&);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "test_allocator.h"
|
#include "test_allocator.h"
|
||||||
|
#include "count_new.hpp"
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
class A
|
class A
|
||||||
{
|
{
|
||||||
@@ -67,48 +51,48 @@ int g(int) {return 0;}
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = A();
|
std::function<int(int)> f = A();
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f.target<A>());
|
assert(f.target<A>());
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), f);
|
std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), f);
|
||||||
assert(A::count == 2);
|
assert(A::count == 2);
|
||||||
assert(new_called == 2);
|
assert(globalMemCounter.checkOutstandingNewEq(2));
|
||||||
assert(f2.target<A>());
|
assert(f2.target<A>());
|
||||||
assert(f2.target<int(*)(int)>() == 0);
|
assert(f2.target<int(*)(int)>() == 0);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = g;
|
std::function<int(int)> f = g;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>());
|
assert(f.target<int(*)(int)>());
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
std::function<int(int)> f2(std::allocator_arg, test_allocator<int(*)(int)>(), f);
|
std::function<int(int)> f2(std::allocator_arg, test_allocator<int(*)(int)>(), f);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f2.target<int(*)(int)>());
|
assert(f2.target<int(*)(int)>());
|
||||||
assert(f2.target<A>() == 0);
|
assert(f2.target<A>() == 0);
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
non_default_test_allocator<std::function<int(int)>> al(1);
|
non_default_test_allocator<std::function<int(int)>> al(1);
|
||||||
std::function<int(int)> f2(std::allocator_arg, al, g);
|
std::function<int(int)> f2(std::allocator_arg, al, g);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f2.target<int(*)(int)>());
|
assert(f2.target<int(*)(int)>());
|
||||||
assert(f2.target<A>() == 0);
|
assert(f2.target<A>() == 0);
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f;
|
std::function<int(int)> f;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
std::function<int(int)> f2(std::allocator_arg, test_allocator<int>(), f);
|
std::function<int(int)> f2(std::allocator_arg, test_allocator<int>(), f);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f2.target<int(*)(int)>() == 0);
|
assert(f2.target<int(*)(int)>() == 0);
|
||||||
assert(f2.target<A>() == 0);
|
assert(f2.target<A>() == 0);
|
||||||
}
|
}
|
||||||
|
@@ -13,26 +13,11 @@
|
|||||||
|
|
||||||
// template<class A> function(allocator_arg_t, const A&, function&&);
|
// template<class A> function(allocator_arg_t, const A&, function&&);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "test_allocator.h"
|
#include "test_allocator.h"
|
||||||
|
#include "count_new.hpp"
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
class A
|
class A
|
||||||
{
|
{
|
||||||
@@ -64,16 +49,16 @@ int A::count = 0;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = A();
|
std::function<int(int)> f = A();
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f.target<A>());
|
assert(f.target<A>());
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), std::move(f));
|
std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), std::move(f));
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f2.target<A>());
|
assert(f2.target<A>());
|
||||||
assert(f2.target<int(*)(int)>() == 0);
|
assert(f2.target<int(*)(int)>() == 0);
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
|
@@ -13,26 +13,11 @@
|
|||||||
|
|
||||||
// function(const function& f);
|
// function(const function& f);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
class A
|
class A
|
||||||
{
|
{
|
||||||
@@ -65,65 +50,65 @@ int g(int) {return 0;}
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = A();
|
std::function<int(int)> f = A();
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f.target<A>());
|
assert(f.target<A>());
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
std::function<int(int)> f2 = f;
|
std::function<int(int)> f2 = f;
|
||||||
assert(A::count == 2);
|
assert(A::count == 2);
|
||||||
assert(new_called == 2);
|
assert(globalMemCounter.checkOutstandingNewEq(2));
|
||||||
assert(f2.target<A>());
|
assert(f2.target<A>());
|
||||||
assert(f2.target<int(*)(int)>() == 0);
|
assert(f2.target<int(*)(int)>() == 0);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = g;
|
std::function<int(int)> f = g;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>());
|
assert(f.target<int(*)(int)>());
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
std::function<int(int)> f2 = f;
|
std::function<int(int)> f2 = f;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f2.target<int(*)(int)>());
|
assert(f2.target<int(*)(int)>());
|
||||||
assert(f2.target<A>() == 0);
|
assert(f2.target<A>() == 0);
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f;
|
std::function<int(int)> f;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
std::function<int(int)> f2 = f;
|
std::function<int(int)> f2 = f;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f2.target<int(*)(int)>() == 0);
|
assert(f2.target<int(*)(int)>() == 0);
|
||||||
assert(f2.target<A>() == 0);
|
assert(f2.target<A>() == 0);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::function<int(int)> f;
|
std::function<int(int)> f;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
assert(!f);
|
assert(!f);
|
||||||
std::function<long(int)> g = f;
|
std::function<long(int)> g = f;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(g.target<long(*)(int)>() == 0);
|
assert(g.target<long(*)(int)>() == 0);
|
||||||
assert(g.target<A>() == 0);
|
assert(g.target<A>() == 0);
|
||||||
assert(!g);
|
assert(!g);
|
||||||
}
|
}
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = A();
|
std::function<int(int)> f = A();
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f.target<A>());
|
assert(f.target<A>());
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
std::function<int(int)> f2 = std::move(f);
|
std::function<int(int)> f2 = std::move(f);
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f2.target<A>());
|
assert(f2.target<A>());
|
||||||
assert(f2.target<int(*)(int)>() == 0);
|
assert(f2.target<int(*)(int)>() == 0);
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
|
@@ -13,26 +13,10 @@
|
|||||||
|
|
||||||
// function& operator=(const function& f);
|
// function& operator=(const function& f);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
class A
|
class A
|
||||||
{
|
{
|
||||||
@@ -65,57 +49,57 @@ int g(int) {return 0;}
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = A();
|
std::function<int(int)> f = A();
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f.target<A>());
|
assert(f.target<A>());
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
std::function<int(int)> f2;
|
std::function<int(int)> f2;
|
||||||
f2 = f;
|
f2 = f;
|
||||||
assert(A::count == 2);
|
assert(A::count == 2);
|
||||||
assert(new_called == 2);
|
assert(globalMemCounter.checkOutstandingNewEq(2));
|
||||||
assert(f2.target<A>());
|
assert(f2.target<A>());
|
||||||
assert(f2.target<int(*)(int)>() == 0);
|
assert(f2.target<int(*)(int)>() == 0);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = g;
|
std::function<int(int)> f = g;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>());
|
assert(f.target<int(*)(int)>());
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
std::function<int(int)> f2;
|
std::function<int(int)> f2;
|
||||||
f2 = f;
|
f2 = f;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f2.target<int(*)(int)>());
|
assert(f2.target<int(*)(int)>());
|
||||||
assert(f2.target<A>() == 0);
|
assert(f2.target<A>() == 0);
|
||||||
}
|
}
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f;
|
std::function<int(int)> f;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
std::function<int(int)> f2;
|
std::function<int(int)> f2;
|
||||||
f2 = f;
|
f2 = f;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f2.target<int(*)(int)>() == 0);
|
assert(f2.target<int(*)(int)>() == 0);
|
||||||
assert(f2.target<A>() == 0);
|
assert(f2.target<A>() == 0);
|
||||||
}
|
}
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = A();
|
std::function<int(int)> f = A();
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f.target<A>());
|
assert(f.target<A>());
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
std::function<int(int)> f2;
|
std::function<int(int)> f2;
|
||||||
f2 = std::move(f);
|
f2 = std::move(f);
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f2.target<A>());
|
assert(f2.target<A>());
|
||||||
assert(f2.target<int(*)(int)>() == 0);
|
assert(f2.target<int(*)(int)>() == 0);
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
|
@@ -13,26 +13,10 @@
|
|||||||
|
|
||||||
// function& operator=(nullptr_t);
|
// function& operator=(nullptr_t);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
class A
|
class A
|
||||||
{
|
{
|
||||||
@@ -65,24 +49,24 @@ int g(int) {return 0;}
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = A();
|
std::function<int(int)> f = A();
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f.target<A>());
|
assert(f.target<A>());
|
||||||
f = nullptr;
|
f = nullptr;
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::function<int(int)> f = g;
|
std::function<int(int)> f = g;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>());
|
assert(f.target<int(*)(int)>());
|
||||||
assert(f.target<A>() == 0);
|
assert(f.target<A>() == 0);
|
||||||
f = nullptr;
|
f = nullptr;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(f.target<int(*)(int)>() == 0);
|
assert(f.target<int(*)(int)>() == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,26 +13,10 @@
|
|||||||
|
|
||||||
// void swap(function& other);
|
// void swap(function& other);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
class A
|
class A
|
||||||
{
|
{
|
||||||
@@ -72,65 +56,65 @@ int h(int) {return 1;}
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f1 = A(1);
|
std::function<int(int)> f1 = A(1);
|
||||||
std::function<int(int)> f2 = A(2);
|
std::function<int(int)> f2 = A(2);
|
||||||
assert(A::count == 2);
|
assert(A::count == 2);
|
||||||
assert(new_called == 2);
|
assert(globalMemCounter.checkOutstandingNewEq(2));
|
||||||
assert(f1.target<A>()->id() == 1);
|
assert(f1.target<A>()->id() == 1);
|
||||||
assert(f2.target<A>()->id() == 2);
|
assert(f2.target<A>()->id() == 2);
|
||||||
f1.swap(f2);
|
f1.swap(f2);
|
||||||
assert(A::count == 2);
|
assert(A::count == 2);
|
||||||
assert(new_called == 2);
|
assert(globalMemCounter.checkOutstandingNewEq(2));
|
||||||
assert(f1.target<A>()->id() == 2);
|
assert(f1.target<A>()->id() == 2);
|
||||||
assert(f2.target<A>()->id() == 1);
|
assert(f2.target<A>()->id() == 1);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f1 = A(1);
|
std::function<int(int)> f1 = A(1);
|
||||||
std::function<int(int)> f2 = g;
|
std::function<int(int)> f2 = g;
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f1.target<A>()->id() == 1);
|
assert(f1.target<A>()->id() == 1);
|
||||||
assert(*f2.target<int(*)(int)>() == g);
|
assert(*f2.target<int(*)(int)>() == g);
|
||||||
f1.swap(f2);
|
f1.swap(f2);
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(*f1.target<int(*)(int)>() == g);
|
assert(*f1.target<int(*)(int)>() == g);
|
||||||
assert(f2.target<A>()->id() == 1);
|
assert(f2.target<A>()->id() == 1);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f1 = g;
|
std::function<int(int)> f1 = g;
|
||||||
std::function<int(int)> f2 = A(1);
|
std::function<int(int)> f2 = A(1);
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(*f1.target<int(*)(int)>() == g);
|
assert(*f1.target<int(*)(int)>() == g);
|
||||||
assert(f2.target<A>()->id() == 1);
|
assert(f2.target<A>()->id() == 1);
|
||||||
f1.swap(f2);
|
f1.swap(f2);
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(f1.target<A>()->id() == 1);
|
assert(f1.target<A>()->id() == 1);
|
||||||
assert(*f2.target<int(*)(int)>() == g);
|
assert(*f2.target<int(*)(int)>() == g);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
{
|
{
|
||||||
std::function<int(int)> f1 = g;
|
std::function<int(int)> f1 = g;
|
||||||
std::function<int(int)> f2 = h;
|
std::function<int(int)> f2 = h;
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(*f1.target<int(*)(int)>() == g);
|
assert(*f1.target<int(*)(int)>() == g);
|
||||||
assert(*f2.target<int(*)(int)>() == h);
|
assert(*f2.target<int(*)(int)>() == h);
|
||||||
f1.swap(f2);
|
f1.swap(f2);
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(*f1.target<int(*)(int)>() == h);
|
assert(*f1.target<int(*)(int)>() == h);
|
||||||
assert(*f2.target<int(*)(int)>() == g);
|
assert(*f2.target<int(*)(int)>() == g);
|
||||||
}
|
}
|
||||||
assert(A::count == 0);
|
assert(A::count == 0);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
}
|
}
|
||||||
|
@@ -12,27 +12,10 @@
|
|||||||
// allocator:
|
// allocator:
|
||||||
// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
|
// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
int A_constructed = 0;
|
int A_constructed = 0;
|
||||||
|
|
||||||
@@ -47,19 +30,23 @@ struct A
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::allocator<A> a;
|
std::allocator<A> a;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
|
globalMemCounter.last_new_size = 0;
|
||||||
A* ap = a.allocate(3);
|
A* ap = a.allocate(3);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
|
assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
a.deallocate(ap, 3);
|
a.deallocate(ap, 3);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
|
|
||||||
|
globalMemCounter.last_new_size = 0;
|
||||||
A* ap2 = a.allocate(3, (const void*)5);
|
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);
|
assert(A_constructed == 0);
|
||||||
a.deallocate(ap2, 3);
|
a.deallocate(ap2, 3);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
}
|
}
|
||||||
|
@@ -12,27 +12,10 @@
|
|||||||
// allocator:
|
// allocator:
|
||||||
// template <class... Args> void construct(pointer p, Args&&... args);
|
// template <class... Args> void construct(pointer p, Args&&... args);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_called = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
int A_constructed = 0;
|
int A_constructed = 0;
|
||||||
|
|
||||||
@@ -80,76 +63,80 @@ int main()
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::allocator<A> a;
|
std::allocator<A> a;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
|
|
||||||
|
globalMemCounter.last_new_size = 0;
|
||||||
A* ap = a.allocate(3);
|
A* ap = a.allocate(3);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
|
assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
|
|
||||||
a.construct(ap);
|
a.construct(ap);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(A_constructed == 1);
|
assert(A_constructed == 1);
|
||||||
|
|
||||||
a.destroy(ap);
|
a.destroy(ap);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
|
|
||||||
a.construct(ap, A());
|
a.construct(ap, A());
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(A_constructed == 1);
|
assert(A_constructed == 1);
|
||||||
|
|
||||||
a.destroy(ap);
|
a.destroy(ap);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
|
|
||||||
a.construct(ap, 5);
|
a.construct(ap, 5);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(A_constructed == 1);
|
assert(A_constructed == 1);
|
||||||
|
|
||||||
a.destroy(ap);
|
a.destroy(ap);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
|
|
||||||
a.construct(ap, 5, (int*)0);
|
a.construct(ap, 5, (int*)0);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(A_constructed == 1);
|
assert(A_constructed == 1);
|
||||||
|
|
||||||
a.destroy(ap);
|
a.destroy(ap);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
|
|
||||||
a.deallocate(ap, 3);
|
a.deallocate(ap, 3);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(A_constructed == 0);
|
assert(A_constructed == 0);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::allocator<move_only> a;
|
std::allocator<move_only> a;
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(move_only_constructed == 0);
|
assert(move_only_constructed == 0);
|
||||||
|
|
||||||
|
globalMemCounter.last_new_size = 0;
|
||||||
move_only* ap = a.allocate(3);
|
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);
|
assert(move_only_constructed == 0);
|
||||||
|
|
||||||
a.construct(ap);
|
a.construct(ap);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(move_only_constructed == 1);
|
assert(move_only_constructed == 1);
|
||||||
|
|
||||||
a.destroy(ap);
|
a.destroy(ap);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(move_only_constructed == 0);
|
assert(move_only_constructed == 0);
|
||||||
|
|
||||||
a.construct(ap, move_only());
|
a.construct(ap, move_only());
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(move_only_constructed == 1);
|
assert(move_only_constructed == 1);
|
||||||
|
|
||||||
a.destroy(ap);
|
a.destroy(ap);
|
||||||
assert(new_called == 1);
|
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||||
assert(move_only_constructed == 0);
|
assert(move_only_constructed == 0);
|
||||||
|
|
||||||
a.deallocate(ap, 3);
|
a.deallocate(ap, 3);
|
||||||
assert(new_called == 0);
|
assert(globalMemCounter.checkOutstandingNewEq(0));
|
||||||
assert(move_only_constructed == 0);
|
assert(move_only_constructed == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,25 +13,10 @@
|
|||||||
|
|
||||||
// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
|
// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
|
||||||
|
|
||||||
// UNSUPPORTED: asan, msan
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <new>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int new_count = 0;
|
#include "count_new.hpp"
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct A
|
struct A
|
||||||
{
|
{
|
||||||
@@ -54,22 +39,22 @@ int A::count = 0;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int nc = new_count;
|
int nc = globalMemCounter.outstanding_new;
|
||||||
{
|
{
|
||||||
int i = 67;
|
int i = 67;
|
||||||
char c = 'e';
|
char c = 'e';
|
||||||
std::shared_ptr<A> p = std::make_shared<A>(i, c);
|
std::shared_ptr<A> p = std::make_shared<A>(i, c);
|
||||||
assert(new_count == nc+1);
|
assert(globalMemCounter.checkOutstandingNewEq(nc+1));
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(p->get_int() == 67);
|
assert(p->get_int() == 67);
|
||||||
assert(p->get_char() == 'e');
|
assert(p->get_char() == 'e');
|
||||||
}
|
}
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
nc = new_count;
|
nc = globalMemCounter.outstanding_new;
|
||||||
{
|
{
|
||||||
char c = 'e';
|
char c = 'e';
|
||||||
std::shared_ptr<A> p = std::make_shared<A>(67, c);
|
std::shared_ptr<A> p = std::make_shared<A>(67, c);
|
||||||
assert(new_count == nc+1);
|
assert(globalMemCounter.checkOutstandingNewEq(nc+1));
|
||||||
assert(A::count == 1);
|
assert(A::count == 1);
|
||||||
assert(p->get_int() == 67);
|
assert(p->get_int() == 67);
|
||||||
assert(p->get_char() == 'e');
|
assert(p->get_char() == 'e');
|
||||||
|
201
test/support/count_new.hpp
Normal file
201
test/support/count_new.hpp
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
#ifndef COUNT_NEW_HPP
|
||||||
|
#define COUNT_NEW_HPP
|
||||||
|
|
||||||
|
# include <cstdlib>
|
||||||
|
# include <cassert>
|
||||||
|
# include <new>
|
||||||
|
|
||||||
|
#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 */
|
Reference in New Issue
Block a user