Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// template <class U> optional<T>& operator=(U&& v);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
static_assert(std::is_assignable<optional<int>, int>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>, int&>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>&, int>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>&, int&>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>&, const int&>::value, "");
|
||||
static_assert(!std::is_assignable<const optional<int>&, const int&>::value, "");
|
||||
static_assert(!std::is_assignable<optional<int>, X>::value, "");
|
||||
{
|
||||
optional<int> opt;
|
||||
opt = 1;
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 1);
|
||||
}
|
||||
{
|
||||
optional<int> opt;
|
||||
const int i = 2;
|
||||
opt = i;
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == i);
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
const int i = 2;
|
||||
opt = i;
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == i);
|
||||
}
|
||||
{
|
||||
optional<std::unique_ptr<int>> opt;
|
||||
opt = std::unique_ptr<int>(new int(3));
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(**opt == 3);
|
||||
}
|
||||
{
|
||||
optional<std::unique_ptr<int>> opt(std::unique_ptr<int>(new int(2)));
|
||||
opt = std::unique_ptr<int>(new int(3));
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(**opt == 3);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// optional<T>& operator=(const optional<T>& rhs);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
static bool throw_now;
|
||||
|
||||
X() = default;
|
||||
X(const X&)
|
||||
{
|
||||
if (throw_now)
|
||||
throw 6;
|
||||
}
|
||||
};
|
||||
|
||||
bool X::throw_now = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2;
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2;
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
optional<X> opt2(X{});
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
try
|
||||
{
|
||||
X::throw_now = true;
|
||||
opt = opt2;
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,148 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// template <class... Args> void optional<T>::emplace(Args&&... args);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
X() : i_(0) {}
|
||||
X(int i) : i_(i) {}
|
||||
X(int i, int j) : i_(i), j_(j) {}
|
||||
|
||||
friend bool operator==(const X& x, const X& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
class Y
|
||||
{
|
||||
public:
|
||||
static bool dtor_called;
|
||||
Y() = default;
|
||||
~Y() {dtor_called = true;}
|
||||
};
|
||||
|
||||
bool Y::dtor_called = false;
|
||||
|
||||
class Z
|
||||
{
|
||||
public:
|
||||
static bool dtor_called;
|
||||
Z() = default;
|
||||
Z(int) {throw 6;}
|
||||
~Z() {dtor_called = true;}
|
||||
};
|
||||
|
||||
bool Z::dtor_called = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<int> opt;
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
optional<int> opt;
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 1);
|
||||
}
|
||||
{
|
||||
optional<int> opt(2);
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
optional<int> opt(2);
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 1);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X());
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1));
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
opt.emplace(1, 2);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1, 2));
|
||||
}
|
||||
{
|
||||
optional<X> opt(X{3});
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X());
|
||||
}
|
||||
{
|
||||
optional<X> opt(X{3});
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1));
|
||||
}
|
||||
{
|
||||
optional<X> opt(X{3});
|
||||
opt.emplace(1, 2);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1, 2));
|
||||
}
|
||||
{
|
||||
Y y;
|
||||
{
|
||||
optional<Y> opt(y);
|
||||
assert(Y::dtor_called == false);
|
||||
opt.emplace();
|
||||
assert(Y::dtor_called == true);
|
||||
}
|
||||
}
|
||||
{
|
||||
Z z;
|
||||
optional<Z> opt(z);
|
||||
try
|
||||
{
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(Z::dtor_called == false);
|
||||
opt.emplace(1);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
assert(Z::dtor_called == true);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// template <class U, class... Args>
|
||||
// void optional<T>::emplace(initializer_list<U> il, Args&&... args);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
static bool dtor_called;
|
||||
constexpr X() : i_(0) {}
|
||||
constexpr X(int i) : i_(i) {}
|
||||
constexpr X(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) {}
|
||||
~X() {dtor_called = true;}
|
||||
|
||||
friend constexpr bool operator==(const X& x, const X& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
bool X::dtor_called = false;
|
||||
|
||||
class Y
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
constexpr Y() : i_(0) {}
|
||||
constexpr Y(int i) : i_(i) {}
|
||||
constexpr Y(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) {}
|
||||
|
||||
friend constexpr bool operator==(const Y& x, const Y& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
class Z
|
||||
{
|
||||
int i_;
|
||||
int j_ = 0;
|
||||
public:
|
||||
static bool dtor_called;
|
||||
constexpr Z() : i_(0) {}
|
||||
constexpr Z(int i) : i_(i) {}
|
||||
constexpr Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1])
|
||||
{throw 6;}
|
||||
~Z() {dtor_called = true;}
|
||||
|
||||
friend constexpr bool operator==(const Z& x, const Z& y)
|
||||
{return x.i_ == y.i_ && x.j_ == y.j_;}
|
||||
};
|
||||
|
||||
bool Z::dtor_called = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
X x;
|
||||
{
|
||||
optional<X> opt(x);
|
||||
assert(X::dtor_called == false);
|
||||
opt.emplace({1, 2});
|
||||
assert(X::dtor_called == true);
|
||||
assert(*opt == X({1, 2}));
|
||||
}
|
||||
}
|
||||
{
|
||||
optional<std::vector<int>> opt;
|
||||
opt.emplace({1, 2, 3}, std::allocator<int>());
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == std::vector<int>({1, 2, 3}));
|
||||
}
|
||||
{
|
||||
optional<Y> opt;
|
||||
opt.emplace({1, 2});
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == Y({1, 2}));
|
||||
}
|
||||
{
|
||||
Z z;
|
||||
optional<Z> opt(z);
|
||||
try
|
||||
{
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(Z::dtor_called == false);
|
||||
opt.emplace({1, 2});
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
assert(Z::dtor_called == true);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,103 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// optional<T>& operator=(optional<T>&& rhs)
|
||||
// noexcept(is_nothrow_move_assignable<T>::value &&
|
||||
// is_nothrow_move_constructible<T>::value);
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
static bool throw_now;
|
||||
|
||||
X() = default;
|
||||
X(X&&)
|
||||
{
|
||||
if (throw_now)
|
||||
throw 6;
|
||||
}
|
||||
X& operator=(X&&) noexcept
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct Y {};
|
||||
|
||||
bool X::throw_now = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
static_assert(std::is_nothrow_move_assignable<optional<int>>::value, "");
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2;
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2;
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
static_assert(!std::is_nothrow_move_assignable<optional<X>>::value, "");
|
||||
optional<X> opt;
|
||||
optional<X> opt2(X{});
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
try
|
||||
{
|
||||
X::throw_now = true;
|
||||
opt = std::move(opt2);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 6);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
}
|
||||
{
|
||||
static_assert(std::is_nothrow_move_assignable<optional<Y>>::value, "");
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// optional<T>& operator=(nullopt_t) noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
struct X
|
||||
{
|
||||
static bool dtor_called;
|
||||
~X() {dtor_called = true;}
|
||||
};
|
||||
|
||||
bool X::dtor_called = false;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<int> opt;
|
||||
static_assert(noexcept(opt = nullopt) == true, "");
|
||||
opt = nullopt;
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
{
|
||||
optional<int> opt(3);
|
||||
opt = nullopt;
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
static_assert(noexcept(opt = nullopt) == true, "");
|
||||
assert(X::dtor_called == false);
|
||||
opt = nullopt;
|
||||
assert(X::dtor_called == false);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
{
|
||||
X x;
|
||||
{
|
||||
optional<X> opt(x);
|
||||
assert(X::dtor_called == false);
|
||||
opt = nullopt;
|
||||
assert(X::dtor_called == true);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
Reference in New Issue
Block a user