Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ int main(int, char**)
std::function<int(int)> f = A();
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f.target<A>());
assert(f.target<int (*)(int)>() == 0);
RTTI_ASSERT(f.target<A>());
RTTI_ASSERT(f.target<int (*)(int)>() == 0);
std::function<int(int)> f2(std::allocator_arg, bare_allocator<A>(),
std::move(f));
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f2.target<A>());
assert(f2.target<int (*)(int)>() == 0);
assert(f.target<A>() == 0);
assert(f.target<int (*)(int)>() == 0);
RTTI_ASSERT(f2.target<A>());
RTTI_ASSERT(f2.target<int (*)(int)>() == 0);
RTTI_ASSERT(f.target<A>() == 0);
RTTI_ASSERT(f.target<int (*)(int)>() == 0);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
{
Expand All @@ -83,14 +83,14 @@ int main(int, char**)
Ref aref(a);
std::function<int(int)> f(aref);
assert(A::count == 1);
assert(f.target<A>() == nullptr);
assert(f.target<Ref>());
RTTI_ASSERT(f.target<A>() == nullptr);
RTTI_ASSERT(f.target<Ref>());
std::function<int(int)> f2(std::allocator_arg, std::allocator<int>{},
std::move(f));
assert(A::count == 1);
assert(f2.target<A>() == nullptr);
assert(f2.target<Ref>());
assert(f.target<Ref>()); // f is unchanged because the target is small
RTTI_ASSERT(f2.target<A>() == nullptr);
RTTI_ASSERT(f2.target<Ref>());
RTTI_ASSERT(f.target<Ref>()); // f is unchanged because the target is small
}
{
// Test that moving a function constructed from a function pointer
Expand All @@ -99,13 +99,13 @@ int main(int, char**)
using Ptr = int(*)(int);
Ptr p = g;
std::function<int(int)> f(p);
assert(f.target<A>() == nullptr);
assert(f.target<Ptr>());
RTTI_ASSERT(f.target<A>() == nullptr);
RTTI_ASSERT(f.target<Ptr>());
std::function<int(int)> f2(std::allocator_arg, std::allocator<int>(),
std::move(f));
assert(f2.target<A>() == nullptr);
assert(f2.target<Ptr>());
assert(f.target<Ptr>()); // f is unchanged because the target is small
RTTI_ASSERT(f2.target<A>() == nullptr);
RTTI_ASSERT(f2.target<Ptr>());
RTTI_ASSERT(f.target<Ptr>()); // f is unchanged because the target is small
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,84 +58,84 @@ int main(int, char**) {
std::function<int(int)> f = A();
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f.target<A>());
assert(f.target<int (*)(int)>() == 0);
RTTI_ASSERT(f.target<A>());
RTTI_ASSERT(f.target<int (*)(int)>() == 0);
std::function<int(int)> f2;
f2 = f;
assert(A::count == 2);
assert(globalMemCounter.checkOutstandingNewEq(2));
assert(f2.target<A>());
assert(f2.target<int (*)(int)>() == 0);
RTTI_ASSERT(f2.target<A>());
RTTI_ASSERT(f2.target<int (*)(int)>() == 0);
}
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f = g;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<int (*)(int)>());
assert(f.target<A>() == 0);
RTTI_ASSERT(f.target<int (*)(int)>());
RTTI_ASSERT(f.target<A>() == 0);
std::function<int(int)> f2;
f2 = f;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f2.target<int (*)(int)>());
assert(f2.target<A>() == 0);
RTTI_ASSERT(f2.target<int (*)(int)>());
RTTI_ASSERT(f2.target<A>() == 0);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<int (*)(int)>() == 0);
assert(f.target<A>() == 0);
RTTI_ASSERT(f.target<int (*)(int)>() == 0);
RTTI_ASSERT(f.target<A>() == 0);
std::function<int(int)> f2;
f2 = f;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f2.target<int (*)(int)>() == 0);
assert(f2.target<A>() == 0);
RTTI_ASSERT(f2.target<int (*)(int)>() == 0);
RTTI_ASSERT(f2.target<A>() == 0);
}
{
typedef std::function<int()> Func;
Func f = g0;
Func& fr = (f = (Func &)f);
assert(&fr == &f);
assert(*f.target<int(*)()>() == g0);
RTTI_ASSERT(*f.target<int(*)()>() == g0);
}
{
typedef std::function<int(int)> Func;
Func f = g;
Func& fr = (f = (Func &)f);
assert(&fr == &f);
assert(*f.target<int(*)(int)>() == g);
RTTI_ASSERT(*f.target<int(*)(int)>() == g);
}
{
typedef std::function<int(int, int)> Func;
Func f = g2;
Func& fr = (f = (Func &)f);
assert(&fr == &f);
assert(*f.target<int(*)(int, int)>() == g2);
RTTI_ASSERT(*f.target<int(*)(int, int)>() == g2);
}
{
typedef std::function<int(int, int, int)> Func;
Func f = g3;
Func& fr = (f = (Func &)f);
assert(&fr == &f);
assert(*f.target<int(*)(int, int, int)>() == g3);
RTTI_ASSERT(*f.target<int(*)(int, int, int)>() == g3);
}
#if TEST_STD_VER >= 11
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f = A();
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f.target<A>());
assert(f.target<int (*)(int)>() == 0);
RTTI_ASSERT(f.target<A>());
RTTI_ASSERT(f.target<int (*)(int)>() == 0);
std::function<int(int)> f2;
f2 = std::move(f);
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f2.target<A>());
assert(f2.target<int (*)(int)>() == 0);
assert(f.target<A>() == 0);
assert(f.target<int (*)(int)>() == 0);
RTTI_ASSERT(f2.target<A>());
RTTI_ASSERT(f2.target<int (*)(int)>() == 0);
RTTI_ASSERT(f.target<A>() == 0);
RTTI_ASSERT(f.target<int (*)(int)>() == 0);
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,47 +61,47 @@ int main(int, char**)
std::function<int(int)> f = A();
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
RTTI_ASSERT(f.target<A>());
RTTI_ASSERT(f.target<int(*)(int)>() == 0);
std::function<int(int)> f2 = f;
assert(A::count == 2);
assert(globalMemCounter.checkOutstandingNewEq(2));
assert(f2.target<A>());
assert(f2.target<int(*)(int)>() == 0);
RTTI_ASSERT(f2.target<A>());
RTTI_ASSERT(f2.target<int(*)(int)>() == 0);
}
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f = g;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
RTTI_ASSERT(f.target<int(*)(int)>());
RTTI_ASSERT(f.target<A>() == 0);
std::function<int(int)> f2 = f;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f2.target<int(*)(int)>());
assert(f2.target<A>() == 0);
RTTI_ASSERT(f2.target<int(*)(int)>());
RTTI_ASSERT(f2.target<A>() == 0);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int)> f;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
RTTI_ASSERT(f.target<int(*)(int)>() == 0);
RTTI_ASSERT(f.target<A>() == 0);
std::function<int(int)> f2 = f;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f2.target<int(*)(int)>() == 0);
assert(f2.target<A>() == 0);
RTTI_ASSERT(f2.target<int(*)(int)>() == 0);
RTTI_ASSERT(f2.target<A>() == 0);
}
{
std::function<int(int)> f;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
RTTI_ASSERT(f.target<int(*)(int)>() == 0);
RTTI_ASSERT(f.target<A>() == 0);
assert(!f);
std::function<long(int)> g = f;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(g.target<long(*)(int)>() == 0);
assert(g.target<A>() == 0);
RTTI_ASSERT(g.target<long(*)(int)>() == 0);
RTTI_ASSERT(g.target<A>() == 0);
assert(!g);
}
#if TEST_STD_VER >= 11
Expand All @@ -110,19 +110,19 @@ int main(int, char**)
std::function<int(int)> f = A();
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
RTTI_ASSERT(f.target<A>());
RTTI_ASSERT(f.target<int(*)(int)>() == 0);
LIBCPP_ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f)));
#if TEST_STD_VER > 17
ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f)));
#endif
std::function<int(int)> f2 = std::move(f);
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f2.target<A>());
assert(f2.target<int(*)(int)>() == 0);
assert(f.target<A>() == 0);
assert(f.target<int(*)(int)>() == 0);
RTTI_ASSERT(f2.target<A>());
RTTI_ASSERT(f2.target<int(*)(int)>() == 0);
RTTI_ASSERT(f.target<A>() == 0);
RTTI_ASSERT(f.target<int(*)(int)>() == 0);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
{
Expand All @@ -134,17 +134,19 @@ int main(int, char**)
Ref aref(a);
std::function<int(int)> f(aref);
assert(A::count == 1);
assert(f.target<A>() == nullptr);
assert(f.target<Ref>());
RTTI_ASSERT(f.target<A>() == nullptr);
RTTI_ASSERT(f.target<Ref>());
LIBCPP_ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f)));
#if TEST_STD_VER > 17
ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f)));
#endif
std::function<int(int)> f2(std::move(f));
assert(A::count == 1);
assert(f2.target<A>() == nullptr);
assert(f2.target<Ref>());
LIBCPP_ASSERT(f.target<Ref>()); // f is unchanged because the target is small
RTTI_ASSERT(f2.target<A>() == nullptr);
RTTI_ASSERT(f2.target<Ref>());
#if defined(_LIBCPP_VERSION)
RTTI_ASSERT(f.target<Ref>()); // f is unchanged because the target is small
#endif
}
{
// Test that moving a function constructed from a function pointer
Expand All @@ -153,16 +155,18 @@ int main(int, char**)
using Ptr = int(*)(int);
Ptr p = g;
std::function<int(int)> f(p);
assert(f.target<A>() == nullptr);
assert(f.target<Ptr>());
RTTI_ASSERT(f.target<A>() == nullptr);
RTTI_ASSERT(f.target<Ptr>());
LIBCPP_ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f)));
#if TEST_STD_VER > 17
ASSERT_NOEXCEPT(std::function<int(int)>(std::move(f)));
#endif
std::function<int(int)> f2(std::move(f));
assert(f2.target<A>() == nullptr);
assert(f2.target<Ptr>());
LIBCPP_ASSERT(f.target<Ptr>()); // f is unchanged because the target is small
RTTI_ASSERT(f2.target<A>() == nullptr);
RTTI_ASSERT(f2.target<Ptr>());
#if defined(_LIBCPP_VERSION)
RTTI_ASSERT(f.target<Ptr>()); // f is unchanged because the target is small
#endif
}
#endif // TEST_STD_VER >= 11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ int main(int, char**)
std::function<int(int)> f = A();
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f.target<A>());
RTTI_ASSERT(f.target<A>());
f = nullptr;
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<A>() == 0);
RTTI_ASSERT(f.target<A>() == 0);
}
{
std::function<int(int)> f = g;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
RTTI_ASSERT(f.target<int(*)(int)>());
RTTI_ASSERT(f.target<A>() == 0);
f = nullptr;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<int(*)(int)>() == 0);
RTTI_ASSERT(f.target<int(*)(int)>() == 0);
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ int main(int, char**) {
std::function<int(int)> f2 = A(2);
assert(A::count == 2);
assert(globalMemCounter.checkOutstandingNewEq(2));
assert(f1.target<A>()->id() == 1);
assert(f2.target<A>()->id() == 2);
RTTI_ASSERT(f1.target<A>()->id() == 1);
RTTI_ASSERT(f2.target<A>()->id() == 2);
f1.swap(f2);
assert(A::count == 2);
assert(globalMemCounter.checkOutstandingNewEq(2));
assert(f1.target<A>()->id() == 2);
assert(f2.target<A>()->id() == 1);
RTTI_ASSERT(f1.target<A>()->id() == 2);
RTTI_ASSERT(f2.target<A>()->id() == 1);
}
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
Expand All @@ -85,13 +85,13 @@ int main(int, char**) {
std::function<int(int)> f2 = g;
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f1.target<A>()->id() == 1);
assert(*f2.target<int (*)(int)>() == g);
RTTI_ASSERT(f1.target<A>()->id() == 1);
RTTI_ASSERT(*f2.target<int (*)(int)>() == g);
f1.swap(f2);
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(*f1.target<int (*)(int)>() == g);
assert(f2.target<A>()->id() == 1);
RTTI_ASSERT(*f1.target<int (*)(int)>() == g);
RTTI_ASSERT(f2.target<A>()->id() == 1);
}
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
Expand All @@ -100,13 +100,13 @@ int main(int, char**) {
std::function<int(int)> f2 = A(1);
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(*f1.target<int (*)(int)>() == g);
assert(f2.target<A>()->id() == 1);
RTTI_ASSERT(*f1.target<int (*)(int)>() == g);
RTTI_ASSERT(f2.target<A>()->id() == 1);
f1.swap(f2);
assert(A::count == 1);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(f1.target<A>()->id() == 1);
assert(*f2.target<int (*)(int)>() == g);
RTTI_ASSERT(f1.target<A>()->id() == 1);
RTTI_ASSERT(*f2.target<int (*)(int)>() == g);
}
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
Expand All @@ -115,13 +115,13 @@ int main(int, char**) {
std::function<int(int)> f2 = h;
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(*f1.target<int (*)(int)>() == g);
assert(*f2.target<int (*)(int)>() == h);
RTTI_ASSERT(*f1.target<int (*)(int)>() == g);
RTTI_ASSERT(*f2.target<int (*)(int)>() == h);
f1.swap(f2);
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(*f1.target<int (*)(int)>() == h);
assert(*f2.target<int (*)(int)>() == g);
RTTI_ASSERT(*f1.target<int (*)(int)>() == h);
RTTI_ASSERT(*f2.target<int (*)(int)>() == g);
}
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
Expand All @@ -134,7 +134,7 @@ int main(int, char**) {
f1.swap(f1);
}
assert(A::count == 1);
assert(f1.target<A>()->id() == 1);
RTTI_ASSERT(f1.target<A>()->id() == 1);
}
assert(A::count == 0);
assert(globalMemCounter.checkOutstandingNewEq(0));
Expand All @@ -143,23 +143,23 @@ int main(int, char**) {
DisableAllocationGuard guard;
((void)guard);
f1.swap(f1);
assert(*f1.target<int (*)()>() == g0);
RTTI_ASSERT(*f1.target<int (*)()>() == g0);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int, int)> f1 = g2;
DisableAllocationGuard guard;
((void)guard);
f1.swap(f1);
assert(*f1.target<int (*)(int, int)>() == g2);
RTTI_ASSERT(*f1.target<int (*)(int, int)>() == g2);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
{
std::function<int(int, int, int)> f1 = g3;
DisableAllocationGuard guard;
((void)guard);
f1.swap(f1);
assert(*f1.target<int (*)(int, int, int)>() == g3);
RTTI_ASSERT(*f1.target<int (*)(int, int, int)>() == g3);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
{
Expand All @@ -169,7 +169,7 @@ int main(int, char**) {
((void)guard);
f1.swap(f1);
assert(A::count == 1);
assert(f1.target<A>()->id() == 1);
RTTI_ASSERT(f1.target<A>()->id() == 1);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A::count == 0);
Expand All @@ -180,7 +180,7 @@ int main(int, char**) {
((void)guard);
f1.swap(f1);
assert(A::count == 1);
assert(f1.target<A>()->id() == 2);
RTTI_ASSERT(f1.target<A>()->id() == 2);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A::count == 0);
Expand All @@ -191,7 +191,7 @@ int main(int, char**) {
((void)guard);
f1.swap(f1);
assert(A::count == 1);
assert(f1.target<A>()->id() == 3);
RTTI_ASSERT(f1.target<A>()->id() == 3);
}
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A::count == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// This test runs in C++03, but we have deprecated using std::function in C++03.
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS

// UNSUPPORTED: -fno-rtti

#include <functional>
#include <new>
#include <cstdlib>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// This test runs in C++03, but we have deprecated using std::function in C++03.
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS

// UNSUPPORTED: -fno-rtti

#include <functional>
#include <typeinfo>
#include <cassert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// template<class D, class T> D* get_deleter(const shared_ptr<T>& p);

// UNSUPPORTED: -fno-rtti

#include <memory>
#include <cassert>
#include "test_macros.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// template<class T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r);

// UNSUPPORTED: -fno-rtti

#include <memory>
#include <type_traits>
#include <cassert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ int main(int, char**)
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 3);
#endif
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ int main(int, char**)
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 3);
#endif
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
Expand All @@ -55,11 +57,13 @@ int main(int, char**)
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count ==1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 1);
#endif
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
Expand All @@ -72,11 +76,13 @@ int main(int, char**)
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count ==1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 1);
#endif
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ int main(int, char**)
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 3);
#endif
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ int main(int, char**)
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 3);
#endif
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
Expand All @@ -60,11 +62,13 @@ int main(int, char**)
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 3);
#endif
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
Expand All @@ -78,11 +82,13 @@ int main(int, char**)
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 3);
#endif
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ int main(int, char**)
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 3);
#endif
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
Expand All @@ -67,11 +69,13 @@ int main(int, char**)
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 1);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 3);
#endif
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ int main(int, char**)
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
#ifndef TEST_HAS_NO_RTTI
std::get_deleter<test_deleter<A> >(p)
assert(d);
assert(d->state() == 3);
#endif
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
Expand All @@ -72,11 +74,13 @@ int main(int, char**)
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 1);
#ifndef TEST_HAS_NO_RTTI
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(d);
assert(d->state() == 3);
#endif
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ int main(int, char**)
const std::shared_ptr<int> p;
assert(!p);
}
#if !defined(TEST_HAS_NO_RTTI)
{
std::shared_ptr<A> basePtr = std::make_shared<B>();
std::shared_ptr<B> sp = std::dynamic_pointer_cast<B>(basePtr);
assert(sp);
}
#endif

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// size_t operator()(type_index index) const;
// };

// UNSUPPORTED: -fno-rtti

#include <typeindex>
#include <type_traits>
#include <cassert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// type_index(const type_info& rhs);

// UNSUPPORTED: -fno-rtti

#include <typeinfo>
#include <typeindex>
#include <cassert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// bool operator==(const type_index& rhs) const;
// bool operator!=(const type_index& rhs) const;

// UNSUPPORTED: -fno-rtti

#include <typeindex>
#include <cassert>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// size_t hash_code() const;

// UNSUPPORTED: -fno-rtti

#include <typeindex>
#include <cassert>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// bool operator> (const type_index& rhs) const;
// bool operator>=(const type_index& rhs) const;

// UNSUPPORTED: -fno-rtti

#include <typeindex>
#include <cassert>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// const char* name() const;

// UNSUPPORTED: -fno-rtti

#include <typeindex>
#include <string>
#include <cassert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// type_index& operator=(const type_index& ti);

// UNSUPPORTED: -fno-rtti

#include <typeindex>
#include <cassert>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// type_index(const type_index& ti);

// UNSUPPORTED: -fno-rtti

#include <typeindex>
#include <cassert>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// size_t operator()(type_index index) const;
// };

// UNSUPPORTED: -fno-rtti

#include <typeindex>
#include <type_traits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <memory>

#include "test_macros.h"
#include "type_id.h"

template <class Tp, class Up>
constexpr bool check_tag(Up) {
Expand Down
46 changes: 0 additions & 46 deletions libcxx/test/support/demangle.h

This file was deleted.

6 changes: 0 additions & 6 deletions libcxx/test/support/experimental_any_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@

#include "test_macros.h"

#if !defined(TEST_HAS_NO_RTTI)
#define RTTI_ASSERT(X) assert(X)
#else
#define RTTI_ASSERT(X)
#endif

template <class T>
struct IsSmallObject
: public std::integral_constant<bool
Expand Down
40 changes: 0 additions & 40 deletions libcxx/test/support/test.support/test_demangle.pass.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: no-exceptions

// "support/test_macros.hpp"
// Make sure the TEST_HAS_NO_EXCEPTIONS macro is NOT defined when exceptions
// are enabled.

// #define TEST_HAS_NO_EXCEPTIONS
// UNSUPPORTED: no-exceptions

#include "test_macros.h"

#if defined(TEST_HAS_NO_EXCEPTIONS)
#error macro defined unexpectedly
#ifdef TEST_HAS_NO_EXCEPTIONS
# error "TEST_HAS_NO_EXCEPTIONS should NOT be defined"
#endif

int main(int, char**) {
try { ((void)0); } catch (...) {}

return 0;
try { (void)0; } catch (...) { }
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
//
//===----------------------------------------------------------------------===//

// "support/test_macros.hpp"
// Make sure the TEST_HAS_NO_EXCEPTIONS macro is defined when exceptions are
// disabled.

// #define TEST_HAS_NO_EXCEPTIONS
// REQUIRES: no-exceptions

#include "test_macros.h"

int main(int, char**) {
#if defined(TEST_HAS_NO_EXCEPTIONS)
try { ((void)0); } catch (...) {} // expected-error {{exceptions disabled}}
#else
try { ((void)0); } catch (...) {}
#error exceptions enabled
// expected-error@-1 {{exceptions enabled}}
#ifndef TEST_HAS_NO_EXCEPTIONS
# error "TEST_HAS_NO_EXCEPTIONS should be defined"
#endif

return 0;
int main(int, char**) {
try { (void)0; } catch (...) { } // expected-error {{exceptions disabled}}
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,22 @@
//
//===----------------------------------------------------------------------===//

// "support/test_macros.hpp"
// Make sure the TEST_HAS_NO_RTTI macro is defined when the -fno-rtti feature
// is defined.

// #define TEST_HAS_NO_RTTI
// REQUIRES: -fno-rtti

#include "test_macros.h"

struct A { virtual ~A() {} };
struct B : A {};
#ifndef TEST_HAS_NO_RTTI
# error "TEST_HAS_NO_RTTI should be defined"
#endif

struct A { virtual ~A() { } };
struct B : A { };

int main(int, char**) {
#if defined(TEST_HAS_NO_RTTI)
A* ptr = new B;
(void)dynamic_cast<B*>(ptr); // expected-error{{cannot use dynamic_cast}}
#else
A* ptr = new B;
(void)dynamic_cast<B*>(ptr);
#error RTTI enabled
// expected-error@-1{{RTTI enabled}}
#endif

return 0;
(void)dynamic_cast<B*>(ptr); // expected-error{{use of dynamic_cast requires -frtti}}
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: -fno-rtti

// "support/test_macros.hpp"
// Make sure the TEST_HAS_NO_RTTI macro is NOT defined when the -fno-rtti
// feature isn't defined.

// #define TEST_HAS_NO_RTTI
// UNSUPPORTED: -fno-rtti

#include "test_macros.h"

#if defined(TEST_HAS_NO_RTTI)
#error Macro defined unexpectedly
#ifdef TEST_HAS_NO_RTTI
# error "TEST_HAS_NO_RTTI should NOT be defined"
#endif

struct A { virtual ~A() {} };
struct B : A {};
struct A { virtual ~A() { } };
struct B : A { };

int main(int, char**) {
A* ptr = new B;
(void)dynamic_cast<B*>(ptr);
delete ptr;

return 0;
return 0;
}
6 changes: 6 additions & 0 deletions libcxx/test/support/test_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@
#define TEST_HAS_NO_RTTI
#endif

#if !defined(TEST_HAS_NO_RTTI)
# define RTTI_ASSERT(X) assert(X)
#else
# define RTTI_ASSERT(X)
#endif

#if !TEST_HAS_FEATURE(cxx_exceptions) && !defined(__cpp_exceptions) \
&& !defined(__EXCEPTIONS)
#define TEST_HAS_NO_EXCEPTIONS
Expand Down
11 changes: 2 additions & 9 deletions libcxx/test/support/type_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
#define SUPPORT_TYPE_ID_H

#include <functional>
#include <typeinfo>
#include <string>
#include <cstdio>
#include <cassert>

#include "test_macros.h"
#include "demangle.h"

#if TEST_STD_VER < 11
#error This header requires C++11 or greater
Expand All @@ -30,12 +28,7 @@ struct TypeID {
{return LHS.m_id != RHS.m_id; }

std::string name() const {
return demangle(m_id);
}

void dump() const {
std::string s = name();
std::printf("TypeID: %s\n", s.c_str());
return m_id;
}

private:
Expand All @@ -55,7 +48,7 @@ struct TypeID {
#endif // _MSC_VER
template <class T>
inline TypeID const& makeTypeIDImp() {
static const TypeID id(typeid(T).name());
static const TypeID id(__PRETTY_FUNCTION__);
return id;
}
#ifdef _MSC_VER
Expand Down