Debian Codegraph @

libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/reference_converts_from_temporary.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // REQUIRES: std-at-least-c++23
10
11 // <type_traits>
12
13 // template<class T, class U> struct reference_converts_from_temporary;
14
15 // template<class T, class U>
16 // constexpr bool reference_converts_from_temporary_v
17 // = reference_converts_from_temporary<T, U>::value;
18
19 #include <cassert>
20 #include <type_traits>
21
22 #include "common.h"
23 #include "test_macros.h"
24
25 template <typename T, typename U, bool Expected>
26 constexpr void test_reference_converts_from_temporary() {
27 assert((std::reference_converts_from_temporary<T, U>::value == Expected));
28 assert((std::reference_converts_from_temporary_v<T, U> == Expected));
29 }
30
31 constexpr bool test() {
32 test_reference_converts_from_temporary<int&, int&, false>();
33 test_reference_converts_from_temporary<int&, int&, false>();
34 test_reference_converts_from_temporary<int&, int&&, false>();
35
36 test_reference_converts_from_temporary<const int&, int&, false>();
37 test_reference_converts_from_temporary<const int&, const int&, false>();
38 test_reference_converts_from_temporary<const int&, int&&, false>();
39
40 test_reference_converts_from_temporary<int&, long&, false>(); // doesn't construct
41
42 test_reference_converts_from_temporary<const int&, long&, true>();
43 test_reference_converts_from_temporary<const int&, long&&, true>();
44 test_reference_converts_from_temporary<int&&, long&, true>();
45
46 assert((std::is_constructible_v<int&, ConvertsToRef<int, int&>>));
47 test_reference_converts_from_temporary<int&, ConvertsToRef<int, int&>, false>();
48
49 assert((std::is_constructible_v<int&&, ConvertsToRef<int, int&&>>));
50 test_reference_converts_from_temporary<int&&, ConvertsToRef<int, int&&>, false>();
51
52 assert((std::is_constructible_v<const int&, ConvertsToRef<int, const int&>>));
53 test_reference_converts_from_temporary<int&&, ConvertsToRef<int, const int&>, false>();
54
55 assert((std::is_constructible_v<const int&, ConvertsToRef<long, long&>>));
56 test_reference_converts_from_temporary<const int&, ConvertsToRef<long, long&>, true>();
57 #ifndef TEST_COMPILER_GCC
58 test_reference_converts_from_temporary<const int&, ConvertsToRefPrivate<long, long&>, false>();
59 #endif
60
61 // Test that it doesn't accept non-reference types as input.
62 test_reference_converts_from_temporary<int, long, false>();
63
64 test_reference_converts_from_temporary<const int&, long, true>();
65
66 // Additional checks
67 test_reference_converts_from_temporary<const Base&, Derived, true>();
68 test_reference_converts_from_temporary<int&&, int, true>();
69 test_reference_converts_from_temporary<const int&, int, true>();
70 test_reference_converts_from_temporary<int&&, int&&, false>();
71 test_reference_converts_from_temporary<const int&, int&&, false>();
72 test_reference_converts_from_temporary<int&&, long&&, true>();
73 test_reference_converts_from_temporary<int&&, long, true>();
74
75 test_reference_converts_from_temporary<int&, ExplicitConversionRef, false>();
76 test_reference_converts_from_temporary<const int&, ExplicitConversionRef, true>();
77 test_reference_converts_from_temporary<int&&, ExplicitConversionRvalueRef, true>();
78
79 return true;
80 }
81
82 int main(int, char**) {
83 test();
84 static_assert(test());
85
86 return 0;
87 }