diff options
-rw-r--r-- | libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp | 10 | ||||
-rw-r--r-- | libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp | 23 |
2 files changed, 25 insertions, 8 deletions
diff --git a/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp index bb9089cd83e..bf7ea92eb90 100644 --- a/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp +++ b/libcxx/test/std/utilities/any/any.class/any.observers/type.pass.cpp @@ -16,6 +16,8 @@ #include <any> #include <cassert> + +#include "test_macros.h" #include "any_helpers.h" int main(int, char**) @@ -24,19 +26,23 @@ int main(int, char**) { any const a; assert(a.type() == typeid(void)); - static_assert(noexcept(a.type()), "any::type() must be noexcept"); + ASSERT_NOEXCEPT(a.type()); } { small const s(1); any const a(s); assert(a.type() == typeid(small)); - } { large const l(1); any const a(l); assert(a.type() == typeid(large)); } + { + int arr[3]; + any const a(arr); + assert(a.type() == typeid(int*)); // ensure that it is decayed + } return 0; } diff --git a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp index 58f58afa99c..d2cf58696f8 100644 --- a/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp +++ b/libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp @@ -22,6 +22,7 @@ #include <type_traits> #include <cassert> +#include "test_macros.h" #include "any_helpers.h" using std::any; @@ -30,21 +31,21 @@ using std::any_cast; // Test that the operators are properly noexcept. void test_cast_is_noexcept() { any a; - static_assert(noexcept(any_cast<int>(&a)), ""); + ASSERT_NOEXCEPT(any_cast<int>(&a)); any const& ca = a; - static_assert(noexcept(any_cast<int>(&ca)), ""); + ASSERT_NOEXCEPT(any_cast<int>(&ca)); } // Test that the return type of any_cast is correct. void test_cast_return_type() { any a; - static_assert(std::is_same<decltype(any_cast<int>(&a)), int*>::value, ""); - static_assert(std::is_same<decltype(any_cast<int const>(&a)), int const*>::value, ""); + ASSERT_SAME_TYPE(decltype(any_cast<int>(&a)), int*); + ASSERT_SAME_TYPE(decltype(any_cast<int const>(&a)), int const*); any const& ca = a; - static_assert(std::is_same<decltype(any_cast<int>(&ca)), int const*>::value, ""); - static_assert(std::is_same<decltype(any_cast<int const>(&ca)), int const*>::value, ""); + ASSERT_SAME_TYPE(decltype(any_cast<int>(&ca)), int const*); + ASSERT_SAME_TYPE(decltype(any_cast<int const>(&ca)), int const*); } // Test that any_cast handles null pointers. @@ -148,6 +149,15 @@ void test_cast_non_copyable_type() assert(std::any_cast<NoCopy>(&ca) == nullptr); } +void test_cast_array() { + int arr[3]; + std::any a(arr); + assert(a.type() == typeid(int*)); // contained value is decayed +// We can't get an array out + int (*p)[3] = std::any_cast<int[3]>(&a); + assert(p == nullptr); +} + void test_fn() {} void test_cast_function_pointer() { @@ -168,6 +178,7 @@ int main(int, char**) { test_cast<small>(); test_cast<large>(); test_cast_non_copyable_type(); + test_cast_array(); test_cast_function_pointer(); return 0; |