1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2008 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 2, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 #include <type_traits>
22 #include <testsuite_hooks.h>
24 #define JOIN( X, Y ) DO_JOIN( X, Y )
25 #define DO_JOIN( X, Y ) DO_JOIN2(X,Y)
26 #define DO_JOIN2( X, Y ) X##Y
28 #define COMMON_TYPE_TEST_1(type1, uid) \
29 typedef common_type<type1>::type JOIN(test_t,uid); \
30 VERIFY( (is_same<JOIN(test_t,uid), JOIN(test_t,uid)>::value) ); \
31 typedef common_type<const type1>::type JOIN(test_t,JOIN(uid,c)); \
32 VERIFY( (is_same<JOIN(test_t,JOIN(uid,c)), \
33 JOIN(test_t,JOIN(uid,c))>::value) ); \
34 typedef common_type<volatile type1>::type JOIN(test_t,JOIN(uid,v)); \
35 VERIFY( (is_same<JOIN(test_t,JOIN(uid,v)), \
36 JOIN(test_t,JOIN(uid,v))>::value) ); \
37 typedef common_type<const volatile type1>::type JOIN(test_t,JOIN(uid,cv)); \
38 VERIFY( (is_same<JOIN(test_t,JOIN(uid,cv)), \
39 JOIN(test_t,JOIN(uid,cv))>::value) ); \
40 typedef common_type<type1 &>::type JOIN(test_t,JOIN(uid,l)); \
41 VERIFY( (is_same<JOIN(test_t,JOIN(uid,l)), \
42 JOIN(test_t,JOIN(uid,l))>::value) ); \
43 typedef common_type<const type1 &>::type JOIN(test_t,JOIN(uid,lc)); \
44 VERIFY( (is_same<JOIN(test_t,JOIN(uid,lc)), \
45 JOIN(test_t,JOIN(uid,lc))>::value) ); \
46 typedef common_type<volatile type1 &>::type JOIN(test_t,JOIN(uid,lv)); \
47 VERIFY( (is_same<JOIN(test_t,JOIN(uid,lv)), \
48 JOIN(test_t,JOIN(uid,lv))>::value) ); \
49 typedef common_type<const volatile type1 &>::type JOIN(test_t,JOIN(uid,lcv)); \
50 VERIFY( (is_same<JOIN(test_t,JOIN(uid,lcv)), \
51 JOIN(test_t,JOIN(uid,lcv))>::value) ); \
52 typedef common_type<type1 &&>::type JOIN(test_t,JOIN(uid,r)); \
53 VERIFY( (is_same<JOIN(test_t,JOIN(uid,r)), \
54 JOIN(test_t,JOIN(uid,r))>::value) ); \
55 typedef common_type<const type1 &&>::type JOIN(test_t,JOIN(uid,rc)); \
56 VERIFY( (is_same<JOIN(test_t,JOIN(uid,rc)), \
57 JOIN(test_t,JOIN(uid,rc))>::value) ); \
58 typedef common_type<volatile type1 &&>::type JOIN(test_t,JOIN(uid,rv)); \
59 VERIFY( (is_same<JOIN(test_t,JOIN(uid,rv)), \
60 JOIN(test_t,JOIN(uid,rv))>::value) ); \
61 typedef common_type<const volatile type1 &&>::type JOIN(test_t,JOIN(uid,rcv)); \
62 VERIFY( (is_same<JOIN(test_t,JOIN(uid,rcv)), \
63 JOIN(test_t,JOIN(uid,rcv))>::value) )
70 bool test __attribute__((unused)) = true;
71 using std::common_type;
75 COMMON_TYPE_TEST_1(int, 1);
76 COMMON_TYPE_TEST_1(double, 2);
77 COMMON_TYPE_TEST_1(A, 3);
78 COMMON_TYPE_TEST_1(B, 4);
81 #define COMMON_TYPE_TEST_2_IMPL(type1, type2, type3, uid) \
82 typedef common_type<type1, type2>::type JOIN(JOIN(test, uid),_t1); \
83 typedef common_type<type2, type1>::type JOIN(JOIN(test, uid),_t2); \
84 VERIFY( (is_same<JOIN(JOIN(test, uid),_t1), type3>::value) ); \
85 VERIFY( (is_same<JOIN(JOIN(test, uid),_t2), type3>::value) )
89 #define COMMON_TYPE_TEST_2(cv_qual, type1, type2, type3, uid) \
90 COMMON_TYPE_TEST_2_IMPL(cv_qual type1, type2, type3, uid); \
91 COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &, type2, type3, JOIN(uid,l)); \
92 COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &&, type2, type3, JOIN(uid,r))
94 #define COMMON_TYPE_TEST_ALL_2(type1, type2, type3, uid) \
95 COMMON_TYPE_TEST_2(NO_CV, type1, type2, type3, uid); \
96 COMMON_TYPE_TEST_2(const, type1, type2, type3, uid); \
97 COMMON_TYPE_TEST_2(volatile, type1, type2, type3, uid); \
98 COMMON_TYPE_TEST_2(const volatile, type1, type2, type3, uid)
102 bool test __attribute__((unused)) = true;
103 using std::common_type;
106 COMMON_TYPE_TEST_ALL_2(int, int, int, 1);
107 COMMON_TYPE_TEST_ALL_2(int, double, double, 2);
108 COMMON_TYPE_TEST_2(NO_CV, A, A, A, 3);
109 COMMON_TYPE_TEST_2(const, A, A, const A, 4);
110 COMMON_TYPE_TEST_2(NO_CV, B, A, A, 5);