Fix some type-traits (is_assignable, etc) dealing with classes that take non-const references as 'right hand side'. Add tests. Fixes PR# 20836

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@218286 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow 2014-09-22 23:58:00 +00:00
parent 6a5a8abe2f
commit d132bf4ef1
6 changed files with 39 additions and 9 deletions

View File

@ -1523,7 +1523,7 @@ struct is_assignable
template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_copy_assignable template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_copy_assignable
: public is_assignable<typename add_lvalue_reference<_Tp>::type, : public is_assignable<typename add_lvalue_reference<_Tp>::type,
const typename add_lvalue_reference<_Tp>::type> {}; typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
// is_move_assignable // is_move_assignable
@ -2637,8 +2637,8 @@ struct _LIBCPP_TYPE_VIS_ONLY is_default_constructible
template <class _Tp> template <class _Tp>
struct _LIBCPP_TYPE_VIS_ONLY is_copy_constructible struct _LIBCPP_TYPE_VIS_ONLY is_copy_constructible
: public is_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type> : public is_constructible<_Tp,
{}; typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
// is_move_constructible // is_move_constructible
@ -2842,8 +2842,7 @@ struct is_trivially_assignable<_Tp&, _Tp&&>
template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_assignable template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_assignable
: public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type, : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
const typename add_lvalue_reference<_Tp>::type> typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
{};
// is_trivially_move_assignable // is_trivially_move_assignable
@ -3034,8 +3033,8 @@ template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_default_constructib
// is_nothrow_copy_constructible // is_nothrow_copy_constructible
template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_constructible template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_constructible
: public is_nothrow_constructible<_Tp, const typename add_lvalue_reference<_Tp>::type> : public is_nothrow_constructible<_Tp,
{}; typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
// is_nothrow_move_constructible // is_nothrow_move_constructible
@ -3119,8 +3118,7 @@ struct is_nothrow_assignable<_Tp&, _Tp&&>
template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_assignable template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_assignable
: public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type, : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
const typename add_lvalue_reference<_Tp>::type> typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
{};
// is_nothrow_move_assignable // is_nothrow_move_assignable

View File

@ -52,6 +52,11 @@ class B
B& operator=(const B&); B& operator=(const B&);
}; };
struct C
{
void operator=(C&); // not const
};
int main() int main()
{ {
test_is_copy_assignable<int> (); test_is_copy_assignable<int> ();
@ -71,4 +76,5 @@ int main()
test_is_not_copy_assignable<B> (); test_is_not_copy_assignable<B> ();
#endif #endif
test_is_not_copy_assignable<void> (); test_is_not_copy_assignable<void> ();
test_is_not_copy_assignable<C> ();
} }

View File

@ -58,6 +58,12 @@ class B
B(const B&); B(const B&);
}; };
struct C
{
C(C&); // not const
void operator=(C&); // not const
};
int main() int main()
{ {
test_is_copy_constructible<A>(); test_is_copy_constructible<A>();
@ -75,6 +81,7 @@ int main()
test_is_not_copy_constructible<char[]>(); test_is_not_copy_constructible<char[]>();
test_is_not_copy_constructible<void>(); test_is_not_copy_constructible<void>();
test_is_not_copy_constructible<Abstract>(); test_is_not_copy_constructible<Abstract>();
test_is_not_copy_constructible<C>();
#if __has_feature(cxx_access_control_sfinae) #if __has_feature(cxx_access_control_sfinae)
test_is_not_copy_constructible<B>(); test_is_not_copy_constructible<B>();
#endif #endif

View File

@ -34,6 +34,11 @@ struct B
void operator=(A); void operator=(A);
}; };
struct C
{
void operator=(C&); // not const
};
int main() int main()
{ {
test_is_nothrow_assignable<int&, int&> (); test_is_nothrow_assignable<int&, int&> ();
@ -46,4 +51,5 @@ int main()
test_is_not_nothrow_assignable<int, int> (); test_is_not_nothrow_assignable<int, int> ();
test_is_not_nothrow_assignable<B, A> (); test_is_not_nothrow_assignable<B, A> ();
test_is_not_nothrow_assignable<A, B> (); test_is_not_nothrow_assignable<A, B> ();
test_is_not_nothrow_assignable<C, C&> ();
} }

View File

@ -70,6 +70,12 @@ struct A
A(const A&); A(const A&);
}; };
struct C
{
C(C&); // not const
void operator=(C&); // not const
};
int main() int main()
{ {
test_is_nothrow_constructible<int> (); test_is_nothrow_constructible<int> ();
@ -80,4 +86,5 @@ int main()
test_is_not_nothrow_constructible<A, int> (); test_is_not_nothrow_constructible<A, int> ();
test_is_not_nothrow_constructible<A, int, double> (); test_is_not_nothrow_constructible<A, int, double> ();
test_is_not_nothrow_constructible<A> (); test_is_not_nothrow_constructible<A> ();
test_is_not_nothrow_constructible<C> ();
} }

View File

@ -34,6 +34,11 @@ struct B
void operator=(A); void operator=(A);
}; };
struct C
{
void operator=(C&); // not const
};
int main() int main()
{ {
test_is_trivially_assignable<int&, int&> (); test_is_trivially_assignable<int&, int&> ();
@ -44,4 +49,5 @@ int main()
test_is_not_trivially_assignable<int, int> (); test_is_not_trivially_assignable<int, int> ();
test_is_not_trivially_assignable<B, A> (); test_is_not_trivially_assignable<B, A> ();
test_is_not_trivially_assignable<A, B> (); test_is_not_trivially_assignable<A, B> ();
test_is_not_trivially_assignable<C&, C&> ();
} }