summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/utilities
diff options
context:
space:
mode:
authorCasey Carter <Casey@Carter.net>2017-04-21 22:38:59 +0000
committerCasey Carter <Casey@Carter.net>2017-04-21 22:38:59 +0000
commitc24d7974bcb9914540f6fcf331e53ae01e90ab05 (patch)
tree75bd48dc227b0573e7b5f7d71aeb6ba3ec467f3d /libcxx/test/std/utilities
parent71c4043ae9769a71e54b2ea7d995a31db24060a5 (diff)
downloadbcm5719-llvm-c24d7974bcb9914540f6fcf331e53ae01e90ab05.tar.gz
bcm5719-llvm-c24d7974bcb9914540f6fcf331e53ae01e90ab05.zip
Expand test coverage for LWG2857
* Cover optional's emplace-from-initializer_list overload * Verify that any::emplace and optional::emplace return a reference to the correct type even for throwing cases. Differential Revision: https://reviews.llvm.org/D32106 llvm-svn: 301055
Diffstat (limited to 'libcxx/test/std/utilities')
-rw-r--r--libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp26
-rw-r--r--libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp4
-rw-r--r--libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp18
3 files changed, 31 insertions, 17 deletions
diff --git a/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp b/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
index 75dfb0a2e70..7ed6121e530 100644
--- a/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
+++ b/libcxx/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
@@ -44,7 +44,7 @@ void test_emplace_type() {
auto &v = a.emplace<Type>();
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
- assert(&v == std::any_cast<Type>(&a));
+ assert(&v == std::any_cast<Type>(&a));
assert(Tracked::count == 0);
assert(Type::count == 1);
@@ -60,7 +60,7 @@ void test_emplace_type() {
auto &v = a.emplace<Type>(101);
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
- assert(&v == std::any_cast<Type>(&a));
+ assert(&v == std::any_cast<Type>(&a));
assert(Tracked::count == 0);
assert(Type::count == 1);
@@ -76,7 +76,7 @@ void test_emplace_type() {
auto &v = a.emplace<Type>(-1, 42, -1);
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
- assert(&v == std::any_cast<Type>(&a));
+ assert(&v == std::any_cast<Type>(&a));
assert(Tracked::count == 0);
assert(Type::count == 1);
@@ -97,7 +97,7 @@ void test_emplace_type_tracked() {
assert(Tracked::count == 1);
auto &v = a.emplace<Type>();
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
- assert(&v == std::any_cast<Type>(&a));
+ assert(&v == std::any_cast<Type>(&a));
assert(Tracked::count == 0);
assertArgsMatch<Type>(a);
@@ -107,7 +107,7 @@ void test_emplace_type_tracked() {
assert(Tracked::count == 1);
auto &v = a.emplace<Type>(-1, 42, -1);
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
- assert(&v == std::any_cast<Type>(&a));
+ assert(&v == std::any_cast<Type>(&a));
assert(Tracked::count == 0);
assertArgsMatch<Type, int, int, int>(a);
@@ -118,7 +118,7 @@ void test_emplace_type_tracked() {
assert(Tracked::count == 1);
auto &v = a.emplace<Type>({-1, 42, -1});
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
- assert(&v == std::any_cast<Type>(&a));
+ assert(&v == std::any_cast<Type>(&a));
assert(Tracked::count == 0);
assertArgsMatch<Type, std::initializer_list<int>>(a);
@@ -129,7 +129,7 @@ void test_emplace_type_tracked() {
assert(Tracked::count == 1);
auto &v = a.emplace<Type>({-1, 42, -1}, x);
static_assert( std::is_same_v<Type&, decltype(v)>, "" );
- assert(&v == std::any_cast<Type>(&a));
+ assert(&v == std::any_cast<Type>(&a));
assert(Tracked::count == 0);
assertArgsMatch<Type, std::initializer_list<int>, int&>(a);
@@ -159,7 +159,8 @@ void test_emplace_throws()
std::any a(small{42});
assert(small::count == 1);
try {
- a.emplace<Type>(101);
+ auto &v = a.emplace<Type>(101);
+ static_assert( std::is_same_v<Type&, decltype(v)>, "" );
assert(false);
} catch (int const&) {
}
@@ -169,7 +170,8 @@ void test_emplace_throws()
std::any a(small{42});
assert(small::count == 1);
try {
- a.emplace<Type>({1, 2, 3}, 101);
+ auto &v = a.emplace<Type>({1, 2, 3}, 101);
+ static_assert( std::is_same_v<Type&, decltype(v)>, "" );
assert(false);
} catch (int const&) {
}
@@ -180,7 +182,8 @@ void test_emplace_throws()
std::any a(large{42});
assert(large::count == 1);
try {
- a.emplace<Type>(101);
+ auto &v = a.emplace<Type>(101);
+ static_assert( std::is_same_v<Type&, decltype(v)>, "" );
assert(false);
} catch (int const&) {
}
@@ -190,7 +193,8 @@ void test_emplace_throws()
std::any a(large{42});
assert(large::count == 1);
try {
- a.emplace<Type>({1, 2, 3}, 101);
+ auto &v = a.emplace<Type>({1, 2, 3}, 101);
+ static_assert( std::is_same_v<Type&, decltype(v)>, "" );
assert(false);
} catch (int const&) {
}
diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
index 0696c11526d..e7f59f1a94c 100644
--- a/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
@@ -254,7 +254,9 @@ int main()
{
assert(static_cast<bool>(opt) == true);
assert(Y::dtor_called == false);
- opt.emplace(1);
+ auto &v = opt.emplace(1);
+ static_assert( std::is_same_v<Y&, decltype(v)>, "" );
+ assert(false);
}
catch (int i)
{
diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
index 1c3c69a7030..f6959c7e9cf 100644
--- a/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
+++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
@@ -11,7 +11,7 @@
// <optional>
// template <class U, class... Args>
-// void optional<T>::emplace(initializer_list<U> il, Args&&... args);
+// T& optional<T>::emplace(initializer_list<U> il, Args&&... args);
#include <optional>
#include <type_traits>
@@ -76,21 +76,27 @@ int main()
X x;
optional<X> opt(x);
assert(X::dtor_called == false);
- opt.emplace({1, 2});
+ auto &v = opt.emplace({1, 2});
+ static_assert( std::is_same_v<X&, decltype(v)>, "" );
assert(X::dtor_called == true);
assert(*opt == X({1, 2}));
+ assert(&v == &*opt);
}
{
optional<std::vector<int>> opt;
- opt.emplace({1, 2, 3}, std::allocator<int>());
+ auto &v = opt.emplace({1, 2, 3}, std::allocator<int>());
+ static_assert( std::is_same_v<std::vector<int>&, decltype(v)>, "" );
assert(static_cast<bool>(opt) == true);
assert(*opt == std::vector<int>({1, 2, 3}));
+ assert(&v == &*opt);
}
{
optional<Y> opt;
- opt.emplace({1, 2});
+ auto &v = opt.emplace({1, 2});
+ static_assert( std::is_same_v<Y&, decltype(v)>, "" );
assert(static_cast<bool>(opt) == true);
assert(*opt == Y({1, 2}));
+ assert(&v == &*opt);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
{
@@ -100,7 +106,9 @@ int main()
{
assert(static_cast<bool>(opt) == true);
assert(Z::dtor_called == false);
- opt.emplace({1, 2});
+ auto &v = opt.emplace({1, 2});
+ static_assert( std::is_same_v<Z&, decltype(v)>, "" );
+ assert(false);
}
catch (int i)
{
OpenPOWER on IntegriCloud