diff --git a/libcxx/include/concepts b/libcxx/include/concepts --- a/libcxx/include/concepts +++ b/libcxx/include/concepts @@ -374,6 +374,14 @@ assignable_from<_Tp&, _Tp> && swappable<_Tp>; +template +concept copyable = + copy_constructible<_Tp> && + movable<_Tp> && + assignable_from<_Tp&, _Tp&> && + assignable_from<_Tp&, const _Tp&> && + assignable_from<_Tp&, const _Tp>; + // [concept.invocable] template concept invocable = requires(_Fn&& __fn, _Args&&... __args) { diff --git a/libcxx/test/std/concepts/object/copyable.h b/libcxx/test/std/concepts/object/copyable.h new file mode 100644 --- /dev/null +++ b/libcxx/test/std/concepts/object/copyable.h @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +#ifndef TEST_STD_CONCEPTS_OBJECT_COPYABLE_H +#define TEST_STD_CONCEPTS_OBJECT_COPYABLE_H + +#include + +#include "movable.h" + +struct no_copy_constructor { + no_copy_constructor(no_copy_constructor const&) = delete; + no_copy_constructor(no_copy_constructor&&) = default; +}; + +struct no_copy_assignment { + no_copy_assignment& operator=(no_copy_assignment const&) = delete; + no_copy_assignment& operator=(no_copy_assignment&&) = default; +}; + +struct no_copy_assignment_mutable { + no_copy_assignment_mutable& + operator=(no_copy_assignment_mutable const&) = default; + no_copy_assignment_mutable& operator=(no_copy_assignment_mutable&) = delete; + no_copy_assignment_mutable& operator=(no_copy_assignment_mutable&&) = default; +}; + +struct no_const_value_assignment { + no_const_value_assignment& + operator=(no_const_value_assignment const) = delete; +}; + +struct derived_from_noncopyable : std::unique_ptr {}; + +struct has_noncopyable { + std::unique_ptr x; +}; +#endif // TEST_STD_CONCEPTS_OBJECT_COPYABLE_H diff --git a/libcxx/test/std/concepts/object/copyable.compile.pass.cpp b/libcxx/test/std/concepts/object/copyable.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/concepts/object/copyable.compile.pass.cpp @@ -0,0 +1,111 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++17 +// UNSUPPORTED: libcpp-no-concepts + +// template +// concept copyable = see below; + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "copyable.h" + +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); + +struct S {}; +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); +static_assert(std::copyable); + +static_assert(std::copyable >); +static_assert(std::copyable >); +static_assert(std::copyable >); +static_assert(std::copyable >); +static_assert(std::copyable > >); +static_assert(std::copyable > >); +static_assert(std::copyable >); +static_assert(std::copyable > >); + +static_assert(std::copyable); +static_assert(std::copyable); + +// Not objects +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); + +// Not copy constructible or copy assignable +static_assert(!std::copyable >); + +// Not assignable +static_assert(!std::copyable); +static_assert(!std::copyable); + +static_assert(!std::copyable); +static_assert(!std::copyable); + +static_assert(std::is_copy_assignable_v); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); +static_assert(!std::copyable); + +int main(int, char**) { return 0; } diff --git a/libcxx/test/std/concepts/object/object.h b/libcxx/test/std/concepts/object/object.h deleted file mode 100644 --- a/libcxx/test/std/concepts/object/object.h +++ /dev/null @@ -1,52 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// -#ifndef TEST_STD_CONCEPTS_OBJECT_H -#define TEST_STD_CONCEPTS_OBJECT_H - -struct has_const_member { - int const x; -}; - -struct has_volatile_member { - int volatile x; -}; - -struct has_cv_member { - int const volatile x; -}; - -struct has_lvalue_reference_member { - int& x; -}; - -struct has_rvalue_reference_member { - int&& x; -}; - -struct has_array_member { - int x[5]; -}; - -struct has_function_ref_member { - int (&f)(); -}; - -struct traditional_copy_assignment_only { - traditional_copy_assignment_only& - operator=(traditional_copy_assignment_only const&); -}; - -struct mutable_copy_assignment { - mutable_copy_assignment& operator=(mutable_copy_assignment&); -}; - -struct const_move_constructor { - const_move_constructor& operator=(const_move_constructor&&) const; -}; - -#endif // TEST_STD_CONCEPTS_OBJECT_H