[libcxx] r301055 - Expand test coverage for LWG2857
Casey Carter via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 21 15:38:59 PDT 2017
Author: caseycarter
Date: Fri Apr 21 17:38:59 2017
New Revision: 301055
URL: http://llvm.org/viewvc/llvm-project?rev=301055&view=rev
Log:
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
Modified:
libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
Modified: libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp?rev=301055&r1=301054&r2=301055&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp Fri Apr 21 17:38:59 2017
@@ -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&) {
}
Modified: libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp?rev=301055&r1=301054&r2=301055&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp Fri Apr 21 17:38:59 2017
@@ -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)
{
Modified: libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp?rev=301055&r1=301054&r2=301055&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp Fri Apr 21 17:38:59 2017
@@ -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)
{
More information about the cfe-commits
mailing list