2222#include < cassert>
2323#include < type_traits>
2424
25+ #include " common.h"
2526#include " test_macros.h"
2627
27- struct NonPOD {
28- NonPOD (int );
29- };
30- enum Enum { EV };
31- struct POD {
32- Enum e;
33- int i;
34- float f;
35- NonPOD* p;
36- };
37- // Not PODs
38- struct Derives : POD {};
39-
40- template <class T , class RefType = T&>
41- struct ConvertsToRef {
42- operator RefType () const { return static_cast <RefType>(obj); }
43- mutable T obj = 42 ;
44- };
45- template <class T , class RefType = T&>
46- class ConvertsToRefPrivate {
47- operator RefType () const { return static_cast <RefType>(obj); }
48- mutable T obj = 42 ;
49- };
50-
51- struct ExplicitConversionRvalueRef {
52- operator int ();
53- explicit operator int &&();
54- };
55-
56- struct ExplicitConversionRef {
57- operator int ();
58- explicit operator int &();
59- };
60-
6128template <typename T, typename U, bool Expected>
6229constexpr void test_reference_constructs_from_temporary () {
6330 assert ((std::reference_constructs_from_temporary<T, U>::value == Expected));
@@ -79,22 +46,17 @@ constexpr bool test() {
7946 test_reference_constructs_from_temporary<const int &, long &&, true >();
8047 test_reference_constructs_from_temporary<int &&, long &, true >();
8148
82- using LRef = ConvertsToRef<int , int &>;
83- using RRef = ConvertsToRef<int , int &&>;
84- using CLRef = ConvertsToRef<int , const int &>;
85- using LongRef = ConvertsToRef<long , long &>;
86-
87- assert ((std::is_constructible_v<int &, LRef>));
88- test_reference_constructs_from_temporary<int &, LRef, false >();
49+ assert ((std::is_constructible_v<int &, ConvertsToRef<int , int &>>));
50+ test_reference_constructs_from_temporary<int &, ConvertsToRef<int , int &>, false >();
8951
90- assert ((std::is_constructible_v<int &&, RRef >));
91- test_reference_constructs_from_temporary<int &&, RRef , false >();
52+ assert ((std::is_constructible_v<int &&, ConvertsToRef< int , int &&> >));
53+ test_reference_constructs_from_temporary<int &&, ConvertsToRef< int , int &&> , false >();
9254
93- assert ((std::is_constructible_v<const int &, CLRef >));
94- test_reference_constructs_from_temporary<int &&, CLRef , false >();
55+ assert ((std::is_constructible_v<const int &, ConvertsToRef< int , const int &> >));
56+ test_reference_constructs_from_temporary<int &&, ConvertsToRef< int , const int &> , false >();
9557
96- assert ((std::is_constructible_v<const int &, LongRef >));
97- test_reference_constructs_from_temporary<const int &, LongRef , true >();
58+ assert ((std::is_constructible_v<const int &, ConvertsToRef< long , long &> >));
59+ test_reference_constructs_from_temporary<const int &, ConvertsToRef< long , long &> , true >();
9860#ifndef TEST_COMPILER_GCC
9961 test_reference_constructs_from_temporary<const int &, ConvertsToRefPrivate<long , long &>, false >();
10062#endif
@@ -105,7 +67,7 @@ constexpr bool test() {
10567 test_reference_constructs_from_temporary<const int &, long , true >();
10668
10769 // Additional checks
108- test_reference_constructs_from_temporary<POD const &, Derives, true >();
70+ test_reference_constructs_from_temporary<const POD &, Derives, true >();
10971 test_reference_constructs_from_temporary<int &&, int , true >();
11072 test_reference_constructs_from_temporary<const int &, int , true >();
11173 test_reference_constructs_from_temporary<int &&, int &&, false >();
0 commit comments