1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03
14 // Test the diagnostics libc++ generates for invalid reference binding.
15 // Libc++ attempts to diagnose the following cases:
16 // * Constructing an lvalue reference from an rvalue.
17 // * Constructing an rvalue reference from an lvalue.
24 static_assert(std::is_constructible<int&, std::reference_wrapper<int>>::value, "");
25 static_assert(std::is_constructible<int const&, std::reference_wrapper<int>>::value, "");
29 std::allocator<void> alloc;
32 std::tuple<int&> t(std::ref(x));
33 assert(&std::get<0>(t) == &x);
34 std::tuple<int&> t1(std::allocator_arg, alloc, std::ref(x));
35 assert(&std::get<0>(t1) == &x);
40 std::tuple<int&> t(r);
41 assert(&std::get<0>(t) == &x);
42 std::tuple<int&> t1(cr);
43 assert(&std::get<0>(t1) == &x);
44 std::tuple<int&> t2(std::allocator_arg, alloc, r);
45 assert(&std::get<0>(t2) == &x);
46 std::tuple<int&> t3(std::allocator_arg, alloc, cr);
47 assert(&std::get<0>(t3) == &x);
50 std::tuple<int const&> t(std::ref(x));
51 assert(&std::get<0>(t) == &x);
52 std::tuple<int const&> t2(std::cref(x));
53 assert(&std::get<0>(t2) == &x);
54 std::tuple<int const&> t3(std::allocator_arg, alloc, std::ref(x));
55 assert(&std::get<0>(t3) == &x);
56 std::tuple<int const&> t4(std::allocator_arg, alloc, std::cref(x));
57 assert(&std::get<0>(t4) == &x);
61 auto cr = std::cref(x);
62 std::tuple<int const&> t(r);
63 assert(&std::get<0>(t) == &x);
64 std::tuple<int const&> t2(cr);
65 assert(&std::get<0>(t2) == &x);
66 std::tuple<int const&> t3(std::allocator_arg, alloc, r);
67 assert(&std::get<0>(t3) == &x);
68 std::tuple<int const&> t4(std::allocator_arg, alloc, cr);
69 assert(&std::get<0>(t4) == &x);