diff --git a/libcxx/test/std/concepts/concepts.lang/concept.assignable/assignable_from.compile.pass.cpp b/libcxx/test/std/concepts/concepts.lang/concept.assignable/assignable_from.compile.pass.cpp --- a/libcxx/test/std/concepts/concepts.lang/concept.assignable/assignable_from.compile.pass.cpp +++ b/libcxx/test/std/concepts/concepts.lang/concept.assignable/assignable_from.compile.pass.cpp @@ -9,550 +9,98 @@ // UNSUPPORTED: c++03, c++11, c++14, c++17 // UNSUPPORTED: libcpp-no-concepts -// template -// concept assignable_from; +// template< class LHS, class RHS > +// concept assignable_from = +// std::is_lvalue_reference_v && +// std::common_reference_with< +// const std::remove_reference_t&, +// const std::remove_reference_t&> && +// requires(LHS lhs, RHS&& rhs) { +// { lhs = std::forward(rhs) } -> std::same_as; +// }; #include +#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "MoveOnly.h" -#ifndef _LIBCPP_HAS_NO_THREADS -# include -#endif - -#include "../support/allocators.h" - -// Note: is_lvalue_reference is checked in all ModelsAssignableFrom calls. -template -constexpr void NeverAssignableFrom() { - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert( - !std::assignable_from); - - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); - static_assert(!std::assignable_from); -} - -template -constexpr bool CheckAssignableFromRvalues() { - NeverAssignableFrom(); - - constexpr bool Result = std::assignable_from; - static_assert(std::assignable_from == Result); - - return Result; -} - -template -constexpr bool CheckAssignableFromLvalues() { - NeverAssignableFrom(); - - constexpr bool Result = std::assignable_from; - static_assert(std::assignable_from == Result); - static_assert(std::assignable_from == Result); - - return Result; -} - -template -constexpr bool CheckAssignableFromLvaluesAndRvalues() { - return CheckAssignableFromLvalues() && - CheckAssignableFromRvalues(); -} - -namespace BuiltinTypes { -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(!CheckAssignableFromLvaluesAndRvalues()); -static_assert(!CheckAssignableFromLvaluesAndRvalues()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues()); -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert(!CheckAssignableFromLvaluesAndRvalues()); -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); - -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues()); - -struct S {}; -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues< - int (S::*)() const, int (S::*)() const noexcept>()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues< - int (S::*)() volatile, int (S::*)() volatile noexcept>()); -static_assert(CheckAssignableFromLvaluesAndRvalues< - int (S::*)() const volatile, int (S::*)() const volatile>()); -static_assert( - CheckAssignableFromLvaluesAndRvalues< - int (S::*)() const volatile, int (S::*)() const volatile noexcept>()); - -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -} // namespace BuiltinTypes - -namespace TypesFitForPurpose { -struct T1 {}; - -struct NoCommonReference {}; -static_assert(!std::common_reference_with); -static_assert(!std::assignable_from); - -struct AssignmentReturnsNonReference { - AssignmentReturnsNonReference operator=(T1); - operator T1() const; +struct NoCommonRef { + NoCommonRef& operator=(const int&); }; -static_assert(std::common_reference_with); -static_assert(!std::assignable_from); - -struct NonCVAssignmentOnly { - NonCVAssignmentOnly& operator=(T1); - operator T1() const; +static_assert(std::is_assignable_v); +static_assert(!std::assignable_from); // no common reference type + +struct Base {}; +struct Derived : Base {}; +static_assert(!std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); + +struct VoidResultType { + void operator=(const VoidResultType&); }; -static_assert( - std::common_reference_with); -static_assert(std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); +static_assert(std::is_assignable_v); +static_assert(!std::assignable_from); -struct NonCVAssignmentOnlyConstQualified { - NonCVAssignmentOnlyConstQualified& operator=(T1) const; - operator T1() const; +struct ValueResultType { + ValueResultType operator=(const ValueResultType&); }; -static_assert(std::common_reference_with< - const T1&, const NonCVAssignmentOnlyConstQualified&>); -static_assert(std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from< - const volatile NonCVAssignmentOnlyConstQualified&, T1>); +static_assert(std::is_assignable_v); +static_assert(!std::assignable_from); -struct NonCVAssignmentVolatileQualified { - NonCVAssignmentVolatileQualified& operator=(T1) volatile; - operator T1() const volatile; +struct Locale { + const Locale& operator=(const Locale&); }; -static_assert(std::common_reference_with< - const T1&, const NonCVAssignmentVolatileQualified&>); -static_assert(std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from< - const volatile NonCVAssignmentVolatileQualified&, T1>); +static_assert(std::is_assignable_v); +static_assert(!std::assignable_from); -struct NonCVAssignmentOnlyCVQualified { - NonCVAssignmentOnlyCVQualified& operator=(T1) const volatile; - operator T1() const volatile; +struct Tuple { + Tuple& operator=(const Tuple&); + const Tuple& operator=(const Tuple&) const; }; -static_assert(std::common_reference_with< - const T1&, const NonCVAssignmentOnlyCVQualified&>); -static_assert(std::assignable_from); -static_assert(!std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); - -struct ConstAssignmentOnly { - const ConstAssignmentOnly& operator=(T1) const; - operator T1() const; -}; -static_assert( - std::common_reference_with); -static_assert(std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); - -struct VolatileAssignmentOnly { - volatile VolatileAssignmentOnly& operator=(T1) volatile; - operator T1() const volatile; -}; -static_assert( - std::common_reference_with); -static_assert(!std::assignable_from); -static_assert(std::assignable_from); - -struct CVAssignmentOnly { - const volatile CVAssignmentOnly& operator=(T1) const volatile; - operator T1() const volatile; -}; -static_assert(std::common_reference_with); -static_assert(std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); - -struct LvalueRefQualifiedWithRvalueT1Only { - LvalueRefQualifiedWithRvalueT1Only& operator=(T1&&) &; - const LvalueRefQualifiedWithRvalueT1Only& operator=(T1&&) const&; - volatile LvalueRefQualifiedWithRvalueT1Only& operator=(T1&&) volatile&; - const volatile LvalueRefQualifiedWithRvalueT1Only& operator=(T1&&) const - volatile&; - operator T1() const volatile; -}; -static_assert(std::common_reference_with< - const T1&, const LvalueRefQualifiedWithRvalueT1Only&>); -static_assert(std::assignable_from); -static_assert( - std::assignable_from); -static_assert( - std::assignable_from); -static_assert(std::assignable_from< - const volatile LvalueRefQualifiedWithRvalueT1Only&, T1&&>); -static_assert(!std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from< - const volatile LvalueRefQualifiedWithRvalueT1Only&, T1&>); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from< - volatile LvalueRefQualifiedWithRvalueT1Only&, const T1&>); -static_assert(!std::assignable_from< - const volatile LvalueRefQualifiedWithRvalueT1Only&, const T1&>); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from< - volatile LvalueRefQualifiedWithRvalueT1Only&, volatile T1&>); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from< - volatile LvalueRefQualifiedWithRvalueT1Only&, const T1&&>); -static_assert(!std::assignable_from< - const volatile LvalueRefQualifiedWithRvalueT1Only&, const T1&&>); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from< - volatile LvalueRefQualifiedWithRvalueT1Only&, volatile T1&&>); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); - -struct NoLvalueRefAssignment { - NoLvalueRefAssignment& operator=(T1) &&; - const NoLvalueRefAssignment& operator=(T1) const&&; - volatile NoLvalueRefAssignment& operator=(T1) volatile&&; - const volatile NoLvalueRefAssignment& operator=(T1) const volatile&&; - operator T1() const volatile; -}; -static_assert( - std::common_reference_with); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert(!std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -static_assert( - !std::assignable_from); -static_assert( - !std::assignable_from); -static_assert(!std::assignable_from); -} // namespace TypesFitForPurpose - -namespace StandardTypes { -static_assert( - CheckAssignableFromLvaluesAndRvalues, std::deque >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, - std::deque >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::deque, std::deque > >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, - std::vector >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, int>()); - -static_assert(CheckAssignableFromLvaluesAndRvalues, - std::forward_list >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::forward_list, std::forward_list >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::forward_list, std::forward_list > >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, - std::vector >()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues, int>()); - -static_assert( - CheckAssignableFromLvaluesAndRvalues, std::list >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, - std::list >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::list, std::list > >()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues, std::vector >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, int>()); - -static_assert(CheckAssignableFromLvaluesAndRvalues, - std::map >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::map, std::map >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::map, - std::map > > >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::map, std::unordered_map >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, - std::pair >()); - -#ifndef _LIBCPP_HAS_NO_THREADS -static_assert(!CheckAssignableFromRvalues()); -static_assert(!CheckAssignableFromLvalues()); -#endif - -static_assert(CheckAssignableFromLvaluesAndRvalues, int>()); -static_assert( - CheckAssignableFromLvaluesAndRvalues, double>()); -static_assert(CheckAssignableFromLvaluesAndRvalues, - std::optional >()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues >()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues >()); - -static_assert( - !std::common_reference_with, std::optional >); -static_assert( - !CheckAssignableFromRvalues, std::optional >()); -static_assert( - !CheckAssignableFromLvalues, std::optional >()); - -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::string, std::basic_string >()); -static_assert( - !CheckAssignableFromLvaluesAndRvalues >()); - -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert(CheckAssignableFromLvaluesAndRvalues()); -static_assert( - CheckAssignableFromLvaluesAndRvalues()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::string_view, std::basic_string_view >()); - -static_assert( - CheckAssignableFromRvalues, std::unique_ptr >()); -static_assert( - !CheckAssignableFromLvalues, std::unique_ptr >()); - -static_assert( - CheckAssignableFromLvaluesAndRvalues, - std::unordered_map >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::unordered_map, - std::unordered_map >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::unordered_map, - std::unordered_map > > >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::unordered_map, std::map >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::unordered_map, std::pair >()); - -static_assert(CheckAssignableFromLvaluesAndRvalues, - std::vector >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, - std::deque >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues< - std::vector, std::vector > >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, - std::deque >()); -static_assert(!CheckAssignableFromLvaluesAndRvalues, int>()); -} // namespace StandardTypes - -int main(int, char**) { return 0; } +static_assert(!std::assignable_from); +static_assert( std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from); +static_assert( std::assignable_from); +static_assert(!std::assignable_from); + +// Finally, check a few simple cases. +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert( std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from); +static_assert( std::assignable_from); +static_assert(!std::assignable_from); +static_assert( std::assignable_from); +static_assert(!std::assignable_from); +static_assert(!std::assignable_from);