Skip to content

Commit 5a8c466

Browse files
committed
Add tests to ensure that reference_wrapper<T> is trivially copyable. This was added to C++1z with the adoption of N4277, but libc++ already implemented it as a conforming extension. No code changes were needed, just more tests.
llvm-svn: 222132
1 parent 9743c9d commit 5a8c466

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

libcxx/test/utilities/function.objects/refwrap/type_properties.pass.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,43 @@
1616

1717
#include <functional>
1818
#include <type_traits>
19+
#include <string>
1920

20-
int main()
21+
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
22+
class MoveOnly
23+
{
24+
MoveOnly(const MoveOnly&);
25+
MoveOnly& operator=(const MoveOnly&);
26+
27+
int data_;
28+
public:
29+
MoveOnly(int data = 1) : data_(data) {}
30+
MoveOnly(MoveOnly&& x)
31+
: data_(x.data_) {x.data_ = 0;}
32+
MoveOnly& operator=(MoveOnly&& x)
33+
{data_ = x.data_; x.data_ = 0; return *this;}
34+
35+
int get() const {return data_;}
36+
};
37+
#endif
38+
39+
40+
template <class T>
41+
void test()
2142
{
22-
typedef std::reference_wrapper<int> T;
23-
static_assert(std::is_copy_constructible<T>::value, "");
24-
static_assert(std::is_copy_assignable<T>::value, "");
43+
typedef std::reference_wrapper<T> Wrap;
44+
static_assert(std::is_copy_constructible<Wrap>::value, "");
45+
static_assert(std::is_copy_assignable<Wrap>::value, "");
2546
// Extension up for standardization: See N4151.
26-
static_assert(std::is_trivially_copyable<T>::value, "");
47+
static_assert(std::is_trivially_copyable<Wrap>::value, "");
48+
}
49+
50+
int main()
51+
{
52+
test<int>();
53+
test<double>();
54+
test<std::string>();
55+
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
56+
test<MoveOnly>();
57+
#endif
2758
}

0 commit comments

Comments
 (0)