From: Marshall Clow Date: Wed, 24 Apr 2019 12:11:12 +0000 (+0000) Subject: Add an any_cast test for array types. Thanks to Jonathan Wakely for the suggestion. X-Git-Tag: llvmorg-10-init~7138 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c564c16308896bdcd5cc84d75eeb3accf287463e;p=platform%2Fupstream%2Fllvm.git Add an any_cast test for array types. Thanks to Jonathan Wakely for the suggestion. llvm-svn: 359085 --- 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 bb9089c..bf7ea92 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 #include + +#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 58f58af..d2cf586 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 #include +#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(&a)), ""); + ASSERT_NOEXCEPT(any_cast(&a)); any const& ca = a; - static_assert(noexcept(any_cast(&ca)), ""); + ASSERT_NOEXCEPT(any_cast(&ca)); } // Test that the return type of any_cast is correct. void test_cast_return_type() { any a; - static_assert(std::is_same(&a)), int*>::value, ""); - static_assert(std::is_same(&a)), int const*>::value, ""); + ASSERT_SAME_TYPE(decltype(any_cast(&a)), int*); + ASSERT_SAME_TYPE(decltype(any_cast(&a)), int const*); any const& ca = a; - static_assert(std::is_same(&ca)), int const*>::value, ""); - static_assert(std::is_same(&ca)), int const*>::value, ""); + ASSERT_SAME_TYPE(decltype(any_cast(&ca)), int const*); + ASSERT_SAME_TYPE(decltype(any_cast(&ca)), int const*); } // Test that any_cast handles null pointers. @@ -148,6 +149,15 @@ void test_cast_non_copyable_type() assert(std::any_cast(&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(&a); + assert(p == nullptr); +} + void test_fn() {} void test_cast_function_pointer() { @@ -168,6 +178,7 @@ int main(int, char**) { test_cast(); test_cast(); test_cast_non_copyable_type(); + test_cast_array(); test_cast_function_pointer(); return 0;