diff --git a/libcxx/include/concepts b/libcxx/include/concepts --- a/libcxx/include/concepts +++ b/libcxx/include/concepts @@ -382,6 +382,9 @@ assignable_from<_Tp&, const _Tp&> && assignable_from<_Tp&, const _Tp>; +template +concept semiregular = copyable<_Tp> && default_initializable<_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 --- a/libcxx/test/std/concepts/object/copyable.h +++ b/libcxx/test/std/concepts/object/copyable.h @@ -36,6 +36,8 @@ }; struct const_copy_assignment { + const_copy_assignment(); + const_copy_assignment(const_copy_assignment const&); const_copy_assignment(const_copy_assignment&&); @@ -53,6 +55,7 @@ }; struct cv_copy_assignment { + cv_copy_assignment(); cv_copy_assignment(cv_copy_assignment const volatile&); cv_copy_assignment(cv_copy_assignment const volatile&&); diff --git a/libcxx/test/std/concepts/object/semiregular.h b/libcxx/test/std/concepts/object/semiregular.h new file mode 100644 --- /dev/null +++ b/libcxx/test/std/concepts/object/semiregular.h @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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_SEMIREGULAR_H +#define TEST_STD_CONCEPTS_OBJECT_SEMIREGULAR_H + +#include + +#include "copyable.h" + +struct derived_from_non_default_initializable : std::nullopt_t {}; +struct has_non_default_initializable { + std::in_place_t x; +}; + +#endif // TEST_STD_CONCEPTS_OBJECT_SEMIREGULAR_H diff --git a/libcxx/test/std/concepts/object/semiregular.compile.pass.cpp b/libcxx/test/std/concepts/object/semiregular.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/concepts/object/semiregular.compile.pass.cpp @@ -0,0 +1,126 @@ +//===----------------------------------------------------------------------===// +// +// 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 semiregular = see below; + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "semiregular.h" + +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); + +struct S {}; +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); +static_assert(std::semiregular); + +static_assert(std::semiregular >); +static_assert(std::semiregular >); +static_assert(std::semiregular >); +static_assert(std::semiregular >); +static_assert(std::semiregular > >); +static_assert(std::semiregular > >); +static_assert(std::semiregular >); +static_assert(std::semiregular > >); + +static_assert(std::semiregular); +static_assert(std::semiregular); + +// Not objects +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); + +// Not copyable +static_assert(!std::semiregular >); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(std::semiregular); +static_assert(!std::semiregular); +static_assert(std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); + +// Not default_initialzable +static_assert(!std::semiregular); +static_assert( + !std::semiregular >); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(std::is_copy_assignable_v); +static_assert(!std::semiregular); +static_assert(!std::semiregular); +static_assert(!std::semiregular); + +static_assert(!std::semiregular); +static_assert(!std::semiregular); + +int main(int, char**) { return 0; }