Instead of writing something like `XFAIL: use_system_cxx_lib && target=...` to XFAIL back-deployment tests, introduce named Lit features like `availability-shared_mutex-missing` to represent those. This makes the XFAIL annotations leaner, and solves the problem of XFAIL comments potentially getting out of sync. This would also make it easier for another vendor to add their own annotations to the test suite by simply changing how the feature is defined for their OS releases, instead of having to modify hundreds of tests to add repetitive annotations. This doesn't touch *all* annotations -- only annotations that were widely duplicated are given named features (e.g. when filesystem or shared_mutex were introduced). I still think it probably doesn't make sense to have a named feature for every single fix we make to the dylib. This is in essence a revert of2659663, but since then the test suite has changed significantly. Back when I did2659663, the configuration files we have for the test suite right now were being bootstrapped and it wasn't clear how to provide these features for back-deployment in that context. Since then, we have a streamlined way of defining these features in `features.py` and that doesn't impact the ability for a configuration file to stay minimal. The original motivation for this change was that I am about to propose a change that would touch essentially all XFAIL annotations for back-deployment in the test suite, and this greatly reduces the number of lines changed by that upcoming change, in addition to making the test suite generally better. Differential Revision: https://reviews.llvm.org/D146359
225 lines
5.9 KiB
C++
225 lines
5.9 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UNSUPPORTED: c++03, c++11, c++14
|
|
|
|
// XFAIL: availability-bad_optional_access-missing && !no-exceptions
|
|
|
|
// <optional>
|
|
|
|
// constexpr optional(optional<T>&& rhs);
|
|
|
|
#include <optional>
|
|
#include <type_traits>
|
|
#include <cassert>
|
|
|
|
#include "test_macros.h"
|
|
#include "archetypes.h"
|
|
|
|
using std::optional;
|
|
|
|
template <class T, class ...InitArgs>
|
|
void test(InitArgs&&... args)
|
|
{
|
|
const optional<T> orig(std::forward<InitArgs>(args)...);
|
|
optional<T> rhs(orig);
|
|
bool rhs_engaged = static_cast<bool>(rhs);
|
|
optional<T> lhs = std::move(rhs);
|
|
assert(static_cast<bool>(lhs) == rhs_engaged);
|
|
if (rhs_engaged)
|
|
assert(*lhs == *orig);
|
|
}
|
|
|
|
template <class T, class ...InitArgs>
|
|
constexpr bool constexpr_test(InitArgs&&... args)
|
|
{
|
|
static_assert( std::is_trivially_copy_constructible_v<T>, ""); // requirement
|
|
const optional<T> orig(std::forward<InitArgs>(args)...);
|
|
optional<T> rhs(orig);
|
|
optional<T> lhs = std::move(rhs);
|
|
return (lhs.has_value() == orig.has_value()) &&
|
|
(lhs.has_value() ? *lhs == *orig : true);
|
|
}
|
|
|
|
void test_throwing_ctor() {
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
|
struct Z {
|
|
Z() : count(0) {}
|
|
Z(Z&& o) : count(o.count + 1)
|
|
{ if (count == 2) throw 6; }
|
|
int count;
|
|
};
|
|
Z z;
|
|
optional<Z> rhs(std::move(z));
|
|
try
|
|
{
|
|
optional<Z> lhs(std::move(rhs));
|
|
assert(false);
|
|
}
|
|
catch (int i)
|
|
{
|
|
assert(i == 6);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
template <class T, class ...InitArgs>
|
|
void test_ref(InitArgs&&... args)
|
|
{
|
|
optional<T> rhs(std::forward<InitArgs>(args)...);
|
|
bool rhs_engaged = static_cast<bool>(rhs);
|
|
optional<T> lhs = std::move(rhs);
|
|
assert(static_cast<bool>(lhs) == rhs_engaged);
|
|
if (rhs_engaged)
|
|
assert(&(*lhs) == &(*rhs));
|
|
}
|
|
|
|
void test_reference_extension()
|
|
{
|
|
#if defined(_LIBCPP_VERSION) && 0 // FIXME these extensions are currently disabled.
|
|
using T = TestTypes::TestType;
|
|
T::reset();
|
|
{
|
|
T t;
|
|
T::reset_constructors();
|
|
test_ref<T&>();
|
|
test_ref<T&>(t);
|
|
assert(T::alive == 1);
|
|
assert(T::constructed == 0);
|
|
assert(T::assigned == 0);
|
|
assert(T::destroyed == 0);
|
|
}
|
|
assert(T::destroyed == 1);
|
|
assert(T::alive == 0);
|
|
{
|
|
T t;
|
|
const T& ct = t;
|
|
T::reset_constructors();
|
|
test_ref<T const&>();
|
|
test_ref<T const&>(t);
|
|
test_ref<T const&>(ct);
|
|
assert(T::alive == 1);
|
|
assert(T::constructed == 0);
|
|
assert(T::assigned == 0);
|
|
assert(T::destroyed == 0);
|
|
}
|
|
assert(T::alive == 0);
|
|
assert(T::destroyed == 1);
|
|
{
|
|
T t;
|
|
T::reset_constructors();
|
|
test_ref<T&&>();
|
|
test_ref<T&&>(std::move(t));
|
|
assert(T::alive == 1);
|
|
assert(T::constructed == 0);
|
|
assert(T::assigned == 0);
|
|
assert(T::destroyed == 0);
|
|
}
|
|
assert(T::alive == 0);
|
|
assert(T::destroyed == 1);
|
|
{
|
|
T t;
|
|
const T& ct = t;
|
|
T::reset_constructors();
|
|
test_ref<T const&&>();
|
|
test_ref<T const&&>(std::move(t));
|
|
test_ref<T const&&>(std::move(ct));
|
|
assert(T::alive == 1);
|
|
assert(T::constructed == 0);
|
|
assert(T::assigned == 0);
|
|
assert(T::destroyed == 0);
|
|
}
|
|
assert(T::alive == 0);
|
|
assert(T::destroyed == 1);
|
|
{
|
|
static_assert(!std::is_copy_constructible<std::optional<T&&>>::value, "");
|
|
static_assert(!std::is_copy_constructible<std::optional<T const&&>>::value, "");
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
int main(int, char**)
|
|
{
|
|
test<int>();
|
|
test<int>(3);
|
|
static_assert(constexpr_test<int>(), "" );
|
|
static_assert(constexpr_test<int>(3), "" );
|
|
|
|
{
|
|
optional<const int> o(42);
|
|
optional<const int> o2(std::move(o));
|
|
assert(*o2 == 42);
|
|
}
|
|
{
|
|
using T = TestTypes::TestType;
|
|
T::reset();
|
|
optional<T> rhs;
|
|
assert(T::alive == 0);
|
|
const optional<T> lhs(std::move(rhs));
|
|
assert(lhs.has_value() == false);
|
|
assert(rhs.has_value() == false);
|
|
assert(T::alive == 0);
|
|
}
|
|
TestTypes::TestType::reset();
|
|
{
|
|
using T = TestTypes::TestType;
|
|
T::reset();
|
|
optional<T> rhs(42);
|
|
assert(T::alive == 1);
|
|
assert(T::value_constructed == 1);
|
|
assert(T::move_constructed == 0);
|
|
const optional<T> lhs(std::move(rhs));
|
|
assert(lhs.has_value());
|
|
assert(rhs.has_value());
|
|
assert(lhs.value().value == 42);
|
|
assert(rhs.value().value == -1);
|
|
assert(T::move_constructed == 1);
|
|
assert(T::alive == 2);
|
|
}
|
|
TestTypes::TestType::reset();
|
|
{
|
|
using namespace ConstexprTestTypes;
|
|
test<TestType>();
|
|
test<TestType>(42);
|
|
}
|
|
{
|
|
using namespace TrivialTestTypes;
|
|
test<TestType>();
|
|
test<TestType>(42);
|
|
}
|
|
{
|
|
test_throwing_ctor();
|
|
}
|
|
{
|
|
struct ThrowsMove {
|
|
ThrowsMove() noexcept(false) {}
|
|
ThrowsMove(ThrowsMove const&) noexcept(false) {}
|
|
ThrowsMove(ThrowsMove &&) noexcept(false) {}
|
|
};
|
|
static_assert(!std::is_nothrow_move_constructible<optional<ThrowsMove>>::value, "");
|
|
struct NoThrowMove {
|
|
NoThrowMove() noexcept(false) {}
|
|
NoThrowMove(NoThrowMove const&) noexcept(false) {}
|
|
NoThrowMove(NoThrowMove &&) noexcept(true) {}
|
|
};
|
|
static_assert(std::is_nothrow_move_constructible<optional<NoThrowMove>>::value, "");
|
|
}
|
|
{
|
|
test_reference_extension();
|
|
}
|
|
{
|
|
constexpr std::optional<int> o1{4};
|
|
constexpr std::optional<int> o2 = std::move(o1);
|
|
static_assert( *o2 == 4, "" );
|
|
}
|
|
|
|
return 0;
|
|
}
|