]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
cfa9a96b | 2 | // |
8d9254fc | 3 | // Copyright (C) 2008-2020 Free Software Foundation, Inc. |
cfa9a96b CF |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
cfa9a96b CF |
9 | // any later version. |
10 | // | |
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
cfa9a96b CF |
19 | |
20 | #include <type_traits> | |
21 | #include <testsuite_hooks.h> | |
22 | ||
23 | #define JOIN( X, Y ) DO_JOIN( X, Y ) | |
24 | #define DO_JOIN( X, Y ) DO_JOIN2(X,Y) | |
25 | #define DO_JOIN2( X, Y ) X##Y | |
26 | ||
27 | #define COMMON_TYPE_TEST_1(type1, uid) \ | |
28 | typedef common_type<type1>::type JOIN(test_t,uid); \ | |
29 | VERIFY( (is_same<JOIN(test_t,uid), JOIN(test_t,uid)>::value) ); \ | |
30 | typedef common_type<const type1>::type JOIN(test_t,JOIN(uid,c)); \ | |
31 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,c)), \ | |
32 | JOIN(test_t,JOIN(uid,c))>::value) ); \ | |
33 | typedef common_type<volatile type1>::type JOIN(test_t,JOIN(uid,v)); \ | |
34 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,v)), \ | |
35 | JOIN(test_t,JOIN(uid,v))>::value) ); \ | |
36 | typedef common_type<const volatile type1>::type JOIN(test_t,JOIN(uid,cv)); \ | |
37 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,cv)), \ | |
38 | JOIN(test_t,JOIN(uid,cv))>::value) ); \ | |
39 | typedef common_type<type1 &>::type JOIN(test_t,JOIN(uid,l)); \ | |
40 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,l)), \ | |
41 | JOIN(test_t,JOIN(uid,l))>::value) ); \ | |
42 | typedef common_type<const type1 &>::type JOIN(test_t,JOIN(uid,lc)); \ | |
43 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,lc)), \ | |
44 | JOIN(test_t,JOIN(uid,lc))>::value) ); \ | |
45 | typedef common_type<volatile type1 &>::type JOIN(test_t,JOIN(uid,lv)); \ | |
46 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,lv)), \ | |
47 | JOIN(test_t,JOIN(uid,lv))>::value) ); \ | |
48 | typedef common_type<const volatile type1 &>::type JOIN(test_t,JOIN(uid,lcv)); \ | |
49 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,lcv)), \ | |
50 | JOIN(test_t,JOIN(uid,lcv))>::value) ); \ | |
51 | typedef common_type<type1 &&>::type JOIN(test_t,JOIN(uid,r)); \ | |
52 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,r)), \ | |
53 | JOIN(test_t,JOIN(uid,r))>::value) ); \ | |
54 | typedef common_type<const type1 &&>::type JOIN(test_t,JOIN(uid,rc)); \ | |
55 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,rc)), \ | |
56 | JOIN(test_t,JOIN(uid,rc))>::value) ); \ | |
57 | typedef common_type<volatile type1 &&>::type JOIN(test_t,JOIN(uid,rv)); \ | |
58 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,rv)), \ | |
59 | JOIN(test_t,JOIN(uid,rv))>::value) ); \ | |
60 | typedef common_type<const volatile type1 &&>::type JOIN(test_t,JOIN(uid,rcv)); \ | |
61 | VERIFY( (is_same<JOIN(test_t,JOIN(uid,rcv)), \ | |
62 | JOIN(test_t,JOIN(uid,rcv))>::value) ) | |
63 | ||
64 | struct A { }; | |
65 | struct B : A { }; | |
66 | ||
67 | void test01() | |
68 | { | |
cfa9a96b CF |
69 | using std::common_type; |
70 | using std::is_same; | |
71 | ||
72 | // Positive tests. | |
73 | COMMON_TYPE_TEST_1(int, 1); | |
74 | COMMON_TYPE_TEST_1(double, 2); | |
75 | COMMON_TYPE_TEST_1(A, 3); | |
76 | COMMON_TYPE_TEST_1(B, 4); | |
77 | } | |
78 | ||
79 | #define COMMON_TYPE_TEST_2_IMPL(type1, type2, type3, uid) \ | |
80 | typedef common_type<type1, type2>::type JOIN(JOIN(test, uid),_t1); \ | |
81 | typedef common_type<type2, type1>::type JOIN(JOIN(test, uid),_t2); \ | |
82 | VERIFY( (is_same<JOIN(JOIN(test, uid),_t1), type3>::value) ); \ | |
83 | VERIFY( (is_same<JOIN(JOIN(test, uid),_t2), type3>::value) ) | |
84 | ||
85 | #define NO_CV | |
86 | ||
87 | #define COMMON_TYPE_TEST_2(cv_qual, type1, type2, type3, uid) \ | |
88 | COMMON_TYPE_TEST_2_IMPL(cv_qual type1, type2, type3, uid); \ | |
89 | COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &, type2, type3, JOIN(uid,l)); \ | |
90 | COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &&, type2, type3, JOIN(uid,r)) | |
91 | ||
92 | #define COMMON_TYPE_TEST_ALL_2(type1, type2, type3, uid) \ | |
93 | COMMON_TYPE_TEST_2(NO_CV, type1, type2, type3, uid); \ | |
94 | COMMON_TYPE_TEST_2(const, type1, type2, type3, uid); \ | |
95 | COMMON_TYPE_TEST_2(volatile, type1, type2, type3, uid); \ | |
96 | COMMON_TYPE_TEST_2(const volatile, type1, type2, type3, uid) | |
97 | ||
98 | void test02() | |
99 | { | |
cfa9a96b CF |
100 | using std::common_type; |
101 | using std::is_same; | |
102 | ||
103 | COMMON_TYPE_TEST_ALL_2(int, int, int, 1); | |
104 | COMMON_TYPE_TEST_ALL_2(int, double, double, 2); | |
105 | COMMON_TYPE_TEST_2(NO_CV, A, A, A, 3); | |
6c5173c0 | 106 | COMMON_TYPE_TEST_2(const, A, A, A, 4); |
cfa9a96b CF |
107 | COMMON_TYPE_TEST_2(NO_CV, B, A, A, 5); |
108 | } | |
109 | ||
110 | int main() | |
111 | { | |
112 | test01(); | |
113 | test02(); | |
114 | return 0; | |
115 | } |