152
|
1 // DR 1512
|
|
2 // Test the composite pointer type of two operands.
|
|
3 // { dg-do compile { target c++11 } }
|
|
4
|
|
5 using nullptr_t = decltype(nullptr);
|
|
6
|
|
7 template <class T, class U> struct same;
|
|
8 template <class T> struct same<T,T> { };
|
|
9
|
|
10 template<typename T>
|
|
11 T fn ()
|
|
12 {
|
|
13 }
|
|
14
|
|
15 // Check that the composite pointer type of T and U is RES.
|
|
16 template<typename T, typename U, typename RES>
|
|
17 void test ()
|
|
18 {
|
|
19 same<decltype(true ? fn<T>() : fn<U>()), RES> s;
|
|
20 }
|
|
21
|
|
22 struct A { };
|
|
23 struct B : A { };
|
|
24
|
|
25 // Test [expr.type]/3.
|
|
26 void
|
|
27 foo ()
|
|
28 {
|
|
29 // if both p1 and p2 are null pointer constants -> std::nullptr_t.
|
|
30 test<nullptr_t, nullptr_t, nullptr_t>();
|
|
31
|
|
32 // if either p1 or p2 is a null pointer constant -> T2 or T1.
|
|
33 test<nullptr_t, const char **, const char **>();
|
|
34 test<const char **, nullptr_t, const char **>();
|
|
35
|
|
36 // if T1 or T2 is 'pointer to cv1 void' and the other type is 'pointer
|
|
37 // to cv2 T', where T is an object type or void -> 'pointer to cv12 void',
|
|
38 // where cv12 is the union of cv1 and cv2.
|
|
39 test<const int *, volatile void *, const volatile void *>();
|
|
40 test<const void *, volatile int *, const volatile void *>();
|
|
41
|
|
42 test<int *, const int *, const int *>();
|
|
43 // Make sure that we propagate 'const' here as per [conv.qual]/3.3.
|
|
44 test<int **, const int **, const int *const *>();
|
|
45 test<int *volatile *, const int **, const int *const volatile *>();
|
|
46 test<int **, volatile int **, volatile int *const *>();
|
|
47
|
|
48 // if T1 is 'pointer to cv1 C1' and T2 is 'pointer to cv2 C2', where C1 is
|
|
49 // reference-related to C2 or C2 is reference-related to C1 -> the cv-combined
|
|
50 // type of T1 and T2 or the cv-combined type of T2 and T1, respectively.
|
|
51 test<const A*, volatile B*, const volatile A *>();
|
|
52 test<const B*, volatile A*, const volatile A *>();
|
|
53
|
|
54 test<const int *A::*, volatile int *A::*, const volatile int *const A::*>();
|
|
55 // FIXME: This doesn't work if they're reference-related but not same.
|
|
56 //test<const int *A::*, volatile int *B::*, const volatile int *const B::*>();
|
|
57 //test<const int *B::*, volatile int *A::*, const volatile int *const B::*>();
|
|
58
|
|
59 // if T1 or T2 is 'pointer to noexcept function' and the other type is
|
|
60 // 'pointer to function', where the function types are otherwise the same
|
|
61 // -> 'pointer to function'.
|
|
62 test<int (*)() noexcept, int (*)(), int (*)()>();
|
|
63 test<int (*)(), int (*)() noexcept, int (*)()>();
|
|
64
|
|
65 // if T1 or T2 is 'pointer to member of C1 of type function', the other type
|
|
66 // is 'pointer to member of C2 of type noexcept function', and C1 is
|
|
67 // reference-related to C2 or C2 is reference-related to C1, where the
|
|
68 // function types are otherwise the same -> 'pointer to member of C2 of type
|
|
69 // function' or 'pointer to member of C1 of type function', respectively.
|
|
70 test<int (A::*)() noexcept, int (A::*)(), int (A::*)()>();
|
|
71 test<int (A::*)(), int (A::*)() noexcept, int (A::*)()>();
|
|
72 }
|